akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000000];
int m[1000000];
int s[1000000];

int isPrime(int x){
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i += 2){
		if (x%i == 0) return 0;
	}
	return 1;
}


int main(){
	int n; int x; int temp = 0;
	for (int i = 0; i <= 1000000; i++){
		s[i] = isPrime(i);
	}
	while (cin >> n >> x, n, x){
		memset(a, 0, sizeof(a));
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; i++){
			cin >> a[i];
			m[a[i]] = 1;
		}
		for (int i = 0; i <= x; i++){
			if (m[i] == 1){
				for (int j = 0; j < n; j++){
					if (x >= a[j] + i){
						m[a[j] + i] = 1;
					}
				}
			}
		}
		bool flag = false;
		for (int i = x; i >0; i--){
			if (m[i] == 1 && s[i] == 1){
				cout << i << endl;
				flag = true;
				break;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 12884
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans=0;
  cin>>N;
  pvec v(N);
  rep(i,N){
    cin>>H>>W;
    v[i]=datas(H+W,H-W);
  }
  vsort(v);
  j=-inf;
  rep(i,N){
    if(j<=v[i].second){
      j=v[i].first;
      ans++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int main() {
   // freopen("in.cpp","r",stdin);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)if(s[i]==',')s[i] = ' ';
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();

    	Long[] L=new Long[N+1];

    	L[0]=2l;
    	L[1]=1l;

    	for(int i=2;i<L.length;i++) {
    		L[i]=L[i-1]+L[i-2];
    	}

    	System.out.println(L[N]);

    }


}



Measured memory_bytes: 21844
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int h = s.nextInt();
    int w = s.nextInt();
    System.out.println((n-h+1)*(n-w+1));
  }
}

Measured memory_bytes: 21076
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
//x.substr(start, length);
/*
// Create a vector containing n 
//vectors of size m.  
    vector<vector<int> > vec( n , vector<int> (m, 0));  
*/
struct type{
    int k, i, j;
};
//to check if a no is prime or not?
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k)
{
	int window_sum = 0;
	int min_window = INT_MAX;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		window_sum += arr[i];
		if (i + 1 >= k)
		{
			if (min_window > window_sum)
			{
				min_window = window_sum;
				last = i;
			}
			window_sum -= arr[i + 1 - k];
		}
	}
	int sum=0;
	for(int i=last-k+1;i<=last;i++)
	{
	    sum+=arr[i];
	}
	return sum;
}
signed main() 
{
    fastio;
    //cout << fixed << setprecision(0);
    char c;
    cin>>c;
    cout<<char(c+1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	ini(n1);
	ini(L);
	ll dp[430][430];
	ll cost[430][430];
	FOR(i,0,n)FOR(i1,0,n){dp[i][i1] = (i == i1?0:INF);}
	FOR(i,0,n1){
		ini(x);
		ini(x1);
		ini(x_);
		dp[x-1][x1-1] = dp[x1-1][x-1] = x_;
	}
	FOR(k,0,n)FOR(i,0,n)FOR(i1,0,n){dp[i][i1] = min(dp[i][i1],dp[i][k]+dp[k][i1]);}
	FOR(i,0,n)FOR(i1,0,n){cost[i][i1] = (i == i1)?0:(dp[i][i1]<=L?1:(1LL<<20));}
	FOR(k,0,n)FOR(i,0,n)FOR(i1,0,n){cost[i][i1] = min(cost[i][i1],cost[i][k]+cost[k][i1]);}
	ini(q);
	while(q--){
		ini(x);
		ini(x1);
		if(cost[x-1][x1-1]>4300)out(-1);
		else{
			out(cost[x-1][x1-1] - 1);
		}
	}
	return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	vector<long> A(3);
	for (int i=0; i<3; i++)
		cin >>A.at(i);
	long S=1;
	for (int i=0; i<3; i++)
		S *=(A.at(i)%2);
	if (0==S) {
		cout <<0 <<endl;
		return 0;
	}
	sort(A.begin(), A.end());
	cout <<A.at(0)*A.at(1) <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };

};

int a,b,c,d,i,n,m,e,k,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[555];
long long l[71];
int s[1];
long long x,y,z,mod=1000000007,hf=(mod+1)/2;

