akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, t;
	cin >> n >> t;
	vector<pair<long long, long long>> a(n);
	for(int i = 0; i < n; ++ i){
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end(), [&](const pair<long long, long long> &x, const pair<long long, long long> &y){
		return x.first || y.first ? (x.second + 1) * y.first < (y.second + 1) * x.first : x.second < y.second;
	});
	vector<long long> dp{0};
	int i = 0;
	for(; i < n && a[i].first; ++ i){
		long long last = dp.back();
		for(int j = int(dp.size()) - 2; j >= 0; -- j){
			ctmin(dp[j + 1], (dp[j] + 1) * (a[i].first + 1) + a[i].second);
		}
		if((last + 1) * (a[i].first + 1) + a[i].second <= t){
			dp.push_back((last + 1) * (a[i].first + 1) + a[i].second);
		}
	}
	int res = 0;
	for(int j = 0; j < int(dp.size()); ++ j){
		int cur = j, sum = dp[j];
		for(int k = i; k < n; ++ k){
			if((sum += a[k].second + 1) <= t){
				++ cur;
			}
			else{
				break;
			}
		}
		ctmax(res, cur);
	}
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define N 200100
using namespace std;
int dp[N][2];
char s[N];
int main(){
	memset(dp,-1,sizeof(dp));
	dp[0][0]=dp[0][1]=0;
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;s[i];i++){
		if(i>=2){
			if(dp[i-2][0]>=0) dp[i][1]=max(dp[i][1],dp[i-2][0]+1);
			if(dp[i-2][1]>=0 && i>=4 && (s[i]!=s[i-2] || s[i-1]!=s[i-3])) dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
		}
		if(i>=1){
			if(dp[i-1][1]>=0) dp[i][0]=max(dp[i][0],dp[i-1][1]+1);
			if(dp[i-1][0]>=0 && i>=2 && s[i]!=s[i-1]) dp[i][0]=max(dp[i][0],dp[i-1][0]+1);
		}
		//printf("%d %d\n",dp[i][0],dp[i][1]);
	}
	printf("%d\n",max(dp[n][0],dp[n][1]));
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<pair<int,int> >arr(n);
	for(int i=0; i<n; i++)
	{
		int num;
		cin>>num;
		arr[i]=make_pair(num,i+1);
	}
	sort(arr.begin(),arr.end());
	for(int i=0; i<n; i++)
	{
		cout<<arr[i].second<<" ";
	}
	return 0;
}

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

