akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     string s;
     cin>>s;
     int left=1e9;
     int right=-1;
     int n=s.length();
     for(int i=0;i<n;i++)
     {
     	    if(s[i]=='A')
     	    	left=min(left,i);
     	    if(s[i]=='Z')
     	    	right=max(right,i);
     }
     cout<<right-left+1<<endl;
     return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll x=__gcd(a,b);
    if(c%x==0)
    {
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;
typedef pair <int, int> pii;

typedef map <int, int> mii;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

int a, b, sum;

bool ok[MXN];

int main () {
    android;
    //freopen ("input.txt", "r", stdin);
    cin >> a >> b;
    for (int i = 1; i <= 999; i ++) {
        sum += i;
        if (sum < a) continue;
        if (sum - a == (sum + i + 1) - b) {
            cout << sum - a;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n;
	cin>>n;
	int now=1000;
	while(now<n)
	{
		now+=1000;
	 } 
	cout<<now-n<<endl;
	return 0;
}



Measured memory_bytes: 3648
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(N):
    A=list(map(int,input().split()))
    val=0
    for i,j in zip(A,B):
        val+=i*j
    if val+C>0:
        count+=1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int n,ans=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if((i+1)&1 && a[i]&1 )
            ans++;
    }
    cout<<ans;
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
    go();
    return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		
		// ?????????????????????
		Dise dise = new Dise();
		// ?????¢?????°??????????????????
		for(int i = 0; i < 6; i++) {
			dise._values[i] = scan.nextInt();
		}
		//??????????????°???????????????
		int q = scan.nextInt();
		// ???????????°????????°?????????
		for(int i = 0; i < q; i++) {
			// ??????
			int top = scan.nextInt();
			int front = scan.nextInt();
			boolean check = false;
			
			// ?¢????
			for(int i2 = 0; i2<4; i2++) {
				// ?????¢????¢????
				if (dise._values[1] == front) {
					// ?????¢????????£????????????????????¢??????????????§??????
					for(int i3 = 0; i3 < 4; i3++) {
						if (dise._values[0] == top) {
							System.out.println(dise._values[2]);
							check = true;
							break; //i3-1
						}
						else dise.MoveEast();
					}
				}
				else {
					dise.MoveSouth();
				}
				if (check == true) break; //i2
			}
			if (check == false) {
				dise.MoveEast();
				dise.MoveSouth();
				// ?????¢????¢????
				if (dise._values[1] == front) {
					// ?????¢????????£????????????????????¢??????????????§??????
					for(int i3 = 0; i3 < 4; i3++) {
						if (dise._values[0] == top) {
							System.out.println(dise._values[2]);
							check = true;
							break; // i3-2
						}
						else dise.MoveEast();
					}
				}
				else { 
					dise.MoveSouth();
					dise.MoveSouth();
					// ?????¢????????£????????????????????¢??????????????§??????
					for(int i3 = 0; i3 < 4; i3++) {
						if (dise._values[0] == top) {
							System.out.println(dise._values[2]);
							check = true;
							break; // i3-3
						}
						else dise.MoveEast();
					}
				}
			}
		}
		
	}
}

// ??????????????????
class Dise {

	public int _values[] = new int[6];
	
	public void Dice(int values[]) {
    	for (int i = 0; i < values.length; i++)
    	this._values[i] = values[i];
	}
    
    public enum ValueType
    {
        Top,
        Front,
        Right,
        Left,
        Back,
        Bottom
    }
    