//string r,r1;
char r[361];
vector<int> v[200101];
P u[1];
queue<int> q;
//set<int> s[2];
//stack<int> s;
map<int,int> p;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng()
bool as(P a,P b)
{
  return a.x<b.x;
}


int main()
{
  int ttt;
  scanf("%d",&ttt);
  for(int tt=1;tt<=ttt;tt++)
  {
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
      scanf("%lld",&o[t]);
    memset(l,0,sizeof(l));
    scanf("%s",r+1);
    for(int t=a;t;t--)
    {
      long long s=1,x=o[t];
      for(int i=62;i>=0;i--)
      if((x&(s<<i))&&l[i])
        x^=l[i];
      if(r[t]=='0')
      {
        for(int i=62;i>=0;i--)
        if(x&(s<<i))
        {
          l[i]=x;
          break;
        }
      }
      else if(x)
      {
        puts("1");
        goto qwe;
      }
    }
    puts("0");
    qwe:;
  }
}



Measured memory_bytes: 8284
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;

    vec cnt(N, 0);
    REP(i, N) cnt[A[i] - 1]++;
    Sort(cnt);
    vec S(N + 1, 0);
    REP(i, N) S[i + 1] = S[i] + cnt[i];

    vec F(N + 2);
    FOR(x, 1, N + 1){
        int i = Upper_bound(cnt, x);
        F[x] = (S[i] + x * (N - i)) / x;
    }
    F[N + 1] = 0;

    vec ans(N + 1, 0);
    IFOR(x, 1, N + 1){
        IFOR(k, F[x + 1] + 1, F[x] + 1) ans[k] = x;
    }

    FOR(i, 1, N + 1) Out(ans[i]);

    return 0;
}


Measured memory_bytes: 12544
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int powmod(int a, int p, int mod) {
    int ans = 1;
    int mul = a;

    for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
        if ((p & 1) == 1) ans = (ans * mul) % mod;
    }

    return ans;
}

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

    int fact = 1;
    for (int i = 1; i <= N; i++) {
        fact *= i;
        fact %= MOD;
    }

    int S[N];
    S[0] = 1;
    for (int i = 1; i < N; i++) {
        S[i] = S[i-1] + powmod(i + 1, MOD - 2, MOD);
        S[i] %= MOD;
    }

    int ret = 0;
    for (int i = 0; i < N; i++) {
        ret += (((score[i] * fact) % MOD) * (S[i] + S[N - 1 - i] - S[0] + MOD)) % MOD;
        ret %= MOD;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int f=1;
    string s;
    cin>>s;
    if(s[0]!='A'){
        f=0;
    }
    else
    {
        s[0]='a';
    }
    int c=0;
    int n=s.length();
    for(int i=2;i<n-1;++i)
    {
        if(s[i]=='C')
        {
            ++c;
            s[i]='c';
        }
    }
    if(c!=1)
        f=0;
    for(int i=0;i<n;++i)
    {
        if((int)(s[i])<96)
        f=0;

    }
    if(f)
        cout<<"AC";
    else
        cout<<"WA";
} 

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

int main(){
  int N;
  cin>>N;
  int a[N];
  map <int,long long> mp;
  for(int i=0;i<N;i++){
    cin>>a[i];
    mp[a[i]]++;
  }
  if((a[0]!=0)||(mp[0]!=1)){
    cout<<0<<endl;
    return 0;
  }
  int si=mp.size();
  long long ans=1;
  sort(a,a+N);
  int maxa=0;
  for(int i=0;i<N;i++){
    maxa=max(maxa,a[i]);
  }
  if(maxa!=si-1){
    cout<<0<<endl;
    return 0;
  }
  for(int i=2;i<si;i++){
    for(int j=0;j<mp[i];j++){
      ans=(ans*mp[i-1])%998244353;
    }
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 6912
N,H=map(int,input().split())
a,b=[0]*N,[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())

a.sort(reverse=True)
b.sort(reverse=True)

def count(n):
    damage=0
    cnt=0
    for i in range(n):
        cnt+=1
        damage+=b[i]
        if damage>=H:
            return cnt
    
    cnt -= (-(H-damage))//a[0]
    return cnt

for i in range(N):
    if b[i]>a[0]:
        continue
    else:
        print(count(i))
        exit()
print(count(N))

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

using namespace std;

const int INF = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int> > v(n, vector<int>(3, 0)), dp(n, vector<int>(3, 0));

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 3; ++j)
            cin >> v[i][j];

    dp[0][0] = v[0][0], dp[0][1] = v[0][1], dp[0][2] = v[0][2];

    for(int i = 1; i < n; ++i)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + v[i][2];
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';

}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //srand (time(0));

    solve();
}






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

