akhauriyash/Code-Regression huggingface dataset:
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(int i = 0; i < a; i++){
        cin >> p[i];
    }
    for(int i = 0; i < b; i++){
        cin >> q[i];
    }
    for(int i = 0; i < c; i++){
        cin >> r[i];
    }
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());
    vector<ll> all;
    for(int i = 0; i < x; i++){
        all.pb(p[i]);
    }
    for(int i = 0; i < y; i++){
        all.pb(q[i]);
    }
    sort(all.begin(), all.end());
    int idx1 = 0, idx2 = 0;
    while(idx1 < c && idx2 < (x + y)){
        if(all[idx2] < r[idx1]){
            all[idx2] = r[idx1];
            idx1++;
        }
        else{
            idx2++;
        }
    }
    ll res = 0;
    for(int i = 0; i < all.size(); i++){
        res += all[i];
    }
    cout << res << "\n";
    return;
}

 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4852
//Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num;
	S(int c, int t, int n) : cost(c), to(t), num(n){}
	bool operator>(const S &s) const {
		return cost > s.cost;
	}
};

const int INF = 1 << 30;
int c, n, m, s, d, ans;
int tocost[101][11];
vector<P> town[101];
priority_queue<S, vector<S>, greater<S> > pq;


void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.to].size(); i++){
			int tt = town[a.to][i].first, cc = town[a.to][i].second;
			if (tocost[tt][a.num] > cc + a.cost){
				tocost[tt][a.num] = cc + a.cost;
				pq.push({ cc + a.cost, tt, a.num });
			}
			if (a.num>0&&tocost[tt][a.num-1] > cc/2 + a.cost){
				tocost[tt][a.num-1] = cc/2 + a.cost;
				pq.push({ cc/2 + a.cost, tt, a.num-1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < 101; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			pq.push({ 0, s, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

Measured memory_bytes: 1236
x, n = map(int, input().split())
Ps = list(map(int, input().split()))

line = [0]*(102)
for p in Ps:
    line[p] = 1

for i in range(101):
    L, R = x-i, x+i
    if line[L] == 0:
        print(L)
        break
    if line[R] == 0:
        print(R)
        break


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
map<string,bool> maps;
main(){
  string s;
  string cpy;
  int flag=0;
  while(cin>>s){
    cpy="";
    for(int i=0;i<s.size();i++){
      if(s[i]!=','&&s[i]!=' '&&s[i]!='.'){
	cpy+=s[i];
      }
      else{
	if(!maps[cpy]&&cpy.size()>=3&&cpy.size()<=6){
	  if(flag){
	    cout<<" ";
	  }
	  cout<<cpy;
	  flag=1;
	  //maps[cpy]=true;
	}
	cpy="";
      }
    }
    if(!maps[cpy]&&cpy.size()>=3&&cpy.size()<=6){
      if(flag){
	cout<<" ";
      }
      cout<<cpy;
      flag=1;
      // maps[cpy]=true;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	
	int n, w[100], sum = 0, ans = 6000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
	}
	
	for (int i = 1; i < n; i++) {
		int mae = 0;
		for (int j = 0; j <= i; j++) {
			mae += w[j];
		}
		int ato = sum - mae;
		ans = min(ans, abs(ato - mae));
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for i in range(m):
  x,y = map(int,input().split())
  graph[x].append(y)
memo = [0]*(n+1)
done = [False]*(n+1)
for i in range(1,n+1):
  if len(graph[i]) == 0:
    done[i] = True
def cnt(i):
  if done[i]:
    return memo[i]
  else:
    l = []
    for j in graph[i]:
      l.append(cnt(j))
    memo[i] = max(l)+1
    done[i] = True
    return memo[i]
ans = [0]*n
for i in range(n):
  ans[i] = cnt(i+1)
print(max(ans))

Measured memory_bytes: 134048
n = int(input())
a = list(map(int, input().split()))

dp = [[0] * 2 for i in range(n + 1)]
dp[0][0] = 0
dp[0][1] = -10**10

for i in range(n):
    dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i])
    dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i])

print(dp[n][0])

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

int main()
{
	int n, num;
	string str;
	vector<int> S{ 1,2,3,4,5,6,7,8,9,10,11,12,13 };
	vector<int> H{ 1,2,3,4,5,6,7,8,9,10,11,12,13 };
	vector<int> C{ 1,2,3,4,5,6,7,8,9,10,11,12,13 };
	vector<int> D{ 1,2,3,4,5,6,7,8,9,10,11,12,13 };


	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> str >> num;

		if (str == "S")
		{
			S[num - 1] = 0;
		}
		else if (str == "H")
		{
			H[num - 1] = 0;
		}
		else if (str == "C")
		{
			C[num - 1] = 0;
		}
		else if (str == "D")
		{
			D[num - 1] = 0;
		}
	}

	for (int i = 0;i < 13;i++)
	{
		if (S[i] != 0)
		{
			cout << "S " << i + 1 << '\n';
		}
	}
	for (int i = 0;i < 13;i++)
	{
		if (H[i] != 0)
		{
			cout << "H " << i + 1 << '\n';
		}
	}
	for (int i = 0;i < 13;i++)
	{
		if (C[i] != 0)
		{
			cout << "C " << i + 1 << '\n';
		}
	}
	for (int i = 0;i < 13;i++)
	{
		if (D[i] != 0)
		{
			cout << "D " << i + 1 << '\n';
		}
	}


	return 0;
}


Measured memory_bytes: 3136
//by shubham_bitsg

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin>>s>>t;
    int c = 0;
    int len = s.length();
    forl(i,0,len) {
        if(s[i]!=t[i])
            c++;
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 3684
s = input()

ans = 0

if s == 'SUN':
  ans = 7
elif s == 'MON':
  ans = 6
elif s == 'TUE':
  ans = 5
elif s == 'WED':
  ans = 4
elif s == 'THU':
  ans = 3
elif s == 'FRI':
  ans = 2
elif s == 'SAT':
  ans = 1

print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;


int main(void){
	ios::sync_with_stdio(false);
	long i, j, k, count, N, a, a1, a2;
	cin >> N;
	long A[N], Y[N];
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	a = A[0];
	a1 = 0;
	a2 = 0;
	for (i = 1; i < N; i++) {
		if (i % 2 == 0) {
			a -= A[i];
		}
		else {
			a += A[i];
		}
	}
	Y[0] = a;
	for (i = 1; i < N; i++) {
		Y[i] = -1 * Y[i - 1] + 2 * A[i];
	}

	cout << Y[N - 1] << endl;
	for (i = 0; i < N - 1; i++) {
		cout << Y[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    int n = s.length();
    VI a(n);
    FOR(i, 0, n)a[i] = s[i] - '0';
    auto dp = vec<ll>(n + 1, 2);
    dp[0][0] = 1;
    FOR(i, 0, n)FOR(small, 0, 2) {
        (dp[i + 1][small || a[i] == 1] += dp[i][small]) %= mod;
        if (small || a[i] == 1) {
            (dp[i + 1][small] += dp[i][small] * 2 % mod) %= mod;
        }
    }
    cout << accumulate(all(dp[n]), 0LL) % mod << "\n";
}

Measured memory_bytes: 6224
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func main() {
	N := ReadInt()
	X := make([]int, N)
	Y := make([]int, N)
	P := make([]int, N)
	for i := 0; i < N; i++ {
		X[i], Y[i], P[i] = ReadInt(), ReadInt(), ReadInt()
	}

	xMin := make([][]int, 1<<N)
	yMin := make([][]int, 1<<N)
	for mask := 0; mask < 1<<N; mask++ {
		xMin[mask] = make([]int, N)
		yMin[mask] = make([]int, N)
		for i := 0; i < N; i++ {
			xMin[mask][i] = 1 << 62
			yMin[mask][i] = 1 << 62
		}
	}

	for mask := 0; mask < 1<<N; mask++ {
		for i := 0; i < N; i++ {
			xMin[mask][i] = Abs(X[i]) * P[i]
			yMin[mask][i] = Abs(Y[i]) * P[i]
			for j := 0; j < N; j++ {
				if mask>>j&1 == 1 {
					// i -> j のコスト
					xMin[mask][i] = Min(xMin[mask][i], Abs(X[i]-X[j])*P[i])
					yMin[mask][i] = Min(yMin[mask][i], Abs(Y[i]-Y[j])*P[i])
				}
			}
		}
	}

	ans := make([]int, N+1)
	for i := 0; i < N+1; i++ {
		ans[i] = 1 << 62
	}
	for xMask := 0; xMask < 1<<N; xMask++ {
		yAll := (1<<N - 1) ^ xMask
		for yMask := yAll; yMask >= 0; yMask-- {
			yMask &= yAll
			cost := 0
			for i := 0; i < N; i++ {
				cost += Min(xMin[xMask][i], yMin[yMask][i])
			}
			k := bits.OnesCount(uint(xMask | yMask))
			ans[k] = Min(ans[k], cost)
		}
	}

	for k := 0; k < N+1; k++ {
		fmt.Println(ans[k])
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 12120
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    ll a,b,c;
    string s;
    ll d[33]={0, 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
};
    cin >> a;
    cout << d[a] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  ll x;
  cin >> x;
  bool f=true;
  rep(i,200){
    rep(j,200){
      if(i*i*i*i*i+j*j*j*j*j==x&&f){cout << i << " "<< -j;f=false;}
      if(i*i*i*i*i-j*j*j*j*j==x&&f){cout << i << " "<< j;f=false;}
    }
  }
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;
	cin>>n;
	cout<<(n*n);
	
	return 0;
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, A[200000]; cin >> N;
	int xorsum = 0;
	REP(i, N){
		cin >> A[i];
		xorsum ^= A[i];
	}
	REP(i, N){
		cout << (xorsum ^ A[i]) << ' ';
	}
	cout << ln;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    //cout << "aaa" << endl;
    //cout << n << k <<endl;
    long min=0, max=0,count=0;
    long sum=0;
    if (n < k){
        cout << 1 << endl;
        return 0;
    }
    for (int l = 0; l < k; l++){
            min = min + l;
    }
    //cout << min <<endl;
    for (int l = n; l > n-k; l--){
            max = max + l;
    }
    //cout << max <<endl;
    count = max - min + 1;
    sum = sum + count;
    for (int i = k; i < n + 1; i++){
        //cout << min << endl;
        //cout << max << endl;
        min = min + i;
        max = max + n - i;
        count = max - min + 1;
        sum = sum + count;
        //cout <<sum<<endl;
        sum = sum % (1000000000+7);
        //cout << i << endl;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>

int main()
{
	int S;
	int n;
	
	scanf("%d", &n);
	
	int res = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &S);
		
		bool ok = false;
		for (int x = 1; x * x < S; x++){
			if ((S + x + 1) % (2 * x + 1) == 0){
				ok = true;
				break;
			}
		}
		res += !ok;
	}
	
	printf("%d\n", res);
	
	return (0);
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll a, b;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(a);
	qread(b);
	if(a <= b){
		puts("unsafe");
	} else {
		puts("safe");
	}
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, k;

int main() {
    cin >> n >> k;
    vector<long long> V(n, 0);
    for(int i = 0; i < n; ++i) cin >> V.at(i);

    int limit = min(n, k);
    long long vans = 0;
    for(int left = 0; left <= limit; ++left) {
        vector<long long> lvec;
        for(int i = 0; i < left; ++i) lvec.emplace_back(V.at(i));
        for(int right = 0; right <= limit-left; ++right) {
            vector<long long> ansvec;
            ansvec = lvec;
            for(int j = 0; j < right; ++j) ansvec.emplace_back(V.at(n-1-j));
            int dust = k-left-right;
            long long sum = 0;
            sort(ansvec.begin(), ansvec.end());
            int anslen = ansvec.size();
            for(int l = 0; l < min(anslen, dust); ++l) {
                if(ansvec.at(l) < 0) ansvec.at(l) = 0;
                else break;
            }

            for(int l = 0; l < ansvec.size(); ++l) sum += ansvec.at(l);
            chmax(vans, sum);
        }
    }
    cout << vans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1e9+7;

lint pow_mod(lint a,lint b,lint p){
  if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}

int main(){
  lint f[100001];
  f[0]=1;
  FOR(i,1,1e5+1){
    f[i]=f[i-1]*i;
    f[i]%=p;
  }
  lint N,K;
  cin>>N>>K;
  lint A[N];
  REP(i,N)cin>>A[i];
  lint ans=0;
  sort(A,A+N);
  REP(i,N){
    if(i<K-1)continue;
    ans+=(A[i]*(f[i]*inv_mod((f[K-1]*f[i+1-K])%p,p)%p)%p)%p;
    ans%=p;
  }
  REP(i,N){
    if(i>N-K)continue;
    ans-=(A[i]*(f[N-i-1]*inv_mod((f[K-1]*f[N-i-K])%p,p)%p)%p)%p;
    if(ans<0)ans+=p;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

int cmp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

void solve() {
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i].first >> a[i].second;

	sort(ALL(a), cmp);
	int t = 0;
	for (int i = 0; i < n; ++i) {
		t += a[i].first;
		if (t > a[i].second) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

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

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,k,ans=0,cnt=0; cin>>n>>k;
    vector<ll> sum(n+2,0);
    rep(i,n+1){
        cnt+=i+1;
        sum[i+1]=cnt;
    }
    for(int i=k;i<=n+1;i++){
        ans=(ans+sum[n+1]-sum[n+1-i]-sum[i]+1)%MOD;
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++)
  {
    cin >> c[i];
    for (int j = 0; j < m; j++)
    {
      cin >> a[i][j];
    }
    // for(int &j : a[i]){
    //   cin>>j;
    // }
  }

  int mn = (1 << 30);

  for (int b = 0; b < (1 << n); b++)
  {
    vector<int> v = {};
    for (int i = 0; i < n; i++)
    {
      if (b & (1 << i))
      {
        v.push_back(i);
      }
    }

    vector<int> u(m, 0);
    for (int i : v)
    {
      for (int j = 0; j < m; j++)
      {
        u[j] += a[i][j];
      }
    }

    bool ok = true;
    for (int i = 0; i < m; i++)
    {
      if (u[i] < x)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      int d = 0;
      for (int i : v)
      {
        d += c[i];
      }
      if (d < mn)
      {
        mn = d;
      }
    }
  }

  if (mn == (1 << 30))
  {
    cout << -1 << endl;
  }
  else
  {
    cout << mn << endl;
  }
}


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

typedef long long ll;

const int Maxn = 200005;

int n;
int a[Maxn];
set <int> S;
int mod;
ll res;

int getMax()
{
	return S.empty()? 0: *S.rbegin() + mod;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	if (a[0] > 0) { printf("-1\n"); return 0; } 
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < getMax()) { printf("-1\n"); return 0; }
		S.insert(a[i] - mod);
		while (!S.empty() && *S.begin() + mod <= 0) S.erase(S.begin());
		res += S.size();
		mod--;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main()
{
	string S;
	cin >> S;

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

	bool can = true;
	for (int i = 0; i < S.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; ++j) {
			string d = divide[j];
			if(S.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	int r = 0;
	int b = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R')r++;
		else if (S[i] == 'B')b++;
	}
	if (r > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main(){
  int n,ans=0;
  std::cin>>n;
  std::vector<int>a(n);
  for(int i=0;i<n;i++){
    std::cin>>a[i];
    while(a[i]%2==0){
      ans++;
      a[i]/=2;
    }
  }
  std::cout<<ans<<std::endl;
  return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
 string a;
  cin >> a;
  if(a == "RRS"||a=="SRR")cout << 2;
  else if(a=="SSS") cout << 0;
  else if(a=="RRR") cout << 3;
  else cout << 1;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int N;
    cin >>N;
        vector<ll > a(N, 0);


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

    }
    ll ans=1;
    ll  d = pow(10,18);
    for (int k = 0; k < N; ++k) {
        if(a[k] == 0 ){
            cout << 0 << endl;
            return 0;
        }

    }
    for (int j = 0; j < N; ++j) {
        ll b = a[j];
        if (ans > LLONG_MAX / b){
            ans = -1;
            break;
        }
        ans *=a[j];
        if(ans > d){
            ans = -1;
            break;
        }

    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
n = gets.to_i
t, a = gets.split(" ").map{|d|d.to_i}
puts gets.split(" ").map{|d|d.to_i}.zip((1..n).to_a).map {|h, i|
  [i, (t - h * 0.006 - a).abs]
}.min{|a,b|
  a[1] <=> b[1]
}[0]


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        char[] s = nsToChars();
        char[] t = nsToChars();
        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == t[i]) {
                count++;
            }
        }
        
        System.out.println(count);
    }
    

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 24148
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 2e5+7;
struct Monstor
{
    int h;
    int x;
    bool operator<(const Monstor&o)const 
    {
        return x < o.x;
    }
};
void discretize(vector<Monstor>& vec)
{
    sort(vec.begin(),vec.end());
}

long long flag[maxn];
int main()
{
    int n,d,a;
    cin>>n>>d>>a;
    vector<Monstor> vec(n);
    for(int i=0;i<n;++i)cin>>vec[i].x>>vec[i].h;
    discretize(vec);
    long long ans = 0;
    long long add = 0;
    for(int i=0;i<n;++i)
    {
        Monstor m = vec[i];
        add += flag[i];
        if(m.h - add <= 0) {
            continue;
        }
        long long rest = m.h - add;
        long long tim =  rest / a + (rest % a > 0);
        ans += tim;
        add += a * tim;
        Monstor o;
        o.x = m.x + d*2;
        int p = lower_bound(vec.begin(),vec.end(),o) - vec.begin();
        if(p < n)
        {
            if(vec[p].x > o.x)
            {
                flag[p] -= a*tim;
            }else {
                if(p+1<n)
                {
                    flag[p+1] -= a*tim;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H'){
		cout<<"H"<<endl;
	}
	else if(a=='H'){
		cout<<"D"<<endl;
	}
	else if(a=='D'&&b=='H'){
		cout<<"D"<<endl;
	}
	else if(a=='D'){
		cout<<"H"<<endl;
	}
}


Measured memory_bytes: 256
m = int(input())
for i in range(m):
    d = input()
    trains = [d]
    for j in range(1, len(d)):
        trains.extend([d[:j][::-1] + d[j:], d[:j] + d[j:][::-1], d[:j][::-1] + d[j:][::-1], d[j:] + d[:j], d[j:][::-1] + d[:j], d[j:] + d[:j][::-1], d[j:][::-1] + d[:j][::-1]])
    print(len(set(trains)))

Measured memory_bytes: 6848
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let mut n: i64 = read();
    let mut s = vec![];
    while n != 0 {
        if n % 2 == 0 {
            s.push(b'0');
        } else {
            n -= 1;
            s.push(b'1');
        }
        n /= -2;
    }
    s.reverse();
    println!(
        "{}",
        if s.is_empty() {
            "0".to_string()
        } else {
            String::from_utf8(s).unwrap()
        }
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll N, A, B, C, D; cin >> N >> A >> B >> C >> D; N--;
  ll K = (D*N - (B-A))/(D + C);
  if(D*N<(B-A)){
    cout << "NO" << endl; return 0;
  }
  ll dai = D*N - (D+C)*K;
  if((B-A) < dai - (D-C)*N) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
N = int(input())
x = int(input())
y = int(input())
A = [x, y]
if x < y:
    x, y = y, x
for i in range(N - 2):
    a = int(input())
    A.append(a)
    if x <= a:
        y = x
        x = a
    elif y < a:
        y = a
if x == y:
    for i in range(N):
        print(x)
else:
    for a in A:
        if a == x:
            print(y)
        else:
            print(x)


Measured memory_bytes: 16908
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
     mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
  int n;
  cin>>n;
  V<ll> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(all(a));
  mint ans=0;
  for(int i=0;i<n;i++){//Tを固定したときの総和
    int r=n-i-1;
    // i桁以降の１の個数の総和は
    //iより左の通り2^i に(その右の通り(各値は2^(r-1)、r個存在)とi桁目の通り(2^r)の和)を掛けたものになる
    mint tmp=mint(2).pow(r);
    if(r)tmp+=mint(2).pow(r-1)*mint(r);
    tmp*=mint(2).pow(i);
    ans+=tmp*(a[i]);
  }
  //Tを決め打ったときT xor S= XとなるSは一意に定まる
  //１つのTにつき T = X xor Sより　XとSのペアは2^n通り存在する
  //よってTを固定したっときの総和に2^nを書けると答えが求まる
   ans*=mint(2).pow(n);
   
   cout<<ans<<"\n";
}

Measured memory_bytes: 48640
n = input()

n1 = int(n[:2])
n2 = int(n[2:])

def date(n1, n2):
    if n1 == 0 and n2 == 0:
        return 'NA'
    if n1 >= 13 and n2 == 0:
        return 'NA'
    if n1 <= 12 and n2 == 0:
        return 'MMYY'
    if n1 == 0 and n2 >= 13:
        return 'NA'
    if n1 == 0 and n2 <= 12:
        return 'YYMM'
    if n1 >= 13 and n2 >= 13:
        return 'NA'
    if n1 >= 13 and n2 <= 12:
        return 'YYMM'
    if n1 <= 12 and n2 >= 13:
        return 'MMYY'
    if n1 <= 12 and n2 <= 12:
        return 'AMBIGUOUS'


print(date(n1, n2))

Measured memory_bytes: 3064
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    int_inputs = list(map(string_to_int, inputs))
    N = len(inputs) // 2
    reds = int_inputs[:N]
    blues = int_inputs[N:]

    reds.sort(key=lambda x: x[0])
    blues.sort(key=lambda x: x[0])

    count = 0
    for bi in range(N):
        candidates = []
        for ri in range(len(reds)):
            if blues[bi][0] > reds[ri][0] and blues[bi][1] > reds[ri][1]:
                candidates.append([ri, reds[ri][0], reds[ri][1]])
        if len(candidates) > 0:
            candidates.sort(key=lambda x: x[2])

            reds.pop(candidates[-1][0])
            count += 1

    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N*2))
    print(ret)


Measured memory_bytes: 3936
import heapq

def d_manhattan(node_list):
    s = 0
    for i in range(9):
        x_goal = i%3
        y_goal = i//3
        x_now = (node_list[i] - 1)%3
        y_now = (node_list[i] - 1)//3
        if y_now == -1:
            y_now = 2
        dx = abs(x_now - x_goal)
        dy = abs(y_now - y_goal)
        s += dx + dy
    return s

def moveNodeE(node_list, space):
    node_tmp = node_list[:]
    node_tmp[space], node_tmp[space + 1] = node_tmp[space + 1], node_tmp[space]
    return node_tmp
def moveNodeW(node_list, space):
    node_tmp = node_list[:]
    node_tmp[space], node_tmp[space - 1] = node_tmp[space - 1], node_tmp[space]
    return node_tmp
def moveNodeN(node_list, space):
    node_tmp = node_list[:]
    node_tmp[space], node_tmp[space - 3] = node_tmp[space - 3], node_tmp[space]
    return node_tmp
def moveNodeS(node_list, space):
    node_tmp = node_list[:]
    node_tmp[space], node_tmp[space + 3] = node_tmp[space + 3], node_tmp[space]
    return node_tmp

class board:
    def __init__(self, node_list, g):
        self.node = node_list
        self.space = node_list.index(0)
        self.g = g
        self.h = d_manhattan(node_list)
        self.f = self.g + self.h

    def makeBoard(self):
        space = self.space
        cost_now = self.f
        x_s = space%3
        y_s = space//3
        if x_s < 2:
            node_tmp = moveNodeE(self.node, space)
            yield board(node_tmp, self.g + 1)
        if x_s > 0:
            node_tmp = moveNodeW(self.node, space)
            yield board(node_tmp, self.g + 1)
        if y_s < 2:
            node_tmp = moveNodeS(self.node, space)
            yield board(node_tmp, self.g + 1)
        if y_s > 0:
            node_tmp = moveNodeN(self.node, space)
            yield board(node_tmp, self.g + 1)

b_open = []
n_close = {}
n_goal = [1,2,3,4,5,6,7,8,0]
n_start = []

for i in range(3):
    inp = list(map(int, input().split()))
    n_start.extend(inp)

b_start = board(n_start, 0)
heapq.heappush(b_open, (b_start.f, b_start.h, 0, b_start))

i = 0
while b_open:
    _, _, _, b_now = heapq.heappop(b_open)
    if b_now.node == n_goal:
        b_goal = b_now
        break
    n_close["".join(map(str, b_now.node))] = i
    for b_new in b_now.makeBoard():
        if "".join(map(str, b_new.node)) in n_close:
            continue
        heapq.heappush(b_open, (b_new.f, b_new.h, i, b_new))
        i += 1

print(b_goal.g)

Measured memory_bytes: 10208
N = int(input())

table = [[0]*10 for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    head, tail = int(s[0]), int(s[-1])
    table[head][tail] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[j][i]

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b;
    char op;
    
    while (1) {
        scanf("%d %c %d", &a, &op, &b);
        
        if (op == '?') {
            break;
        }else if (op == '+') {
            printf("%d\n", a+b);
        }else if (op == '-') {
            printf("%d\n", a-b);
        }else if (op == '*') {
            printf("%d\n", a*b);
        }else if (op == '/') {
            printf("%d\n", a/b);
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    string S;
    cin >>N>>K>>S;
    vector<ll>P;
    ll cnt=0;
    ll now=N-1;
    char n = S[0];
    rep2(i,N-1){
        if(S[i]!=n){
            now--;
        }
        n=S[i];
    }

    cout<<min(N-1,now+K*2)<<endl;





    return 0;
    

}

Measured memory_bytes: 3720
<?php
//$queueからarray_shift()でひとつ頭を取り出す。
//$ary[]に体節の並びを保持。体節の長さ分だけfor(foreach)でまわして $ary[$i] と $ary[$i+1] とを比較
//もし、色が違えば$queueに次階層の状態を追加($array_push)
//体節の色がすべて同じなら終了する。

$file_handle = fopen('php://stdin', "r");	//fopen()は同位フォルダにファイルがあればその名前のみでOK


//wfs
function wfs() {
	global $cnt;
	global $sec;
	global $ary_start;
	global $goal_flag;
	global $queue;

	$queue[0] = $ary_start;			//スタートを$queueに入れて開始
	$queue_size = count($queue[0]);	//キューの長さを取得
	$queue[0]['sec'] = 0;			//スタート時の秒数(階層の深さ)を入れる
	while (!empty($queue)) {		//$queueが1つ以上あればループ
	   $cur = array_shift($queue);	//配列$queueの頭から１つ取り出す。
	   
	   //終了条件。全ての配列が同じ色なら終了
	   $cnt = 0;	//カウントの初期化
	   for($i=0; $i<$queue_size; $i++){
	       if ($cur[$i] !== $cur[0]){ break; }
	       $cnt++;
	   }
	   if ($cnt === $queue_size) {
	       $goal_flag = 1;
	       $sec = $cur['sec'];	//ゴールした時の秒数
	       break;	//色がすべて同じならwhileを抜ける
	   }
	   
	   //探索
	    for($i=0; $i<$queue_size-1; $i++){
	    	if ($cur[$i] !== $cur[$i+1]){	//隣接する体節の色が違う場合
    			$new = $cur;
    			$new['sec'] = $cur['sec'] + 1;		//（バグ３に関して）キュー自身に階層情報を持たせるのが一番早い
	    		//変化する色ごとに場合分け
	    		if ($cur[$i] !== 'r' && $cur[$i+1] !== 'r'){	//次の階層で赤になる場合
	    			$new[$i] = 'r';  $new[$i+1] = 'r';
	    		} else if ($cur[$i] !== 'g' && $cur[$i+1] !== 'g'){
	    			$new[$i] = 'g';  $new[$i+1] = 'g';
	    		} else {
	    			$new[$i] = 'b';  $new[$i+1] = 'b';
	    		}
	    		$str = toString($new);
	    		if (empty($visited[$str])){	//未探索の場合。バグの原因２。この再訪防止処置が無いと同じパターンを何度も辿ることになり効率が非常に悪くなる
		    		array_push($queue, $new);
				    $visited[$str] = 1;		//pushしたキューを探索済みに追加
				}
	    	}
	    }
	    //$sec++;
	    //バグの原因３。一番嵌った場所。位置がNG。階層が進んだところでインクリメントする必要あり。
	    //これだとnodeをひとつ調べるたびに秒数が増えていってしまう。
	}
}

//再訪防止用。配列のキーに文字列を設定するために使用
function toString($ary){
	$str = '';
	foreach ($ary as $key => $val){
		if (is_numeric($key)) {		//配列のキーが数値ならば（secがあるので）
			$str = $str.$val;
		}
	}
	return $str;
}


while (1){
	//変数の初期化
	$cnt = 0;	//終了条件に使用
	$sec = 0;
	$goal_flag = 0;
	$queue = array();

	//ファイル読み込み
	$stdin = trim(fgets($file_handle));
	//終了条件
	if ($stdin == '0'){		//バグの原因１。 === とか == 0 だとバグ
		break;
	}
	$ary_start = str_split($stdin);
	

	//探索
	wfs();

	//出力
	if ($goal_flag === 1){
		echo $sec;
	} else {
		echo 'NA';
	}
	echo PHP_EOL;
}

fclose($file_handle);

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> monsters(N);
    for (int i = 0; i < N; i++)
    {
        cin >> monsters.at(i);
    }
    sort(monsters.begin(), monsters.end());
    ll answer = monsters.at(0);    
    for(int i = 0; i < N; i++)
    {
        ll prev = monsters.at(i);
        while(prev % answer)
        {
            ll tmp = answer;
            answer = prev % answer;
            prev = tmp;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1152