int main(){
	long long a;
	cin>>a;
	for(int i=1;i<10;i++){
		if(a%i==0&&a/i<10){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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


int main(){
    
    ll a, b, c;
    cin >> a >> b >> c;
    
    ll ans = 0;
    for(;;ans++){
        if(a % 2 || b % 2 || c % 2)break;
        if(a == b && b == c){
            ans = -1;
            break;
        }
        ll A = (b + c) / 2;
        ll B = (a + c) / 2;
        ll C = (a + b) / 2;
        a = A;
        b = B;
        c = C;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, a, b, c, x;
  while (cin >> n >> a >> b >> c >> x, n) {
    vi y(n);
    rep(i, n) cin >> y[i];
    int p = 0;
    rep(i, 10001) {
      if (x == y[p]) p++;
      if (p == n) {
        cout << i << endl;
        goto next;
      }
      x = (a * x + b) % c;
    }
    cout << -1 << endl;
  next:;
  }
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll a = 0;
  ll b = 0;
  ll ans = 0;
  cin >> a >> b;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  a++;
  b++;
  for (ll i = 1; i < 41; i++) {
    ll b_one,a_one;
    b_one = (powl(2,i-1))*floorl((b/powl(2,i)));
    if( b%ll(powl(2,i)) > powl(2,i-1)) b_one += b%ll(powl(2,i))-powl(2,i-1);
    a_one = (powl(2,i-1))*floorl(((a-1)/powl(2,i)));
    if( (a-1)%ll(powl(2,i)) > powl(2,i-1)) a_one += (a-1)%ll(powl(2,i))-powl(2,i-1);
    if ((b_one-a_one)%2==1){
      ans += powl(2,i-1);
    }

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


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


int main() {
	long long N, M;

	/*
		464
		696
		464
	*/

	//よって裏を向いているカードの数は，(N-2) * (M-2) 枚

	cin >> N >> M;

	if(N * M == 1) {
		cout << 1 << endl;
	} else if(N == 1) {
		cout << max(M - 2, 0LL) << endl;
	} else if(M == 1) {
		cout << max(N - 2, 0LL) << endl;
	} else {
		cout << max((M - 2) * (N - 2), 0LL) << endl;
	}
}


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

typedef long long ll;
using namespace std;

int main()
{
  int N, M; cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; ++i) cin >> X[i];

  if (N >= M) {
    cout << 0;
    return 0;
  }

  sort(X.begin(), X.end());

  vector<int> diff(M-1);
  for (int i = 0; i < M-1; ++i) {
    diff[i] = abs(X[i] - X[i+1]);
  }

  sort(diff.begin(), diff.end());

  ll ans = 0;
  for (int i = 0; i <= M-N-1; ++i) {
    ans += diff[i];
  }

  cout << ans << endl;
}

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

using namespace std;

#define rep1(i,n) for(int i=1;i<=n;++i)

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;
  rep1(i,max(A,B+1)){
    if (A%i == 0 && B%i == 0){
      v.push_back(i);
    }
  }
  cout << v[v.size()-K] << endl;
}

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

#define MAX 100000
typedef long long ll;
int n,k;
ll T[MAX];

int check(ll P){
  int i=0;
  for(int j=0;j<k;j++){
    ll s = 0;
    while(s + T[i] <= P){
      s += T[i];
      i++;
      if(i == n) return n;
    }
  }
  return i;
}

ll solve(){
  ll left = 0;
  ll right = 100000 * 10000;
  ll mid;
  while(right-left>1){
    mid = (left+right)/2;
    int v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  cin >> n >> k;
  for(int i=0;i<n;i++) cin >> T[i];
  ll ans = solve();
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3888
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	int s = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	int cnt = s/(4*m);
	if(s%(4*m)) cnt+=1;
	int res = 0;
	for(int i=0;i<n;i++){
		if(a[i] >= cnt) res++;
	}
	if(res>=m){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <string>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;

int main()
{

    string S;

    cin >> S;


    if(S =="ABC"){


        cout << "ARC" << endl;

    }
    else{


        cout << "ABC" << endl;
        
    }



    

    

    
    return 0;
}

Measured memory_bytes: 3620
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll long long int
#define   dl double  
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
// Creates a min heap 
//priority_queue <int, vector<int>, greater<int> > pq; 
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll bigmod(ll a,ll b,ll cnt)
{
    ll x;
    if(b==0)
        return 1LL;
        else{
        x=bigmod(a,b/2LL,cnt);
        x=(x%cnt*x%cnt)%cnt;
        if(b%2LL==1LL)
            return (x%cnt*a%cnt)%cnt;
        else
        return x%cnt;
        }
}
ll dp[2000010];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ll a, b, c=0, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string str, str1, str2;
    scll(n);
    cin>>str;
    for(i=1;i<=200005;i++)
    {
        l1=__builtin_popcountll(i);
        dp[i]=1+dp[i%l1];
    }
    for(i=n-1;i>=0;i--)
    {
        if(str[i]=='1')
            cnt++;
    }
    if(cnt==0)
    {
        for(i=0;i<n;i++)
            cout<<1<<'\n';
    }
    else
    {
        if(cnt!=1){
    for(i=n-1;i>=0;i--)
    {
        ans1=(ans1%(cnt-1)+((str[i]-'0')*bigmod(2LL,n-i-1,cnt-1))%(cnt-1))%(cnt-1);
    }
    }
     for(i=n-1;i>=0;i--)
    {
        ans2=(ans2%(cnt+1)+((str[i]-'0')*bigmod(2LL,n-i-1,cnt+1))%(cnt+1))%(cnt+1);
    }

    for(i=0;i<n;i++)
    {
        if(str[i]=='1')
        {
            if(cnt==1)
            {
                cout<<0<<'\n';
            }
            else
            {
                cout<<1+dp[((ans1%(cnt-1)-bigmod(2LL,n-i-1,cnt-1)%(cnt-1))+(cnt-1))%(cnt-1)]<<'\n';
            }
        }
        else
        {

          cout<<1+dp[(ans2%(cnt+1)+bigmod(2LL,n-i-1,cnt+1)%(cnt+1))%(cnt+1)]<<'\n';
        }
    }
}
   // cout<<__builtin_popcountll(200005);



return 0;
}

Measured memory_bytes: 5256
import math
MOD = 10**9+7
s = [int(x) if x!="?" else -1 for x in input()]
n =len(s)
A=13
data=[4,3,12,9,10,1]*math.ceil(n/6)
data=data[-n:]

dp=[[0 for i in range(A+1)] for j in range(n+1)]
dp[0][0]=1

def benri(a,i,j):
	if j-a*data[i]%A>=0:
		re = j-a*data[i]%A
	else:
		re = j-a*data[i]%A+13
	return re

for i in range(n):
	for j in range(A+1):
		if s[i]!=-1:
			dp[i+1][j]=dp[i][benri(s[i],i,j)]%MOD

		else:
			for c in range(10):
				dp[i+1][j]+=dp[i][benri(c,i,j)]%MOD

			
			
# print(dp)
print(dp[n][5]%MOD)
				


Measured memory_bytes: 70528
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long binpow(long long a, long long b, long long m = mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	read(n);
	vpi p(n + 1);
	FOR (i, 1, n) cin >> p[i].fi >> p[i].se;
	sort(++all(p));
	
	int ans = 0, mx1 = -inf, mx2 = -inf;
	FORD (i, n, 1)
	{
	    int x = p[i].fi, y = p[i].se;
	    mx1 = max(mx1, x + y);
	    mx2 = max(mx2, x - y);
	    ans = max({ans, mx1 - (x+y), mx2 - (x-y)});
	}
	
	cout << ans;
}



















Measured memory_bytes: 6400
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	S = input()
	S = S[:-1]

	if S == "Sunny":
		print("Cloudy")
	elif S == "Cloudy":
		print("Rainy")
	else:
		print("Sunny")



if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
main = getContents >>= putStr . fout . treasure_hunt 0 0 (pi/2.0) . map fin . init . lines
fin s = (read $ takeWhile (/= ',') s, read $ tail $ dropWhile (/= ',') s)
fout = unlines . map (takeWhile (/= '.') . show)

treasure_hunt x y r [] = [x,y]
treasure_hunt x y r ((d,a):das) = treasure_hunt (x+(cos r * d)) (y+(sin r*d)) (r+r') das
 where r' = a * pi / (-180.0)

Measured memory_bytes: 4148
"""

https://atcoder.jp/contests/arc100/tasks/arc100_c

情報を再利用するのがメイン
K=Xの時は,K=X-1の時の答えに加え、 i or j == K の場合を考えればいい
or がKとなる場合、0の桁は両方0で、1の桁は片方が1ならよい
1では3通りの分け方があるので、3^N…

大きいほうから考えてみる？
最後は、当然最大のやつ2個→その2つのindex のORまではそれが保持

dp[X] = X と orしてもXのままのindexの集合における最大 & 2番目
→とすれば、1の桁全てに関して0にしてみた奴とXを見れば推移できる

O(2^N * logMAX(A)) で解けそうだ

"""

from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.append(float("-inf"))

dp = []
ans = 0
aaa = []

for i in range(2**N):

    if i == 0:
        dp.append( ( 0,-1 ) )
        continue

    na,nb = i,-1
    
    for j in range(N):

        if (2**j) & i > 0:

            ta,tb = dp[i ^ (2**j)]
            if A[na] < A[ta]:
                nb = na
                na = ta
            elif A[nb] < A[ta] and ta != na:
                nb = ta

            if A[nb] < A[tb]:
                nb = tb

    #print (i,na,nb)
    ans = max(A[na] + A[nb] , ans)
    aaa.append(ans)
    dp.append( ( na,nb ) )

print ("\n".join(map(str,aaa)))


Measured memory_bytes: 146040
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    int ans=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

cnt = [[0, 0] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        cnt[i][bool(v & (1 << i))] += 1


# print(cnt[:5])
sub = [[0, 0] for _ in range(60)]

# "001"
# "010"
# "011"

result = 0
for i, c in enumerate(cnt):
    for j, delete in enumerate(a[:-1]):
        target = not (delete & (1 << i))
        result += (c[target] - sub[i][target]) * (1 << i)

        # print(i, ":", int(target), c[target], result, sub[i], "->", sub[i][target])

        sub[i][not target] += 1

    # print(result)
    # print("-----")
    # if i > 5: break

# print(result)


# for p, delete in enumerate(a):
#     for i, cs in enumerate(cnt):
#         if delete & (1 << i):
#             target = 0
#         else:
#             target = 1
#
#         result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))


Measured memory_bytes: 139220
#include<iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main(){
  long long N, K;
  cin>>N>>K;
  long long A[N];
  for(long long i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A, A + SIZE_OF_ARRAY(A), std::greater<>());
  unsigned long long sum=0;
  for(long long i=K;i<N;i++){
    sum+=A[i];
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
dic={}
a=list(map(int,input().split()))
current=0
dic[0]=1
for i in range(n):
  current=(current+a[i])%m
  if current in dic:
    dic[current]+=1
  else:
    dic[current]=1
ans=0
for i in dic:
  ans+=(dic[i]*(dic[i]-1))//2
print(ans)

Measured memory_bytes: 62576
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

struct Horizontal {
	int pointA;
	int pointB;
};

inline static Horizontal perse_linecomb(string comb);

inline static Horizontal perse_linecomb(string comb) {
	Horizontal horizon;
	int canma_point = comb.find(",");

	horizon.pointA = stoi(comb.substr(0,canma_point));
	horizon.pointB = stoi(comb.substr(canma_point + 1));

	return horizon;
}

int main(void) {
	int vertical_num;
	int horizontal_num;

// enter number of vertical line
	// cout << "enter vertical line number:";
	cin >> vertical_num;
	vector<int> line(vertical_num);
	for(int i = 0; i < vertical_num; i++) {
		line.at(i) = i + 1;
	}

// enter number of horizontal line
	// cout << "enter horizontal line number:";
	cin >> horizontal_num;

//
	vector<Horizontal> horizontal_line(horizontal_num);
	// cout << "enter " << horizontal_num << " points" << endl;
	for(int i = 0; i < horizontal_num; i++) {
		string comb;
		// cout << i + 1 << " line: ";
		cin >> comb;
		horizontal_line.at(i) = perse_linecomb(comb);
	}

	for(const Horizontal &x : horizontal_line) {
		int temp;
		temp = line.at(x.pointA - 1);
		line.at(x.pointA - 1) = line.at(x.pointB - 1);
		line.at(x.pointB - 1) = temp;
	}

// print console
	for(int i = 0; i < vertical_num; i++) {
		cout << line.at(i) << endl;
	}

}



Measured memory_bytes: 3048
from bisect import bisect_right

x = int(input())
l = []

for i in range(2, 10):
    j = 1
    while j ** i <= 1000:
        y = j ** i
        if y not in l:
            l.append(y)
        j += 1

l.sort()
print(l[bisect_right(l, x)-1])

Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    int n;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        Deque<Integer> deque = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                deque.offerLast(sc.nextInt());
            } else {
                deque.offerFirst(sc.nextInt());
            }
        }
        if (n % 2 == 1) {
            for (int i = 0; i < n; i++) {
                System.out.print(deque.pollLast());
                if (i < n - 1) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.print(deque.pollFirst());
                if (i < n - 1) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                }
            }
        }
    }

    void solve() {
        Deque<Integer> deque = new LinkedList<>();

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 74040
#include<bits/stdc++.h>
using namespace std;
int n, a, b;
int cutbit(int x, int bit){
    int now = (x - ((x >> bit) << bit));
    int res = ((x >> (bit + 1)) << bit) + now;
    return res;
}
int ins(int x, int bit, bool c){
    int now = (x >> bit) << bit;
    x += (now << 1)  - now;
    return c ? (x ^ (1 << bit)) : x;
}
vector<int> go(int a, int b, int curbit){
    if(curbit == 0){
        return {a , b};
    }
    int idx = __builtin_ctz(a ^ b);
    int x = cutbit(a, idx); int y = cutbit(b, idx);
    int z = x ^ 1;
    auto u = go(x, z, curbit - 1) ;
    auto v = go(z, y, curbit - 1) ;

    if(a & (1 << idx)){
        for(int &i : u)
            i = ins(i, idx, true);
        for(int i : v)
            u.push_back(ins(i, idx, false));
    }
    else{
        for(int &i : u)
            i = ins(i, idx, false);
        for(int i : v){
            u.push_back(ins(i, idx, true));
        }
    }
    return u;
}

int main(){
    scanf("%d %d %d", &n, &a , &b);
    if(! ( (__builtin_popcount(a) % 2) ^ (__builtin_popcount(b) % 2) ))
        return !printf("NO");
    auto v = go(a, b, n - 1);
    printf("YES\n");
    for(int i = 0 ; i < (int)v.size() ; i++){
        printf("%d ", v[i]);
    }
}
/**

*/


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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];

    int cou=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-i-1;j++){
            if(a[j]>a[j+1]){
                swap(a[j],a[j+1]);
                cou++;
            }
        }
    }
    for(int i=0;i<n;i++)cout << a[i] << (i!=n-1?" ":"\n");
    cout << cou << endl;
}



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

using namespace std;
typedef long long ll;
const int MAXN = 200100;
const int P = (1 << 19);
const int MAXP = 2 * P + 100;

int N, K;
pair <ll, int> ps[MAXN];

int seg[MAXP];

void upd (int x)
{
    x += P;
    while (x)
    {
        seg[x]++;
        x /= 2;
    }
}

int cg (int x)
{
    int res = 0;
    x += P;
    while (x > 1)
    {
        if (x % 2 == 1)
            res += seg[x-1];
        x /= 2;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N >> K;
    ps[0] = make_pair (0, 0);
    for (int i = 0; i < N; i++)
    {
        int x; cin >> x;
        ps[i+1] = make_pair (ps[i].first + (x - K), i + 1);
    }
    N++;

    sort (ps, ps + N);
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += cg (ps[i].second);
        upd (ps[i].second);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6272
#include <stdio.h>
#define MAX 30

int main(){
	int ary[MAX];
	int w;//??????
	int n;//?¨????
	int left,right;
	int i;
	int tmp;

	scanf("%d",&w);
	scanf("%d",&n);

	for(i=0; i<w; i++)
		ary[i] = i + 1; 

	for(i=0; i<n; i++){
		scanf("%d,%d",&left,&right);
		tmp = ary[left-1];
		ary[left-1] = ary[right-1];
		ary[right-1] = tmp;
	}

	for(i=0; i<w; i++)
		printf("%d\n", ary[i]);

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int n;
    cin>>n;
    int b[n+2];
    for(int i = 1; i < n; i++)cin>>b[i];
    int sum = b[1] + b[n-1];
    for(int i = 1; i < n-1; i++)
    {
        if(b[i] > b[i+1])sum += b[i+1];
        else sum += b[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, sort)
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Ord
import Data.Coerce

sortDown :: forall a. Ord a => [a] -> [a]
sortDown = coerce (sort :: [Down a] -> [Down a])

exchangeOne :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
exchangeOne !gA !sA !bA !gB !sB !bB !n =
  let dg = gB - gA
      ds = sB - sA
      db = bB - bA
      l = sortDown $ filter (\(d,x) -> d > 0) [(dg, gA), (ds, sA), (db, bA)]
  in case l of
       [] -> n
       [(dx,xA)] -> let (qx,rx) = n `quotRem` xA
                        -- A で qx * gA 個のどんぐりを売却し、金 qx グラムを得る。
                        -- B で金 qx グラムを売却し、 qx * gB 個のどんぐりを得る。
                    in n + qx * dx
       [(dx,xA),(dy,yA)] -> maximum [ n + x * dx + y * dy
                                    | x <- [0..n `quot` xA]
                                    , let y = (n - x * xA) `quot` yA
                                    ]
       [(dx,xA),(dy,yA),(dz,zA)] -> maximum [ n + x * dx + y * dy + z * dz
                                            | x <- [0..n `quot` xA]
                                            , y <- [0..(n - x * xA) `quot` yA]
                                            , let z = (n - x * xA - y * yA) `quot` zA
                                            ]

main = do
  n <- readLn
  [gA,sA,bA] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  [gB,sB,bB] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ exchangeOne gB sB bB gA sA bA $ exchangeOne gA sA bA gB sB bB n


Measured memory_bytes: 2428
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0;true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void AnsYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void AnsYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}







//ここまでライブラリ
//ここから本文





int main() {
	string a, b;
	cin >> a >> b;
	int c = stoi(a + b);
	AnsYes((c == (int)sqrt(c) * (int)sqrt(c)));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;


int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<LL>> x(N,vector<LL> (3));
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            cin >> x[i][j];
        }
    }
    LL ans=-LINF;
    for(int k=0;k<(1<<3);k++){
        vector<LL> mx;
        for(int i=0;i<N;i++){
            LL t=0;
            for(int j=0;j<3;j++){
                if(k&(1<<j)) t+=x[i][j];
                else t-=x[i][j];
            }
            mx.pb(t);
        }
        sort(RAll(mx));
        ans=max(ans,accumulate(mx.begin(),mx.begin()+M,0LL));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    string n;
    cin >> n;
    if(n[0]=='7'||n[1]=='7'||n[2]=='7'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int h, w;
    cin>>h>>w;
    rep(i, h) {
        string s;
        cin>>s;
        cout<<s<<endl<<s<<endl;
    }
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


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

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3636
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())
T = str(input())

ans = float('inf')
for i in range(len(S)):
    count = 0
    flag = False
    for j in range(len(T)):
        if i+j >= len(S):
            flag = True
            break
        if S[i+j] != T[j]:
            count += 1
    if flag:
        continue
    else:
        ans = min(ans,count)

print(ans)

Measured memory_bytes: 68324
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  int a[100010] = {0}, b;
  for(int i = 0;i < n;i ++){
    scanf("%d",&b);
    a[b] ++;
  }

  int max = a[0] , temp;
  for(int i = 1;i < 100000;i ++){
    temp = a[i-1] + a[i] + a[i+1];
    if(temp > max){
      max = temp;
    }
  }

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

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int main(int argc, char* argv[])
{
	int n;
	scanf("%d", &n);
	deque<int> q;
	for (int i = 0; i < n; i++) {
		int j;
		scanf("%d", &j);
		if (i & 1) q.push_front(j);
		else q.push_back(j);
	}

	for (int i = 0; i < n; i++) {
		if (n & 1) {
			printf("%d ", q.back());
			q.pop_back();
		}
		else
		{
			printf("%d ", q.front());
			q.pop_front();
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2944
'use strict';

const main = arg => {
    const input = arg.trim().split('\n');
    const N = input[0];
    const S = input[1];
    let count = 0;
    for (let i = 0; i < 1000; i++) {
        let target = ('000' + i).slice(-3).split('').map(n => `[^${n}]*${n}`).join('');
        // ^[^1]*1[^2]*2[^3]*3
        let re = new RegExp(`^${target}`);
        if (S.match(re)) {
            count += 1;
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

const int maxn = 3e5 + 10;

int t[4 * maxn];

int st, ed, dt, res;

void get(int v, int l, int r) {
    if (l >= ed || r <= st) return;
    if (st <= l && r <= ed) {
        res = max(res, t[v]);
        return;
    }
    get(2 * v, l, (l + r) / 2);
    get(2 * v + 1, (l + r) / 2, r);
}

void upd(int v, int l, int r) {
    if (l >= ed || r <= st) return;
    if (st <= l && r <= ed) {
        t[v] = max(t[v], dt);
        return;
    }
    upd(2 * v, l, (l + r) / 2);
    upd(2 * v + 1, (l + r) / 2, r);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        st = a[i] - k, ed = a[i] + k + 1, res = 0;
        get(1, 0, maxn);
        st = a[i], ed = a[i] + 1, dt = res + 1;
        upd(1, 0, maxn);
    }
    cout << t[1] << "\n";
    return 0;
}


Measured memory_bytes: 13836
using System;
using System.Collections.Generic;

namespace ABC160e
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);
            int a = int.Parse(s[2]);
            int b = int.Parse(s[3]);
            int c = int.Parse(s[4]);

            var t = Console.ReadLine().Split(' ');
            List<long> p = new List<long>();
            for (int i = 0; i < a; i++)
            {
                p.Add(long.Parse(t[i]));
            }
            p.Sort();

            var u = Console.ReadLine().Split(' ');
            List<long> q = new List<long>();
            for (int i = 0; i < b; i++)
            {
                q.Add(long.Parse(u[i]));
            }
            q.Sort();

            var v = Console.ReadLine().Split(' ');
            List<long> r = new List<long>();
            for (int i = 0; i < c; i++)
            {
                r.Add(long.Parse(v[i]));
            }
            r.Sort();

            long max = 0;
            List<long> eat = new List<long>();
            for (int i = 0; i<x ; i++)
            {
                long z = p[p.Count - 1 - i];
                max += z;
                eat.Add(z);
            }

            for (int i = 0; i < y; i++)
            {
                long z = q[q.Count - 1 - i];
                max += z;
                eat.Add(z);
            }
            eat.Sort();

            int len = r.Count-1;
            for (int i = 0; i < eat.Count; i++)
            {
                long e = eat[i];
                if(len < 0) { break; }
                if (e < r[len])
                {
                    max += (r[len] - e);
                    len -= 1;
                }
            }
            Console.WriteLine(max);
        }
    }
}


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

str_list = input().split(' ')
a = [int(x) for x in str_list]

count = 0
tgt = 1
for n in range(N):
    if a[n]==tgt:
        count += 1
        tgt += 1
if count==0:
    print(-1)
else:
    print(N-count)


Measured memory_bytes: 25768
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
        var max = a.First();
        var min = a.Last();
        a = a.Skip(1).Take(n - 2).ToArray();
        StringBuilder builder = new StringBuilder();
        foreach (var item in a)
        {
            if (item > 0)
            {
                builder.AppendLine($"{min} {item}");
                min -= item;
            }
            else
            {
                builder.AppendLine($"{max} {item}");
                max -= item;
            }
        }
        builder.AppendLine($"{max} {min}");
        max -= min;
        Console.WriteLine(max);
        Console.Write(builder.ToString());
    }
}


Measured memory_bytes: 37344
n = gets.to_i
a = gets.split.map(&:to_i)
gets; m = gets.split.map(&:to_i)

list = {}
1.upto(n) do |i|
  a.combination(i).each do |e|
    list[e.inject(:+)] = nil
  end
end
m.each do |e|
  puts list.key?(e) ? 'yes' : 'no'
end

Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin >> s;
    int mn = INF;
    REP(i, SZ(s)) {
        string t = s.substr(i, 3);
        if (SZ(t) < 3) break;
        int x = stoi(t);
        chmin(mn, abs(x - 753));
    }
    cout << mn << endl;
    return (0^_^0);
}



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

int main(){
  lint N,ans=0;
  cin>>N;
  if((lint)sqrt(N)*(lint)sqrt(N)==N){
    ans=sqrt(N);
  }
  lint s=(lint)sqrt(N);
  if(ans==0){
    for(lint t=s;1LL<=t;t--){
      if(N%t==0){
        ans=N/t;
        break;
      }
    }
  }

  int cont=0;
  while(ans!=0){
    ans=ans/10LL;
    cont++;
  }

  cout<<cont<<"\n";
  return 0;
}


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

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  set<ll> st;
  st.insert(0);
  st.insert(n + 1);
  for (int i = 1; i <= n; i++) {
    ll l = *(--st.lower_bound(b[i])), r = *(st.upper_bound(b[i]));
    ans += (b[i] - l) * (r - b[i]) * (ll)i;
    st.insert(b[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12800
S=list(str(int(input())))
K=int(input())

if K!=1 and len(S)!=1 and int(S[0])==1:
    num1 = 0
    for i in S:
        if int(i)==1:
            num1 +=1
        else:
            break
    if K<=num1:
        print(1)
    else:
        print(S[num1])
else:
    print(S[0])

Measured memory_bytes: 3060
#require 'pp'

_ = gets
s1 = gets.chomp!
s = s1.chars

ans = Array.new(300)

head = 150
tail = 151

open_cnt = 0
close_cnt = 0
index = 0
while s.empty?.!
    c = s.shift
    if c == "("
        open_cnt += 1
    else
        if open_cnt > 0
            open_cnt -= 1
        else
            close_cnt += 1
        end
    end
end

#pp open_cnt
#pp close_cnt

close_cnt.times do |ch|
    print "("
end
print s1
open_cnt.times do |ch|
    print ")"
end
puts ""


Measured memory_bytes: 1788
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
  n <- getInt
  s <- BS.getLine

  dp <- IO.newArray ((0,0),(n+1,n+1)) 0 :: IO (IO.IOUArray (Int,Int) Int)
  v <- VM.new 1
  VM.write v 0 0

  forM_ [n-1,(n-2)..0] $ \ !i ->
    forM_ [n-1,(n-2)..(i+1)] $ \ !j ->
      when (BS.index s i == BS.index s j) $ do
        dpij <- IO.readArray dp (i,j)
        dpi1j1 <- IO.readArray dp (i+1, j+1)
        let nv = max dpij (dpi1j1 + 1)
        IO.writeArray dp (i,j) nv
        res <- VM.read v 0
        VM.write v 0 $ max res $ min nv (j-i)

  ans <- VM.read v 0
  print ans

Measured memory_bytes: 196604
#include<stdio.h>
int main(void){
	int x,c,counter=1;
	while(1){
		scanf("%d",&x);
		if(x==0){
			break;
		}
		printf("Case %d: %d\n",counter,x);
		counter++;
	}
	return 0;
}
		
		
		
		

Measured memory_bytes: 600
def main():
    _ = int(input())
    X = list(map(int, input().split()))
    min = 10**8
    i = 0
    cnt = 0

    while True:
        sum = 0
        for a in X:
            sum += (a - i) ** 2
        i += 1
        if sum < min:
            min = sum
            cnt += 1
        if i > cnt:
            break
    print(min)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060