int A[1000005],n;

int binarysearch(int key)
{
    int left=0,right=n;
    int mid=(left+right)/2;
    while(left<right)
    {
        mid=(left+right)/2;
        if(A[mid]==key)
        {
            return 1;
        }
        else if(A[mid]<key)
        {
            left=mid+1;
        }
        else
        {
            right=mid;
        }
    }
    return 0;
}

int main()
{
    int key,i,q;
    int cnt=0;
    cin>>n;
    for(i=0;i<n;++i)
    {
        cin>>A[i];
    }

    cin>>q;

    for(i=0;i<q;++i)
    {
        cin>>key;
        cnt+=binarysearch(key);
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3388
def General_Binary_Increase_Search(L,R,cond,Integer=True,ep=1/(1<<20)):
    """条件式が単調増加であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """
    if not(cond(R)):
        return False

    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                R=C
            else:
                L=C
        return R
    else:
        while (R-L)>=ep:
            C=L+(R-L)/2
            if cond(C):
                R=C
            else:
                L=C
        return R

def f(R):
    I=0
    S=0
    for a in Pos:
        if I<Negative:
            while a*Neg[I]<=R:
                I+=1
                if I==Negative:
                    break

        S+=I
    return S

def g(R):
    S=0

    I=Positive
    for a in Pos:
        if I>0:
            while a*Pos[I-1]>R:
                I-=1
                if I==0:
                    break
        S+=I
        if a*a<=R:
            S-=1

    J=0
    for b in Neg:
        if J<Negative:
            while b*Neg[-(J+1)]<=R:
                J+=1
                if J==Negative:
                    break
        S+=J
        if b*b<=R:
            S-=1

    return S>>1
#================================================
N,K=map(int,input().split())

A=list(map(int,input().split()))
A.sort()

Pos=[a for a in A if a>0]
Neg=[a for a in A if a<0]

Positive=Zero=Negative=0
for a in A:
    if a>0:
        Positive+=1
    elif a==0:
        Zero+=1
    else:
        Negative+=1

Pos_Count=(Positive*(Positive-1))//2+(Negative*(Negative-1))//2
Neg_Count=Positive*Negative
Zero_Count=(N*(N-1))//2-(Pos_Count+Neg_Count)

H=max(A,key=lambda a:abs(a))
H=H*H+1

if Neg_Count+1<=K<=Neg_Count+Zero_Count: #ゼロ確定
    Ans=0
elif K<=Neg_Count: #負確定
    Ans=General_Binary_Increase_Search(-H,0,lambda x:f(x)>=K)
else: #正確定
    Ans=General_Binary_Increase_Search(0,H,lambda x:g(x)>=K-(Neg_Count+Zero_Count))

print(Ans)

Measured memory_bytes: 105680
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
 
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n,W;
		cin>>n>>W;
		int dp[n+1][W+1];
		memset(dp,0,sizeof(dp));
		int w[n+1],val[n+1];
		rep(i,1,n+1) cin>>w[i]>>val[i];
		rep(i,1,n+1)
		{
		    rep(j,1,W+1)
		    {
		        if(j-w[i]>=0) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);
		        else dp[i][j]=(dp[i-1][j]);
		    }
		}
		cout<<dp[n][W];
	}
}

Measured memory_bytes: 82356
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class UnionFind{
private:
    std::vector<int> par;
    std::vector<int> rank;
public:
    void init(int N){
        par.resize(N);
        rank.resize(N);
        for(int a = 0;a < N;a++)
        {
            par[a]=a;
            rank[a]=0;
        }
    }
    int root(int a)
    {
        return par[a] == a ? a : par[a] = root(par[a]);
    }
    void connect(int a,int b)
    {
        a = root(a);
        b = root(b);
        if(a==b)return;

        if(rank[a] < rank[b]){
            par[a] = b;
        }else{
            par[b] = a;
            if(rank[a] == rank[b])rank[a]++;
        }
    }
    bool check(int a,int b){
        a = root(a);
        b = root(b);
        if(a == b)return true;
        else return false;
    }
};
int main(){
    CIN(N);CIN(M);
    I vec;
    UnionFind Uni;
    Uni.init(N+1);
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    REP(a,M){
        CIN(c);CIN(d);
        Uni.connect(c, d);
    }
    int ans = 0;
    REP(a,N){
        if(Uni.check(a+1, vec.at(a)))ans++;
    }
    COUT(ans);
    return 0;
}


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

