akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
	int N;
	const int n = 1000000;
	int A[n];
	int M[n] = {0};

	cin >> N;

	for (int i = 0; i < N - 1; i++)
	{
		cin >> A[i];
		M[A[i]] += 1;
	}

	for (int i = 1; i < N + 1; i++)
	{
		cout << M[i] << endl;
	}

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b;
	ll k;
	//string s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	cin >> a >> b;

	if (a == 1 && b == 1) {
		s_ans = "Draw";
	}
	else if (a == 1) {
		s_ans = "Alice";
	}
	else if (b == 1){
		s_ans = "Bob";
	}
	else {
		if (a < b) {
			s_ans = "Bob";
		}
		else if (a > b) {
			s_ans = "Alice";
		}
		else {
			s_ans = "Draw";
		}
	}

	cout << s_ans << "\n";

	return;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_a();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define LL long long
#define PII pair<int , int>
#define PLL pair<long long , long long>
#define INPUT freopen("input.txt", "r", stdin);

using namespace std;
 
const LL MOD = 1e9+7;

LL c,d,e,f,g,x,y,z,m,n,temp,cnt,ans,sum,t,q;
string str,str1,st2;
vector< int > nums;
const int MAXW = 1e5+1;
LL dp[1001][1001];
LL w[100];
LL v[100];
// LL solve(int i , int rem ){

//     if(i== n)return 0;

//     LL &ret = dp[i][rem];
//     if(ret!=-1)return ret;
//     ret=0;
//     LL choice1 = solve(i+1 , rem);
//     LL choice2=0;
//     if( rem - w[i]>=0)
//         choice2= v[i]+solve(i+1, rem-w[i]);
    