    // memo 0:top, 1:front, 2:r, 3:l, 4:back, 5:bottom
    public void MoveWest()
    {
        int tmp = this._values[0];
        this._values[0] = this._values[2];
        this._values[2] = this._values[5];
        this._values[5] = this._values[3];
        this._values[3] = tmp;
    }
    public void MoveEast()
    {
        int tmp = this._values[0];
        this._values[0] = this._values[3];
        this._values[3] = this._values[5];
        this._values[5] = this._values[2];
        this._values[2] = tmp;
    }
    public void MoveNorth()
    {
        int tmp = this._values[0];
        this._values[0] = this._values[1];
        this._values[1] = this._values[5];
        this._values[5] = this._values[4];
        this._values[4] = tmp;
    }
    public void MoveSouth()
    {
        int tmp = this._values[0];
        this._values[0] = this._values[4];
        this._values[4] = this._values[5];
        this._values[5] = this._values[1];
        this._values[1] = tmp;
    }


}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m;
    cin>>n>>m;
    vector<P> p(m);
    rep(i,m) cin>>p[i].first>>p[i].second;
    vector<vector<int>> nu(n+1);
    rep(i,m){
        nu[p[i].first].push_back(p[i].second);
    }
    rep(i,n+1){
        nu[i].push_back(0);
        sort(btoe(nu[i]));
    }
    rep(i,m){
        int f=p[i].first, s=p[i].second;
        int sta=0, goa=nu[f].size()-1;
        int mid=(sta+goa)/2;
        while(goa-sta>1){
            if(nu[f][mid]<s) sta=mid;
            else goa=mid;
            mid=(sta+goa)/2;
        }
        int x=goa;
        cout<<f/100000<<(f/10000)%10<<(f/1000)%10<<(f/100)%10<<(f/10)%10<<f%10<<x/100000<<(x/10000)%10<<(x/1000)%10<<(x/100)%10<<(x/10)%10<<x%10<<endl;
    }
    return 0;
}

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

int n;
int a[200010];