//素集合データ構造
// ref:https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
struct union_find {
    // parent[v]==w(>=0):vの親はw
    // parent[v]==k(<0):vは根&&vの属するグループの要素数は-k
    vector<long long int> parent;
    //コンストラクタ
    union_find(long long int n) {
        parent.assign(n, -1);
    }
    // vの根を求める
    //求めると同時に親を根に置き換える(木の圧縮)
    long long int root(long long int v) {
        if (parent[v] < 0) {
            return v;
        } else {
            parent[v] = root(parent[v]);
            return parent[v];
        }
    }
    // vが属するグループの要素数を求める
    long long int size(long long int v) {
        return -parent[root(v)];
    }
    // vとwを繋げる
    void unite(long long int v, long long int w) {
        v = root(v);
        w = root(w);
        if (v == w) return;
        if (parent[v] < parent[w]) swap(v, w);
        parent[w] += parent[v];
        parent[v] = w;
    }
    // vとwが同値か判定
    bool isSame(long long int v, long long int w) {
        return root(v) == root(w);
    }
};

int n, m, k;

int main() {
    cin >> n >> m >> k;
    vector<int> num_friends(n, 0);
    union_find uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        num_friends[a]++;
        num_friends[b]++;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        ans[i] = uf.size(i) - 1;
        ans[i] -= num_friends[i];
    }
    for (int i = 0; i < k; i++) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        if (uf.isSame(c, d)) {
            ans[c]--, ans[d]--;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n,m;
    cin>>n>>m;
    if(m==n)
        cout<<"Yes\n";
    else
        cout<<"No\n";
  return 0;
 }


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << max(a+b, max(a+a-1, b+b-1)) << '\n';
	return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H; cin >> W >> H;
    int x, y; cin >> x >> y;
    bool center = false;
    if ((W - x) == x && (H - y) == y) center = true; 
    cout << fixed << setprecision(12) << (W * H / 2.0) << " " << center << endl;

    return 0;
}


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

//

int main(){
    int a,b,c; cin>>a>>b>>c;
    map<int,int> m;
    m[a]++; m[b]++; m[c]++;
    cout<<m.size()<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<int> data = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            Console.Write(data[n - 1]);
            for (int i = n - 2; i >= 0; i--)
            {
                Console.Write(" " + data[i]);
            }
            Console.WriteLine();       
        }
    }
}


