akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

  if(n%2==0){
    cout<<0.50000000000<<endl;
  }else{
cout<<setprecision(10)<<(((n/2)+1)/(n*1.0))<<endl;
}
}


Measured memory_bytes: 256
//B - 105
#include <stdio.h>

int main(void){
    int n, i, j, cnt=0, ans=0;
    scanf("%d", &n);
    for(i=1; i<=n; i+=2){
        cnt=0;
        for(j=1; j<=i; j++){
            if(i%j==0)cnt++;
            if(cnt==8)ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

int d, s, t;
void run(){
    cin >> d >> t >> s;
    DEBUG(d <= s * t ? "Yes" : "No");
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios_base::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i <= N; i++)
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e9+7;
const int N = 2e5+10;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}


void solve()
{
  string str;cin>>str;
  if(str=="ABC")puts("ARC");
  else puts("ABC");
  

    
}

int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

Measured memory_bytes: 3572
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

void b_oddstring(void) {
	string s;
	string out_string = "";
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if ((i & 0x1) == 0x0) {
			out_string += s[i];
		}
	}
	cout << out_string << endl;
}

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

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans=0;
  string T="ABC";
  rep(i,N-T.size()+1){
    int cnt=0;
     rep(j,3) {
      if(S[i+j]==T[j]){
        cnt++;
      }
      if(cnt==3) ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n, a, y, z;
  cin >> n;
    y = 0;
  z = 200;
  while (n > 0 ){
    cin >> a;
    y = 0;    
    while( a % 2 == 0){
          a = a / 2;
          y++;}
     if ( z > y){z = y;} 
    n = n - 1;
  }
  cout << z << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    string n;
    cin >> n;
    if(n[n.size() - 1] == 's'){
        n = n + "es";
    }else{
        n = n + "s";
    }
    cout << n << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 610
#define ll long long
#define mod 1000000007
using namespace std;
int link[N],tot[N][N];
ll f[N][N],h[N<<1];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	n<<=1;
	for(int i=1;i<=k;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		link[u]=v;
		link[v]=u;
	}
	h[0]=1,h[1]=0;
	for(int i=2;i<=n;i+=2) h[i]=h[i-2]*(i-1)%mod;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		tot[i][j]=tot[i][j-1]+(!link[j]);
	}
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
		{
			bool have=false;
			for(int l=i;l<=j;l++)
				if(link[l] && (link[l]>j || link[l]<i)) have=true;
			if(have) continue;
			f[i][j]=h[tot[i][j]];
			for(int l=i+1;l<=j-1;l++)
			f[i][j]=(f[i][j]-f[i][l]*h[tot[l+1][j]]%mod+mod)%mod;
		}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		ans=(ans+f[i][j]*h[n-k*2-tot[i][j]]%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4608
// Template
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
//using namespace atcoder;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

int main() {
    int n;
    cin >> n;
    int g = 0;
    auto rec = [&](auto f, int x, int y) -> int {
        if (x < y) return 0;
        if (x % y == 0) return x / y;
        int z = x / y + 1, w = x / y * y;
        x -= (x - w) / z * z;
        if (x % y == 0) return x / y;
        return f(f, x - z, y);
    };
    rep(i, n) {
        int a, k;
        cin >> a >> k;
        g ^= rec(rec, a, k);
    }
    cout << (g ? "Takahashi\n" : "Aoki\n");
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n;
  string s,ss,ans;
  cin>>n>>s>>ss;
  ans=s;
  if(s==ss){cout<<n<<endl;return 0;}
  rep(i,n+1){
    ans=s;
    for(int j=n-1-i;j<n;j++)ans+=ss[j];
    //cout<<s<<" "<<ans<<endl;
    if(ans.find(ss)!=-1)break;
    
  }
  cout<<ans.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/

/*実行開始からの経過時間を表すよ。
while (clock() < 1900000) { ; }
*/

/*まだ使えないテクニックのメモだよ。
for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ
*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/
ll ans[100005];
ll a[100005];

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

	for (int i = 0; i < m; i++) {
		cin >> a[i];
		ans[a[i]] = INF;
	}

	bool r = true;

	if (a[0] == 1&&m!=0) {
		ans[1] = 0;
		r = false;
	}
	if (r) { ans[1] = 1; }
	ans[0] = 1;

	for (int i = 2; i <= n; i++) {
		bool x = true;
		bool y = true;
		if (ans[i - 1] == INF) {
			x = false;
		}
		if (ans[i - 2] == INF) {
			y = false;
		}

		if (ans[i] != INF) {
			if (x) { ans[i] = (ans[i] + ans[i - 1]) % MOD; }
			if (y) { ans[i] = (ans[i] + ans[i - 2]) % MOD; }
		}

	}

	cout << ans[n]%MOD << endl;


	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    cin >> S;
    string ans = "AC";

    if(S.at(0) != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    int count = 0;
    for(int i=2; i < S.size()-1; i++) {
        if(S.at(i) == 'C') {
            count++;
        } else if(!islower(S.at(i))) {
            cout << "WA" << endl;
            return 0;
        }
    }
    if(count != 1) {
        cout << "WA" << endl;
        return 0;
    }

    if(!islower(S.at(S.size()-1))) {
        cout << "WA" << endl;
        return 0;
    }
    if(!islower(S.at(1))) {
        cout << "WA" << endl;
        return 0;
    }
    
    cout << "AC" << endl;

    return 0;
}



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

int main(){
    int a[1000][1000],b[1000];
    int n, m, h;
    int i, j;
    
    
    cin >> n >> m;
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    
    for(j = 0; j < m; j++) cin >> b[j];
    
    for(i = 0; i < n; i++){
        h = 0;
        for(j = 0; j < m; j++){
            h += a[i][j]*b[j];
        }
        cout << h << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3464
#include <stdio.h>

int main(void){
  char b, C[128];
  scanf("%c", &b);
  C['A'] = 'T';
  C['G'] = 'C';
  C['T'] = 'A';
  C['C'] = 'G';
  printf("%c", C[b]);
  return 0;
}

Measured memory_bytes: 128
#解説解法
#15:49
n = int(input())
a = list(map(int,input().split()))
b = [a[0]]
for i in range(1,n):
  b.append(b[-1] + a[i])
c = []
for i in range(n):
  c.append([abs(b[i] - b[-1]/2),i])
h = -1
j = min(c,key= lambda x:x[0])[1]
p = 0
q = 0
r = b[j]
s = b[-1] - r
#print(p,q,r,s)
can = []
for i in range(n-2):
  q += a[i]
  while True:
    pnew = p + a[h+1]
    qnew = q - a[h+1]
    if abs(pnew-qnew) < abs(p-q):
      h += 1
      p = pnew
      q = qnew
    else:
      break
  r -= a[i]
  while True:
    rnew = r + a[j+1]
    snew = s - a[j+1]
    if abs(rnew-snew) < abs(r-s):
      j += 1
      r = rnew
      s = snew
    else:
      break
  if 1 <= i < n-2:
    can.append(max(p,q,r,s) - min(p,q,r,s))
    #print(p,q,r,s)
#print(can)
print(min(can))

Measured memory_bytes: 60556
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double hRad = M_PI * 2.0 * (h / 12.0 + m / 60.0 / 12.0);
    double mRad = M_PI * 2.0 * (m / 60.0);

    double res = sqrt(a * a + b * b - 2.0 * a * b * cos(hRad - mRad));
    cout << fixed << setprecision(30) << res;
    return 0;
}

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

int main() {
    int n, temp, maximum = -1, minimum = INT_MAX;
    cin >> n;
    rep(i, n) {
        cin >> temp;
        if(temp < minimum) minimum = temp;
        if(temp > maximum) maximum = temp;
    }
    cout << maximum - minimum << endl;
}

Measured memory_bytes: 256
Module Module1

    Sub Main()
        'let'
        Dim tmp() As String = Console.ReadLine().Split()
        Dim N As Long = tmp(0)
        Dim A As Long = tmp(1)
        Dim B As Long = tmp(2)

        'var'
        Dim cnt As Long = 0

        For i As Long = 1 To N
            'let'
            Dim str As String = Convert.ToString(i)
            'var'
            Dim j As Long = 0

            For Each c As Char In str
                j += CLng(c & "")
            Next

            If A <= j AndAlso j <= B Then
                cnt += i
            End If
        Next

        Console.WriteLine(cnt)

    End Sub

End Module

Measured memory_bytes: 13268
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Map<Integer, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            long b = Long.parseLong(sc.next());
            if (map.containsKey(a)) {
                map.put(a, map.get(a) + b);
            } else {
                map.put(a, b);
            }
        }
        sc.close();

        // 主処理
        List<Integer> keys = new ArrayList<>();
        for (int key : map.keySet()) {
            keys.add(key);
        }
        Collections.sort(keys);

        long countSum = 0;
        int result = 0;
        for (int key : keys) {
            long count = map.get(key);
            countSum += count;
            if (k <= countSum) {
                result = key;
                break;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 64556
unittest
{
	assert( [ "2 2 2" ].parse.expand.solve == "Yes" );
	assert( [ "3 4 5" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	return ( a == b && b == c ) ? "Yes" : "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,counter,save;
  cin >> N;
  save = -1;
  for (int i=0;i<N;i++){
    cin >> a;
    counter=0;
    while(a%2==0){
      a/=2;
      counter+=1;
    }

  if (counter < save)
       save =counter;
else if(save==-1)
     save =counter;

  else 
      continue; 
  }
  cout << save << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
struct BIT{
	int bit[200005],N=200005;
	void add(int pos,int v){
		while(pos<=N){
			bit[pos]+=v;
			pos+=pos&-pos;
		}
	}
	int sum(int pos){
		int ret=0;
		while(pos){
			ret+=bit[pos];
			pos&=pos-1;
		}
		return ret;
	}
}Tree1,Tree2;
int q;
vector<pair<int,int> >query;
map<int,int>mp,mp2;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>q;
	for(int i=1;i<=q;i++){
		int t;cin>>t;
		if(t==1){
			int a,b;
			cin>>a>>b;
			mp[a];
			query.push_back(make_pair(a,b));
		}else{
			query.push_back(make_pair(inf,inf));
		}
	}
	int _=0;for(auto &p:mp)p.second=++_;
	for(auto p:mp)mp2.insert(make_pair(p.second,p.first));
	int add=0;
	for(auto p:query){
		if(p.first==inf){
			int S=Tree1.sum(200003);S=(S+1)/2;
			int l=-1,r=200005;
			while(r-l>1){
				int mid=l+r>>1;
				if(Tree1.sum(mid)>=S)r=mid;
				else l=mid;
			}
			cout<<mp2[r]<<" ";
			int pre=Tree1.sum(r),suf=Tree1.sum(200003)-pre;
			int ans=0;
			ans+=pre*mp2[r]-Tree2.sum(r);
			ans+=(Tree2.sum(200003)-Tree2.sum(r))-suf*mp2[r];
			cout<<ans+add<<endl;
		}else{
			Tree1.add(mp[p.first],1);
			Tree2.add(mp[p.first],p.first);
			add+=p.second;
		}
	}
	return 0;
}

Measured memory_bytes: 20076
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    const long long mod=1000000007;
    long long n,m,ans=1;
    cin >> n >> m;
    if(abs(n-m)>1) cout << 0 << endl;
    else{
        for(long long i=1; i<=max(m,n); i++){
            ans*=i;
            ans%=mod;
            if(i<=min(m,n)){
                ans*=i;
                ans%=mod;
            }
        }
        if(m==n){
            ans*=2;
            ans%=mod;
        }
        cout << ans << endl;
    }
}


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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 3e5 + 10;
const int SIZ = 3e5 + 10;
const int mod = 998244353;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "4";

int a[siz];
int seg[4 * siz];

void pos_update(int id, int st, int ed, int pos, int val) {
    if (st == ed) {
        seg[id] = max(seg[id], val);
        return;
    }

    int mid = (st + ed) / 2;
    if (pos <= mid) {
        pos_update(2 * id, st, mid, pos, val);
    } else {
        pos_update(2 * id + 1, mid + 1, ed, pos, val);
    }

    seg[id] = max(seg[2 * id], seg[2 * id + 1]);
}

int range_max(int id, int st, int ed, int lt, int rt) {
    if (rt < st || ed < lt) {
        return 0;
    }

    if (lt <= st && ed <= rt) {
        return seg[id];
    }

    int mid = (st + ed) / 2;
    int m1 = range_max(2 * id, st, mid, lt, rt);
    int m2 = range_max(2 * id + 1, mid + 1, ed, lt, rt);
    return max(m1, m2);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];

        a[i]++;
    }

    for (int i = 1; i <= n; i++) {
        pos_update(1, 1, SIZ - 1, a[i], range_max(1, 1, SIZ - 1, max(a[i] - k, 1LL), min(a[i] + k, SIZ - 1)) + 1);
    }

    cout << range_max(1, 1, n, 1, n) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";

    return 0;
}


Measured memory_bytes: 14088
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if b > c {
		b, c = c, b
	}
	if a > b {
		a, b = b, a
	}
	fmt.Printf("%d %d %d\n", a, b, c)
	return
}



Measured memory_bytes: 1132
use proconio::*;

fn main() {
    input! {s: String, t: String}
    let (s, t) : (String, String) = (s, t);
    let (s_chars, t_chars): (Vec<char>,Vec<char>) = (s.chars().collect(), t.chars().collect());
    let mut max = 0;
    let mut count = 0;
    for i in 0.. s_chars.len() - t_chars.len() + 1 {
        for j in 0.. t_chars.len() {
            if s_chars[i+j] == t_chars[j] {
                count += 1;
            }             
        }
        if count > max { max = count; }
        count = 0;
    }
    println!("{}", t_chars.len() - max);
}


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

void bsort2(int a[], int b[], int lim)
{
	int tmp;

    for (int i = 0; i <= lim-1; i++)
        for (int j = lim; i < j; j--)
		{
            if (a[j-1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;

				tmp = b[j];
				b[j] = b[j-1];
				b[j-1] = tmp;
            }
        }	
}

int main()
{	
	int n;
	int tre[10000];
	int brg[10000];
	int sum;
	bool judge;

	while( cin >> n, n)
	{
		memset( brg, 0, sizeof(brg));
		memset( tre, 0, sizeof(tre));
		sum = 0;
		judge =0;
		
		for( int i = 0; i < n; i++)
		{
			cin >> tre[i] >> brg[i];
		}
		
		bsort2( brg, tre, n-1);

		for( int i = 0; (i < n && !judge); i++)
		{
			sum += tre[i];
			if( sum > brg[i])
				judge = 1;
		}

		if(judge)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;

	}


	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B);
	int min_a = 1e9, min_b = 1e9;
	for (int i = 0; i < A; ++i) {
		cin >> a[i];
		min_a = min(a[i], min_a);
	}
	for (int i = 0; i < B; ++i) {
		cin >> b[i];
		min_b = min(b[i], min_b);
	}
	int ans = min_a + min_b;
	for (int i = 0; i < M; ++i) {
		int x, y, c;
		cin >> x >> y >> c;
		--x; --y;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N, K;
    cin >> N >> K;

    double ans = 0.0;
    for (int n = 1; n <= N; ++n)
    {
        // cout << (1 << (int)ceil(log2((double)K / n))) << "\n";
        if (n < K)
        {
            ans += 1.0 / (1 << (int)ceil(log2((double)K / n))) / N;
        }
        else
        {
            ans += 1.0 / N;
        }
    }

    cout << setprecision(12) << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n+1];
		for(int i=0;i<=n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int br[]=new int[n];
		for(int i=0;i<n;i++)
		{
			br[i]=scan.nextInt();
		}
		long ans=0;
		for(int i=0;i<n;i++)
		{
			int cur=br[i];
			int max=Math.min(ar[i],cur);
			ans+=max;
			cur-=max;
			int sec=Math.min(cur,ar[i+1]);
			ar[i+1]=ar[i+1]-sec;
			ans+=sec;
			
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 64272
var
	f:boolean;
	n,i,x:longint;
begin
	read(n);
    f:=false;
    for i:=1 to n do
    begin
    	read(x);
        f:=f or (x mod 2=1); 
    end;
    if f then writeln('first')
    else writeln('second');
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	string s, ans;
	cin >> s;
	rep(i,s.size()){
		if(i%2==1) continue;
		else ans.push_back(s[i]);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
	int month, day; cin >> month >> day;
	while (month != 0 && day != 0) {
		if (month >= 1) day = day;
		if (month >= 2) day = day + 31;
		if (month >= 3) day = day + 29;
		if (month >= 4) day = day + 31;
		if (month >= 5) day = day + 30;
		if (month >= 6) day = day + 31;
		if (month >= 7) day = day + 30;
		if (month >= 8) day = day + 31;
		if (month >= 9) day = day + 31;
		if (month >= 10) day = day + 30;
		if (month >= 11) day = day + 31;
		if (month >= 12) day = day + 30;
		if (day % 7 == 0) cout << "Wednesday" << endl;
		if (day % 7 == 1) cout << "Thursday" << endl;
		if (day % 7 == 2) cout << "Friday" << endl;
		if (day % 7 == 3) cout << "Saturday" << endl;
		if (day % 7 == 4) cout << "Sunday" << endl;
		if (day % 7 == 5) cout << "Monday" << endl;
		if (day % 7 == 6) cout << "Tuesday" << endl;
		cin >> month >> day;
	}
	return 0;
}


Measured memory_bytes: 2996
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
iix = lambda x:list(int(input()) for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
##########
def main(n,b):
    a = [0]*n
    a[0] = b[0]
    a[-1] = b[-1]
    for i in range(1,n-1):
        a[i] = min(b[i-1],b[i])
    print(sum(a))

n = ii()
b = mi()
main(n,b)

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

bool used[100000] = {};
vector<int> G[100000];

int nxt(int v){
	for(int to : G[v]){
		if(!used[to]) return to;
	}
	return -1;
}

int main(){
	int n,d[100000] = {};
	bool flag = false;
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
		d[a]++;
		d[b]++;
	}
	queue<int> que;
	for(int i = 0;i < n;i++){
		if(d[i] == 1) que.push(i);
	}
	while(!que.empty()){
		int v = que.front(),nextv = nxt(v);que.pop();
		if(used[v]) continue;
		if(nextv == -1){
			flag = true;
			break;
		}
		used[v] = true;
		used[nextv] = true;
		for(int to : G[nextv]){
			if(!used[to]){
				d[to]--;
				if(d[to] == 1) que.push(to);
			}
		}
	}
	for(int i = 0;i < n;i++) if(!used[i]) flag = true;
	if(flag) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
typedef long long ll;
const ll mod = 1e9+7;

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;}

//繰り返し自乗法によるmod累乗計算
//a = 底、　n = 指数
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//nCa 
ll comb(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}


int main(){
  int s;
  cin >> s;
  map<int, int> mp;
  mp[s]++;
  int cnt = 1;
  while(1){
    if(s%2 == 0) s /= 2;
    else s = 3*s + 1;
    if(mp[s]){
      cout << cnt+1 << endl;
      return 0;
    }
    mp[s]++;
    cnt++;
  }

}






Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,ab,a,b,ans;
string s[10010];

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> s[i];
    int k = s[i].size();
    for(int j=0;j<k-1;j++){
      if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
    }
    if(s[i]!="AB"){
      string temp = "";
      temp+= s[i][0];
      temp+= s[i][k-1];
      if( temp=="BA" )ab++;
      if( temp[0]=='B' && temp[1]!='A' )b++;
      if( temp[1]=='A' && temp[0]!='B')a++;
    }
  }
  //cerr << b << " " << a << "  " << ans << " " << ab << endl;
  if( ab ){
    ans+= ab-1;
    if(a){ans++;a--;}
    if(b){ans++;b--;}
  }
  ans+= min( b, a );
  cout << ans << endl;

return 0;
}
///....


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

const ll mod = 1000000007;
const ll b = 10007;

ll mpow(ll x, ll n) {
    ll res = 1;
    while (n != 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return res;
}

// s0中のs1を探す
int search_hash(string s0, string s1, int x) {
    ll l0 = s0.size(), l1 = s1.size();
    ll h0 = 0, h1 = 0, bp = mpow(b, s1.size());

    if (l0 < l1) return -1;

    for (int i = 0; i < l1; i++) {
        h0 = (h0 * b + s0[i]) % mod;
        h1 = (h1 * b + s1[i]) % mod;
    }
    for (int i = 0; i + l1 <= l0; i++) {
        if (h0 == h1 && i >= x + s1.size()) return i;
        if (i + l1 < s0.size()) h0 = (h0 * b + s0[i + l1] - s0[i] * bp % mod + mod) % mod;
    }
    return -1;
}

int n;

bool solve(int len, string s) {
    for (int i = 0; i + 2 * len <= s.size(); i++) {
        string s1 = s.substr(i, len);
        if (search_hash(s, s1, i) != -1) return true;
    }
    return false;
}

int binary_search(int ok, int ng, string s) {
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (solve(mid, s)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

int main() {
    string s;
    cin >> n >> s;
    int ans = binary_search(-1, s.size(), s);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		for(i=0; i<n; i++) {
			h[i] = sc.nextInt();
			if(max < h[i]) max = h[i];
		}
		sc.close();
		sc = null;
		int ans = 0;
		for(i=1; i<=max; i++) {
			boolean f = false;
			for(int j=0; j<n; j++) {
				if(!f && h[j] >= i) {ans++;f = true;}
				else if(f &&  h[j] < i) {f = false;}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

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

  int N;
  cin >> N;
  vector<int> v(N);
  int a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    v[i] = a - (i + 1);
  }
  sort(v.begin(), v.end());
  const int b = v[N / 2];

  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += abs(v[i] - b);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rint register int
#define ll long long
#define pa pair<int,int>
using namespace std;
struct node{int to,next;} e[1010100];
int h[1010100],tot,N,K,dep[2020],sz,fl;
pa tmp[110100];
inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
inline void DFS(int now,int ffa){
	for(rint i=h[now];i;i=e[i].next){
		int to=e[i].to;if(to==ffa) continue;
		dep[to]=dep[now]+1;
		if(K&1){
			if(dep[to]<=K/2) sz++;
			else if(dep[to]==(K+1)/2) {
				if(!fl) fl=1,sz++;
			}
		} 
		else if(dep[to]<=K/2) sz++;
		DFS(to,now);
	}
}
inline int Get_ans(int center){
	memset(dep,0,sizeof(dep));sz=fl=0;
	DFS(center,0);
	sz++;
	return N-sz;
}
inline void DFS2(int now,int ffa){
	if(dep[now]<=(K-1)/2) sz++;
	for(rint i=h[now];i;i=e[i].next){
		int to=e[i].to;if(to==ffa) continue;
		dep[to]=dep[now]+1;DFS2(to,now);
	}
}
int main(){
	cin>>N>>K;
	if(K==1) {
		cout<<N-2<<endl;
		return 0;
	}
	if(K>=N-1) {
		cout<<0<<endl;
		return 0;
	}
	for(rint i=1;i<N;++i){
		int a,b;cin>>a>>b;
		add(a,b);add(b,a);
		tmp[i].first=a,tmp[i].second=b;
	}int ans=1e9;
	if(K&1) {
		for(rint i=1;i<N;++i) {
			int a=tmp[i].first,b=tmp[i].second;
			sz=0;
			memset(dep,0,sizeof(dep));
			DFS2(a,b);
			DFS2(b,a);
			ans=min(ans,N-sz);
		}cout<<ans;
		return 0;
	}
	
	for(rint i=1;i<=N;++i){
		ans=min(ans,Get_ans(i));
	}cout<<ans;
	return 0;
} 

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

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3620
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> M >> K;
	vector<pair<int, int>>P;
	UnionFind uf(N);
	for (int i = 0; i < K; i++) {
		cin >> L >> R >> H;
		if (H) {
			P.push_back({ L,R });
		}
		else {
			uf.Unite(L, R);
		}
	}
	for (auto i : P) {
		if (uf.Check_Same(i.first, i.second)) {
			cout << "No\n";
			return 0;
		}
	}
	vector<int>sz(N);
	for (int i = 0; i < N; i++) {
		sz[uf.Find(i)]++;
	}
	//for (auto i : sz)cout << i << endl;
	vector<int>one;
	for (int i = 0; i < N; i++) {
		if (sz[i] == 1)one.push_back(i);
	}
	int used = 0;
	for (auto i : sz) {
		used += max(0,i - 1);
	}
	long long int node = one.size();
	for (auto i : sz) {
		node += i >= 2;
	}
	//cout << used << " " << node << endl;
	if (P.empty()) {
		if (M >= N - 1 && M <= used + node * (node - 1) / 2)cout << "Yes\n";
		else cout << "No\n";
	}
	else {
		if (M >= N && M <= used + node * (node - 1) / 2)cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 3188
#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; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
#define MOD (ll)(1e9 +7)
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,c,f,m;
	cin>>n>>m>>k;
	vc a(n+1),b(m+1);
	for(i=1;i<=n;i++){
	cin>>a[i];
	a[i]+=a[i-1];}
	for(i=1;i<=m;i++){
	cin>>b[i];
	b[i]+=b[i-1];}
	j=0;ll ans=0;
	for(i=n;i>=0;i--)
	{
	    for(;j<=m;j++)
	    {
	        if(a[i]+b[j]>k)
	            break;
	        else
	            ans=max(ans,i+j);
	    }
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 6392
n,a = map(int,input().split())
x = list(map(int,input().split()))
max_x = max(x)
dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(n+1):
  for j in range(n+1):
    for k in range(n*max_x+1):
      if i>=1 and k < x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]
      elif i>=1 and j>= 1 and k>= x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
      else:
        continue
ans = 0
for j in range(1,n+1):
  if j*a <= n*max_x+1:
    ans += dp[n][j][j*a]
print(ans)

Measured memory_bytes: 92636
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >>N;
    vector<int>C(N), V(N);
    vector<int>a(N);
    int ans=0;
    rep(i,N){
        cin >> V[i];
    }
    rep(i,N){
        cin >> C[i];
        a[i]=V[i]-C[i];
    }

    sort(a.begin(), a.end(), greater<int>());

    for(auto x:a){
        if(x>0){
            ans+=x;
        }
    }

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


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let ab = read_vec::<i32>();
    let a1 = ab[0] + ab[1];
    let a2 = ab[0] - ab[1];
    let a3 = ab[0] * ab[1];
    let mut v = Vec::new();
    v.push(a1);
    v.push(a2);
    v.push(a3);
    let ans = v.iter().max().unwrap();
    println!("{}",ans);
}


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

if sum(A) < sum(B):
    print(-1)
    exit()
diff = []
for i in range(N):
    diff.append(B[i] - A[i])
diff.sort()
s = 0
answer = 0
for x in diff:
    if x > 0:
        answer += 1
        s += x
for x in diff:
    if s <= 0:
        break
    answer += 1
    s += x  
print(answer)


Measured memory_bytes: 18292
#include<stdio.h>

typedef struct {
  char mark[5];
  int  num;
}card;

int bubble(int kosuu, card trump[])
{
 int i, j, box1 ;
 char box2; 
  
 
 for(i = 1;i <= kosuu;i++) {
   for(j = kosuu;j > i;j--) {
     if (trump[j].num < trump[j-1].num) {
       box1  = trump[j-1].num;
       box2  = trump[j-1].mark[0];      
       trump[j-1].num     = trump[j].num;
       trump[j-1].mark[0] = trump[j].mark[0];
       trump[j].num     = box1;
       trump[j].mark[0] = box2;
     }
   }
 }
 
 for(i = 1;i < kosuu;i++){
   printf("%c%d ", trump[i].mark[0], trump[i].num);
 }
 printf("%c%d\n", trump[i].mark[0], trump[i].num);
 printf("Stable\n");
 return 0;
}

int select(int kosuu, card trump[])
{
 int i, j,  min, minnum, box1,flag=0;
 char box2;
   
 for(i = 1;i <= kosuu;i++){
   min = trump[i].num;
   for(j = i + 1;j <= kosuu;j++){
     if(trump[j].num < min){
       min = trump[j].num;
       minnum = j;
     }
   }
   if(min < trump[i].num){
      box1  = trump[i].num;
      box2  = trump[i].mark[0];
      trump[i].num     = min;
      trump[i].mark[0] = trump[minnum].mark[0];
      trump[minnum].num     = box1;
      trump[minnum].mark[0] = box2;
      if( (trump[minnum].num == trump[minnum-1].num) || (trump[i].num == trump[i+1].num) ){
        flag++;
      }
   }
 }
 
 for(i = 1;i < kosuu;i++){
   printf("%c%d ", trump[i].mark[0], trump[i].num);
 }
 printf("%c%d\n", trump[i].mark[0], trump[i].num);

 if(flag == 0) 
   printf("Stable\n");
 else
   printf("Not stable\n");
 return 0;
}

int main()
{
 int i, kosuu;
 card trump[40],copy1[40];
   
 scanf("%d", &kosuu);
   
 for(i = 1;i <= kosuu;i++){ 
   scanf("%1s%d",&trump[i].mark,&trump[i].num);
 }
 
 for(i = 1;i <=kosuu; i++){
   copy1[i].mark[0] = trump[i].mark[0];
   copy1[i].num     = trump[i].num;
 }
 bubble(kosuu,trump);
 select(kosuu,copy1);
 
 return 0;
}

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

int main(void){
        int m[100001];
        for (int i = 0; i < 100001; i++) {
                m[i] = 0;
        }
        int N, A, sum = 0;
        cin >> N;
        for (int i = 0; i < N; i++) {
                cin >> A;
                if (m[A] == 0) {
                        m[A]++;
                } else {
                        sum++;
                }
        }
        if (sum % 2 == 0) {
                cout << N - sum;
        } else {
                cout << N - sum - 1;
        }
        return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if (x-r < 0 || x + r > W){
			System.out.println("No");
		} else if (y-r < 0 || y + r > H){
			System.out.println("No");
		} else if (x-r >= 0 || x + r <= W){
			System.out.println("Yes");
		} else if (y-r >= 0 || y + r <= H){
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 26244
N = int(input())
H = list(map(int, input().split()))

H = H[::-1] # リストをリバースする
ans = 0
val = 0

for i in range(1, N):
    if H[i-1] <= H[i]:
        val += 1
    else:
        val = 0
    ans = max(ans, val)

print(ans)

Measured memory_bytes: 14252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N,K;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>K;
	cout<<(K>1?N-(K-1)-1:0)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
int main(){
 int a,b,c,k;
  std::cin>>a>>b>>c>>k;
  
  if(a>=k){
    std::cout<<k<<'\n';
    return 0;
  }
  
  k -= a;
  if (b>=k) {
    std::cout << a << '\n';
    return 0;
  }
  
  k-=b;
  std::cout << a-k << '\n';
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
string s;
deque<int> p[26];
int f[N];
void add(int i,int v)
{
    for (; i < N; i += i & -i)
        f[i] += v;
}
int qry(int i)
{
    int r = 0;
    for (; i; i ^= i & - i)
        r += f[i];
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        p[s[i]-'a'].push_back(i+1);
        add(i+1,1);
    }
    int mi = -1;
    for (int i = 0; i < 26; ++i)
        if (p[i].size() & 1) {
            if (mi != -1 || n % 2 == 0) {
                cout << "-1\n";
                return 0;
            }
            mi = i;
        }
    long long ans = 0;
    for (int i = 1, j = n; i < j; ++i, --j) {
        pair<int,int> best(INT_MAX,INT_MAX);
        for (int c = 0; c < 26; ++c) {
            if (p[c].size() > 1) {
                int l = qry(p[c].front()), r = qry(p[c].back());
                int w = l-1 + n-i*2+2-r;
                best = min(best, {w,c});
            }
        }
        ans += best.first;
        auto & q = p[best.second];
        add(q.front(),-1);
        add(q.back(),-1);
        q.pop_front();
        q.pop_back();
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
   int n;
   	while(1){
   		cin>>n;
   		if(n==0) break;
   		vi h(n+1);
   		int ans;
   		rep(i,0,n+1){
   			cin>>h[i];
   		}
   		rep(i,0,n+1){
   			vi d;
   			rep(j,0,n+1){
   				if(i==j) continue;
   				d.push_back(h[j]);
   			}
   			int diff=d[1]-d[0];
   			bool f=true;
   			rep(j,2,n){
   				if(d[j]-d[j-1]!=diff) f=false;
   			}
   			if(f){
   				ans=h[i];
   				break;
   			}
   		}
   		o(ans);
   	}
}

Measured memory_bytes: 1216