bool check(int x){
	for (int l = n, r = n; l > 1; l--, r++){
		if ((a[l] >= x) == (a[l - 1] >= x)) return (a[l] >= x);
		if ((a[r] >= x) == (a[r + 1] >= x)) return (a[r] >= x);
	}
	return a[1] >= x;
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i < 2 * n; i++){
		scanf("%d", &a[i]);
	}
	int l = 1, r = 2 * n - 1;
	while (l < r){
		int mid = l + r + 1 >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
int N, X;
long long l[300010], r[300010], b[300010];

bool good(long long need) {
	long long extra = need % X;
	need /= X;
	if(need >= N) return true;

	long long sum = 0;
	vector <pair <long long, int>> v;
	for(int i = 1; i <= N; i++) {
		sum -= l[i] * b[i];
		v.emplace_back(r[i] * (X - b[i]) + l[i] * b[i], i);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for(int i = 0; i < need; i++) {
		sum += v[i].first;
	}
	if(extra == 0) return sum >= 0;
	long long ans = sum;
	for(int i = need; i < N; i++) {
		int id = v[i].second;
		long long diff = extra - b[id];
		ans = max(ans, sum + l[id] * diff + l[id] * b[id]);
		ans = max(ans, sum + r[id] * diff + l[id] * b[id]);
	}
	sum += v[need].first;
	for(int i = 0; i < need; i++) {
		int id = v[i].second;
		long long diff = extra - b[id];
		ans = max(ans, sum - r[id] * (X - b[id]) + l[id] * diff);
		ans = max(ans, sum - r[id] * (X - b[id]) + r[id] * diff);
	}
	return ans >= 0;
}

long long search(long long b, long long e) {
	if(b == e) {
		return b;
	}
	long long mid = (b + e) >> 1;
	if(good(mid)) {
		return search(b, mid);
	} else {
		return search(mid + 1, e);
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &N, &X);
	for(int i = 1; i <= N; i++) {
		scanf("%lld %lld %lld", &b[i], &l[i], &r[i]);
	}
	printf("%lld\n", search(0, 1LL * X * N));
	return 0;
}

Measured memory_bytes: 8788
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  int n = s.length();
  string ans;
  if (s[0] == s[n-1] && n % 2 == 0) ans = "First";
  else if (s[0] == s[n-1] && n % 2 == 1) ans = "Second";
  else if (s[0] != s[n-1] && n % 2 == 0) ans = "Second";
  else if (s[0] != s[n-1] && n % 2 == 1) ans = "First";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*

fun main(args : Array<String>) {
    println(inOutExec(null))
}

fun inOutExec(scanner: Scanner?): String {
    val (numOfPref, numOfCity) = readLine()!!.split(" ").map { it.toInt() }

    val citiesIn = mutableListOf<Pair<Int, Int>>()
    repeat(numOfCity) {
        val (pref, year) = readLine()!!.split(" ").map { it.toInt() }
        citiesIn.add(Pair(pref, year))
    }

    val cityCodeMap = citiesIn
            .asSequence()
            .groupByTo(mutableMapOf()) { it.first }
            .flatMap { entry -> entry.value
                    .sortedBy { info -> info.second }
                    .mapIndexed { index, pair ->
                        val sb = StringBuilder().append(pair.first.toString().padStart(6, '0'))
                                        .append((index+1).toString().padStart(6, '0'))
                        pair to sb.toString() }
            } // Pair<Pair<Int, Int>, String>
            .toMap()

    return citiesIn.joinToString(separator = "\n", postfix = "\n") { cityCodeMap[it]!! }
}


Measured memory_bytes: 122948
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)


struct Edge {
  int to, cost;
  Edge(int to, int cost) : to(to), cost(cost) {}
};

typedef vector<vector<Edge> > Graph;

int n, m;

void computeOrder(const Graph& dag, int v, vector<int>& orders, int& curOrder) {
  rep(ei, dag[v].size()) {
    Edge e = dag[v][ei];
    if (orders[e.to] == -1) {
      computeOrder(dag, e.to, orders, curOrder);
    }
  }
  orders[v] = --curOrder;
}

vector<int> topoSort(const Graph& dag) {
  int curOrder = n;
  vector<int> orders(n, -1);
  rep(v, n) if(orders[v] == -1) computeOrder(dag, v, orders, curOrder);
  vector<int> topoVerts(n);

  rep(v, n) topoVerts[orders[v]] = v;
  return topoVerts;
}

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

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(Edge(b, c));
  }

  vector<int> topoVerts = topoSort(g);
  vector<int> dist(n, 0);
  dist[0] = 0;  // start
  rep(i, n) {
    int v = topoVerts[i];
    rep(ei, g[v].size()) {
      Edge e = g[v][ei];
      dist[e.to] = max(dist[e.to], dist[v] + e.cost);
    }
  }

  cout << dist[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1220
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
	return x;
    else
	return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
	if(m%2)
	    r=(r*n)%p;
	n=(n*n)%p;
	m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
	if (n%i == 0 || n%(i+2) == 0)
	   return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
	if (i <= r)
	    z[i] = min (r - i + 1, z[i - l]);
	while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	    ++z[i];
	if (i + z[i] - 1 > r)
	    l = i, r = i + z[i] - 1;
    }
    return z;
}
int f(int x,vector<int>&a)
{
	int p=0;
	for(int i=0;i<a.size();i++)
	{
		p=p+x%a[i];
	}
	return p;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/     
   int n;
   cin>>n;
   int ans=0;
   while(n--)
   {
   	int x;
   	cin>>x;
   	ans=ans+x-1;
   }
   cout<<ans<<endl;
}      	


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

answer = 0
b_list = 0
for idx, moji in enumerate(S):
    if moji == "a" and answer < A + B:
        answer += 1
        print("Yes")
        continue
    elif moji == "b":
        b_list += 1
        if answer < A + B and b_list <= B:
            answer += 1
            print("Yes")
            continue
    print("No")


Measured memory_bytes: 4712
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <cassert>

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

using namespace std;

tuple<int, char> parsel(string s) {
    return make_tuple(s.size() - 1, s.back());
}
int c = 0;
int solve(int level,  const vector<tuple<int, char>>& code) {
    int l; char op; tie(l, op) = code[c]; c+=1;
    assert(level == l);
    if(isdigit(op)) {
        int num = op - '0';
        return num;
    }
    assert(op == '+' || op == '*');
    vector<int> vs;
    while (c < code.size() && get<0>(code[c]) > level){
        vs.push_back(solve(level + 1, code));
    }
    if (op == '+') {
        int res = 0;
        REP(i, vs.size()) res += vs[i];
        return res;
    }else{
        int res = 1;
        REP(i, vs.size()) res *= vs[i];
        return res;
    }
}
int main() {
    while(true) {
        int n; cin >> n;
        if (n == 0) break;
        vector<tuple<int, char>> code(n);
        REP(i, n) {
            string k; cin >> k;
            code[i] = parsel(k);
        }
        c = 0;
        cout << solve(0, code) << endl;
    }
}