//     ret=max(choice1,choice2);
//     return ret;
// }
int main()
{
    bool readfromfile=false; if(!readfromfile){SLAY} else{INPUT}

    cin>>n>>m;
    memset(dp , 0 , sizeof(dp));
    for(int i = 0 ; i < n ;i++){
        cin>>str;
        for(int j=0;j < m;j++){
            if(str[j]=='.')dp[i][j]=-1;
            else dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i = 0 ; i < n ;i++){
        for(int j=0;j < m;j++){
            if(i==0&&j==0)continue;
            if(dp[i][j]==0)continue;
            LL up=0, left=0;
            if(i>0)up=dp[i-1][j];
            if(j>0)left=dp[i][j-1];
            dp[i][j]=(up+left)%MOD;
        }
    }

    cout<<dp[n-1][m-1];
    cout<<endl;

    return 0;
}

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

int main(){

  int y,m,d;

  while(cin >> y >> m >> d){

    if(y < 1868 || (y == 1868 && m <= 9 && d < 8)) cout << "pre-meiji" << endl;
    else if(y < 1912 || (y == 1912 && m <= 7 && d < 30)) cout << "meiji " << y-1867 << " " << m << " " << d << endl;
    else if(y < 1926 || (y == 1926 && m <= 12 && d < 25)) cout << "taisho " << y-1911 << " " << m << " " << d << endl;
    else if(y < 1989 || (y == 1989 && m <= 1 && d < 8)) cout << "showa " << y-1925 << " " << m << " " << d << endl;
    else cout << "heisei " << y-1988 << " " << m << " " << d << endl;

  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int S = 100005;
int W , n;
long long dp[N][S];
array<long long, 2> itens[N];

int32_t main(){
	scanf("%d%d" , &n , &W);
	for(int i = 0 ; i < N ; i ++){
		for(int j = 0 ; j < S ; j ++) dp[i][j] = (long long) 1e18;
	}
	for(int i = 0 ; i < N; i ++){
		dp[i][0] = 0ll;
	}
	for(int i = 1 ; i <= n; i ++){
		scanf("%lld%lld" , &itens[i][0] , &itens[i][1]);
	}
	for(int i = 1 ; i <=n ; i ++){
		for(long long j = 0 ; j < S ; j ++){
			dp[i][j] = dp[i-1][j];
			if(j >= itens[i][1]){
				dp[i][j] = min(dp[i][j] , itens[i][0] + dp[i-1][j - itens[i][1]]);
			}
		}

	}
	long long ans = 0;
	for(int i = 1 ; i <= n; i ++){
		for(int j = 0 ; j < S ; j++){
			if(dp[i][j] <= W){
				ans = max(ans , j*1ll);
			}
		}
	}
	printf("%lld\n" , ans);
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,q;
    string s;
    cin>>n>>q>>s;
    vi cs(n);
    REP(i,1,n){
        cs[i]=cs[i-1];
        if(s[i-1]=='A'&&s[i]=='C'){
            cs[i]++;
        }
    }
    cerr<<cs<<endl;
    int l,r;
    REP(i,q){
        cin>>l>>r;
        cout<<cs[r-1]-cs[l-1]<<endl;
    }
    return 0;
}


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

int main() {
  int n;
  cin >>n;
  int a =0;
  
  for (int i=0; i<26; ++i) {
    for (int j=0; j<15; ++j) {
      if (4*i+7*j == n) {
        a=1;
      }
    }
  }
  
  if (a==1) cout << "Yes";
  else cout <<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int H, W; cin >> H >> W;
    vector<string> a(H);
    readv(a);
    vec c(26, 0);
    REP(i, H) REP(j, W) c[a[i][j] - 'a']++;

    int n4, n2, n1;
    if(H % 2 == 0 && W % 2 == 0) n4 = (H / 2) * (W / 2), n2 = 0, n1 = 0;
    else if(H % 2 == 0) n4 = (H / 2) * (W / 2), n2 = H / 2, n1 = 0;
    else if(W % 2 == 0) n4 = (H / 2) * (W / 2), n2 = W / 2, n1 = 0;
    else n4 = (H / 2) * (W / 2), n2 = H / 2 + W / 2, n1 = 1;

    REP(i, 26){
        n4 -= c[i] / 4;
        c[i] %= 4;
        n2 -= c[i] / 2;
        c[i] %= 2;
        n1 -= c[i];
    }
    if(n4 < 0){
        n2 += 2 * n4;
        n4 = 0;
    }
    Ans(n1 == 0 && n2 == 0 && n4 == 0, "Yes", "No");

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);

        //変数の格納
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a>b) {
            if(c>a) {
                String anString = b+" "+c+" "+a;
                System.out.println(anString);
            }
            else if(c>b) {
                String anString =b+" "+c+" "+a;
                System.out.println(anString);
            }
            else {
                String anString =c+" "+b+" "+a;
                System.out.println(anString);
            }
        }

        else {
            if(c>b) {
                String anString =a+" "+b+" "+c;
                System.out.println(anString);
            }
            else if(c>a) {
                String anString =a+" "+c+" "+b;
                System.out.println(anString);
            }
            else {
                String anString =c+" "+a+" "+b;
                System.out.println(anString);
            }
        }

    }

}



