akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int main() {
    ll n, q;
    string s;
    cin >> n >> s >> q;
    REP(aaa, q){
        ll k;
        cin >> k;
        
        ll d_cnt = 0, m_cnt = 0, dm = 0, ans = 0;
        REP(i, n){
            if(s[i] == 'D'){
                d_cnt++;
            }
            else if(s[i] == 'M'){
                dm += d_cnt;
                m_cnt++;
            }
            else if(s[i] == 'C'){
                ans += dm;
            }
            
            if(i - k + 1 >= 0){
                if(s[i - k + 1] == 'D'){
                    d_cnt--;
                    dm -= m_cnt;
                }
                else if(s[i - k + 1] == 'M'){
                    m_cnt--;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1412
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;


int main() {
	int N = 200000;
	int X;
	cin >> X;
	vector<bool> isPrime(N, true);
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 2; i < N; i++) {
		if (!isPrime[i])continue;
		for (int k = 2*i; k < N; k += i)isPrime[k] = false;
	}

	for (int i = X; i < N; i++) {
		if (isPrime[i]) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int level[500][500];

void fill(vector<int> &a, int now) {
	int n = a.size();
	if (n < 2) {
		return;
	}
	vector<int> l;
	vector<int> r;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			l.push_back(a[i]);
		} else {
			r.push_back(a[i]);
		}
	}
	for (int i = 0; i < l.size(); i++) {
		for (int j = 0; j < r.size(); j++) {
			level[l[i]][r[j]] = now;
			level[r[j]][l[i]] = now;
		}
	}
	fill(l, now + 1);
	fill(r, now + 1);
}

int main() {
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		a.push_back(i);
	}
	fill(a, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			cout << level[i][j] << ' ';
		}
		cout << endl;
	}
}

Measured memory_bytes: 1408
/*************************
__________________________
|                         |
|     Don't Hack Me!      |
|  Go Find Someone Else!  |
|_________________________|
        \_(O_O)_/
          |   |
          -----
          _| |_

*************************/

#include <bits/stdc++.h>
#include <iostream>


#define f first
#define s second
#define pb push_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define MAXN 1000005
using namespace std;

typedef long long ll;


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

    vector <int> a(n + 1, 0);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector <int> an(n + 1);
    an[2] = abs(a[2] - a[1]);
    for(int i = 3; i <= n; i++)
    {
        an[i] = min(an[i - 1] + abs(a[i] - a[i - 1]),an[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << an[n];
    return 0;
}


Measured memory_bytes: 4040
s = [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]
K = int(input())
print(s[K-1])


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
	lli H, W, M, x, y, I, J;
	cin>>H>>W>>M;
	// vector<pair<lli, lli> > A;
	vector<lli> h(H+1, 0), w(W+1, 0);
	set<pair<lli, lli > > S;
	for (lli i = 0; i < M; ++i)
	{
		cin>>x>>y;
		h[x]++;
		w[y]++;
		S.insert(make_pair(x, y));
		// A.push_back(make_pair(x, y));
	}
	map<lli, vector<lli> > horizontal, vertical;
	for (lli i = 1; i <= H; ++i)
	{
		horizontal[h[i]].push_back(i);
	}
	for (lli i = 1; i <= W; ++i)
	{
		vertical[w[i]].push_back(i);
	}
	// map<lli, vector<lli> >::iterator itr = horizontal.rbegin();
	lli h_max = horizontal.rbegin()->first;
	lli w_max = vertical.rbegin()->first;
	vector<lli> h_vec = horizontal.rbegin()->second;
	vector<lli> w_vec = vertical.rbegin()->second;
	
	for (lli i = 0; i < h_vec.size(); ++i)
	{
		I = h_vec[i];
		for (lli j = 0; j < w_vec.size(); ++j)
		{
			J = w_vec[j];
			// cout<< "searching "<< I<< " " << J << endl;
			if(S.find(make_pair(I, J))==S.end()){
				cout<<h_max + w_max; 
				return 0;
			}
		}
	}
	// cout << "out ";
	cout << h_max + w_max -1;
	return 0;
}

Measured memory_bytes: 36088
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
vector<LL> A;
vector<LL> imos;





//サブ関数
//入力
void input()
{
	cin >> N;
	A.push_back(0);
	REP(i, N) {
		LL tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	A.push_back(0);
}

//imos[i]=Aiまでの総距離
void make_imos()
{
	imos.push_back(0);
	REP(i, N+1) {
		imos.push_back(imos.back() + abs(A[i] - A[i + 1]));
	}
	imos.push_back(imos.back());
}


//計算
void calc()
{
	make_imos();

	REP(i, N) {
		//Aiへの移動をやめると、
		//0→A(i-1)→A(i+1)→0のルートでよくなる
		LL ans = imos[i];
		ans += abs(A[i] - A[i + 2]);
		ans += imos.back() - imos[i + 2];
		cout << ans << endl;
	}
}


//出力
void output()
{
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	//debug();
	
	return 0;
}


Measured memory_bytes: 2932
import Foundation

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

func main(){
    let aryInts = readInts()
    let n = aryInts[0]
    let _ = aryInts[1]
    var ans = String()
    
    var aryStr: [String] = []
    
    for _ in 1...n {
        aryStr.append(readLine()!)
    }
    let aryans = aryStr.sorted { $0 < $1 }
    
    for i in 0..<aryans.count {
        ans += aryans[i]
    }
    
    print(ans)
}

main()




Measured memory_bytes: 13532
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        int ans = 0;
        
        for(int i = 1; i <= n; i++){
            int num = i;
            int total = 0;
            boolean isLast = false;
            
            while(!isLast){
                if(num >= 10){
                    total += num % 10;
                    num /= 10;
                }else{
                    total += num;
                    isLast = true;
                }
            }
            
            if(a <= total && total <= b){
                ans += i;
            }
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32724
#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;
  cin >> n;
  vl x(n),q(n,-1);
  rep(i,n)cin >> x[i];
  int ans = 0;
  rep(i,n){
    int a = lower_bound(rng(q),x[i]) - q.begin();
    //show(a);
    q[a-1] = x[i];
  }
  rep(i,n){
    ans+=(q[i]!=-1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<bits/stdc++.h>
using namespace std; 
  
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;

int rtsum(int x)
{
	int sum=0;
	for (int i=1;i<=x;i++) sum+=i;
	return sum;
}

int main() 
{
	int a,b,x=0;
	cin>>a>>b;
	int cha=b-a;
	cout<<rtsum(cha)-b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll A , B , C ; cin >> A >> B >> C;
  if((A+B) >= C) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
//power ll power(ll a,ll b){if(b==0) return 1LL;if(b&1) return a*power(a,b-1);else return power(a,b/2)*power(a,b/2);}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll cmp(string s,string ss)
{
   ll sz=s.size()-1;
   ll cnt=0;
   fr(i,0,sz) if(s[i]!=ss[i]) cnt++;
   return cnt;
}
void solve()
{
    string s,ss;
    cin>>s>>ss;
    ll sz=s.size()-1,szz=ss.size()-1;
    ll mn=INT_MAX;
    fr(i,0,sz-szz)
    {
       string sb=s.substr(i,szz+1);
       ll res=cmp(sb,ss);
       mn=min(mn,res);
    }
    cout<<mn<<endl;



}
int main()
{
    rj
    solve();



    return 0;
}



Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(ll i = 0;i < n;i++)
#define FOR(i,a,b) for(ll i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

const int MAX = 1e4 + 1;
const int NMAX = 100 + 1;
bool dp[NMAX][MAX];
int main() {
	MEM(dp, false);
	dp[0][0] = true;
	int n;
	cin >> n;
	vector<int> s(n);
	REP(i, n)cin >> s[i];

	FOR(i, 1, n + 1) {
		int y = s[i - 1];
		REP(j, MAX) {
			if (j - y < 0)dp[i][j] = dp[i - 1][j];
			else dp[i][j] = dp[i - 1][j] || dp[i - 1][j - y];
		}
	}
	ll ans = 0;
	FOR(i, 1, MAX) {
		if (dp[n][i] && i % 10 != 0)ans = i;
	}
	dump(ans);
}




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

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

  int ans = 0, x = 0;
  for (int i = 0; i < n; i++) {
    if (h.at(i) > x) {
      ans += h.at(i) - x;
    }
    x = h.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=2e5+5;
int times[maxn];
int count(int a)
{
    int cnt=0;
    for(int lg=0;(1<<lg)<=a;lg++)
        if(a&(1<<lg))
            cnt++;
    return cnt;
}
int mod_up[maxn],mod_down[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string ss;
    cin>>ss;
    for(int i=1;i<=n;i++)
        times[i]=times[i%count(i)]+1;
    int ones=0;
    for(int i=0;i<(int)ss.length();i++)
        ones+=(ss[i]=='1');
    int up=ones+1,down=ones-1;
    if(up)
    {
        mod_up[(int)ss.length()-1]=1%up;
        for(int i=(int)ss.length()-2;i>=0;i--)
            mod_up[i]=(2*mod_up[i+1])%up;
    }
    if(down)
    {
        mod_down[(int)ss.length()-1]=1%down;
        for(int i=(int)ss.length()-2;i>=0;i--)
            mod_down[i]=(2*mod_down[i+1])%down;
    }
    int bas_up=0,bas_down=0;
    for(int i=0;i<(int)ss.length();i++)
    {
        bas_up=(bas_up+(ss[i]=='1')*mod_up[i])%up;
        if(down)
            bas_down=(bas_down+(ss[i]=='1')*mod_down[i])%down;
    }
    for(int i=0;i<(int)ss.length();i++)
    {
        int res=0;
        if(ss[i]=='0')
        {
            int val=(bas_up+mod_up[i])%up;
            res=times[val]+1;
        }
        else
        {
            if(down==0) res=0;
            else
            {
                int val=(bas_down+down-mod_down[i])%down;
                res=times[val]+1;
            }
        }
        cout<<res<<'\n';
    }
    return 0;
}


Measured memory_bytes: 6084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int k;
cin>>k;

ll ans=0;
rep(i,k)rep(j,k)rep(s,k){
  ans+=gcd(gcd(i,j),s);
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

 	string s;
 	cin >> s;
 	int a = 0;
 	int b = 0;
 	int c = 0;
 	int d = 0;
 	for (auto t : s) {
 		if (t == 'N') {
 			a = 1;
 		}
 		if (t == 'S') {
 			b = 1;
 		}
 		if (t == 'W') {
 			c = 1;
 		}
 		if (t == 'E') {
 			d = 1;
 		}
 	}
 	if (a != b || c != d) {
 		cout << "No" << endl;
 	} else {
 		cout << "Yes" << endl;
 	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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 (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    string s;
    cin >> s;

    char c = s[0];
    for(int i =1; i < s.size(); ++i){
        if(c == s[i]){
            ppp("Bad");
            return 0;
        }
        c = s[i];
    }

    ppp("Good");

    return 0;
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  n++;
  ll ans=n-k+1;
  for(ll i=k;i<=n;i++){
    ans-=i*i;
    ans+=n*i;
    ans%=1000000007;
  }
  cout << ans << endl;
}

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

int main() {
  int S;
  cin >> S;
  
  vector<int> A(4);
  for (int i = 0; i < A.size(); i++){
    A.at(i) = S%10;
    S = S/10;
  }
  reverse(A.begin(), A.end());
  for (int a : A){
//    cout << a << endl;
  }
  
  if (A.at(0)+A.at(1)+A.at(2)+A.at(3)==7)
    cout << A.at(0) << "+" << A.at(1) << "+" << A.at(2) << "+" << A.at(3) << "=7" << endl;
  else if (A.at(0)+A.at(1)+A.at(2)-A.at(3)==7)
    cout << A.at(0) << "+" << A.at(1) << "+" << A.at(2) << "-" << A.at(3) << "=7" << endl;
  else if (A.at(0)+A.at(1)-A.at(2)+A.at(3)==7)
    cout << A.at(0) << "+" << A.at(1) << "-" << A.at(2) << "+" << A.at(3) << "=7" << endl;
  else if (A.at(0)+A.at(1)-A.at(2)-A.at(3)==7)
    cout << A.at(0) << "+" << A.at(1) << "-" << A.at(2) << "-" << A.at(3) << "=7" << endl;
  else if (A.at(0)-A.at(1)+A.at(2)+A.at(3)==7)
    cout << A.at(0) << "-" << A.at(1) << "+" << A.at(2) << "+" << A.at(3) << "=7" << endl;
  else if (A.at(0)-A.at(1)+A.at(2)-A.at(3)==7)
    cout << A.at(0) << "-" << A.at(1) << "+" << A.at(2) << "-" << A.at(3) << "=7" << endl;
  else if (A.at(0)-A.at(1)-A.at(2)+A.at(3)==7)
    cout << A.at(0) << "-" << A.at(1) << "-" << A.at(2) << "+" << A.at(3) << "=7" << endl;
  else if (A.at(0)-A.at(1)-A.at(2)-A.at(3)==7)
    cout << A.at(0) << "-" << A.at(1) << "-" << A.at(2) << "-" << A.at(3) << "=7" << endl;
}


Measured memory_bytes: 256
A, B, C, D, E, F = gets.chomp.split(" ").map(&:to_i)

limit = E.to_f / (100 + E)

tmp = 0
max_s =0
max_sw = 0
for a in 0..(F/100/A)
    for b in 0..((F-100*a*A)/100/B)
        next if a + b == 0
        for c in 0..((F-100*a*A-100*b*B)/C)
            for d in 0..((F-100*a*A-100*b*B-c*C)/D)
 #               printf "%d %d %d %d\n", a, b, c, d
                sw = c*C+d*D+a*A*100+b*A*100
                s = c*C+d*D
                n = s.to_f / sw
#                printf "%f\n", n 
                break if n > limit
                if tmp < n
                    tmp = n
                    max_s = s
                    max_sw = sw
                end
            end
        end
    end
end
if max_s > 0
    puts "#{max_sw} #{max_s}"
else
    puts "#{100*A} #{max_s}"
end

Measured memory_bytes: 1788
o,x,b;main(i,a){for(;~scanf("%*d%s"+!i*3,&a);i=o==3?o=b=x=!printf("%d\n",x):0)for(a%=6,a-5?b=b*2+1,x+=b/8,b&=7:o++;!a&b;b/=2)x++;}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int NS;
int S[MAX_N];
int NT;
int T[MAX_N];

// not the most left
int binarySearch(int A[], int N, int key){
	int left = 0;
	int right = N;
	while (left < right){
		int mid = (left + right) / 2;
		if (A[mid] == key) { return mid; }
		else if (key < A[mid]){ right = mid; }
		else { left = mid + 1; }
	}
	return -1;
}

int main() {

	cin >> NS;
	rep(i, NS){ cin >> S[i]; }
	cin >> NT;
	rep(i, NT){ cin >> T[i]; }

	int ret = 0;
	rep(i, NT){ 
		if (binarySearch(S, NS, T[i]) >= 0) ret++;
	}
	cout << ret << endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <numeric>
#define all(x) (x).begin(), (x).end()
#define rep(i, x) for (int i = 0; i < (x); ++i)
using namespace std;
using ll = long long;


int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p, q;
    priority_queue<ll> r;

    ll tmp;
    rep(i, a) {
        cin >> tmp;
        p.push_back(tmp);
    }
    rep(i, b) {
        cin >> tmp;
        q.push_back(tmp);
    }
    rep(i, c) {
        cin >> tmp;
        r.push(tmp);
    }
    sort(all(p));
    sort(all(q));
    reverse(all(p));
    reverse(all(q));

    priority_queue<ll, vector<ll>, greater<ll>> best;

    rep(i, x) best.push(p[i]);
    rep(i, y) best.push(q[i]);

    int n = (int)best.size();
    rep (i, n) {
        if (r.empty()) break;
        ll candidate = r.top(); // 候補の最大値
        ll element = best.top(); // 採用の最小値

        if (candidate > element) {
            r.pop();
            best.pop();
            best.push(candidate);
        }
    }

    ll ans = 0;
    while (!best.empty()) {
        ll val = best.top();
        ans += val;
        best.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4724
import java.util.Arrays;
import java.util.Scanner;

//Osaki
public class Main{

	int f(String s){
		String[] t = s.split(":");
		return Integer.parseInt(t[0])*3600+Integer.parseInt(t[1])*60+Integer.parseInt(t[2]);
	}
	
	class R implements Comparable<R>{
		int s, t;
		public R(int s, int t) {
			this.s = s;
			this.t = t;
		}
		public int compareTo(R o) {
			return s!=o.s?s-o.s:t-o.t;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			R[] r = new R[n*2];
			for(int i=0;i<n;i++){
				r[i] = new R(f(sc.next()), 1); r[i+n] = new R(f(sc.next()), 0); 
			}
			Arrays.sort(r);
			int res = 0, c = 0;
			for(int i=0;i<2*n;i++){
				if(r[i].t==1)c++;
				else c--;
				res = Math.max(res, c);
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int sum = 0;

			if (n == 0 && x == 0) {
				break;
			} else {
				for (int i = 1; i <= n; i++) {
					for (int j = i + 1; j <= n; j++) {
						for (int k = j + 1; k <= n; k++) {
							if (i + j + k == x) {
								sum++;
							}
						}
					}
				}
				System.out.println(sum);
			}
		}
	}
}


Measured memory_bytes: 26572
#include<iomanip>
#include<iostream>
#include<cmath>
using namespace std;

int main(void){
    double x,y,s,PI=3.1415926535;
    cin >> x >> y >> s;
    cout << fixed << setprecision(8) << 0.5 * x * y * sin(s*PI/180) << endl;
    cout << fixed << setprecision(8) << x + y + sqrt(pow(x,2) + pow(y,2) - 2*x*y*cos(s*PI/180)) << endl;
    cout << fixed << setprecision(8) << y * sin(s*PI/180) << endl;
    return 0;
}



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

l = input().split()

for i in range(len(l)):
    l[i] = int(l[i])

l.sort(reverse = True)

lmax = int(l[0])

lsum = 0

for i in range(len(l)):
    lsum += int(l[i])

lsum -= lmax

if(lmax < lsum):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int x,y;
  cin>>x>>y;
  cout<<x+y/2<<endl;
  return 0;
}


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

int main(){
  int n,whole=0,sum1=0,sum2=0,sa,mini;
  cin>>n;
  int w[n];
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  for(int i=0;i<n;i++){
    whole+=w[i];
  }
  mini=10000;
  sum2=whole;
  for(int i=0;i<n;i++){
    sum1+=w[i];
    sum2-=w[i];
    sa=abs(sum1-sum2);
    if(sa<=mini)mini=sa;
  }
  cout<<mini<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a.at(i);
  ll sum = 0;
  ll cnt1 = 0;
  rep(i,n) {
    if(i%2==0) {
      sum += a[i];
      if(sum>0) continue;
      else {
        cnt1 += (1-sum);
        sum = 1;
      }
    }
    else {
      sum += a[i];
      if(sum<0) continue;
      else {
        cnt1 += (sum+1);
        sum = -1;
      }
    }
  }
  sum = 0;
  ll cnt2 = 0;
  rep(i,n) {
    if(i%2==1) {
      sum += a[i];
      if(sum>0) continue;
      else {
        cnt2 += (1-sum);
        sum = 1;
      }
    }
    else {
      sum += a[i];
      if(sum<0) continue;
      else {
        cnt2 += (sum+1);
        sum = -1;
      }
    }
  }
  cout << min(cnt1,cnt2) << endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import Counter
s=input()
a=len(s)
counter = Counter(s[2:a-1])
if s[0]!="A":
  print("WA")
  
elif counter["C"]!=1:
  
    print("WA")
else:
  
  s[1:].replace("C","c",1)
  if s[1:].replace("C","c",1).islower()==False:
    print("WA")
  else:
    print("AC")



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

int coratz(int n) {
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;
} 
int main() {
	int s;
	cin >> s;
	set<int> h;
	h.insert(s);
	int a, b = s;
	int cnt = 1;
	while (true)
	{
		a = coratz(b);
		h.insert(a);
		cnt++;
		if (cnt != h.size()) break;
		b = a;
	}
	cout << cnt << endl;
	 
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

vector<lint> divisor(lint n) {
	vector<lint> ret;
	for (lint i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.emplace_back(i);
			if (i * i != n) ret.emplace_back(n / i);
		}
	}
	sort(ret.begin(), ret.end(), greater<lint>());
	return ret;
}

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, K;
	cin >> A >> B >> K;

	vector<lint> div;
	div = divisor(gcd(A, B));

	cout << div[K - 1] << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	int from1[200001] = {};
	int toN[200001] = {};
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		if(a == 1) from1[b]++;
		if(b == n) toN[a]++;
	}
	for(int i = 1; i <= n; i++){
		if(from1[i] > 0 && toN[i] > 0){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1792
// PCK2016予選７　イワシロ・イッツァ
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0341&lang=ja
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string T,B;
    int dp[1001][1001];
    cin >> T >> B;
 
    if(T[0]==B[0]){
        dp[0][0]=1;
    }
    else{
        dp[0][0]=0;
    }
    for(int j=1;j<T.size();j++){
       dp[0][j]=dp[0][j-1];
        if(T[j]==B[0]){
            dp[0][j]++;
        }
    }
 
    for(int i=1;i<B.size();i++){
        dp[i][0]=0;
        for(int j=1;j<T.size();j++){
            dp[i][j]=dp[i][j-1];
            if(B[i]==T[j]){
                dp[i][j]=(dp[i][j]+dp[i-1][j-1])%1000000007;
            }
        }
    }
    cout << dp[B.size()-1][T.size()-1] << endl;
}


Measured memory_bytes: 7140
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct etree { ll from, to, cost; };
struct people { ll v, k, year; };
bool comp(const etree& e1, const etree& e2) {
	return e1.cost < e2.cost;
}
bool comp2(const people& e1, const people& e2) {
	return e1.year < e2.year;
}
#define ALL(x) (x).begin(),(x).end()


int main() {
	int abc[27][200010] = { 0 };
	string s;
	cin >> s;
	ll ans = (s.size() - 1)*s.size() / 2 + 1;
	for (int i = 0;i < s.size();i++) {
		abc[(int)(s[i] - 'a')][i]++;
		for (int j = 0;j < 26;j++) {
			abc[j][i + 1] = abc[j][i];
		}
	}
	for (int i = 0;i < s.size() - 1;i++) {
		ans -= abc[(int)(s[i] - 'a')][s.size()] - abc[(int)(s[i] - 'a')][i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 21760
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]
  F[n] = F[n-1] + F[n-2]
  return F[n]

n = int(input())
for i in range(n+1):
  result = fib(i)
print(result)

Measured memory_bytes: 7656
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 101;

int w[N];

int main()
{
	fio;
	int n, s1 = 0, s2 = 0;
	cin >> n;
	for(int i=1; i<=n; i++)
	{
		cin >> w[i];
		s2 += w[i];
	}
	int ans = INF;
	for(int i=1; i<n; i++)
	{
		s1 += w[i];
		s2 -= w[i];
		ans = min(ans, abs(s2 - s1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
int main(){
    int k,s; cin>>k>>s;
    int rst = 0;
    rep(0,x,k+1){
        rep(0,y,k+1){
            if(x+y>=s-k && x+y <= s){
                rst++;
            }
        }
    }

    cout << rst << endl;
}

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

int n, a[200005];
int lt=1, rt, md, ans;

int f(int p) {
	int i, t;
	map<int,int> mp;
	if(p==1) {
		for(i=2; i<=n; i++) if(a[i] <= a[i-1]) return 0;
		return 1;
	}
	for(i=2; i<=n; i++) if(a[i] <= a[i-1]) {
		t = a[i];
		mp.erase(mp.upper_bound(t), mp.end());
		for(; t && mp[t]==p-1; t--) mp.erase(t);
		if(!t) return 0;
		else mp[t]++;
	}
	return 1;
}

int main() {
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	rt = n;
	while(lt<=rt) {
		md = lt+rt >> 1;
		if(f(md)) ans = md, rt = md-1;
		else lt = md+1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int N;
	scanf("%d", &N);
	int P;
	int min = 300000;
	int ans = 0;
	for (int x = 0; x < N; x++) {
		scanf("%d",&P);
		if (P < min) {
			ans++;
			min = P;
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String code = sc.nextLine().replace("\n", "");
        sc.close();

        for (int i = 1; i < code.length(); i++) {
            if (code.charAt(i - 1) == code.charAt(i)) {
                System.out.println("Bad");
                System.exit(0);
            }
        }
        System.out.println("Good");
    }
}


Measured memory_bytes: 22996
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;
 
int main()
{
    int w,h,n,x,y,z;
    cin>>w>>h>>n;
    bool a[w]={0},b[h]={0};
    rep(i,n) {
        cin>>x>>y>>z;
        if     (z==1) for(int i=0;i<x;i++) a[i]=1;
        else if(z==2) for(int i=x;i<w;i++) a[i]=1;
        else if(z==3) for(int i=0;i<y;i++) b[i]=1;
        else if(z==4) for(int i=y;i<h;i++) b[i]=1;
    }
    cout<<count(a,a+w,0)*count(b,b+h,0)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N , M; cin >> N >> M;
    vll A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    vvi Q(M, vi(2));
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        Q[i][0] = b; Q[i][1] = a; 
    }
    sort(Q.begin(),Q.end());
    ll h = 0;
    for(int i=M-1; i>=0; i--){
        ll c = 0;
        while(Q[i][0] > A[h]&&c < Q[i][1]){
            A[h] = Q[i][0];
            c++; h++;
        }
    }
    ll sum = 0;
    for(int i=0; i<N; i++){
        sum += A[i];
    }
    cout << sum;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e15;
const int MB = 20;
const int MOD = 1e9 + 7;


void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(all(a));
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] == a[j]) continue;
			for (int c = j + 1; c < n; c++) {
				if (a[i] != a[c] && a[j] != a[c] && a[c] < a[i] + a[j]) ans++;
			}
		}
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3656
import math

n = int(input())
s = input()

R, G, B = s.count("R"), s.count("G"), s.count("B")
ans = R * G * B

for i in range(n):
    for j in range(n):
        c1 = i
        c2 = i + j
        c3 = i + j * 2
        if c3 >= n: break
        if c1 == c2 == c3: continue
        if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]:
            ans -= 1

print(ans)
# 012 024 036 048
# 123 135 147 159

Measured memory_bytes: 73640
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp
# MOD=1000000007



# 優先度付きキュー
class PriorityQueue
  # 優先度付きキューのノードクラス
  class Node
    include Comparable
    attr_accessor :priority
    def initialize(priority)
      @priority=priority
    end
    def <=>(other)
      return @priority<=>other.priority
    end
  end

  def initialize
    @nodes = [nil]
  end

  # Nodeクラスのノードを保存する
  def <<(new_node)
    @nodes << new_node
    bubble_up(@nodes.size-1)
  end
  alias :push :<<

  # 最大優先度のノードを取り出す
  def >>
    return nil if empty?
    exchange(1,@nodes.size-1)
    max=@nodes.pop
    bubble_down(1)
    return max
  end
  alias :pop :>>

  def empty?
    return @nodes.size==1
  end


  # ヒープ内で適切な位置になるように要素を上に移動させる
  def bubble_up(index)
    parent_index=index/2
    return if index<=1
    return if @nodes[parent_index]>=@nodes[index]
    exchange(index, parent_index)
    bubble_up(parent_index)
  end
  # ヒープ内で適切な位置になるように要素を下に移動させる
  def bubble_down(index)
    child_index=index*2
    return if child_index>@nodes.size-1
    child_index+=1 if child_index<@nodes.size-1 && @nodes[child_index+1]>@nodes[child_index]
    return if @nodes[index]>@nodes[child_index]
    exchange(index,child_index)
    bubble_down(child_index)
  end
  
  # @nodes内のa番目の要素とb番目の要素を交換する
  def exchange(a,b)
    @nodes[a], @nodes[b] = @nodes[b], @nodes[a]
  end
end


N,M=gets.split.map(&:to_i)
task_part=Array.new(10**5+1){Array.new}
N.times do |i|
  a,b=gets.split.map(&:to_i)
  task_part[a-1] << b
end

PQ=PriorityQueue.new
ans=0

M.times do |t|
  task_part[t].each do |b|
    PQ << PriorityQueue::Node.new(b)
  end
  ans+=PQ.pop.priority if !PQ.empty?
end


puts ans

Measured memory_bytes: 16636
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int m,n;
	cin>>m>>n;
	int a[m+1];
	int f=0;
	for(int i=1;i<=m;i++)
	{
		a[i]=-1;
	}
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		if(a[x]==-1 || a[x]==y)
		a[x]=y;
		else
		f=1;
	}
	if(a[1]==0)
	f=1;
	if(m==1 && a[1]==-1)
	a[1]=0;
	else if(a[1]==-1)
	a[1]=1;
	
	if(m==1 && a[1]==0)
	f=0;
	if(f==1)
	{
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		if(a[i]==-1)
		a[i]=0;
		cout<<a[i];
	}
	return 0;
 } 

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

LL dfs(const LL H)
{
    if (H == 0)
        return 0;
    return 2 * dfs(H/2) + 1;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    LL H;
    while (cin >> H) {
        cout << dfs(H) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using ll = long long int;

constexpr double pi = 3.1415926535;

int main(int argc,char *argv[])
{
	double r;
	std::cin >> r;

	std::cout << std::fixed << std::setprecision(15) << 2.0 * pi * r << std::endl;

	return 0;
}


Measured memory_bytes: 3792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> matrix;

vector<int> edges[100005];
int dp[100005];
int par[100005];

int color[100005];
int n;

void bfs() {
  queue<int> q;
  for(int i = 1; i <= n; i++) if(color[i]) q.push(i);
  while(!q.empty()) {
    int curr = q.front();
    q.pop();
    for(int out: edges[curr]) {
      if(color[out] == 0) {
        color[out] = color[curr];
        q.push(out);
      }
    }
  }
}

void solve() {
  cin >> n;
  for(int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for(int i = 2; i <= n; i++) dp[i] = 1e9;
  queue<int> q;
  q.push(1);
  while(!q.empty()) {
    int curr = q.front();
    q.pop();
    for(int out: edges[curr]) {
      if(dp[out] == 1e9) {
        dp[out] = dp[curr] + 1;
        par[out] = curr;
        q.push(out);
      }
    }
  }
  vector<int> v;
  v.push_back(n);
  int curr = n;
  while(curr != 1) {
    curr = par[curr];
    v.push_back(curr);
  }
  reverse(v.begin(), v.end());
  for(int i = 0; i < v.size(); i++) {
    if(color[v[i]] == 0) color[v[i]] = 1;
    if(color[v[v.size()-1-i]] == 0) color[v[v.size()-1-i]] = -1;
  }
  bfs();
  int pos = 0;
  for(int i = 1; i <= n; i++) pos += color[i];
  if(pos > 0) cout << "Fennec\n";
  if(pos == 0) cout << "Snuke\n";
  if(pos < 0) cout << "Snuke\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 7672
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define ll long long
const int inf = 1000000000; // 10^9

int main(){
    ll n, k, h[210000];
    ll sum = 0;
    cin >> n >> k;
    rep(i, n) cin >> h[i];

    sort(h, h+n, greater<int>());
    for(int i = k; i < n; i++) sum += h[i];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    char str[105]={0};
    scanf("%s", str);
    long i;
    long x=0;
    long max=0;
    for(i=0; i<n; i++) {
        if(str[i]=='I') x++;
        else            x--;
        max=MAX(max,x);
    }
    printf("%ld\n", max);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int test[123456];
int main() {
	long long n, a, sum = 0, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; test[a]++;
	}
	for (int h = 1; h < 111111; h++) {
		if (test[h] > 0) { sum += test[h] - 1; }
	}
	cout << n - sum - (sum % 2) << endl;
	cin >> n;
}

Measured memory_bytes: 640