Measured memory_bytes: 3136
//  Suraj Saste

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define mkp make_pair
#define in insert
#define fe first
#define se second
#define ms(x,i) memset(x,i,sizeof(x))
#define prec(x) cout<<std::setprecision(x)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll fpow(ll n, ll k, ll p=mod) {ll r=1; n=n%p; while(k>0){ if(k&1){ r=(r*n)%p; } k=k>>1; n=(n*n)%p; } return r;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}

int main()
{
	fast;
	ll n,k;cin>>n>>k;
	vector<bool> dp(k+1);
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	for(ll i=0;i<=k;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(i>=a[j]&&!dp[i-a[j]])
			{
				dp[i]=true;
			}
		}
	}
	if(dp[k])cout<<"First";
	else cout<<"Second";
	return 0;
}


Measured memory_bytes: 3676
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize
    }
    let ans = dfs(&vec![], n);
    println!("{}", ans);
}

fn dfs(d: &Vec<usize>, n: usize) -> usize {
    if n < vec_to_num(d) {
        return 0;
    }
    let mut res = 0;
    if (3..=7).step_by(2).all(|x| d.contains(&x)){
        res += 1;
    }
    for i in 0..3 {
        let mut nd = d.clone();
        nd.push(i * 2 + 3);
        res += dfs(&nd, n)
    }
    res
}

fn vec_to_num(d: &Vec<usize>) -> usize {
    let mut res = 0;
    for &i in d {
        res = res * 10 + i;
    }
    res
}

Measured memory_bytes: 2156
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N,M;

map<Int,Int> A;

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

    for(int i = 0;i < N;i++) {
        Int a;
        cin>>a;
        A[a]++;
    }

    for(int i = 0;i < M;i++) {
        Int b,c;
        cin>>b>>c;
        A[c] += b;
    }


    Int sum = 0;
    for(auto it = A.rbegin();it != A.rend();it++) {
        //cout<<it->first<<endl;
        if(it->second <= N)
            sum += (it->first)*(it->second);
        else {
            sum += (it->first)*N;
            break;
        }
        N -= it->second;
        if(N <= 0)
            break;
    }

    cout<<sum<<endl;

    return 0;
}



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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


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

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

    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int m1 = H1 * 60 + M1;
    int m2 = H2 * 60 + M2;

    int ans = m2 - m1 - K;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
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<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

string str;
ll a, b, c, n, m,x ,t;
vector<ll> v;

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	cin >> n >> x >> t;
	ll num = (n + x - 1) / x;
	cout <<  num * t << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()

const int MAX_N=5000;

// win[i]にjが含まれるならiはjに勝った
// win[i]にjが含まれるならiはjに負けた
vector<int> win[MAX_N+1];
vector<int> lose[MAX_N+1];

// 順位表
vector<int> ord;

// "順位は決定している"フラグ
int used[MAX_N+1]={0};

void tsort(int v){
    // "vの順位は決定した"フラグを立てる
    used[v]=true;
    for(int i=0; i<lose[v].size(); i++){
        if(!used[lose[v][i]]) tsort(lose[v][i]);
    }
    // vがordに追加される時点で，
    // vから到達可能な全ての頂点，すなわち，vより順位が高くないことが確定したチームは
    // 必ずordに追加されている
    ord.pb(v);
}