Measured memory_bytes: 26196
def divisors(n, sort=False):
    """
    nの約数をO(√n)で列挙する
    """
    d = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            d.append(i)
            if i != n // i:
                d.append(n//i)
    if sort:
        d.sort()
    return d


C = [list(map(int, input().split())) for _ in range(3)]
if sum([sum(r) for r in C]) == 0:
    print('Yes')
    exit(0)
    
for a0 in divisors(sum(C[0])):
    a = [a0, None, None]
    b = [None, None, None]
    b[0] = C[0][0] - a[0]
    a[1] = C[1][0] - b[0]
    a[2] = C[2][0] - b[0]
    b[1] = C[0][1] - a[0]
    b[2] = C[0][2] - a[0]
    ok = True
    for i in range(3):
        for j in range(3):
            if C[i][j] != a[i] + b[j]:
                ok = False
    if ok:
        print('Yes')
        exit(0)
print('No')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


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


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int n;
    ll d;
    cin >> n >> d;
    d *= d;

    int ans(0);
    rep(i,n){
        ll x,y;
        cin >> x >> y;

        if((x*x+y*y)<=d)   ans++;
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for(auto x : mp) {
    chmax(mx, x.se);
  }
  V<string> v;
  for(auto x : mp) {
    if(x.se == mx) v.push_back(x.fi);
  }
  sort(all(v));
  rep(i,sz(v)) cout << v[i] << endl;
} 

Measured memory_bytes: 27168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
  string s, t;
  cin >> s >> t;
  auto rs = s;
  auto rt= t;
  reverse(ALL(rs));
  reverse(ALL(rt));
  if(rs == t && rt == s) cout << "YES" << endl;
  else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int inf = 1e9;
string t;
int res, n;

int sum(string t){
	int u, r;
	u = r = 0;
	for(int i = 0; i < t.size(); ++i){
		if(t[i]=='D')u++;
		if(t[i]=='P'&&t[i+1]=='D')r++;
	}
	return u + r;
}

int main(){
	cin>>t;
	n = t.size();
	string s = t;
	int u = 0;
	for(int i = 0; i < n; ++i){
		if(s[i]=='?')s[i]='D';
		if(s[i]=='D')u++;
	}
	for(int i = 0; i < n; ++i){
		if(t[i]=='?'){
			if(t[i+1]=='D'){
				t[i]='P';
			}
			else t[i]='D';
		}
	}
	if(sum(t) > sum(s)){
		cout<<t<<endl;
	}
	else{
		cout<<s<<endl;
	}
	return 0;
}


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

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> h(n);
rep(i, n){
  cin >> h[i];
}
rep(i,n){
  if(h[i]>=k)ans++;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
ok=[0]*(n+1)
pe=[0]*(n+1)
for _ in range(m):
    q,s=input().split()
    q=int(q)
    if s=="WA" and ok[q]==0:
        pe[q]+=1
    else:
        ok[q]=1
for i in range(n+1):
    if ok[i]==0:
        pe[i]=0
print(sum(ok),sum(pe))


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

int N, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> R;
  if (N >= 10) {
    cout << R;
  } else {
    cout << R + 100 * (10 - N);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.1415926535897932384626

int main()
{
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k)
  {
    cout << s << endl;
  }
  else
  {
    cout << s.substr(0, k) << "..." << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;



ll dist[310][310];
ll num[310][310];
ll s[100010];
ll t[100010];


void warshall_floyd(ll n, ll cost[310][310]){
    rep(k, n){
        rep(i, n){
            rep(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        }
    }
}

int main(){
    ll n, m, l; cin >> n >> m >> l;

    rep(i, n) rep(j, n) if (i != j) dist[i][j] = LINF, num[i][j] = LINF;

    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    ll q; cin >> q;
    rep(i, q){
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
    }

    warshall_floyd(n, dist);

    rep(i, n) rep(j, n){
        if (i == j) continue;
        if (dist[i][j] <= l) num[i][j] = 1;
    }

    warshall_floyd(n, num);


    rep(i, q){
        if (num[s[i]][t[i]] == LINF) cout << -1 << endl;
        else cout << num[s[i]][t[i]] - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> k;
	vector<vector<int>> a;
	k.resize(n);
	a.resize(n);
	for(int i=0; i<n; i++){
		cin >> k[i];
		a[i].resize(k[i]);
		for(int j=0; j<k[i]; j++){
			cin >> a[i][j];
		}
	}

	int sum(0);
	for(int i=0; i<m; i++){
		bool all = true;
		for(int j=0; j<n; j++){
			bool like = false;
			for(int l=0; l<k[j]; l++){
				if(a[j][l]==i+1) like = true;
			}
			if(!like) all = false;
		}
		if(all) sum ++;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
S = list(input())
ans = True
for i in range(len(S)):
  if i % 2 != 0:
    if S[i] != "L" and S[i] != "U" and  S[i] != "D":
      ans = False
  else:
    if S[i] != "R" and S[i] != "U" and S[i] != "D":
      ans = False
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int m = INF;
    rep(i, N) {
        int cnt = 0;
        while(true) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
                cnt++;
            } else break;
        }
        m = min(m, cnt);
    }
    cout << m << endl;



    return 0;
}


Measured memory_bytes: 256
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val degrees = IntArray(n)
  repeat(m) {
    val (v1Raw, v2Raw) = fastReadInts(2)
    val v1 = v1Raw - 1
    val v2 = v2Raw - 1
    degrees[v1] += 1
    degrees[v2] += 1
  }
  val ans = degrees.all { it % 2 == 0 }
  println(if (ans) "YES" else "NO")
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n;
    cin>>n;
    long long ansA=0, ansB=n-1;
    for(long long i=2 ; (i*i)<=n ; ++i)
    {
        if(n%i==0)
        {
            long long a = i-1;
            long long b = n/i-1;
            if((a+b)<(ansA+ansB))
            {
                ansA=a;
                ansB=b;
            }
        }
    }
    cout<<ansA+ansB<<endl;
    return 0;
}

Measured memory_bytes: 256
a =  int(input())
c = 0
for x in range(a):
    if((x+1) % 3 ==0 and (x+1) % 5 == 0):
        continue
    elif ((x+1)%3 ==0):
        continue
    elif ((x+1)%5 == 0):
        continue
    else:

        c+=x+1
print(c)

Measured memory_bytes: 9172
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        if(A>B) {
        	int cE=C-(A-B);
        	if(cE<0) {
        		cE=0;
        	}
        	System.out.println(cE);
        }else {
        	System.out.println(C);
        }
        
        
        
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<int> V(N), W(N);
    rep(i, N) {
        V[i] = items[i].first;
        W[i] = items[i].second;
    }
    ll Q;
    cin >> Q;
    int C = 1 << 10;
    vector<vector<ll>> dp(min(N + 1, (ll)(C) + 1), vector<ll>(100001, 0));
    rep2(i, 1, min(N + 1, (ll)(C) + 1)) {
        rep(j, 100001) {
            ll par = i / 2;
            dp[i][j] = dp[par][j];
            if (j - items[i - 1].second >= 0) {
                dp[i][j] = max(dp[i][j], dp[par][j - items[i - 1].second] + items[i - 1].first);
            }
        }
    }
    vector<ll> ans(Q);
    vector<P> query(Q);
    rep(q, Q) cin >> query[q].first >> query[q].second;
    rep(q, Q) {
        int v = query[q].first;
        int L = query[q].second;
        vector<int> use;
        v--;
        int u = v;
        use.push_back(u);
        while (u != 0) {
            u = (u - 1) / 2;
            use.push_back(u);
        }
        if (v < (C)) {
            ans[q] = dp[v + 1][L];
            continue;
        }
        sort(use.begin(), use.end());
        int n = use.size();
        vector<int> use_p;
        int last = -1;
        rep(i, n) {
            if (use[i] >= (C)) {
                use_p.push_back(use[i]);
            } else {
                last = max(last, use[i]);
            }
        }
        ll a = 0;
        rep(i, 1 << (int) use_p.size()) {
            int value = 0;
            int weight = 0;
            rep(j, use_p.size()) {
                if (i & (1 << j)) {
                    value += V[use_p[j]];
                    weight += W[use_p[j]];
                    if (weight > L) break;
                }
            }
            if (L - weight < 0) continue;
            a = max(a, dp[last + 1][L - weight] + value);
        }
        ans[q] = a;
    }
    rep(q, Q) {
        cout << ans[q] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 815264
N = int(input())
S = input()

ans = 0
for i in range(N):
    X = S[:i]
    Y = S[i:]
    cnt = 0
    for j in range(97,123):
        index = chr(j)
        if X.find(index) != -1 and Y.find(index) != -1:
            cnt += 1
        ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 39664
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<iostream>
using namespace std;
int t[100005],x[100005],y[100005];
int main()
{
	int n,k=1,i,s=0;
	scanf("%d",&n);
	x[0]=y[0]=0;
	for(i=1;i<=n;i++)
	scanf("%d%d%d",&t[i],&x[i],&y[i]);
	for(i=1;i<=n;i++)
	{
		s=fabs(x[i]-x[i-1])+fabs(y[i]-y[i-1]);
		if((t[i]-t[i-1])>=s&&(t[i]-t[i-1])%s==0)
		k=1;
		else
		{
			k=0;
			break;
		}
	}
	if(k)
 	printf("Yes\n");
 	else
 	printf("No\n");
} 

Measured memory_bytes: 1408
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    auto s = readln.chomp;
    auto t = readln.chomp;
    
    auto input = new int[][] (300);
    
    foreach (i, e; s) {
        input[e] ~= (i+1).to!int;
    }
    
    debug { input.writeln; }
    
    auto pos = input.map!assumeSorted;
    
    long ans = 0;
    int cpos = 0;
    foreach (e; t) {
        if (pos[e].empty()) {
            writeln(-1);
            return;
        }
        
        auto r = pos[e].upperBound(cpos);
        if (r.empty()) {
            ans += s.length - cpos;
            cpos = 0;
            r = pos[e].upperBound(0);
        }
        
        auto nxt = r[0];
        ans += nxt - cpos;
        
        debug { writeln(e, ' ', ans, ' ', nxt); }
        
        cpos = nxt;
    }
    
    ans.writeln;
}

Measured memory_bytes: 3608
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    r,g,b = LI()
    ans = ["YES","NO"]
    print(ans[((((((g<<1)&b)<<1)+((g<<1)^b))&((1<<1)|1))>>int(math.log(max(1,(((((g<<1)&b)<<1)+((g<<1)^b))&((1<<1)|1))&(-(((((g<<1)&b)<<1)+((g<<1)^b))&((1<<1)|1)))),(1<<1))))&1])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38512
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[31],b;
  memset(a,0,sizeof(a));
  for(i=0;i<28;i++){
    cin>>b;
    a[b]=1;
  }
  for(i=1;i<31;i++){
    if(a[i]==0)
      cout<<i<<endl;
  }
  return 0;
}

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

using i64 = int64_t;

int main() {
	int N;
	i64 K;
	cin >> N >> K;
	
	vector<i64> A(N);
	for (int i=0; i<N; ++i) cin >> A[i];
	sort(A.begin(), A.end(), greater<i64>());
	
	auto less_count = [&](i64 x) {
		i64 cnt = 0;
		for (int i=1; i<N; ++i) {
			int lb = -1, ub = i;
			while (ub - lb > 1) {
				int med = (lb + ub) / 2;
				if ((A[i] > 0 and A[i] * A[med] > x) or (A[i] <= 0 and A[i] * A[med] <= x)) lb = med;
				else ub = med;
			}
			cnt += (A[i] > 0 ? i - ub : ub);
		}
		return cnt;
	};
		
	i64 lb = -1e18 - 1, ub = 1e18;
	while (ub - lb > 1) {
		i64 med = (lb + ub) / 2;
		if (K <= less_count(med)) ub = med;
		else lb = med;
	}
	cout << ub << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int right[n+1],left[n+1];
		string s;
		right[0]=left[0]=0;//0:floor 1:on the stand
		rep(i,n){
			cin>>s;
			if(s=="lu"){//lu:left up
				left[i+1]=1;
				right[i+1]=right[i];
			}else if(s=="ru"){//ru:right up
				right[i+1]=1;
				left[i+1]=left[i];
			}else if(s=="ld"){//ld:left down
				left[i+1]=0;
				right[i+1]=right[i];
			}else if(s=="rd"){//rd:right down
				right[i+1]=0;
				left[i+1]=left[i];
			}
		}
		int cnt=0;
		for(int i=2;i<=n;i+=2){
			if(right[i-2]!=right[i] && left[i-2]!=left[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, x, y, d;
    cin >> n >> x >> y;
    x--, y--;
    vector<int> v(n, 0);
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            d = min({j - i, abs(j-x) + 1 + abs(y-i), abs(y-j) + 1 + abs(x-i)});
            v[d]++;
        }
    }
    for(int i = 1; i < n; i++){
        printf("%d\n", v[i]);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define eps 1e-9
#define PI 2 * acos (0.0)
using namespace std;

int ar[100005];


int main()
{

    //freopen("0.in","r",stdin);
   // freopen("0.out","w",stdout);

    /*
    cout << fixed << setprecision(4);
    std::ios::sync_with_stdio(false);

	*/
    int a,b,c,d,e,x,y,z;

    char ch;

    cin>>ch;

    if(ch == 'a' || ch =='e' || ch == 'i' || ch == 'o' || ch == 'u')
    {
        cout<<"vowel"<<endl;
    }
    else
    {
        cout<<"consonant"<<endl;
    }

    return 0;
}


Measured memory_bytes: 764
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(P: int, Q: int, R: int):
    print(sum([P,Q,R])-max([P,Q,R]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    P = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(P, Q, R)

if __name__ == '__main__':
    main()


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

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

const int INF = 1e9 + 7;

using namespace std;

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

  int r;
  cin >> r;

  cout << r * r << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long mod = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


int s[15];
int n;
int ans = 0;
void dfs(int i, int sum, int now) {
	if (i == n - 1) {
		ans += sum + now;
	}
	else {
		dfs(i + 1, sum + now, s[i + 1]);
		dfs(i + 1, sum, now * 10 + s[i + 1]);
	}
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string str; cin >> str;
	n = str.size();
	rep(i, str.size()) {
		s[i] = str[i] - '0';
	}
	dfs(0, 0,s[0]);
	cout << ans << endl;
	return 0;
}

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

inline bool isPeriodic(const vector<int> &s, int t){
  int n = s.size();
  for(int i=0;i<t;i++){
    for(int j=i;j+t<n;j+=t){
      if(s[j] != s[j+t])return false;
    }
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i,n)cin >> s[i];

  int ans = 1;
  for(int x=1;x*x<=n;x++){
    if( n%x == 0 ){
      if(isPeriodic(s,x))ans = max(ans, n/x);
      if(isPeriodic(s,n/x))ans = max(ans, x);
    }
  }

  cout << ans << endl;
}

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

int main(){

  int N;
  cin >> N;

  map<long long,int> mp;
  long long count = 0;

  for(int i=0;i<N;i++){
    int a;
    cin >> a;

    count += mp[i-a];
    mp[i+a]++;
  }

  cout << count << endl;

}

Measured memory_bytes: 26348
#include<iostream>
#include<cstdlib>
#include<istream>
#include <stdio.h>
#include<vector>
#include <fstream>
#include <string>
#include<stdio.h>
using namespace std;
int main() {
	int X, A;
	cin >> X >> A;
	if (X >= A) {
		cout << 10 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<int> s(N);
    bool isAll10x = true;
    int ans       = 0;
    rep(i, N) {
        cin >> s[i];
        if (s[i] % 10 != 0) isAll10x = false;
        ans += s[i];
    }
    if (isAll10x) {
        cout << 0 << endl;
        return 0;
    }
    if(ans%10!=0) {
        cout << ans << endl;
        return 0;
    }
    sort(all(s));
    for (auto e : s) {
        if (e % 10 != 0) {
            cout << ans - e << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3608
fun main(args: Array<String>) {
    val (k, x) = readLine()!!.split(" ").map { it.toInt() }

    val ans = mutableListOf<Int>()
    for ( i in 1..k-1) {
        ans.add(x-i)
    }
    ans.reverse()

    for ( i in 0..k-1) {
        ans.add(x+i)
    }

    println(ans.joinToString(" "))
}

Measured memory_bytes: 36144
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

int main()
{
	int a[5];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	int ans = a[2] * 10 + a[1] + a[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    ll n,m;
    cin>>n>>m;
    ll ans=n*(n-1)/2+m*(m-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int a;
	string s;
	cin>>a;
	cin>>s;
	if(a>=3200)cout<<s<<endl;
	else cout<<"red"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


int main(){
    ll n, C;
    cin >> n >> C;
    vector<vector<ll>>dp(C+1, vector<ll>(10001,-LINF));
    dp[0][0]=0;
    rep(n){
        ll a, b, c;
        cin >> a >> b >> c;
        rrep(i,c,C+1){
            rep(j,a,10001)chmax(dp[i][j],dp[i-c][j-a]+b);
            rep(j,b,10001)chmax(dp[i][j],dp[i-c][j-b]+a);
        }
    }
    ll ans=0;
    rep(C+1)rep(j,10001)chmax(ans,min(j,dp[i][j]));
    cout << ans << endl;
}


Measured memory_bytes: 10804
// finish date: 2018/02/02
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

// finish date: 2018/01/31
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;


int main() {
    int H, W, N;
    cin >> H >> W >> N;
    int a, b;
    vl black(10, 0);
    black[0] = (ll) (H - 2) * (W - 2);
    map<pair<int, int>, ll> mp;
    rep(i, N) {
        cin >> a >> b;
        for (int i = -2; i <= 0; i++) {
            for (int j = -2; j <= 0; j++) {
                if ((0 < a + i && a + i <= H - 2) && (0 < b + j && b + j <= W - 2)) {
                    mp[{a + i, b + j}]++;
                }
            }
        }
    }
    for (auto entry:mp) black[entry.second]++;

    black[0] -= mp.size();
    rep(i, 10) cout << black[i] << endl;


    return 0;
}



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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

int main() {
	int n,m;
	ll ans;
	//入力
	cin >> n >> m;
	vector<int> a(n);
	vector<pair<int, int>> bc;
	rep(i, n) cin >> a[i];
	rep(i, m) {
		int b, c;
		cin >> b >> c;
		bc.push_back(pair<int, int>(b, c));
	}
	//sort:a()は昇順,bc()はsecondの逆順
	sort(a.begin(), a.end());
	sort(bc.begin(),bc.end(), compare_by_b);
	//先頭から割り当て
	ans = 0;
	int ap = 0;
	rep(i, bc.size()) {
		rep(j, bc[i].first) {
			if (a[ap] < bc[i].second) {
				a[ap] = bc[i].second;
			}
			ans += a[ap];
			if (ap+1 < n)
				++ap;
			else
				goto OWARI;
		}
	}
	for (int i = ap;i<n;++i)
		ans += a[i];
OWARI:

	cout << ans << endl;
}


Measured memory_bytes: 4712
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n, l;
  cin >> n >> l;
  int ans = 0,sum = 0,diff = 1001001;
  rep(i,n){
    sum+=l+i;
  }
  rep(i,n){
    int x = 0;
    rep(j,n){
      if(i == j)continue;
      x+=l+j;
    }
    if(diff>abs(sum-x)){
      diff = abs(sum-x);
      ans = x;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n, p, q; cin >> n >> p >> q;
  vll c(n);
  ll sum = 0;
  for(int i=0;i<n;++i) {
    cin >> c[i];
    sum += c[i];
    c[i] = p * i + c[i];
  }
  sort(c.begin(), c.end());
  ll ans = sum;
  for(int i=0;i<=n;++i) {
    ans = max(ans, sum + p * q * i + p * i * (i - 1));
    if(i != n) sum -= c[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 6808
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;
int main(){
    int N;
    long long K;
    cin>>N>>K;
    int A[N];
    int rireki[N];

    for(int i=0;i<N;i++){
        int A_;
        cin>>A_;
        A[i]=A_-1;
        rireki[i]=0;
    }
    rireki[0]=1;
    int loop=0;
    int target=A[0];
    bool loop_start=false;
    int start=1;
    int loop_point=0;
    while(1){
        rireki[target]++;




        if(rireki[target]==2&&!loop_start){
            loop_start=true;
        }
        if(loop_start){
            loop++;
        }else{
            start++;
        }
        if(rireki[target]>=3){
            loop_point=target;
            break;
        }
        target=A[target];
        

    }
    loop--;
    if(K-start>0){
        int amari=(K-start)%loop;
        target=loop_point;
        if(amari!=0){
            for(int i=0;i<amari;i++){
                target=A[target];
            }
        }else{
        }
    }else{
        target=A[0];
        for(int i=1;i<K;i++){
            target=A[target];
        }

    }

    cout<<target+1;
}





Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());
 
    int ans = 0;
 
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] and vec[i] != vec[j] and
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
int i,n,j=0,t;
int a,b;
cin>>n;
cin>>a>>b;
for(i=a;i<=b;i++)
{
    if(i%n==0)
        j++;
}
if(j!=0)
    cout<<"OK"<<endl;
else cout<<"NG"<<endl;

return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define N 20
using P=pair<int, int>;
using T=tuple<int, int, int>;
#define MP make_pair
#define MT make_tuple
#define REP(x,y,z) for(int x=y;x<=z;x++)
char m[N+5][N+5];
int H, W;
int dirs[][2] = {
    {0, -1}, // up
    {0, 1},  // down
    {-1, 0}, // left
    {1, 0}   // right
};
queue<T> q;
int mw[N+5][N+5];
int maxw;
void init()
{
    maxw = 0;
    while(!q.empty()) q.pop();
    memset(mw, -1, sizeof(mw));
}
bool ok(int i, int j)
{
    return i >= 1 && i <= H && j >= 1 && j <= W &&
        m[i][j] == '.' && mw[i][j] == -1;
}
void bfs(int i, int j, int w)
{
    if(!ok(i, j)) return;
    mw[i][j] = w;
    q.push(MT(i, j, w));
    while(!q.empty())
    {
        tie(i, j, w) = q.front(); q.pop();
        // printf(">> %d %d %d\n", i, j, w);
        for(int d = 0; d < 4; d++)
        {
            int ti = i+dirs[d][0], tj = j+dirs[d][1];
            if(ok(ti, tj))
            {
                mw[ti][tj] = w+1;
                q.push(MT(ti, tj, mw[ti][tj]));
            }
        }
    }
    for(int a = 1; a <= H; a++)
        for(int b = 1; b <= W; b++)
            maxw = max(maxw, mw[a][b]);
}

void dbg()
{
    puts("mw[]: ");
    for(int a = 1; a <= H; a++)
    {
        for(int b = 1; b <= W; b++)
            printf("%3d ", mw[a][b]);
        puts("");
    }
}

int main(int argc, char *argv[])
{
    while(~scanf("%d %d", &H, &W))
    {
        // printf("> %d %d\n", h, w);
        getchar();
        for(int i = 1; i <= H; i++)
        {
            for(int j = 1; j <= W; j++)
            {
                m[i][j] = getchar();
            }
            getchar();
        }

        // for(int i = 1; i <= h; i++)
        // {
        //     for(int j = 1; j <= w; j++)
        //         printf("%c ", m[i][j]);
        //     puts("");
        // }

        int ans = 0;
        for(int i = 1; i <= H; i++)
            for(int j = 1; j <= W; j++)
            {
                init();
                bfs(i, j, 0);
                // dbg();
                // printf("> ans = %d\n", ans);
                ans = max(ans, maxw);
            }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m);
    for (int i = 0; i < m; i++) std::cin >> a[i];

    std::vector<i64> c(n + 1);
    c[0] = 1;
    for (int i = 1, j = 0; i <= n; i++) {
        if (j < m && a[j] == i) { j++; continue; }
        if (i > 0) c[i] += c[i - 1];
        if (i > 1) c[i] += c[i - 2];
        c[i] %= mod;
    }
    std::cout << c[n] << std::endl;

    return 0;
}


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

int main(){
    int n,k;
    cin >>n>>k;
    vector<int> nu(n,0);
    for(int i = 0 ;i <k;i++){
        int a;
        cin >> a;
        for(int j = 0; j<a;j++){
            int l;
            cin >> l;
            nu[l-1] = 1;
        }
    }
    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(nu[i] == 0){
            cnt++;
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 3624