akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define vii vector<ll>
#define all(x) x.begin(),x.end()
#define mod 998244353
#define pb push_back
#define ii pair<int,int>
#define iii pair<ll,ll>
#define MAX 10000000000000000
#define pi 3.1415926535
typedef long long ll;
ll tree[800005], a[200005], h[200005], dp[200005];

ll build(int ind, int s, int e) {
    if(s==e) {
        tree[ind] = 0;
        dp[s] = 0;
        return tree[ind];
    }

    int mid = (s+e)/2;

    tree[ind] = max(build(2*ind, s, mid), build(2*ind+1, mid+1, e));
    return tree[ind];
}

ll get(int idx, int s, int e, int l, int r) {
    if(l>e || r<s) return INT_MIN;

    if(l<=s&&e<=r)
        return tree[idx];

    int mid = (s+e)/2;

    return max(get(2*idx,s,mid,l,r), get(2*idx+1,mid+1,e,l,r));
}

void update(int idx, int s, int e,int pos, ll val) {
    if(s==e) {
        dp[pos] = val;
        tree[idx] = val;
        return ;
    }
    
    int mid = (s+e)/2;

    if(pos>=s&&pos<=mid)
        update(2*idx, s, mid, pos, val);
    else
        update(2*idx+1, mid+1, e, pos, val);
    
    tree[idx] = max(tree[2*idx], tree[2*idx+1]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n; cin>>n;
    f(i,0,n) cin>>a[i];
    f(i,0,n) cin>>h[i];

    build(1, 0, n-1);
    // f(i,0,2*n) cout<<tree[i]<<" ";
    // cout<<endl;
    f(i,0,n) {
        ll val = get(1, 0, n-1, 0, a[i]-1);
        update(1, 0, n-1, a[i]-1, val+h[i]);
    }
    ll ans = -1;
    // f(i,0,n) cout<<dp[i]<<" ";
    // cout<<endl;
    f(i,0,n) {
        ans = max(ans, dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10496
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	if(a > b){
        	if(a>c && c>b) System.out.println("Yes");
          	else System.out.println("No");
        }else{
        	if(a<c && c<b) System.out.println("Yes");
          	else System.out.println("No");
        }
    }
}

Measured memory_bytes: 35656
import sys

max_diff = -sys.maxsize - 1
for idx in range(int(input())):
    Rt = int(input())
    if(idx):
        tmp = Rt - min_num
        if(tmp > max_diff):
            max_diff = tmp
        if(Rt < min_num):
            min_num = Rt
    else:
        min_num = Rt
print(max_diff)



Measured memory_bytes: 5616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[][] sw=new int[N][2];
		long cnt=0;
		for(int i=0; i<N; i++) {
			sw[i][0]=sc.nextInt();
			sw[i][1]=sc.nextInt();
		}
		for(int i=N-1; i>=0; i--) {
			if((cnt+sw[i][0])%sw[i][1]==0) {
				//
			}
			else {
				cnt+=sw[i][1]-(cnt+sw[i][0])%sw[i][1];
			}
		}
		System.out.println(cnt);
	}
	static class SC {

		private BufferedReader reader = null;

		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 46060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;

int main() {
  string s;
  cin >> s;
  string t=s;
  reverse(all(t));
  int ans=0;
  rep(i,s.size()/2){
    if(s[i]!=t[i])
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int temp[3009][3009];

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

  int i, j, posJ;
  int len1, len2;

  string str1, str2;
  stack<char > st;

  cin >> str1 >> str2;
  len1 = str1.length();
  len2 = str2.length();

  for(i = 1; i <= len2; i++) for(j = 1; j <= len1; j++) {
    if(str1[j - 1] == str2[i - 1]) temp[i][j] = 1 + temp[i - 1][j - 1];
    else temp[i][j] = max(temp[i - 1][j], temp[i][j - 1]);
  }

  posJ = len1;
  for(i = len2; i > 0; i--) for(j = posJ; j > 0; j--) {
    if(temp[i][j] == temp[i - 1][j - 1] + 1) {
      if(temp[i][j] == temp[i - 1][j] + 1 && temp[i - 1][j] == temp[i][j - 1]) {
        st.push(str1[j - 1]);
        posJ = j - 1;
        break;
      } else {
        if(temp[i - 1][j] > temp[i][j - 1]) {
          posJ = j;
          break;
        } else continue;
      }
    } else {
      if(temp[i - 1][j] > temp[i][j - 1]) {
        posJ = j;
        break;
      } else continue;
    }
  }

  //if(st.size() == 0) printf("The answer is (an empty string).");
  /*else*/ while(!st.empty()) {
    printf("%c", st.top());
    st.pop();
  }
  return 0;
}


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

using lint=long long;

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

   vector<lint> imos0(2*M+1);
   vector<lint> imos1(2*M+1);

   auto add=[&](vector<lint> &a,int l,int r,int val){ a[l]+=val; a[r+1]-=val; };
   for(int i=0;i<N-1;i++){
      int s=a[i],t=a[i+1];
      if(s>t) t+=M;

      // add (1+t)-x to [s+1,t]
      add(imos0,s+1,t,1+t);
      add(imos1,s+1,t,-1);
      // add (t-s) to [t+1,s+M]
      add(imos0,t+1,s+M,t-s);
   }
   for(int i=1;i<2*M;i++){
      imos0[i]+=imos0[i-1];
      imos1[i]+=imos1[i-1];
   }

   lint ans=(lint)N*M;
   for(int i=0;i<M;i++){
      lint sum=(imos1[i]*i+imos0[i])+(imos1[i+M]*(i+M)+imos0[i+M]);
      ans=min(ans,sum);
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    cout << (x ^ 1) << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#define int long long
//#define _DEBUG
using namespace std;
string sa, sb;
int T[1009][1009];
int solve(){
    int sal = sa.length(), sbl = sb.length();
    for(int a=0; a<=sal; a++){
        for(int b=0; b<=sbl; b++){
            if(a==0){
                T[a][b] = b;
            }else if(b==0){
                T[a][b] = a;
            }else{
                T[a][b] = 
                    min(min(T[a][b-1]+1, T[a-1][b]+1),
                    T[a-1][b-1]+((sa[a-1]==sb[b-1])?0:1));
            }
        }
    }
    return T[sal][sbl];
}
signed main(){
    while(cin >> sa >> sb){
        cout << solve() << endl;
    }
}


Measured memory_bytes: 11076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n;
ll a[100005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n%2==0){
        ll m=n/2;
        ll ans=0;
        for(int i=0;i<m;i++){
            ans=ans-a[i]*2;
        }
        for(int i=m;i<n;i++){
            ans=ans+a[i]*2;
        }
        ans+=a[m-1];
        ans-=a[m];
        cout<<ans<<endl;
    }else{
        ll m=n/2;
        ll ans=0;
        for(int i=0;i<=m;i++){
            ans=ans-a[i]*2;
        }
        for(int i=m+1;i<n;i++){
            ans=ans+a[i]*2;
        }
        if(a[m-1]+a[m]>3*a[m]-a[m+1]){
            ans=ans+a[m-1]+a[m];
            cout<<ans<<endl;
        }else{
            ans=ans+a[m]*3-a[m+1];
            cout<<ans<<endl;
        }
    }
    
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b&&b==c&&c==a){
		cout << "Yes" << endl;
	}
	else {
		cout << "No"<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T, T) {
    let v: Vec<T> = read_vec();
    (v[0], v[1], v[2])
}

fn main() {
    let N = read_line().parse().unwrap();
    let mut info: Vec<_> = (0..N).map(|_| {
        read_tuple::<i32>()
    }).collect();
    info.sort_by(|a, b| a.2.cmp(&b.2).reverse());
    for cx in 0..101 {
        for cy in 0..101 {
            let mut H = -1;
            let mut ok = true;
            for &(x, y, h) in &info {
                let dx = (x-cx).abs();
                let dy = (y-cy).abs();
                if H == -1 {
                    H = h + dx + dy;
                } else {
                    if h == 0 {
                        if H - dx - dy > 0 {
                            ok = false;
                            break;
                        }
                    } else {
                        if H - dx - dy != h {
                            ok = false;
                            break;
                        }
                    }
                }
            }
            if ok {
                println!("{} {} {}", cx, cy, H);
                return;
            }
        }
    }
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
n = int(raw_input())
s = [''.join(sorted(raw_input())) for _ in range(n)]
d = {}
ans = 0
for si in s:
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

Measured memory_bytes: 20684
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string ans = "No";
    while (n > 0) {
        if (n % 10 == 9) {
            ans = "Yes";
            break;
        }
        n /= 10;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 * ??§????????¨?°????????????\?????????

????????????????????????????°?????????¨??§???????????\????????????????????°????????????????????????????????????

Input
????????????1???????????????????????????

Output
????????????????????????????°?????????¨??§???????????\??????????????????????????????????????????????????¢????????????????????\???????????????????????????????????????????????????

Constraints
??\?????????????????????????????? < 1200
Sample Input
fAIR, LATER, OCCASIONALLY CLOUDY.
Sample Output
Fair, later, occasionally cloudy.

 */

#include <iostream>
#include <locale>
#include <sstream>

int main(int argc, char const *argv[]) {
  std::string FromStr = "fAIR, LATER, OCCASIONALLY CLOUDY.";
  std::string ToStr;
  unsigned short NumberOfCharacters = 0;
  std::ostringstream oss;

  while (true) {
    getline(std::cin, FromStr);
    NumberOfCharacters = FromStr.length();
    if (NumberOfCharacters > 1200) {
      std::cout << "Error: Input string must be under 1200 characters."
                << std::endl;
    } else {
      break;
    }
  }

  for (size_t i = 0; i < NumberOfCharacters; i++) {
    char ToChar;
    if (isupper(FromStr[i])) {
      ToChar = tolower(FromStr[i]);
    } else {
      ToChar = toupper(FromStr[i]);
    }
    oss << ToChar;
  }
  std::cout << oss.str() << std::endl;
  return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://atcoder.jp/contests/abc150/submissions/16076721
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    cin >> a;
    rep(i, n) a[i] /= 2;
    
    // X=ak'*(2p+1)
    set<int> s;
    rep(i, n) {
        int cnt = 0;
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ++cnt;
        }
        s.emplace(cnt);
    }
    if (sz(s) != 1) {
        cout << 0 << endl;
        return;
    }
    // cerr << s << endl;
    
    // X'=ak''(2p+1)
    int beki = pow_(2, *(s.begin()));
    // a[i]はすでに割れてる
    // cerr << beki << endl;
    m /= beki;
    
    ll L = 1;
    rep(i, n) {
        L = lcm(L, a[i]);
        if (L > m) {
            cout << 0 << endl;
            return;
        }
    }
    cout << (m / L + 1) / 2 << endl;
}



Measured memory_bytes: 3712
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Date;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String s = sc.next();
		Date d = new Date(s);
		Date h = new Date("2019/04/30");
		if (d.after(h)) {
			out.println("TBD");
		} else {
			out.println("Heisei");
		}
		sc.close();
	}

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

}


Measured memory_bytes: 22096
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;


typedef struct{
    int backnum;
    double time;
} runner;

void q_sort(runner data[], int begin, int end);

int main(int argc, const char * argv[])
{
    int a = 0;
    runner data[3][8];
    runner under[6];
    for (int i = 0; i < 3; i++) {
        for (int k = 0; k < 8; k++) {
            cin >> data[i][k].backnum >> data[i][k].time;
        }
    }
    for (int i = 0; i < 3; i++) {
        q_sort(data[i], 0, 7);
    }
    for (int i = 0; i < 3; i++){
        for (int k = 2; k < 4; k++) {
            under[a] = data[i][k];
            a++;
        }
    }
    q_sort(under, 0, 5);
    for (int i = 0; i < 3; i++) {
        for (int k = 0; k < 2; k++) {
            printf("%d %.2f\n", data[i][k].backnum, data[i][k].time);
        }
    }
    for (int i = 0; i < 2; i++) {
        printf("%d %.2f\n", under[i].backnum, under[i].time);
    }
    return 0;
}

void q_sort(runner data[], int begin, int end){
    int i = begin;
    int k = end;
    runner pivot;
    runner temp;
    pivot = data[(begin + end) / 2];
    while (1) {
        while (data[i].time < pivot.time) {
            i++;
        }
        while (pivot.time < data[k].time) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = data[i];
        data[i] = data[k];
        data[k] = temp;
        i++;
        k--;
    }
    if (begin < i - 1) {
        q_sort(data, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(data, k + 1, end);
    }
}

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

int main() {
    int n, h, h_max, r;
    cin >> n;
    for(auto i = 0; i != n; ++i) {
        cin >> h;
        if(i == 0)
        {
            h_max = h;
            r = 1;
        }
        else {
            if(h >= h_max) {
                ++r;
                h_max = h;
            }
        }
    }
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

class mll
{
public:
  ll x;
  constexpr mll(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  constexpr mll operator-() const
  {
    return mll(-x);
  }
  constexpr mll& operator+=(const mll& a)
  {
    x += a.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  constexpr mll& operator-=(const mll& a)
  {
    x += MOD - a.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  constexpr mll& operator*=(const mll& a)
  {
    x *= a.x;
    x %= MOD;
    return *this;
  }
  constexpr mll operator+(const mll& a) const
  {
    mll ret(*this);
    ret += a;
    return ret;
  }
  constexpr mll operator-(const mll& a) const
  {
    mll ret(*this);
    ret -= a;
    return ret;
  }
  constexpr mll operator*(const mll& a) const
  {
    mll ret(*this);
    ret *= a;
    return ret;
  }
  constexpr mll pow(ll t) const
  {
    mll ret = 1;
    mll a = *this;
    while (t > 0)
    {
      if (t % 2 == 1)
        ret *= a;
      
      a *= a;
      t /= 2;
    }
    return ret;
  }
  constexpr mll inv() const
  {
    return pow(MOD - 2);
  }
  constexpr mll& operator/=(const mll& a)
  {
    return (*this) *= a.inv();
  }
  constexpr mll operator/(const mll& a) const
  {
    mll ret(*this);
    ret /= a;
    return ret;
  }
};
ostream& operator<<(ostream& os, const mll& m)
{
  os << m.x;
  return os;
}
mll modpow(mll a, ll n)
{
  return a.pow(n);
}
class mllcombination
{
public:
  vector<mll> fac, finv, inv;

  mllcombination(ll M)
  {
    fac.resize(M + 1);
    finv.resize(M + 1);
    inv.resize(M + 1);

    fac.at(0) = 1, finv.at(0) = 1;
    fac.at(1) = 1, finv.at(1) = 1, inv.at(1) = 1;

    for (ll i = 2; i <= M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i;
      inv.at(i) = -inv.at(MOD % i) * (MOD / i);
      finv.at(i) = finv.at(i - 1) * inv.at(i);
    }
  }

  mll P(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(N - K);
  }

  mll C(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(K) * finv.at(N - K);
  }

  mll H(ll N, ll K)
  {
    return C(N + K - 1, K);
  }
};

int main()
{
  ll B, W;
  cin >> B >> W;

  mllcombination com(B + W);

  mll P = 0, Q = 0;
  for (ll i = 0; i < B + W; i++)
  {
    mll ans = ((mll)1 - P + Q) / 2;
    cout << ans << endl;

    P += com.C(i, B - 1) * modpow((mll)1 / 2, i + 1);
    Q += com.C(i, W - 1) * modpow((mll)1 / 2, i + 1);
  }
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, t;
	cin >> k >> t;
	vector<int> a(t);
	rep(i, t) cin >> a[i];
	int mx = *max_element(a.begin(), a.end());
	int ans = max(0, mx - 1 - (k - mx));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2;
typedef pair<int, P2> P3; typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact; constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int w, h, a[55][55];

int main(){
	while(cin >> w >> h,w){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> a[i][j];
			}
		}
		
		int c = 0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(a[i][j] != 1) continue; c++;
				
				queue<P> qu; qu.push({i, j}); a[i][j] = 2;
				while(!qu.empty()){
					auto p = qu.front(); qu.pop();
					
					for(int k = 0; k < 8;){
						int nx = p.first + around[k], ny = p.second + around[++k];
						if(nx<0||ny<0||nx>=h||ny>=w||a[nx][ny] != 1) continue;
						a[nx][ny] = 2;
						qu.push({nx, ny});
					}
				}
			}
		}
		
		cout << c << endl;
	}

	return 0;
}



Measured memory_bytes: 3040
import Control.Monad
import Data.List
import Control.Applicative
import Debug.Trace

main = do
  n <- readLn
  [a,b,c] <- replicateM 3 getLine
  putStrLn $ show $ cnt a b c n

cnt :: [Char] -> [Char] -> [Char] -> Int -> Int
cnt (a:as) (b:bs) (c:cs) n
  |n <= 0 = 0
  |((a:as) == (b:bs)) && ((b:bs) == (c:cs)) = 0
  |(a == b) && (b == c) = (+) 0 $ cnt as bs cs (n -1)
  |length (filter (== a) [b,c]) == 1 = (+) 1 $ cnt as bs cs (n -1)
  |(b == c) = (+) 1 $ cnt as bs cs (n -1)
  |otherwise =  (+) 2 $ cnt as bs cs (n -1)
cnt _ _ _ 0 = 0  

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

int main() {
  int N;
  cin >> N;
  bool a=false;
  for(int i=1;i<N+1;i++){
    int c=i*1.08;
    if(c==N){
      a=true;
      cout << i << endl;
    }
  }
  if(!a){
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double pi = 3.141592653589793;

int main() { 
  int a, b, h, m;
  double ans;
  double c;
  cin >> a >> b >> h >> m;
  // ll a_angle = h * 30 + 0.5 * m;
  double a_angle = h * 30 + 0.5 * m;
  // ll b_angle = 6 * m;
  double b_angle = 6 * m;
  // int angle = a_angle - b_angle;
  double angle = a_angle - b_angle;
  if (angle < 0) {
    angle = angle * (-1);
  }
  if (angle > 180) {
    angle = 360 - angle;
  }
  c = angle / 180.0;
  ans = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(pi * c));
  cout << fixed;
  cout << setprecision(20) << ans << endl;
  return 0;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,L;
  cin>>N>>L;
  vector<string>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  sort(A.begin(),A.end());
  string ans="";
  for(int i=0;i<N;i++)
    ans+=A.at(i);
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
//#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string S, T;
	cin >> S >> T;
	if (S.size() < T.size()) {
		cout << "UNRESTORABLE";
		return 0;
	}
	string a = "??";
	for (int i = 0; i < S.size() - T.size() + 1; i++) {
		bool can = true;
		string ans;
		for (int j = 0; j < T.size(); j++) {
			if (S[j + i] == '?')continue;
			else if (S[j + i] != T[j])can = false;
		}
		if (can) {
			for (int k = 0; k < i; k++) {
				if (S[k] == '?')ans.push_back('a');
				else ans.push_back(S[k]);
			}
			ans += T;
			for (int l = T.size() + i; l < S.size(); l++) {
				if (S[l] == '?')ans.push_back('a');
				else ans.push_back(S[l]);
			}
			if (a == "??")a = ans;
			else a = min(a, ans);
		}
	}
	if (a == "??")cout << "UNRESTORABLE";
	else cout << a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <ll>v;
int main()
{
    long long int a,b,sum=0,n,i=0,avg,m,ans1=0,ans2=0;
    cin>>n;
    m=n;
    while(n--)
    {
        cin>>a;
        sum+=a;
        v.push_back(a);
    }
    ll l=v.size();
    avg=sum/m;
    if(avg*m!=sum)
    {
        for(i=0; i<l; i++)
        {
            ans1+=(v[i]-avg)*(v[i]-avg);
        }
        avg++;
        for(i=0; i<l; i++)
        {
            ans2+=(v[i]-avg)*(v[i]-avg);
        }
        //cout<<ans1<<' '<<ans2<<endl;
        cout<<min(ans1,ans2)<<endl;
    }
    else
    {
        for(i=0; i<l; i++)
        {
            ans1+=(v[i]-avg)*(v[i]-avg);
        }
        cout<<ans1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    ll N,a;
    cin >> N;
    vector<ll> A;
    rep(i,N){
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end(), greater<ll>());

    ll first=0,second=0;
    ll i2=-1;
    llrep(i,A.size()){
        if (i+1<A.size() && A[i]==A[i+1]){
            first = A[i];
            i2 = i+2;
            break;
        }
    }
    if (i2==-1){
        cout << 0 << endl;
        return 0;
    }
    for(ll i=i2; i<A.size(); i++){
        if (i+1<A.size() && A[i]==A[i+1]){
            second = A[i];
            break;
        }
    }
    cout << first * second << endl;

    return 0;
}


Measured memory_bytes: 1400
//類題ABC137D
#include<stdio.h>
#define ll long long
#define min(p,q)((p)<(q)?(p):(q))

//*
//プラキュー（二分ヒープ）（最低限バージョン）
//int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
int PQhikaku(ll*heap,int i,int j){return heap[i]<heap[j];}
void heap_utod(ll*heap,int n){
	if(2*n>heap[0])return;
	int rflag=(2*n+1<=heap[0])&&(PQhikaku(heap,2*n,2*n+1));
	if(PQhikaku(heap,n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heap_utod(heap,2*n+rflag);
	}
}
void heap_dtou(ll*heap,int n){
	if(n==1||PQhikaku(heap,n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heap_dtou(heap,n/2);
}
ll PQpop(ll*heap){
	ll rr=heap[1];
	heap[1]=heap[heap[0]--];
	heap_utod(heap,1);
	return rr;
}
void PQpush(ll*heap,ll n){
	heap[++heap[0]]=n;
	heap_dtou(heap,heap[0]);
}
//*/

ll h[100010];
ll a[100010];
ll b[100010];
ll c[100010];
ll d[100010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%lld%lld",a+i,b+i);
	for(int i=0;i<m;i++)scanf("%lld%lld",c+i,d+i);
	{
		int mm=2e9;
		int crr=0;
		for(int i=0;i<m;i++)if(d[i]<mm){
			c[crr]=c[i];
			d[crr]=d[i];
			mm=d[i];
			crr++;
		}
		c[crr]=2e9;
		d[crr]=1;
		crr++;
		m=crr;
	}
	
	int crr=0;
	ll ans=0;
	int limit=2e9;
	for(int i=0;i<m;i++){
		while(crr<n&&a[crr]<c[i])PQpush(h,b[crr++]);
		while(h[0]&&limit>d[i])ans+=PQpop(h),limit--;
		limit=d[i];
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 5700
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
set<ll> s;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
void primeFactors(ll n)  
{  
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
            {
              
                if(i>=2)
                s.insert(i);
			}
  
            else 
            {
            
            if(i>=2)
               s.insert(i);
               if(n/i>=2)
               s.insert(n/i);
			}
        } 
    }   
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll x;
	cin>>x;
	ll ans=0;
	ans+=(x/500)*1000;
	x%=500;
	ans+=(x/5)*5;
	cout<<ans;
 cout<<"\n"; 
 } 
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Long[] A = new Long[N];
    for(int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    Arrays.sort(A, Comparator.reverseOrder());
    ArrayList<Long> sides = new ArrayList<>();
    boolean flag = false;
    long result = 0;

    for(int i = 0; i < A.length - 1; i++) {
      long bar1 = A[i];
      long bar2 = A[i + 1];
      if (bar1 == bar2 && !flag) {
        sides.add(bar1);
        flag = true;
      } else {
        flag = false;
      }
      if (sides.size() == 2) {
        result = sides.get(0) * sides.get(1);
        break;
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 62796
package main

import "fmt"

var (
	x = []int{0, 1, 0, -1}
	y = []int{1, 0, -1, 0}
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	s := make([]string, h)
	for i := range s {
		fmt.Scan(&s[i])
	}

	for i := 0; i < h; i++ {
	L:
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				for k := 0; k < 4; k++ {
					if i+y[k] < 0 || i+y[k] >= h || j+x[k] < 0 || j+x[k] >= w {
						continue L
					}
					if s[i+y[k]][j+x[k]] == '#' {
						continue L
					}
				}
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    while (1) {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x <= y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
const int N=1e6+10;
using namespace std;
ll a,b,k;

int main() {
  cin>>a>>b>>k;
  if(k<a){
      cout<<a-k<<" "<<b<<endl;
      return 0;
  }
  else if(k>=a && b>=(k-a)){
      cout<<0<<" "<<b+a-k<<endl;
  }
  else
      cout<<"0 0"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		sD();
	}
	
	void sD() {
		int N = sc.nextInt();
		long K = sc.nextLong();
		long A[] = new long[N];
		for(int i = 0; i < N; i++) A[i] = sc.nextLong();
		//ビットごとの1の数を数える。
		int bitCount[] = new int[64];//インデックス：右からiビット
		Arrays.fill(bitCount, 0);
		for(int i = 0; i < N; i++) {
			for(int j = 0; A[i] >= (1l << j) ; j++) {
				if(((A[i] >> j) & 1) == 1) {
					bitCount[j]++;
				}
			}
		}
		//System.out.println(Arrays.toString(bitCount));
		
		//Xを求める
		long X = 0;
		for(int i = 62; i >= 0; i--) {//0~62ビットに数値、63ビットに符号。
			//0が多いビットは1、1が多いビットは0にしたい
			if(bitCount[i] < N - bitCount[i]) {
				long bit = 1l << i;
				if(X + bit <= K) X += bit;//Kを超えない
			}
		}
		//System.out.println(X);
		
		//答えを求める
		long ans = 0;
		for(int i = 0; i < N; i++) ans += (A[i] ^ X);
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 61004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 cs[26];
string NG = "zyxwvutsrqponmlkjihgfedcba";

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    if(s==NG){
        cout<<-1<<endl;
        return 0;
    }
    int n = s.size();
    if(n!=26){
        for(auto a : s){
            cs[(int)(a-'a')] = 1;
        }
        rep(i, 26){
            if(cs[i] == 0){
                cout<<s<<(char)(i+'a')<<endl;
                return 0;
            }
        }
    }else{
        string t = s;
        next_permutation(all(t));
        for(int i=0; i<26; i++){
            if(s[i]==t[i]){
                cout<<s[i];
            }else{
                cout<<t[i]<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
//xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int a,b,h,m; cin >> a >> b >> h >> m;
  int hunsin = m*6;
  double jisin = (h*60+m)*0.5;
  double kakudo = abs(hunsin-jisin);
  if(kakudo > 180) kakudo = 360-kakudo;
  cout << setprecision(15) <<
   (double)sqrt(a*a+b*b-2*a*b*cos(2*M_PI*kakudo/360.0));
}


Measured memory_bytes: 4228
s = input()
ans = [0]*len(s)
a = [-1]
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        a.append(i)
a.append(len(s)-1)
for i in range(len(a)//2):
    ans[a[2*i+1]] += (a[2*i+1]-a[2*i]+1)//2 + (a[2*i+2]-a[2*i+1])//2
    ans[a[2*i+1]+1] += (a[2*i+1]-a[2*i])//2 + (a[2*i+2]-a[2*i+1]+1)//2
print(' '.join(map(str,(ans))))

Measured memory_bytes: 51012
#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 ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];

void solve()
{
	string s, t;
	cin >> s >> t;
	int ret = INF;
	int n = s.size();
	int m = t.size();
	int left = n;
	for(int i = 0; i < n; i++, left--)
	{
		if(left < m) break;
		int ptr = i;
		int temp = 0;
		for(int j = 0; j < m; j++) temp += (s[ptr++] != t[j]);
		ret = min(ret, temp);
	}
	cout << ret << endl;
}

 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

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

int solve( int N ){
if( N == 1 ) return 1;

int ans = 2 * solve(N/2) + 1;
N /= 2;
return ans;

}


signed main() {
int H;
cin >> H;
int a = solve(H);
cout << a << endl;

}
  

  

  

  



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

using namespace std;

int main() {
	int h;
	while (cin >> h) {
		if (h == 0) {
			break;
		}
		vector< vector<int> > data(h, vector<int>(5));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> data[i][j];
			}
		}
		int point = 0;
		while (true) {
			vector< vector<int> > prev = data;
			int ans = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < 3; j++) {
					if (data[i][j] == data[i][j + 1] && data[i][j] == data[i][j + 2]) {
						if (j < 2 && data[i][j] == data[i][j + 3]) {
							if (j < 1 && data[i][j] == data[i][j + 4]) {
								ans += data[i][j] * 5;
								data[i][j] = data[i][j + 1] = data[i][j + 2] = data[i][j + 3] = data[i][j + 4] = 0;
								continue;
							}
							ans += data[i][j] * 4;
							data[i][j] = data[i][j + 1] = data[i][j + 2] = data[i][j + 3] = 0;
							continue;
						}
						ans += data[i][j] * 3;
						data[i][j] = data[i][j + 1] = data[i][j + 2] = 0;
						break;
					}
				}
			}
			for (int j = 0; j < 5; j++) {
				for (int i = h-1; i >=0; i--) {
					if (data[i][j] == 0) {
						for (int k = i -1; k >= 0; k--) {
							if (data[k][j] != 0) {
								data[i][j] = data[k][j];
								data[k][j] = 0;
								break;
							}
						}
					}
				}
			}
			point += ans;
			if (data == prev) {
				break;
			}
		}
		cout << point << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// range sum query using fenwick tree
// note index starts at 1

class fenwick_tree {
	vector<long> t;
	long size;
public:
	fenwick_tree(long n) {
		t.assign(n + 1, 0);
		size = n + 1;
	}

	long LSOne(long k) {	// least significant 1-bit
		return k & (-k);
	}

	void update(long index, long val) {	// can go up or go down
		for (; index < size; index += LSOne(index)) t[index] += val;
	}

	long query_full(long a, long b) {		// range query
		return query(b) - ((a <= 1) ? 0 : query(a - 1));
	}

	long query(long b) {	// range query 1..b
		if (b < 1) return 0;

		long sum = 0;
		for (; b; b -= LSOne(b)) sum += t[b];
		return sum;
	}
};



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

	long long n, i, j, k, ans, a, b, c, x, y, xx, yy, p, v;
	cin >> n;
	vector<pair<long long, long long>> d(n);
	for (i = 0; i < n; i++) {
		cin >> x;
		d[i] = { x, i + 2 };
	}

	sort(d.rbegin(), d.rend());

	fenwick_tree ft(n + 3);
	ft.update(1, 1); 
	ft.update(n + 2, 1);

	ans = 0;
	for (i = 0; i < n; i++) {
		p = d[i].second;

		a = p + 1; b = n + 2;
		while (a < b) {
			c = (a + b) / 2;
			v = ft.query_full(p + 1, c);
			if (v >= 1) b = c;
			else a = c + 1;
		}
		y = a;

		if (y == n + 2) yy = y;
		else {
			a = p + 1; b = n + 2;
			while (a < b) {
				c = (a + b) / 2;
				v = ft.query_full(p + 1, c);
				if (v >= 2) b = c;
				else a = c + 1;
			}
			yy = a;
		}
			   
		a = 1; b = p - 1;
		while (a < b) {
			c = (a + b + 1) / 2;
			v = ft.query_full(c, p - 1);
			if (v >= 1) a = c;
			else b = c - 1;
		}
		x = b;

		if (x == 1) xx = 1;
		else {
			a = 1; b = p - 1;
			while (a < b) {
				c = (a + b + 1) / 2;
				v = ft.query_full(c, p - 1);
				if (v >= 2) a = c;
				else b = c - 1;
			}
			xx = b;
		}

		v = (y - p) * (x - xx) + (p - x) * (yy - y);
		ans += d[i].first * v;

		ft.update(p, 1);
	}

	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 2560
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func readLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	ss := strings.Split(readLine(), " ")
	tt := make([]int, len(ss))
	for i := 0; i < len(ss); i++ {
		tt[i], _ = strconv.Atoi(ss[i])
	}
	sort.Ints(tt)
	fmt.Println(tt[2]*10 + tt[1] + tt[0])
}


Measured memory_bytes: 640
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    long N;
    cin>>N;
    long t[N],a[N];
    for(long i=0;i<N;i++ ){
        cin>>t[i]>>a[i];
    }
    long A=1,T=1;
    for(long i=0;i<N;i++){
        long n,na,nb;
        if(T%t[i]==0) {na=T/t[i];} else {na=T/t[i]+1;}
        if(A%a[i]==0) {nb=A/a[i];} else {nb=A/a[i]+1;}
        if(na>nb) {n=na;}
        else {n=nb;}
        T=n*t[i]; A=n*a[i];
        
    }
    cout<<A+T;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p = 1e9 + 7;
LL n, a, b, ans;

LL qwe(LL a, LL n) { //快速幂
	LL res = 1LL;
	while(n) {
		if(n & 1) res = res * a % p;
		a = a * a % p;
		n >>= 1LL;
	}
	return res % p;
}

LL inv(LL x) { //逆元
	return qwe(x, p - 2) % p;
}

LL C(LL n, LL m) { //组合数
	LL res = 1LL;
	for(LL i = 1, j = n; i <= m; i++, j--) {
		res = res * j % p;
		res = res * inv(i) % p;
	}
	return res;
}

LL lucas(LL a, LL b) {
	if(a < p && b < p) return C(a, b);
	return C(a % p, b % p) * lucas(a / p, b / p) % p;
}

int main() {
	cin >> n >> a >> b;
	ans = (qwe(2LL, n) - (lucas(n, a) % p + lucas(n, b) % p) % p - 1 + p) % p;
	cout << ans << endl;
    return 0;
}

/*
n和m较大, 且p为素数时
Lucas定理作用: c(n, m) mod p
C(n, m) % p = C(n / p, m / p) * C(n % p, m % p) % p
=> Lucas(n, m) % p = Lucas(n / p, m / p) * C(n % p, m % p) % p
*/

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }
    let sum = s
        .chars()
        .map(|x| x as i64 - '0' as i64)
        .fold(0, |acc, x| acc + x);
    if (sum % 9) == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2392
A,B,C,D = map(int,input().split())
def f(x,y):
  if x<y:
    x,y = y,x
  if y==0:
    return x
  return f(y,x%y)
E = C*D//f(C,D)
C = B//C-A//C+1 if A%C==0 else B//C-A//C
D = B//D-A//D+1 if A%D==0 else B//D-A//D
E = B//E-A//E+1 if A%E==0 else B//E-A//E
print(B-A-C-D+E+1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
#include<string>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

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

	if(S[2] == S[3] && S[4] == S[5])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

readInts = map read . words <$> getLine :: IO [Int]

solve [r, d, x2000] = take 10 $ drop 1 $ iterate next x2000
  where
    next x = r * x - d

main = readInts >>= mapM_ print . solve


Measured memory_bytes: 508
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<double> V(N);
    for(int i=0; i<N; i++) cin >> V[i];

    sort(V.rbegin(), V.rend());
    for(int i=0; i<N-1; i++) {
        double a = V.back(); V.pop_back();
        double b = V.back(); V.pop_back();
        V.emplace_back((a + b) / 2);
        sort(V.rbegin(), V.rend());
    }
    cout << fixed << setprecision(15) << V[0] << endl;
    return 0;
}


Measured memory_bytes: 256