int main(){
    int n,m;cin>>n>>m;
    while(m--){
        //頂点w(winner), l(loser)を入力
        int w,l;cin>>w>>l;
        // win[w]にlを含める
        // lose[l]にwを含める
        win[w].pb(l);
        lose[l].pb(w);
    }

    // この時点では誰が1位か分からないので，
    // 誰かに勝っていれば，自分を1位としてトポロジカルソートを行う
    // 実際の順位と異なる可能性はあるが，
    // 与えられた情報だけに矛盾しなければいいのでこれでOK
    for(int i=1; i<=n; i++)
        if(!win[i].size()) tsort(i);

    // "他のソート結果が存在する"フラグ
    bool exi=0;
    for(int i=1; i<n; i++){
        // "i位のチームにi+1位のチームが勝った"という情報が与えられているか？
        bool ok=find(all(lose[ord[i]]), ord[i-1])==lose[ord[i]].end();
        // 与えられていればフラグを立てる
        exi|=ok;
    }

    // 出力
    for(int i=0; i<ord.size(); i++){
        cout<<ord[i]<<endl;
    }
    // 存在するかどうかを出力
    cout<<exi<<endl;
}

Measured memory_bytes: 2792
import Data.List
import Data.Maybe

solve :: [Int] -> [Int] -> [Int] -> Int
solve n p q = abs $ a - b
  where
    np = sort $ permutations n
    a = succ . fromJust $ elemIndex p np
    b = succ . fromJust $ elemIndex q np

main :: IO ()
main = do
    n <- readLn :: IO Int
    p <- map read . words <$> getLine :: IO [Int]
    q <- map read . words <$> getLine :: IO [Int]
    print $ solve [1..n] p q

Measured memory_bytes: 20988
N = int(input())
arr = list(map(int, input().split()))
if N == 0:
    if arr[0] == 1:
        print(1)
    else:
        print(-1)
    exit()
else:
    if arr[0] != 0:
        print(-1)
        exit()
sum_arr = [0]*N
sum_arr[0] = arr[-1]
for i in range(1,N):
    sum_arr[i] = sum_arr[i-1]+arr[N-i]
sum_arr = sum_arr[::-1]
ans = [0]*(N+1)
ans[0] = 1
for i in range(1,N+1):
    if ans[i-1]-arr[i-1] < 0:
        print(-1)
        exit()
    tmp = min((ans[i-1]-arr[i-1])*2,sum_arr[i-1])
    ans[i] = tmp
for i in range(min(25,N+1)):
    if ans[i] > 2**i:
        print(-1)
        exit()
if ans[N] != arr[-1]:
    print(-1)
    exit()
print(sum(ans))

Measured memory_bytes: 22216
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val s = sc.next()
    val one = s.count(_ == '1')
    val zero = s.count(_ == '0')

    println(math.min(one, zero) * 2)
  }

}


Measured memory_bytes: 30976
#include<iostream>
#include<string>
#define endl '\n'
using namespace std;




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

	int k;
	cin >> k;
	int r = k % 10;
	if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9)
		cout << "hon";
	else if (r == 0 || r == 1 || r == 6 || r == 8)
		cout << "pon";
	else
		cout << "bon";



	return 0;
}





Measured memory_bytes: 3652
a,b,c=map(int,input().split())
lst=[a,b,c]
lst.sort()
dif1=lst[2]-lst[1]
dif2=lst[2]-lst[0]
q1,mod1=divmod(dif1,2)
q2,mod2=divmod(dif2,2)
dif3=min(dif1,dif2)
if mod1==mod2:
  if mod1==0:
    print(q1+q2)
  else:
    print(q1+q2+1)
else:
  print(q1+q2+2)
  



Measured memory_bytes: 3060
def main():
    inputs = input().split()
    N, X = int(inputs[0]), int(inputs[1])
    L = list(map(int, input().split()))

    D_old = 0.0
    count = 1
    for l in L:
        D = D_old + l
        if D <= X:
            count += 1
        D_old = D
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-10;

int main(){
	int n, m;
	cin>>n>>m;
	vector<pii> v(m);
	rep(i, m) cin>>v[i].fi>>v[i].se;
	sort(all(v));

	int l = n + 1, r = 0;
	pii tmp;
	int ans = 0;
	for(int i = 0; i < m; i++){
		if(v[i].fi >= l && v[i].se <= r) continue;
		tmp = v[i];
		for(int j = i + 1; j < m; j++){
			if((tmp.fi >= v[j].fi || r + 1 >= v[j].fi)&& tmp.se <= v[j].se) tmp = v[j];
		}
		if(tmp.fi > r + 1){
			break;
		}
		ans++;
		//cout<<" "<<i<<" "<<tmp.fi<<" "<<tmp.se<<" "<<endl;
		l = min(l, tmp.fi);
		r = max(r, tmp.se);
	}
	if(l == 1 && r == n) cout<<ans<<endl;
	else cout<<"Impossible"<<endl;
	
}

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if ( x - r >= 0 && x + r <= W ) {
        if ( y - r >= 0 && y + r <= H )
        {
            cout << "Yes"s << endl ;
        } else {
            cout << "No"s << endl ;
        }
    } else {
        cout << "No"s << endl ;
    }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }

  cout << sum << endl;
}

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