Measured memory_bytes: 18288
n,m = map(int,input().split())
a = 0
for i in range(m):
    if n % 2 == 0 and n % 4 != 0 and n-4*i-2 == 0:
        a = 1
    elif n % 4 == 0 and i == (n//2-1) // 2 + 1:
        a = 1
    print('{} {}'.format(i+1, n-i-a))

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

int main() {
  int a;
  cin>>a;
  string p1,p2,p3;
  cin>>p1>>p2>>p3;
  
  int answer=0;
  vector<char> vec(3);
  
  for(int i=0;i<a;i++){
    vec.at(0)=p1.at(i);
    vec.at(1)=p2.at(i);
    vec.at(2)=p3.at(i);
    
    sort(vec.begin(),vec.end());
    
    if(vec.at(0)!=vec.at(1)){
      answer++;
    }
    if(vec.at(1)!=vec.at(2)){
      answer++;
    }
  }
  
  cout<<answer<<endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int l[n];
  for (int i=0; i<n; i++) cin >> l[i];
  sort(l, l+n, greater<int>());
  int ans = 0;
  for (int i=0; i<k; i++) ans += l[i];
  cout << ans << endl;
}

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

int main(){
  int a,b,k;
  cin>>a>>b>>k;
  vector<int> v;
  for(int i=1;i<=min(a,b);i++){
    if(a%i==0 && b%i ==0){
      v.push_back(i);
    }
  }
  sort(v.begin(),v.end());
  cout<<v[v.size()-k]<<endl;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
const ll mod=1e9+7;
const int maxn = 3001;

ld dp[maxn][maxn];
ld p[maxn];
int n;

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	cout.setf(ios::fixed);cout.precision(15);
	cin>>n;
	fre(i,1,n){
		cin>>p[i];
	}
	dp[0][0]=1;
	fre(i,1,n){
		fre(j,0,i-1){
			dp[i][j]+=(1.0-p[i])*dp[i-1][j];
			dp[i][j+1]+=p[i]*dp[i-1][j];
		}
	}
	ld ans=0;
	fre(i,(n+1)/2,n){
		ans+=dp[n][i];
	}
	output(ans);
	return 0;
}

Measured memory_bytes: 68992
#include <stdio.h>
#include <math.h>

int main(){
  int sw=1;
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  while(A>0 && C>0){
    if(sw==1) C-=B;
    else A-=D;
    sw*=-1;
  }
  if(sw<0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1660
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vector<pi> g[100005];
int vis[100005];
int loc[100005];

void dfs(int cur, int num){
	if(vis[cur]) return;
	vis[cur] = 1;
	loc[cur] = num;
	for(pi x : g[cur]) dfs(x.fi, num + x.se);
}

int vis1[100005];
vi ord;

void dfs0(int cur){
	vis1[cur] = 1;
	for(pi x : g[cur]) if(!vis1[x.fi]) dfs0(x.fi);
	ord.pb(cur);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi l(m), r(m), d(m);
	rep(i, m){
		cin >> l[i] >> r[i] >> d[i];
		l[i]--, r[i]--;
		g[l[i]].pb(mp(r[i], d[i])); //hmm lol
		//g[r[i]].pb(mp(l[i], d[i]));
	}
	memset(vis1, 0, sizeof(vis1));
	rep(i, n) if(!vis1[i]) dfs0(i);
	reverse(all(ord));
	memset(vis, 0, sizeof(vis));
	rep(i, n) if(!vis[ord[i]]) dfs(ord[i], 1e7);
	int f = 1;
	rep(i, m){
		if(loc[r[i]] - loc[l[i]] != d[i]){
			f = 0;
			break;
		}
	}
	if(f) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main(){
   int n,k;
   cin>>n>>k;
   string ans="";
   while(n){
     ans=char('0'+n%k)+ans;
     n/=k;
   }
   cout<<ans.length();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
    int N = 0;
    scanf("%d", &N);

    int cnt = 0;
    for (int i = 1; i < N; i++) {
        int a = N - i;
        if ( a <= i ) {
            break;
        }
        cnt++;
    }

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


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

int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ret = 0;
  if(d <= a){
    ret = d;
  }else{
    ret += a;
    if(a+b < d){
      ret -= d - a - b;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
    int n;
    cin >> n;
    vector <int> check(n); 
    rep(i, n){
        int a, b;
        cin >> a >> b;
        if(a == b){
            check[i]++;
        }
    }
    rep(i, n - 2){
        if(check[i] == 1 && check[i + 1] == 1 && check[i + 2] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double x1 = scan.nextDouble();
		double y1 = scan.nextDouble();
		double x2 = scan.nextDouble();
		double y2 = scan.nextDouble();
		scan.close();
		double dbX = Math.pow(x2 - x1, 2);
		double dbY = Math.pow(y2 - y1, 2);
		double dbAns = Math.sqrt(dbX + dbY);
		System.out.println(dbAns);
	}
}

Measured memory_bytes: 18380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;cin >> n >> k;
	vector<pii> a(n);
	rep(i,n) cin >> a.at(i).first >> a.at(i).second;
	sort(all(a));
	ll t = 0;
	rep(i,n){
		t += a.at(i).second;
		if(t >= k){
			cout << a.at(i).first << endl;
			break;
		}
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <queue>
#include <limits>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

//===
template<class T>
struct Edge {
    int src, to;
    T cost;

    Edge (int to, T cost):
        src(-1), to(to), cost(cost) {};
    Edge (int src, int to, T cost):
        src(src), to(to), cost(cost) {};

    operator int() const {
        return to;
    };
};

template <class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using UnWeightedGraph = vector<vector<int> >;
//===

//===
// require graph/basic.cpp
// #include <limits>
// #include <queue>
// if s->u path is nothing, min_cost[u] = numeric_limits<T>::max()
// time:O((V+E) log V)
template<class T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;

    vector<T> min_cost(g.size(), INF);
    //vector<T> restore(g.size(), -1);
    priority_queue<P, vector<P>, greater<P> > que;
    que.emplace(0, s);

    while (!que.empty()) {
        T cost = que.top().first;
        int pos = que.top().second;
        que.pop();

        if (min_cost[pos] != INF) continue;
        min_cost[pos] = cost;
        for (Edge<T> e:g[pos]) {
            if (min_cost[e.to] <= cost + e.cost) continue;
            que.emplace(cost + e.cost, e.to);
            //restore[npos] = pos;
        }
    }

    return min_cost;
};
//===

int AOJ_GRL_1_A() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m, r;
    int s, t, d;
    const llong INF = numeric_limits<int>::max();

    cin >> n >> m >> r;
    
    WeightedGraph<int> g(n);
    for (int i = 0; i < m; i++) {
        cin >> s >> t >> d;

        g[s].emplace_back(t, d);
    }

    vector<int> dist = dijkstra(g, r);
    for (int i = 0; i < n; i++) {
        if (dist[i] == INF) cout << "INF" << '\n';
        else cout << dist[i] << '\n';
    }

    return 0;
}

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



Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
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; }
int main(void){
    int n, goal; cin>>n>>goal;
    long long ans =INF;
    vector <int> bonus(n);
    vector <int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i]>>bonus[i];
    }
    int bit;
    for(bit=0;bit<(1<<n);bit++){
        int tmp =0;
            vector <bool>  done(n,false) ;
            long long count=0;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
               // cout<<i<<'*';
                tmp+=bonus[i]+p[i]*(i+1)*100;
                count+=p[i];
                done[i]=true;
            }
            //cout<<count<<endl;
            //if(count==70) cout<<"???"<<endl; 
            //if(ok) chmin(ans,count);
            
        }
        bool ok=(tmp>=goal);
            if(!ok){
                for(int j=n-1;j>=0;j--){
                    if(done[j]) continue;
                 for(int k=0;k<p[j];k++){
                    tmp+=(j+1)*100; count++;
                    if(tmp>=goal) ok=true;
                    if(ok) break;
                 }
                 if(ok) break;
                }
            }
            if(ok) chmin(ans,count);
        //cout<<endl;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector <int> a(n);
  vector <int> b(n);
  vector <int> c(n - 1);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n - 1; i++) cin >> c[i];

  int pre = -2;
  int sat = 0;
  for (int i = 0; i < n; i++) {
    int at = a[i] - 1;
    sat += b[at];
    if (at == 1 + pre) {
      sat += c[pre];
    }
    pre = at;
  }
  cout << sat << endl;
  return 0;  
}

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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    string s,s1,s2="";
    cin>>s>>s1;
    ll z=0,x=0;
    for(ll i=0;i<s.length()+s1.length();i++){
        if(i%2==0){
            s2+=s[z];
            z++;
        }
        else{
            s2+=s1[x];
            x++;
        }
    }
    cout<<s2<<endl;

    return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX 110000
vector<ll> G[MAX];
ll dp[MAX]={};
bool used[MAX]={};
ll solve(int v,int prev){
  if(used[v]) return dp[v];
  used[v] = true;
  ll mv=0,res = 0,ndc=0;
  vector<ll> nd;
  for(auto nv:G[v]){
    if(nv!=prev){
      mv = max(mv,solve(nv,v));
      nd.push_back(dp[nv]);
      ndc++;
    }
  }
  if(ndc==0){
    return dp[v] = 1;
  }else{
    sort(nd.begin(),nd.end());
    for(int i=0;i<ndc;i++){
      res = max(res+1,nd[i]+1);
    }
    return dp[v] = res;
  }
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  vector<ll> a(n-1);
  for(int i=0;i<n-1;i++){
    cin >> a[i];
    a[i]--;
    G[i+1].push_back(a[i]);
    G[a[i]].push_back(i+1);
  }
  solve(0,-1);
  for(int i=0;i<n;i++){
//    cout << dp[i]<<" "<<i<<endl;
  }
  cout << dp[0]-1<<endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;


bool check(deque<char> &s,deque<char> &t) {
  rep(i,(int)s.size()) if( s[i] != t[i] ) return false;
  return true;
}

int main() {
  deque<char> s,t;
  string a;
  cin >> a;
  rep(i,(int)a.size()) s.push_back(a[i]);
  cin >> a;
  rep(i,(int)a.size()) t.push_back(a[i]);
  int n = s.size();
  rep(_,n+1) {
    if( check(s,t) ) { puts("Yes"); return 0; }
    s.push_front(s[(int)s.size()-1]);
    s.pop_back();
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
n, k = map(int, input().split())
r, s, p = map(int, input().split())
point = defaultdict(int)
point["r"] = p
point["p"] = s
point["s"] = r
t = input()
ans = 0
hand = [-1] * k
for i in range(n):
    if i < k:
        ans += point[t[i]]
        hand[i] = 1
    elif t[i] != t[i - k] or hand[i % k] != 1:
        ans += point[t[i]]
        hand[i % k] = 1
    elif hand[i % k] == 1:
        hand[i % k] = -1
print(ans)
    

Measured memory_bytes: 4212
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	double a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double k = a*e-b*d;
		double x = (e*c-b*f)/k;
		double y = (a*f-d*c)/k;
		if (x==-0) x = 0;
		if (y==-0) y = 0;
		printf("%.3lf %.3lf\n",x,y);
	}

	return 0;
}

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

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

    if ((N + M) % 2 == 0)
    {
        printf("%d\n", (N + M) / 2);
    }
    else
    {
        printf("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 256
S = input()


def is_palindrome(s):
    for i in range(len(s) // 2):
        if s[i] != s[len(s) - 1 - i]:
            return False
    return True


N = len(S)

if not is_palindrome(S):
    print('No')
    exit()

if not is_palindrome(S[:(N - 1) // 2]):
    print('No')
    exit()

if not is_palindrome(S[(N + 3) // 2 - 1:]):
    print('No')
    exit()

print('Yes')


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

int main(){
  int N; cin >> N;
  string S; cin >> S;
  int x = 0;
  int ans = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i]=='I'){
      x++;
    }
    else
    {
      x--;
    }
    ans = max(ans,x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (isok).erase(unique(ALL((isok))),(isok).end())
# define LOWER(s)    transform(ALL((maze)),(maze).begin(),TL<char>)
# define UPPER(s)    transform(ALL((maze)),(maze).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m, x;
bool isc[1010];

int main() {
	cin >> n >> m >> x;
	REP(i, m) {
		int a;
		cin >> a;
		isc[a] = true;
	}
	int ans = 0;
	for (int i = x; i >= 0; i--) {
		if (isc[i])ans++;
	}
	int num = 0;
	for (int i = x; i <= n; i++) {
		if(isc[i])num++;
	}
	cout << min(ans, num) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define vin vector<int>
#define vcn vector<char>
#define ver pair<int,int>
#define ld long double
#define pb push_back
#define x first
#define y second
#define blush fflush(stdout);fflush(stdin);
#define $(a) (int)a.size()
#define scanf ;
#define printf ;
using namespace std;
void i_love_misaka_mikoto();
int32_t main(){
    #ifdef RNS
        freopen("input.txt","r",stdin);
        #ifndef DBG
        freopen("output.txt","w",stdout);
        #endif
    #else
        ios_base::sync_with_stdio(false);
    #endif
    i_love_misaka_mikoto();
    #ifdef RNS
        cout<<'\n'<<(ld)clock()/CLOCKS_PER_SEC<<" セクンド\n";
    #endif
    return 0;
}

int sp[3013][3013];

void i_love_misaka_mikoto(){
    string s, t;
    cin>>s>>t;
    s='.'+s;
    t='.'+t;
    for(int i=1;i<$(s);i++){
        for(int j=1;j<$(t);j++){
            if(s[i]==t[j]){
                sp[i][j]+=sp[i-1][j-1]+1;
            }
            else
                sp[i][j]=max(sp[i-1][j], sp[i][j-1]);
        }
    }
    int i=$(s)-1, j=$(t)-1;
    string ans="";
    while(i!=0&&j!=0){
        if(s[i]==t[j]){
            ans=s[i]+ans;
            i--, j--;
        }
        else{
            if(sp[i-1][j]>sp[i][j-1])i--;
            else j--;
        }
    }
    cout<<ans;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(v[i] >= k){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 640