akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

// https://atcoder.jp/contests/abc162/tasks/abc162_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();


		long ans = 0L;
		for(int i =1;i<=n;i++) {
			if(!(i%3==0||i%5==0)) {
				ans = ans + i;
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 35900
#include<stdio.h>

int main(){
  int w, n, i, destination[30];
  scanf("%d", &w);
  scanf("%d", &n);
  for(i=0; i<w; i++){
    destination[i] = i+1;
  }
  int num1, num2, temp;
  for(i=0; i<n; i++){
    scanf("%d,%d", &num1, &num2);
    temp = destination[num1-1];
    destination[num1-1] = destination[num2-1];
    destination[num2-1] = temp;
  }
  for(i=0; i<w; i++){
    printf("%d\n", destination[i]);
  }
  return 0;
}

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

int A[100000];
int B[100000];
int C[100000];

ll S[100010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = 0; i < N; i++){
		cin >> B[i];
	}
	for(int i = 0; i < N; i++){
		cin >> C[i];
	}
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	for(int i = 0; i < N; i++){
		int num = lower_bound(A, A + N, B[i]) - A;
		S[i + 1] = S[i] + num;
	}

	ll sum = 0;
	for(int i = 0; i < N; i++){
		int idx = lower_bound(B, B + N, C[i]) - B;
		sum += S[idx];
	}
	cout << sum << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    vector<double> v(n);
    for (size_t i = 0; i < n; ++i)
        cin >> v[i];
    if (n == 0)
        cout << 0.0 << endl;
    else {
        priority_queue<double, vector<double>, std::greater<double>> pq;
        for (auto e : v)
            pq.emplace(e);
        auto av = pq.top();
        while (pq.size() > 1) {
            auto v1 = pq.top();
            pq.pop();
            auto v2 = pq.top();
            pq.pop();
            av = (v1 + v2) / 2.0;
            pq.push(av);
        }
        cout << av << endl;
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while (cin>>n, n) {
        map<int, int> m;
        int c=0, res=0, a;
        for (int i=0; i<n; ++i) {
            cin >> a;
            int &ma = m[a];
            ++ma;
            if (c < ma) {
                c = ma; res = a;
            }
            if (n < c*2 || (c+n-1-i)*2 <= n) {
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                break;
            }
        }
        if (n < c*2) {
            cout << res << endl;
        } else {
            cout << "NO COLOR" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2748
import sys
import bisect

input = sys.stdin.readline

N,Q=map(int,input().split())
A=list(map(int,input().split()))
X=[int(input()) for i in range(Q)]

XLIST=[]
for i in range(1,N//2+1):
    if i+1<=N and 2*i+1<=N:
        XLIST.append((A[-i-1]+A[-2*i-1])/2)



SUM=[0]
for a in A:
    SUM.append(SUM[-1]+a)

SUMODD=[0]
for i in range(N-1,-1,-2):
    SUMODD.append(SUMODD[-1]+A[i])

ANSLIST=[]
ANSLEN=(N+1)//2

for i in range(ANSLEN):
    ANS=0

    ANS+=SUM[-1]-SUM[-1-ANSLEN+i]

    ANS+=SUMODD[-1]-SUMODD[-1-i]

    ANSLIST.append(ANS)
    
XLIST.reverse()

for x in X:
    print(ANSLIST[bisect.bisect_left(XLIST,x)])


Measured memory_bytes: 66668
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
  	int n, q, a, b, c, d[100005] = {};
  	ll z = 0;
  	cin >> n;
  	for (int i = 1; i <= n; i++) cin >> a, z += a, d[a]++;
  	cin >> q;
  	while (q--) {
      cin >> b >> c;
      z += 1ll * d[b] * (c - b);
      cout << z << '\n';
      d[c] += d[b];
      d[b] = 0;
    }
}

Measured memory_bytes: 3508
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,v,p,v1,x1,minn,a[100003],b[100003],sum,l,r,mid,che;
int check(int x)
{
	for(int i=1;i<=n;i++)
		b[i]=a[i];
	x1=x,che=b[x]+m;
	for(int i=n-p+2;i<=n;i++)
		b[i]+=m;
	if(x<n-p+2)
		b[x]+=m;
	else
		b[n-p+1]+=m;
	for(int i=2;i<=n;i++)
		if(b[i]<=b[i-1])
			swap(b[i],b[i-1]);
	for(int i=n;i>=1;i--)
		if(b[i]==che)
		{
			x1=i;
			break;
		}
	if(x1+p<=n)
		return 0;	
	v1=v-p,sum=0;
	minn=b[n-p+1];
	for(int i=1;i<=n-p;i++)
	{
		sum+=minn-b[i];
		if(minn-b[i]>=m)
			sum-=minn-b[i]-m;
	}
	if(sum<v1*m)
		return 0;
	return 1;
}
signed main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	l=1,r=n-p;
	//cout<<check(4);
	//return 0;
	while(l<=r)
	{
		mid=(l+r)/2;
		if(check(mid)==1)
			r=mid-1;
		else
			l=mid+1;
	}	
	cout<<n-l+1;
	return 0;
}


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

int main() {
  int N,A;
  int p;
  cin >> N;
  cin >> A;
  p = N % 500;
  if (p > A){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.StringTokenizer;
class Graph {
    private int v;
    private LinkedList<Integer>[] adj_lists;
    private int[] maxLens;
    //node starts from 1;
    Graph (int v){
        this.v = v;
        adj_lists = new LinkedList[v + 1];
        maxLens = new int[v + 1];
        for (int i = 1; i < v + 1; i++){
            adj_lists[i] = new LinkedList<Integer>();
            maxLens[i] = -1;
        }
    }

    public void addEdge(int source, int dest){
        adj_lists[source].add(dest);
        //adj_lists[dest].add(source);
    }

    public LinkedList<Integer> getAdjs(int node){
        return adj_lists[node];
    }

//    public boolean isEnd(int node){
//        return adj_lists[node].isEmpty();
//    }

    public int DFS(int node){

        if (maxLens[node] != -1){
            return maxLens[node];
        }else{
            int maxlen = 0;
            for (int child : getAdjs(node)){
              maxlen = Math.max(maxlen, 1 + DFS(child));
              maxLens[node] = maxlen;
            }
            return maxlen;
        }
    }

    public int findLongestPath(){
        int maxLen = 0;
        for (int i = 1; i < adj_lists.length; i++ ){

            maxLen = Math.max(DFS(i),maxLen);
        }
        return maxLen;
    }

}

public class Main{




 public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
 
        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
 
        Graph g = new Graph(n);
 
        for(int i=0 ; i<m ; i++) {
            st = new StringTokenizer(br.readLine());
            int u = Integer.parseInt(st.nextToken());
            int v = Integer.parseInt(st.nextToken());
            g.addEdge(u, v);
        }
 
        int ans = g.findLongestPath();
        pw.print(ans);
        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }

}

Measured memory_bytes: 61828
n, m, l = map(int, input().split())
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))
for j in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    li = []
    for j in range(l):
        su = 0
        for k in range(m):
            su += a[i][k] * b[k][j]
        li.append(su)
    print(" ".join(list(map(str, li))))


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define vpp             vector <pair<int, pii>>
#define mii             map <int, int>
#define mpi             map <pii, int>
#define msi             map < string, int >
#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))
#define spi             set <pii>
#define endl            "\n"
#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2000005;




void solve()
{
	int n, m;
	cin >> n >> m;
	int a1, a2;

	if (m < 2) a1 = 0;
	else a1 = (m * (m - 1)) / 2;
	if (n < 2) a2 = 0;
	else a2 = (n * (n - 1)) / 2;
	cout << a1 + a2 << endl;
	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



	//cout << setprecision(9) << fixed;
	clock_t z = clock();
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	cerr << "Total Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

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

ll gcd(ll x, ll y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
ll lcm(ll x, ll y){
    //掛け算をする前に割り算をすることでx*yがllに治らない場合をケアしている
    return x/gcd(x,y)*y;
}
ll f(ll x, ll c, ll d){
    ll res = x;
    res -= x/c;
    res -= x/d;
    res += x/lcm(c,d);
    return res;
}

//f(x) x以下でcでもdでも割り切れない数　を用意すると
//f(b)-f(a)が求めたい数になる
//f(x)=x-x/c-x/d+x/(c*d)
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll commoncd = lcm(c,d);
    ll ans = f(b,c,d) - f(a-1,c,d);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n,K;
int a[110];
int sg[100010];
inline int mex(const unordered_set<int>&s){
	for(int i=0;;i++){
		if(s.find(i)==s.end())
			return i;
	}
}

int main(){
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	for(int i=1;i<=K;i++){
		unordered_set<int>s;
		s.clear();
		for(int j=1;j<=n;j++)
			if(i-a[j]>=0)
				s.insert(sg[i-a[j]]);
		sg[i]=mex(s);
	}
	if(sg[K]==0)
		puts("Second");
	else
		puts("First");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int x; cin >> x;
    set<int> s{0};
    int time = 0;
    int dist = 0;
    while(dist < x) {
        time++;
        dist += time;
    }

    cout << time <<endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner; 
 
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
 
       for(int i =1; i<=10 ; i++){
           if(N <= 1000*i){
               System.out.println(1000*i-N);
               break;
           }
       }
        }
 
    }

Measured memory_bytes: 35844
#coding:utf-8

S = input()
N = len(S)
ans = 0
SR = []
if S[0] == '0':
	for i in range(N):
		SR.append('0')
		SR.append('1')
else:
	for i in range(N):
		SR.append('1')
		SR.append('0')

for i in range(N):
	if S[i] != SR[i]:
		ans += 1
		
print(ans)

Measured memory_bytes: 4724
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))

    total_b = 0
    for i in range(N):
        benefit = V[i] - C[i]
        if(benefit > 0):
            total_b += benefit
    print(total_b)


if(__name__ == '__main__'):
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if(a > b){
		cout << "a > b" << endl;
	}else if(a == b){
		cout << "a == b" << endl;
	}else{
		cout << "a < b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
using namespace std;
 
int main(void){
  int n,year,ope,bfmoney,tax,interest,max,get,tempmoney=0;
  double up_yatta,temp;
   
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
     
    max = 0;
     
    cin >> bfmoney;
    cin >> year >> ope;
 
    tempmoney = bfmoney;
 
    for( int j = 0 ; j < ope ; j++ ){
      get = 0;temp = 0;
      bfmoney = tempmoney;
      cin >> interest >> up_yatta >> tax;
       
      if( interest == 1 ){
    for( int k = 0 ; k < year ; k++ ){
       
      get = up_yatta * bfmoney;
      bfmoney += get - tax;
       
    }  
      }
           
      else{
    for( int k = 0 ; k < year ; k++ ){
       
      temp = bfmoney * up_yatta;
      get += temp;
      bfmoney -= tax;
    }
     
    bfmoney += get;
      }
      if( max < bfmoney ) max = bfmoney;
    } 
     
    cout << max << endl;
     
     
  }
  return 0;
   
}

Measured memory_bytes: 1232
#include <stdio.h>

int main(void){
int H,W,c,d=0;
while(1){
scanf("%d",&H);
scanf("%d",&W);

if(H==0&&W==0){break;}

else{
for(c=1;c<=H;c++){
	if(c==1||c==H){
		for(d=1;d<=W;d++){
		printf("#");
		}
	}
	else{
		for(d=1;d<=W;d++){
			if(d==1||d==W){
			printf("#");
			}
			else{
			printf(".");
			}
		}
	
}
printf("\n");}
printf("\n");
}
}
return 0;
}

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

int n, m;
bool c[2][200001];

int main() {
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1)c[0][b] = true;
		else if (a == n)c[1][b] = true;

		if (b == 1)c[0][a] = true;
		else if (b == n)c[1][a] = true;
	}

	bool flag = false;
	for (int i = 2; i < n; i++) {
		if (c[0][i] && c[1][i])flag = true;
	}

	if (flag) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

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

using namespace std;

int main()
{

    int n,i,j,t,f=0,c=0,mem;
    string s,gv;
    vector<string> str;
    vector<string>::iterator its;
    vector<int> tm;
    vector<int>::iterator itn;
    cin>>n;
    for (i=1;i<=n;++i){

        cin>>s>>t;
        str.push_back(s);
        tm.push_back(t);

    }
    cin>>gv;

    for(its=str.begin(),itn=tm.begin();its!=str.end(),itn!=tm.end();++its,++itn){

        if((*its)==gv){

            f=1;
            mem = (*itn);

        }
        if(f==1){

            c+=(*itn);

        }

    }
    cout<<(c-mem)<<endl;
    return 0;


}



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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

int main(void) {
    rep(i, 5) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()

#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define shandom_ruffle random_shuffle
#define funoredered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xc0c0c0c0;
constexpr double EPS = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll modPow( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

inline int cmp_double( double x, double y, double tol = EPS) {
    return (x <= y + tol) ? ( x + tol < y) ? -1 : 0 : 1;
}

constexpr int ms = 1e5 + 13;

int dp[3][ms];
int val[3][ms];

int main()
{
	ios::sync_with_stdio(0); cin.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 3; ++j) {
            cin >> val[j][i];
        }
    }
    for(int i = 0; i < 3; ++i) dp[i][0] = val[i][0];

    for(int d = 1; d < n; ++d) {
        for(int x = 0; x < 3; ++x) {
            dp[x][d] = -1;
            for(int old = 0; old < 3; ++old) {
                if(old == x) continue;
                dp[x][d] = max( dp[x][d], dp[old][d - 1] );
            }
            dp[x][d] += val[x][d];
        }
    }

    int res = -1;
    for(int i = 0; i < 3; ++i) res = max( res, dp[i][n - 1] );
    
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>

#define F1(x,y,z) for(int x=(y);x<(z);x++)
#define F2(x,y,z) for(int x=(y);x<=(z);x++)
#define F3(x,y,z) for(int x=(y);x>(z);x--)
#define F4(x,y,z) for(int x=(y);x>=(z);x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second

#define MAX 100005
#define AMAX 53
#define MOD 1000000007

#define f(c,d) ((1<<(c))*(d))

using namespace std;

char x[20],y[20]="CODEFESTIVAL2016";
int ans;

int main(){
	scanf("%s",x);
	F1(a,0,16)if(x[a]!=y[a])ans++;
	printf("%d\n",ans);
	#ifdef LOCAL_PROJECT
	system("pause");
	#endif
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define pr(x) cerr<<#x<<"="<<x<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (ll ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define N 1001000
vector<ll> st[30],x,y;
ll n,a[N],c[N],need[N],tag[N],i,id[N],ans,cnt;
char ch[N];
ll query(ll x)
{
	ll ret=0;
	while (x>0) ret+=c[x],x-=(x&-x);
	return ret;
}
void add(ll x)
{
	while(x<=(ll)y.size()) c[x]+=1,x+=(x&-x);
}
ll calc(ll n)
{
	ll ret=0;
	for (i=1;i<=n;i++)
	{
		ret+=query(id[i]);
		add(id[i]);
		//pr(i),pr(ret);
	}
	return ret;
}
int main()
{
	scanf("%s",ch);
	ll n=(ll)strlen(ch);
	for (i=0;i<n;i++) a[i+1]=ch[i]-'a'+1,need[ch[i]-'a'+1]++;
	ll f=0;for (i=1;i<=26;i++) if (need[i]%2==1) {if(f==0) f=i;else {printf("-1\n");return 0;}}
	//pri(need,10);
	for (i=1;i<=26;i++) need[i]/=2;
	if (f==0)
	{
		for (i=1;i<=n;i++)	{if (need[a[i]]>0) cnt++,need[a[i]]--,tag[i]=1,ans+=i-cnt,x.pb(i);else y.pb(i);}
	}
	else 
	{
		need[f]++;
		int cnt1=0;
		for (i=1;i<=n;i++)
		{
			if (need[a[i]]>0)
			{
				if (need[a[i]]==1&&a[i]==f) need[a[i]]--,tag[i]=2,ans+=cnt1;
				else 
				{
					cnt++;
					need[a[i]]--,tag[i]=1,ans+=i-cnt;
					//pr(i),pr(cnt);
					x.pb(i);
				}
			}	
			else y.pb(i),cnt1++;
		}
	}
	//pri(tag,n);
	//pri(x,x.size()-1);
	//pri(y,y.size()-1);
	for (i=0;i<(ll)x.size();i++) st[a[x[i]]].pb(i+1);
	for (i=0;i<(ll)y.size();i++) id[i+1]=st[a[y[i]]].back(),st[a[y[i]]].pop_back();
	//pri(id,n);
	//pr(ans);
	ans+=calc((ll)y.size());
	printf("%lld\n",ans);
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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 ); }


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

    int W, a, b;
    cin >> W >> a >> b;
    int ma = max(a, b);
    int mi = min(a, b);
    cout << max(0, ma - (mi + W)) << endl;
    return 0;
}

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

int main(){
  int N, W;
  cin >> N >> W;
  
  for(int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  string s;
  for(int i = 0; i < N; i++){
    cin >> s;
    cout << "#"+s+"#" << endl;
  }
  
  for(int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
}

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


ll modinv(ll a, ll m) {
  ll b = m;
  ll u = 1;
  ll v = 0;

  while (b > 0) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }

  u %= m;
  if (u < 0) u += m;
  return u;
}

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

  vector<ll> A(N);
  rep(i, N) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  vector<ll> c(N + 1, 0);
  c.at(K - 1) = 1;
  for(int i = 1; i <= N; i++) {
    if (i <= K - 1) continue;
    int x = i - (K - 1);
    c.at(i) = (c.at(i - 1) * i % mod) * modinv(x, mod) % mod;
  }

  ll ans = 0;
  rep(i, N) {
    if (i >= K - 1) {
      ans += c.at(i) * A.at(i) % mod;
      ans %= mod;
    }
    if (N - i - 1 >= K - 1) {
      ans -= c.at(N - i - 1) * A.at(i) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(24) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

bool pairCompare(const pair<int, int> &firstElof, const pair<int, int> &secondElof)
{
    return firstElof.second < secondElof.second;
}

void solve()
{
    int n, m;
    cin >> n >> m;
    set<int> s;
    vector<pair<int, int>> v(200200, make_pair(0, 0));
    rep(i, n)
    {
        int a;
        cin >> a;
        s.insert(a);
        v[a].first = a;
        v[a].second++;
    }
    sort(v.begin(), v.end(), pairCompare);
    ll sum = 0;
    int c = s.size();
    rep(i, v.size())
    {
        if (c <= m)
        {
            break;
        }
        if (v[i].second != 0)
        {
            sum += v[i].second;
            c--;
        }
    }
    P(sum);
}

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


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll N,M,X,ans=0,cmp=0;
    cin >> N >> M >> X;
    ll A[M];
    map<ll,ll>m;
    for(ll i = 0; i < M; i++) {
        cin >> A[i];
        m[A[i]]++;
    }
    for(ll i = X+1; i <= N; i++) {
        if(m[i] == 1) {
            ans++;
        }
    }
    for(ll i = X-1; i >= 0; i--) {
        if(m[i] == 1) {
            cmp++;
        }
    }
    ans = min(ans,cmp);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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 all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int m;

vi lis(55555, 1);
vi prime_nums;

int main()
{
    cin >> m;
    lis[0] = 0; lis[1] = 0;
    int n = lis.size();

    rep(i, n){
        if(lis[i] == 0) continue;
        prime_nums.pb(i);
        for(int j = i + 1; j < n; j++){
            if(lis[j] == 0) continue;
            if(j % i == 0) lis[j] = 0;
        }
    }
    vi candidates;
    for(int prime_num: prime_nums){
        if(prime_num % 5 == 1) candidates.pb(prime_num);
    }
    rep(i, m) cout << candidates[i] << " ";
    cout << endl;

    return 0;

}

Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        char[] s_char = s.toCharArray();
        Arrays.sort(s_char);
        String s_asc = new String(s_char);

        String t = sc.next();
        char[] t_char = t.toCharArray();
        Arrays.sort(t_char);
        String t_asc = new String(t_char);
        String t_desc = new StringBuilder(t_asc).reverse().toString();
        
        if (s_asc.compareTo(t_desc) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<cstring>

int OutCount,PointCount,HitCount;

int Check(const char* str){
  if( strcmp(str,"HIT") == 0 )
		return 0;
	
	else if( strcmp(str,"HOMERUN") == 0 )
		return 1;
	
	else if( strcmp(str,"OUT") == 0 )
		return 2;
}
int main(){
  int n;
	char Input[10];
	scanf("%d",&n);
	while( n-- ){
		OutCount=PointCount=HitCount=0;
		
		while(OutCount < 3){
			scanf("%s",Input);
			switch(Check(Input)){
				case 0:
					HitCount++;
					if(HitCount==4)++PointCount, --HitCount;
					break;
				case 1:
					PointCount+=HitCount+1;
					HitCount=0;
					break;
				case 2:
					OutCount++;
					break;
			}
		}
		printf("%d\n",PointCount);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
#include <sstream>
using namespace std;

vector<string> split(string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while(getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}


long long splitsum(string s){
    long long sum = 0;
    vector<string> num = split(s,'+');
    for(int i = 0;i < num.size();i++){
        sum += stoll(num[i]);
    }
    return sum;
}

int main(void){
    string s;
    cin >> s;
    long long sum = 0;
    int bit = pow(2,s.size()-1);
    for(int i = 0;i < bit;i++){
        string s2 = s;
        int j = i;
        int insert = 0;
        while(j != 0){
            if(j % 2 == 1){
                insert++;
                s2.insert(s2.begin()+insert,'+');
            }
            insert++;
            j /= 2;
        }
        sum += splitsum(s2);
    }
    cout << sum << endl;
}


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

int main(){
  int ans = 0;
  int newans = 0;

  int n, h, p;

  scanf("%d", &n);

  scanf("%d", &h);
  p = h;

  for(int i = 1; i < n; i++){
    scanf("%d", &h);

    if (p >= h) newans++;
    else{
      if(newans > ans){
        ans = newans;
        newans = 0;
      }
      else newans = 0;
    }
    p = h;
  }

  if (newans > ans) ans = newans;

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

  return 0;
}

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

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

    vector<int> vec((N+1), 0);

    int a, b;
    for(int i=0; i<M; i++) {
        cin >> a >> b;
        vec[a] += 1;
        vec[b] += 1;
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<ll> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

bool gre(ll a, ll b){
  return a>b;
}
int main () {
  IN(x);
  IN(y);
  IN(z);
  IN(k);

  VIN(a, x);
  VIN(b, y);
  VIN(c, z);

  sort(ALL(a), gre);
  sort(ALL(b), gre);
  sort(ALL(c), gre);

  int ca=0;
  int cb=0;
  int cc=0;

  ll res = a[ca]+b[cb]+c[cc];
  
  auto comp = [](vector<ll> l, vector<ll> r) {
    return (l[3]>r[3]
    || (l[3]==r[3]&&l[0]>r[0])
    || (l[3]==r[3]&&l[0]==r[0]&&l[1]>r[1])
	    || (l[3]==r[3]&&l[0]==r[0]&&l[1]==r[1]&&l[2]>r[2]));
  };
  
  set<vector<ll>, decltype(comp)> pq(comp);
  vector<vector<vector<bool> > > mem(x, vector<vector<bool> >(y, vector<bool>(z, true)));
  pq.insert({0,0,0,res});
  REP(i,k){
    cout << (*pq.begin())[3] << endl;
    ca=(*pq.begin())[0];
    cb=(*pq.begin())[1];
    cc=(*pq.begin())[2];
    //    cout<<ca<<','<<cb<<','<<cc<<endl;
    pq.erase(pq.begin());
    if (ca<x-1 && mem[ca+1][cb][cc]){
      pq.insert({ca+1, cb, cc, a[ca+1]+b[cb]+c[cc]});
      mem[ca+1][cb][cc]=false;
    }
    if (cb<y-1 && mem[ca][cb+1][cc]){
      pq.insert({ca, cb+1, cc, a[ca]+b[cb+1]+c[cc]});
      mem[ca][cb+1][cc]=false;
    }
    if (cc<z-1 && mem[ca][cb][cc+1]){
      pq.insert({ca, cb, cc+1, a[ca]+b[cb]+c[cc+1]});
      mem[ca][cb][cc+1]=false;
    }
  }
}


Measured memory_bytes: 182272
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG

int main() {
    int a, b;
    cin >> a >> b;
    int ans = a * b - a - b + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
	float n;
	int m;
	const char *rank[] = {"light fly", "fly", "bantam", "feather", "light", "light welter",
		"welter", "light middle", "middle", "light heavy", "heavy"};
	while(~scanf("%f\n", &n)){
		if(n <= 48.0) m = 0;
		else if(n <= 51.0) m = 1;
		else if(n <= 54.0) m = 2;
		else if(n <= 57.0) m = 3;
		else if(n <= 60.0) m = 4;
		else if(n <= 64.0) m = 5;
		else if(n <= 69.0) m = 6;
		else if(n <= 75.0) m = 7;
		else if(n <= 81.0) m = 8;
		else if(n <= 91.0) m = 9;
		else m = 10;
		puts(rank[m]);
	}
	return 0;
}

Measured memory_bytes: 1040
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    ll n;
    cin >> n;
    n--;
    cout << n * (n + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void){
    long N,i,ans,count,counter;
    scanf("%ld",&N);
    long int A[N];
    for(i=0;i<N;i++){
        scanf("%ld",&A[i]);
    }
    qsort(A,N,sizeof(long int),cmpnum);
    ans = A[N-1];
    count = N-2;
    counter = N-2;
    while(count>0){
        if(count==1){
            ans += A[counter];
            break;
        }
        ans += A[counter] * 2;
        count -= 2;
        counter--;
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 4688
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,k:usize,
        ab:[(Usize1,Usize1);n-1],
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in ab.iter() {
        g[a].push(b);
        g[b].push(a);
    }
    let mut md = ModComb::new(1010101, MOD);
    let mut q = VecDeque::new();
    let mut ans = 1;
    let mut visited = vec![false; n];
    q.push_back((0, 0));
    while let Some(x) = q.pop_front() {
        let (now, depth) = x;
        visited[now] = true;
        if depth == 0 {
            ans = k as i64;
            let ln = g[now].len();
            ans *= md.perm(k as i64 - 1, ln as i64);
            ans %= MOD;
        }
        if depth >= 1 {
            let ln = g[now].len();
            ans *= md.perm(k as i64 - 2, ln as i64 - 1);
            ans %= MOD;
        }
        for &nx in g[now].iter() {
            if !visited[nx] {
                q.push_back((nx, depth + 1));
            }
        }
        ans = (ans + MOD) % MOD;
    }
    println!("{}", ans % MOD);
}
const MOD: i64 = 1000000007;
/// x ^ n % m
pub fn mod_pow(x: i64, n: i64, m: i64) -> i64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}
struct ModComb {
    fact: Vec<i64>,
    fact_inv: Vec<i64>,
    n: usize,
    p: i64,
}
impl ModComb {
    fn initialize(&mut self) {
        let n = self.n;
        self.fact[0] = 1;
        for i in 1..n {
            self.fact[i] = (self.fact[i - 1] * i as i64) % self.p;
        }
        self.fact_inv[n - 1] = mod_pow(self.fact[n - 1], self.p - 2, self.p);
        for i in (0..n - 1).rev() {
            self.fact_inv[i] = (self.fact_inv[i + 1] * (i + 1) as i64) % self.p;
        }
    }
    fn new(max_n: usize, p: i64) -> ModComb {
        let mut ft = ModComb {
            fact: vec![0; max_n + 1],
            fact_inv: vec![0; max_n + 1],
            n: max_n + 1,
            p: p,
        };
        ModComb::initialize(&mut ft);
        ft
    }
    fn fact(&self, n: usize) -> i64 {
        self.fact[n]
    }
    fn comb(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        (self.perm(n, k) * self.fact_inv[k as usize]) % self.p
    }
    fn perm(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        self.fact[n as usize] * self.fact_inv[(n - k) as usize] % self.p
    }
    fn nsk(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        let mut res = 0;
        for i in 0..k + 1 {
            let v = self.comb(k, i) * mod_pow(i, n, self.p) % self.p;
            if (k - i) % 2 == 1 {
                res = (res + self.p - v) % self.p;
            } else {
                res = (res + v) % self.p;
            }
        }
        return res * self.fact_inv[k as usize] % self.p;
    }
}


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

int main() {
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;
    }else {
        cout<<"IMPOSSIBLE"<<endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def input_int_array():
    return map(int, input().split())


MOD = 998244353


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0] * (n)
    count[0] = 1
    accum = [0] * (n + 1)
    accum[1] = 1

    for i in range(1, n):
        j = i + 1
        for l, r in spans:
            start = max(0, j - r - 1)
            end = max(0, j - l)
            count[i] += accum[end] - accum[start]
        accum[j] = accum[j-1] + count[i] % MOD
    print(count[n-1] % MOD)


answer()


Measured memory_bytes: 76612
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    
    int cnt = 0;
    int pos = 0;

    rep(i, s.size()){
        if(s[i] == '('){
            while(cnt < 0)s.insert(0, "("), cnt++, i++;
            cnt++;
        }
        else cnt--;
    }
    while(cnt < 0)s.insert(0, "("), cnt++;
    while(cnt > 0)s.insert(s.size(), ")"), cnt--;
    cout << s;
}


Measured memory_bytes: 256
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

A.reverse()

dp = [A[0]]

for a in A[1:]:
    idx = bisect.bisect_right(dp, a)
    if idx == len(dp):
        dp.append(a)
    else:
        dp[idx] = a

print(len(dp))

Measured memory_bytes: 14292
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n,m; cin >> n >> m;
  if(n == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3540
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] maxes = new int[c + 1];
		for (int i = 1; i <= c; i++) {
		    maxes[i] = sc.nextInt();
		}
		PriorityQueue<Ball> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    queue.add(new Ball(sc.nextInt(), sc.nextInt()));
		}
		long total = 0;
		while (queue.size() > 0 && m > 0) {
		    Ball b = queue.poll();
		    if (maxes[b.color] == 0) {
		        continue;
		    }
		    maxes[b.color]--;
		    total += b.value;
		    m--;
		}
		System.out.println(total);
	}
	
	static class Ball implements Comparable<Ball> {
	    int color;
	    int value;
	    
	    public Ball(int color, int value) {
	        this.color = color;
	        this.value = value;
	    }
	    
	    public int compareTo(Ball another) {
	        return another.value - value;
	    }
	}
}



Measured memory_bytes: 104360
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

int main()
{
	ll n;
	cin>>n;
	vector<ll>v(n);
	ll sum = 0;
	FOR(i,0,n)
	{
		cin>>v[i];
		sum = sum ^ v[i];
	}
	if(n %2 == 0)
	{
		FOR(i,0,n)
		{
			cout<<(sum^v[i])<<" ";
		}
	}
	else
	{
		cout<<1<<" ";
		sum ^= v[0];
		FOR(i,1,n)
		{
			cout<<(sum^v[i]^1)<<" ";
		}
	}
	
 	return 0;
}


Measured memory_bytes: 4816
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
int main(){	
	string ptr;
	cin>>ptr;
	int f=1;
	for(int i=0;i<ptr.length();i++){
		if(ptr[i]>='A'&&ptr[i]<'Z'){
			f=0;
			break;
		}
	}
	if(f==0){
		cout<<"No"<<endl;
		return 0;
	}
	if(ptr.length()==6){
		if(ptr[2]==ptr[3]&&ptr[4]==ptr[5]){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}else{
		cout<<"No"<<endl; 
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
	int n, m, acc=0, pen=0; cin>>n>>m;
	vector <bool> test(n+1);
	vector <int> arr(n+1);
	vector <int> p(m);
	vector <string> s(m);
	for (int i=0; i<m; i++)
	{
		cin>>p[i];
		cin>>s[i];
		if (test [p[i]]==false && s[i]=="AC")
		{
			test[p[i]]=true;
			acc++;
			pen+=arr[p[i]];
		}
		if (test[p[i]]==false && s[i]=="WA")
		{
			arr[p[i]]++;
		}
	}
	cout<<acc<<endl<<pen<<endl;
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>

using namespace std;

int main()
{
	int n;
	int i,sum=0;
	cin >> n;
	for (i = 1; i <= n; i++)
		if (i % 2 != 0)
			sum++;

	

	cout << sum/(double)n << endl;

	return 0;
} 


Measured memory_bytes: 256
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const N = parseInt(inputList[0].split(" ")[0]);
    const M = parseInt(inputList[0].split(" ")[1]);
    const K = parseInt(inputList[0].split(" ")[2]);
    const A = inputList[1].split(" ").map(ele => parseInt(ele));
    const B = inputList[2].split(" ").map(ele => parseInt(ele));

    if (K < A[0] && K < B[0]) {
        console.log(0);
    } else {

        let addA = [0]
        for (let i = 0; i < N; i++) {
            addA.push(addA[i] + A[i])
        }

        let addB = [0]
        for (let i = 0; i < M; i++) {
            addB.push(addB[i] + B[i])
        }

        let result = 0;
        let k = M;
        for (let j = 0; j < addA.length; j++) {
            if (addA[j] > K) {
                break;
            }

            while (addB[k] > K - addA[j]) {
                k--;
            }
            result = Math.max(result, j + k);
        }
        console.log(result)
    }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 83492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	vector<ll> ans = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	cin >> k;
	print(ans[k-1])
	return 0;
}

Measured memory_bytes: 256
import math

a, b, c, k = map(int, input().split())

if k % 2 != 1:
    if a-b == 0:
        print(0)
    else:
        print(a - b if abs(math.log10(abs(a-b))) <= 18 else "Unfair")
else:
    if a-b == 0:
        print(0)
    else:
        print(b - a if abs(math.log10(abs(a-b))) <= 18 else "Unfair")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int a,b;
  cin>>a>>b;
  int cur = 1;
  int ans = 0;
  while(cur < b){
    cur += a-1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp
n = s.length
str1 = s[0..(n-1)/2-1]
str2 = s[(n+3)/2-1..-1]
idx = str1.length / 2 - 1
if str1 == str2.reverse && str1[0..idx] == str1.reverse[0..idx] && str2[0..idx] == str2.reverse[0..idx]
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

# 区間スケジューリング
ab = sorted(ab, key = lambda x: x[1])
tmp_end = ab[0][1]
n_remove_bridge = 1

for idx in range(1,M):
    if tmp_end <= ab[idx][0]:
        tmp_end = ab[idx][1]
        n_remove_bridge += 1

print(n_remove_bridge)

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

int main()
{
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy";
  else if(s=="Cloudy")
    cout<<"Rainy";
  else if(s=="Rainy")
    cout<<"Sunny";   
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	int x,y;
	int cand;
	int ans=1e+9;
	for (int i = 0; i <=n; i++) {
		cand=0;
		x=i;
		y=n-i;
		while (x>0) {
			cand+=x%6;
			x/=6;
		}
		while (y>0) {
			cand+=y%9;
			y/=9;
		}
		ans=min(ans,cand);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256