int a, b, c;

int main ()
{
	scanf ("%d %d %d", &a, &b, &c);

	int ans = 0;
	while (true)
	{
		if (a % 2 != 0)
			break;

		if (b % 2 != 0)
			break;

		if (c % 2 != 0)
			break;

		if (a == b && b == c)
		{
			printf ("-1\n");
			return 0;
		}

		int x = a / 2;
		int y = b / 2;
		int z = c / 2;

		a = y + z;
		b = x + z;
		c = z + y;

		++ans;
	}

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

Measured memory_bytes: 256
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#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;
using namespace std;
int main()
{
    ll x,y,a,b,c,i,k,ca=0,cb=0,sum=0;
    vl v1,v2,v3;
    cin>>x>>y>>a>>b>>c;
    for(i=0 ; i<a ; i++)
    {
        cin>>k;
        v1.pb(k);
    }
    for(i=0 ; i<b ; i++)
    {
        cin>>k;
        v2.pb(k);
    }
    for(i=0 ; i<c ; i++)
    {
        cin>>k;
        v3.pb(k);
    }
    sort(v1.begin(),v1.end(),greater<int>());
    sort(v2.begin(),v2.end(),greater<int>());
    for(i=0 ; i<x ; i++)
    {
        v3.pb(v1[i]);
    }
    for(i=0 ; i<y ; i++)
    {
        v3.pb(v2[i]);
    }
    sort(v3.begin(),v3.end(),greater<int>());
    for(i=0 ; i<x+y ; i++)
    {
        sum+=v3[i];
    }
    cout<<sum<<endl;





    return 0;
}



Measured memory_bytes: 7536
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	int arr[n];
	int sum = 0, MIN = INT_MAX;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		sum += arr[i];
		if(arr[i] % 10){
			MIN = min(MIN, arr[i]);
		}
	}

	if(sum % 10){
		cout << sum;
		return 0;
	}
	else cout << (MIN == INT_MAX ? 0 : sum - MIN);

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, s{};
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i != N; ++i) {
    cin >> a[i];
    s += a[i];
    a[i] <<= 1;
  }
  a.pop_back();
  partial_sum(begin(a), end(a), begin(a));
  auto m = *min_element(begin(a), end(a),
                        [&](ll x, ll y) { return abs(s - x) < abs(s - y); });
  cout << abs(s - m) << endl;
}


Measured memory_bytes: 4840
n, x = map(int, input().split())

ans = 0
def rec(a,b):
    global ans
    if a > b:
        a,b = b,a
    if b%a == 0:
        k = b//a
        ans += (2*k-1)*a
    else:
        k = b//a
        ans += 2*k*a
        rec(a, b%a)
ans += n
rec(n-x,x)
print(ans)

Measured memory_bytes: 38384
import sys

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    solve()


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    dc = dict()

    for i in range(N):
        dc[i+1] = 0

    for i, a in enumerate(As):
        dc[a] += 1

    for value in dc.values():
        print(value)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39164
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FUP(i, a, b) for(int i = a; i <= b; i++)
#define FDOWN(i, a, b) for(int i = a; i >= b; i--)
#define MS(a, b) memset(a, b, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define CIN(a) cin >> a;
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a
#define COUT2(a, b) cout << a << ' ' << b
#define COUT3(a, b, c) cout << a << ' ' << b << ' ' << c
#define ENDL cout << '\n'
int dy[4] = { -1, 1, 0, 0 };
int dx[4] = { 0, 0, 1, -1 };

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

	int D, T, S;
	CIN3(D, T, S);
	if (S * T >= D) COUT("Yes");
	else COUT("No");

	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int n;
		cin >> n;

		vector<int> a( n );
		for( int i = 0; i < n; ++i ) { cin >> a[i]; }
		sort( a.begin(), a.end() );

		double x = a[n-1] / 2.0;
		double y = DBL_MAX;
		int r = 0;
		for( int i = 0; i < n-1; ++i ) {
			double t = abs( x - a[i] );
			if( t < y ) {
				y = t;
				r = i;
			}
		}

		cout << a[n-1] << ' ' << a[r] << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

#define max_n 100005
#define max_h 10002
int arr[max_n],n,k;
long dp[max_n];

long solve(int idx)
{
	if(idx==n-1)
	{
		return 0;
	}
	if(dp[idx]!=-1)
	{
		return dp[idx];
	}
	long best=LONG_MAX;
	for(int i=idx+1;i<=idx+k&&i<n;i++)
	{
		best=min(best,abs(arr[i]-arr[idx])+solve(i));
	}
	return dp[idx]=best;
}

signed main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	assert(2<=n<=max_n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	cout<<solve(0)<<endl;
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
using namespace std;
const int NK_MAX = 50;
int main (void) {
    int N;
    int K;
    int l[NK_MAX];
    int ans = 0;

    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> l[i];

    sort(l, l + N, greater<int>());

    for (int i = 0; i < K; i++) ans += l[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def resolve():
	a, b, c, x, y = map(int, input().split())
	v = float('inf')
	for i in range(10**5+1):
		t = i*c*2 + max([0, x-i])*a + max([0, y-i])*b
		v = min(v, t)
	print(v)
resolve()

Measured memory_bytes: 40940
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

cnt = 0
for i in t:
    l = 0
    r = n-1

    while l <= r:
        half = (l+r)//2
        if s[half] == i:
            cnt += 1
            break
        elif i < s[half]:
            r = half-1
        else:
            l = half+1

print(cnt)



Measured memory_bytes: 16712
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    ll n,m;
    scanf("%lld%lld",&n,&m);
    vector<pair<ll,ll>> a;
    ll x,y=1;
    for(int i=0;i<n;i++){
        scanf("%lld",&x);
        a.push_back({x,y});
    }
    for(int i=0;i<m;i++){
        scanf("%lld%lld",&x,&y);
        a.push_back({y,x});
    }
    sort(a.rbegin(),a.rend());
    debug(a);
    ll ans=0;
    int j=0;
    while(n>0){
        ans+=a[j].first*(min(n,a[j].second));
        n-=(min(a[j].second,n));
        j++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 7464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  for (int i=0; i < N; i++) {
    int l,r;
    cin >> l >> r;
    M += r - l + 1;
  }
  
  cout << M;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void)
{
    cin>>s;
    n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<n;j++)
            {
                if(s[j]=='F')
                {
                    printf("Yes");
                    exit(0);
                }
            }
        }
    }
    printf("No");
}

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

using namespace std;
using ll = long long;

int n;

const ll MOD = 998244353;

vector<pair<int, int>> ds;

ll dp[200005];

class Seg{
public:
    int seg[200005*4];

    void update(int targ, int val, int l=0, int r=200005, int idx=1){
        if(targ<l||targ>r) return;
        if(l==r){
            seg[idx] = val;
            return;
        }
        int mid = (l+r)/2;
        update(targ, val, l, mid, idx*2);
        update(targ,val, mid+1, r, idx*2+1);
        seg[idx] = max(seg[idx*2], seg[idx*2+1]);
    }

    int query(int x, int y, int l=0, int r=200005, int idx=1){
        if(x>r || y<l) return 0;
        if(x<=l && r<=y) return seg[idx];
        int mid = (l+r)/2;
        return max(query(x,y,l,mid, idx*2), query(x,y,mid+1,r,idx*2+1));
    }
} seg;

ll dp_dfs(int a){
    if(a>=n) return 1;
    if(dp[a]!=-1) return dp[a];
    int val = seg.query(a,a);
    return dp[a] = (dp_dfs(val) + dp_dfs(a+1))%MOD;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=0;i<n;i++){
        int x, d;
        cin>>x>>d;
        ds.emplace_back(x, d);
    }
    sort(ds.begin(), ds.end());
    memset(dp, -1, sizeof(dp));
    for(int i=n-1;i>=0;i--){
        auto p = ds[i];
        pair<int, int> q = {p.first+p.second, 0};
        int ub = upper_bound(ds.begin(), ds.end(), q) - ds.begin();
        if(ub==i+1){
            seg.update(i, i+1);
        }else{
            int val = seg.query(i+1, ub-1);
            seg.update(i, val);
        }
    }
    ll ans = dp_dfs(0);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 12912
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,t;
    cin >> n >> t;

    vector<LL> a(n),b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    LL ans = 1333;
    for(int i = 0; i < n; i++){
        if(b[i] <= t){
            ans = min(ans,a[i]);
        }
    }

    if(ans != 1333){
        cout << ans << endl;
    }else{
        cout << "TLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] != s[i+1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}
//Saw the editorial

Measured memory_bytes: 3712
#include<stdio.h>

#define MAX 500001

int heap;

void maxHeapify(int *, int);
void buildMaxHeap(int *);

int main(){
  int A[MAX];
  int i;

  scanf("%d",&heap);
  for(i=1;i<=heap;i++) scanf("%d",&A[i]);

  buildMaxHeap(A);

  for(i=1;i<=heap;i++) printf(" %d",A[i]);
  printf("\n");
  
  return 0;
}

void maxHeapify(int *A, int i){
  int left,right,largest,tmp;

  left=2*i;
  right=left+1;

  if(left<=heap && A[left]>A[i]) largest=left;
  else largest=i;
  if(right<=heap && A[right]>A[largest]) largest=right;

  if(largest!=i){
    tmp=A[largest];
    A[largest]=A[i];
    A[i]=tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;

  for(i=heap/2;1<=i;i--) maxHeapify(A,i);
}



Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    private long[][] combos;

    private void generateCombos(int n) {
        combos = new long[n + 1][n + 1];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    combos[i][j] = 1L;
                } else {
                    combos[i][j] = combos[i - 1][j - 1] + combos[i - 1][j];
                }
            }
        }
    }

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        Long[] values = new Long[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextLong();
        }
        Arrays.sort(values, Collections.reverseOrder());
        generateCombos(n);

        double sum = 0.0;
        for (int i = 0; i < a; i++) {
            sum += values[i];
        }
        System.out.println(String.format("%.6f", sum / a));

        int cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < n; i++) {
            if (values[i].equals(values[a - 1])) {
                cnt1++;
                if (i < a) {
                    cnt2++;
                }
            }
        }
        long result = 0L;
        if (values[0].equals(values[a - 1])) {
            for (int i = a; i <= b; i++) {
                result += combos[cnt1][i];
            }
        } else {
            result = combos[cnt1][cnt2];
        }
        System.out.println(result);
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}

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

int main(){
    int n;
    int m;
	cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < m; i++){
      	int x;
      	cin >> x;
      	sum += x;
    }
    if(n < sum){
    	cout << "-1" << endl;
    }else{
      	cout << (n - sum) << endl;  
    }
	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,x,count=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(500*i+100*j+k*50==x)
				count++;
			}
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string a,b;
  std::cin >> a >> b;

  if(a == b)
    std::cout << "EQUAL" << '\n';
  else if(a < b || a.size() < b.size())
    std::cout << "LESS" << '\n';
  else
    std::cout << "GREATER" << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    try {
      final int n = scanner.nextInt();
      final int a = scanner.nextInt();
      final int b = scanner.nextInt();
      final int[] cnt = new int[3];

      for (int i = 0; i < n; i++) {
        final int p = scanner.nextInt();
        int j = 0;
        if (a < p) j++;
        if (b < p) j++;
        cnt[j]++;
      }

      OptionalInt ans = Arrays.stream(cnt).min();
      System.out.print(ans.getAsInt());
    } finally {
      scanner.close();
    }
  }
}


Measured memory_bytes: 27732