akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long MOD=1000000007;
long powmod(long x,long p){return (p==0?1:(p%2?powmod(x,p-1)*x%MOD:powmod(x,p/2)*powmod(x,p/2)%MOD));}
long inv(long x){return powmod(x,MOD-2);}
long COM(long n,long k){long r=1;for(long i=0;i<k;i++){r=r*(n-i)%MOD;r=r*inv(i+1)%MOD;}return r;}
int main(){
  long n,a,b;cin>>n>>a>>b;
  cout<<(powmod(2,n)-1+(MOD-COM(n,a))+(MOD-COM(n,b)))%MOD;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)cout << C << endl;
	else if (A == C)cout << B << endl;
	else cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cerr << i << ' '; cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 2019;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, k;
	cin >> n >> k;
	VecP a(n);
	rep(i, n) cin >> a[i].sc >> a[i].fs;

	sort(all(a));
	reverse(all(a));
	Vec cs(n);
	rep(i, n){
		if(i == 0) cs[i] = a[i].fs;
		else cs[i] = cs[i - 1] + a[i].fs;
	}

	VecB used(n, false);
	unordered_set<ll> ust;

	ll ans = 0, sum = 0;
	ll l = k - 1, r = 0;
	repn(i, k){
		while(r < n && ust.find(a[r].sc) != ust.end()) r++;
		if(r >= n) break;
		ust.insert(a[r].sc);
		used[r] = true;
		if(r <= l) chmax(ans, cs[l] + i * i);
		else{
			sum += a[r].fs;
			while(used[l]){
				sum += a[l--].fs;
			}
			l--;
			if(l < 0) break;
			chmax(ans, cs[l] + sum + i * i);
		}
		ce({l, r, ans});
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 6028
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int cap=scn.nextInt();
		long[] c=new long[n+1];
		long[] v=new long[n+1];
		
		
		for(int i=0;i<n;i++) {
			long a=scn.nextLong();
			long b=scn.nextLong();
			c[i]=a;
			v[i]=b;
			
			
		}
		System.out.println(kp(c,v,cap,0));
				

	}
	public static long kp(long[] c,long[] v,int cap,int vidx) {
		long[][] dp=new long[c.length+1][cap+1];
		for(int i=0;i<=c.length;i++) {
			for(int j=0;j<=cap;j++) {
				if(i==0||j==0) {
					dp[i][j]=0;
				}else {
					
					
					if(j>=c[i-1]) {
						//System.out.println(j-c[i-1]);
						dp[i][j]=Math.max(dp[i-1][j], v[i-1]+dp[i-1][(int) (j-c[i-1])]);
					}else {
						dp[i][j]=dp[i-1][j];
					}
					
				}
				
			}
		}
		
		
		return dp[c.length-1][cap];
		
		
		
		
	}

}


Measured memory_bytes: 140516
import sys
input = sys.stdin.readline

def main():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

    base_w = wv[0][0]
    dic = {wv[0][0]:[], wv[0][0]+1:[], wv[0][0]+2:[], wv[0][0]+3:[]}
    for i in range(N):
        w, v = wv[i]
        dic[w].append(v)
    
    # python3.7.2だと奇跡的に辞書型が宣言順になってたけど，
    # python3.4.3だと順序が保証されないのでちゃんとソートしないとだめ!
    wv = sorted(list(dic.items()))
    tmp = [None for i in range(4)]
    for i in range(4):
        num, l = wv[i]
        l = sorted(l, reverse=True)
        for j in range(1, len(l)):
            l[j] += l[j-1]
        tmp[i] = [0] + l

    # for i in range(4):
    #     print(tmp[i][:10])

    ans = 0
    for i in range(len(tmp[0])):
        for j in range(len(tmp[1])):
            for k in range(len(tmp[2])):
                for l in range(len(tmp[3])):
                    weight = base_w * i + (base_w + 1) * j + (base_w + 2) * k + (base_w + 3) * l
                    if weight <= W:
                        val = tmp[0][i] + tmp[1][j] + tmp[2][k] + tmp[3][l]
                        if ans < val:
                            ans = val
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a >= k)pf(k);
    else if(a + b >= k)pf(a);
    else pf(a - (k - a - b));
    return 0;
}


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

const int INF = 2e9;

int main(){
    ll n;
    cin >> n;
    string ans = "";
    while(n>0){
        n--;
        ans += char('a' + n%26);
        n /= 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}

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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

int main(void) {
    string s;
    cin >> s;
    UInt len = s.length();
    Int k;
    cin >> k;
    for (Int i = 1; i <= len; ++i) {
        if (s[i - 1] == '1' && k == i) {
            cout << '1' << endl;
            break;
        } else if (s[i - 1] != '1') {
            cout << s[i - 1] << endl;
            break;
        }
    }
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N;
    private List<int>[] Edge;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        Edge = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            Edge[i] = new List<int>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int a = sc.NextInt();
            int b = sc.NextInt();
            Edge[a].Add(b);
            Edge[b].Add(a);
        }

        // node iの子が k個
        // 部分木 k個
        // アンテナが無い木が2つ以上ある
        // 無い部分木を区別できない
        // 無い木は1つ以下

        // 次数が3以上の頂点を根として見る
        // 親側には必ずアンテナがある
        // 

        int root = -1;
        for (int i = 0; i < N; i++)
        {
            if (Edge[i].Count >= 3) root = i;
        }

        if (root == -1)
        {
            Console.WriteLine(1);
            return;
        }
        Console.WriteLine(Search(root, -1));
    }

    // 現在地、親、置く必要があるか?
    int Search(int n, int parent)
    {
        int sum = 0;
        int cnt = 0;
        foreach (int to in Edge[n])
        {
            if (parent == to) continue;
            int t = Search(to, n);
            if (t == 0) cnt++;
            sum += t;
        }

        if (cnt >= 1) sum += cnt - 1;
        return sum;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 33576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n;
  cin >> n;
  vector<pair<ll,ll>> a(n);
  rep(i,n) {
    int t;
    cin >> t;
    a[i]= {t,i};
  }
  sort(a.rbegin(),a.rend());

  ll dp[n+1][n+1];
  rep(i,n+1)rep(j,n+1)dp[i][j] = 0;

  rep1(i,n){
    ll val = a[i-1].first;
    ll pre_pos = a[i-1].second;
    for(int j=0;j<=i;j++){
      if(j-1>=0) dp[i][j] = dp[i-1][j-1] + abs(j-1 - pre_pos)*val;
      if(i-1>=j) dp[i][j] = max(dp[i][j],dp[i-1][j] + abs(n - (i-1-j) -1 - pre_pos)*val);
      // cout << i << " " << j <<" "<< dp[i][j] << endl;
    }
  }
  ll ans =0;
  rep(i,n+1){
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;


  return 0;
    

}


Measured memory_bytes: 34976
H, W = list(map(int, input().split()))
# Hを３分割してH_minとH_maxを作る→H_max-H_min=1より、面積の差はW

# Wを３分割しても同様。面積の差はH
def Diff(H, W):
    # H方向に２分割してからW方向に２分割することを考える
    H_min = int(H / 3)
    H_max = int(H / 3) + 1
    #Hとして当てはまるのは上のいずれか
    W_short = int(W / 2)
    W_long = W - W_short
    S_1_1 = [H_min * W, (H - H_min) * W_short, (H - H_min) * W_long]
    S_1_2 = [H_max * W, (H - H_max) * W_short, (H - H_max) * W_long]
    D_1_1 = max(S_1_1) - min(S_1_1)
    D_1_2 = max(S_1_2) - min(S_1_2)
    return min(D_1_1, D_1_2)
R = []
R.append(H)
R.append(W)
R.append(Diff(H, W))
R.append(Diff(W, H))
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    print(min(R))


Measured memory_bytes: 3064
#include <iostream>
#define ll long long 
using namespace std;
ll power(ll k,ll n){
 ll prod=1;
 while(n){
  if(n%2) prod=prod*k;
   k=k*k;
   n/=2;
 }
 return prod;


}
int main() {
   #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n,k; cin>>n>>k;
 ll ans=k*power(k-1,n-1);
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 3616
#include <cstdio>

int main() {
  //入力
  int a,b,c;
  std::scanf("%d %d %d",&a,&b,&c);
 
  if(a < b && b < c) {
    std::printf("Yes");
  }
  
  else if(!(a < b && b < c)) {
    std::printf("No");
  }
  

  
  std::printf("\n");
  
  
  return 0;
}



Measured memory_bytes: 2712
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

int main() {
#ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
#endif
    //ios_base::sync_with_stdio(false);
    //
    multiset<int> a;

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a.insert(x);
    }

    int m;
    cin >> m;
    for (int j = 0; j < m; ++j) {
        int x;
        cin >> x;
        auto it = a.find(x);
        if (it == a.end()) {
            cout << "NO\n";
            return 0;
        }
        a.erase(it);
    }

    cout << "YES\n";

    return 0;
}



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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	int k;
	cin >> k;
	if(k%2==0||k%5==0) {
		cout << "-1";
		return;
	}
	int track=0, ans=-1;
	for(int i=0;;i++) {
		track=(track*10+7)%k;
		if(track==0) {
			ans=i+1;
			break;
		}
	}
	cout << ans;
}
int main(){
   fastio();
   go();

   return 0;
}




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

int N;
double x[10], y[10];

double dist(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx + dy*dy, 0.5);
}

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> x[i] >> y[i];
  double sum = 0.0;
  vector<int> towns(N);
  for (int i = 0; i < N; i++) towns[i] = i+1;
  do {
    for (int i = 0; i < N-1; i++) {
      sum += dist(towns[i], towns[i+1]);
    }
  } while (next_permutation(towns.begin(), towns.end()));
  int fact = 1;
  for (int i = 2; i <= N; i++) fact *= i;
  cout << fixed << setprecision(12) << sum/fact << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  ci(A[0]);
  
  FOR(i,1,n){
    ci(A[i]);
    A[i]+=A[i-1];
  }
  ll ans=100;
  FOR(i,0,n-1){
    ans=min(ans,abs(A[n-1]-2*A[i]));
  }
  co(ans)
}

Measured memory_bytes: 256
from fractions import gcd

def init(init_val):
    for i in range(n):
        seg[i+num-1] = init_val[i]
    for i in range(num-2,-1,-1) :
        seg[i] = gcd(seg[2*i+1],seg[2*i+2]) 

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = gcd(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return I
    p += num-1
    q += num-2
    res = I
    while q-p>1:
        if p&1 == 0:
            res = gcd(res,seg[p])
        if q&1 == 1:
            res = gcd(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = gcd(res,seg[p])
    else:
        res = gcd(gcd(res,seg[p]),seg[q])
    return res


I = 0
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n = int(readline())
a = [int(i) for i in readline().split()]
num = 2**(n-1).bit_length()
seg=[I]*2*num
init(a)
ans = 1
for i in range(n):
  ans = max(ans,gcd(query(0,i),query(i+1,n)))
  
print(ans)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N);

  int k, s;
  for (int i = 0; i < M; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      s--;
      a[s] |= 1 << i;
    }
  }

  int p = 0;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    p |= x << i;
  }
  
  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if ((i>>j) & 1) {
        sum ^= a[j];
      }
    }
    if (sum == p) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,s=[-1]*-~n,[-1]*-~n
for i,(a,b)in enumerate(t):
  x,y=sorted((r(a),r(b)))
  if(x!=y)*m>i:
    p[x]+=p[y]
    p[y]=x
  if(x!=y)*i<m:
    s[a]-=1
    s[b]-=1
print(*[s[i+1]-p[r(i+1)]for i in range(n)])

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  string s;
  cin >> s;
  int n = s.size();

  int ans = 0;
  REP(i, n / 2) {
    if (s[i] != s[n - i - 1]) {
      ans++;
    }
  }
  ANS(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int A, B;
    cin >> A >> B;
    cout << max(0, A - 2 * B) << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();
        int n3 = sc.nextInt();

        Integer red[] = new Integer[n1];
        Integer green[] = new Integer[n2];
        Integer cls[] = new Integer[n3+r+g];

        for(int i=0;i<n1;i++)
            red[i] = sc.nextInt();
        
        for(int i=0;i<n2;i++)
            green[i] = sc.nextInt();
        
        for(int i=0;i<n3;i++)
            cls[i] = sc.nextInt();
        
        Arrays.sort(red,Collections.reverseOrder());
        Arrays.sort(green,Collections.reverseOrder());
        //Arrays.sort(cls,Collections.reverseOrder());

        for(int i=0;i<r;i++){
            cls[n3+i] = red[i];
        }

        for(int i=0;i<g;i++){
            cls[n3+r+i]=green[i];
        }

        Arrays.sort(cls,Collections.reverseOrder());

        long deliciousness = 0;
        for(int i=0;i<r+g;i++){
            deliciousness += cls[i];
        }

        System.out.println(deliciousness);

    }
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int X, N;
  cin >> X >> N;
  vector< int > P(N);
  cin >> P;
  int ret = inf, tap;
  for(int k = 0; k <= 101; k++) {
    bool ok = true;
    for(int i = 0; i < N; i++) {
      ok &= P[i] != k;
    }
    if(ok) {
      if(chmin(ret, abs(X - k))) tap = k;
    }
  }
  cout << tap << "\n";
}


Measured memory_bytes: 3656
cnt = 0


def insertion_sort(seq, n, g):
    global cnt
    for i in range(g, n):
        v = seq[i]
        j = i - g
        while j >= 0 and seq[j] > v:
            seq[j + g] = seq[j]
            j = j - g
            cnt = cnt + 1
        seq[j + g] = v


def shell_sort(seq, n):
    g = 1
    G = []
    while g <= n:
        G.append(g)
        g = 3 * g + 1
    print(len(G))
    print(' '.join(map(str, reversed(G))))

    for g in reversed(G):
        insertion_sort(seq, n, g)
    return seq

n = int(input())
a = [int(input()) for _ in range(n)]
ans = shell_sort(a, n)
print(cnt)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 127924
# coding: utf-8

# In[33]:


"""問題文

とある世界では、今日はクリスマスイブです。

高羽氏の庭には N
本の木が植えられています。i 本目の木 (1≤i≤N) の高さは hi

メートルです。

彼は、これらの木のうち K

本を選んで電飾を施すことにしました。より美しい光景をつくるために、できるだけ近い高さの木を飾り付けたいです。

より具体的には、飾り付ける木のうち最も高いものの高さを hmax
メートル、最も低いものの高さを hmin メートルとすると、hmax−hmin が小さいほど好ましいです。hmax−hmin

は最小でいくつにすることができるでしょうか？
制約

    2≤K<N≤105

1≤hi≤109
hi

    は整数である。

入力

入力は以下の形式で標準入力から与えられる。

N

 K


h1


h2


:


hN


出力

hmax−hmin

としてありうる最小の値を出力せよ。
入力例 1
Copy

5 3
10
15
11
14
12

出力例 1
Copy

2
"""


# In[45]:


N,K=map(int,input().split(" "))


# In[46]:


p=[]
for i in range(N):
    p.append(int(input()))


# In[49]:


p.sort()


# In[56]:


print(min(p[i+K-1]-p[i] for i in range(N-K+1)))



Measured memory_bytes: 7388
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, t;
int a[100001];

int main(int argc, char **argv) {
	cin >> n >> t;
	REP(i, n) cin >> a[i];
	a[n] = -1;

	int x = 0, mi = a[0];
	REP(i, n) {
		mi = min(mi, a[i]);
		x = max(x, a[i] - mi);
	}

	mi = a[0];
	int mic = 1, mac = 0, res = 0;
	FOR(i, 1, n + 1) {
		if (a[i] == mi) {
			++mic;
		}
		else if (a[i] - mi == x) {
			++mac;
		}
		else if (a[i] < mi) {
			res += min(mic, mac);
			mi = a[i];
			mic = 1;
			mac = 0;
		}
	}
	cout << res << endl;


	return 0;
}


Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 10000000100;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppd pair<double,double>
#define ppp pair<ll,pp>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll n;
int main() {
	cin >> n;
	ll num = 1,ct=2,m=-1;
	vector<ll>v[1000];
	while (num < 100000) {
		if (num == n)m=ct;
		num += ct; ++ct;
	}
	if (m==-1) {
		cout << "No" << endl;
		return 0;
	}
	else {
		ct = 1;
		rep(i, m) {
			for (int j = i + 1; j < m; ++j) {
				v[i].pb(ct); v[j].pb(ct);
				++ct;
			}
		}
		cout <<"Yes"<<endl<<m<<endl;
		rep(i, m) {
			cout <<v[i].size() << " ";
			rep(j, v[i].size())cout << v[i][j] << (j == v[i].size()-1 ? "\n" : " ");
		}
	}
	return 0;
}

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

using namespace std;

int H, W;
char s[2020][2020];
int h[2020][2020];
int w[2020][2020];

int main() {
  cin >> H >> W;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      cin >> s[y][x];
    }
  }

  int cnt = 0;
  for (int y = 0; y < H; y++) {
    cnt = 0;
    for (int x = 0; x < W; x++) {
      if (s[y][x] == '#') {
        cnt = 0;
        continue;
      }
      cnt++;
      w[y][x] = cnt;
    }
    cnt = 0;
    for (int x = W - 1; 0 <= x; x--) {
      if (s[y][x] == '#') {
        cnt = 0;
        continue;
      }
      cnt = max(cnt, w[y][x]);
      w[y][x] = cnt;
    }
  }

  for (int x = 0; x < W; x++) {
    cnt = 0;
    for (int y = 0; y < H; y++) {
      if (s[y][x] == '#') {
        cnt = 0;
        continue;
      }
      cnt++;
      h[y][x] = cnt;
    }
    cnt = 0;
    for (int y = H - 1; 0 <= y; y--) {
      if (s[y][x] == '#') {
        cnt = 0;
        continue;
      }
      cnt = max(cnt, h[y][x]);
      h[y][x] = cnt;
    }
  }

  int ans = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      ans = max(ans, h[y][x] + w[y][x] - 1);
    }
  }

  cout << ans << endl;

  return 0;
}

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

As = []
for i in range(0,N):
    As.append(int(input()))

start = As[0]
steps = 1

if start == 2:
    print(steps)
    exit()

while True:
    next = As[start - 1]
    steps += 1
    if next == 2:
        break
    else:
        if next == start or steps > N:
            print(-1)
            exit()

    start = next

print(steps)

Measured memory_bytes: 7084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
const int maxn = 10000;
using namespace std;

int main()
{
    long long a[150];
    int n,i;
    long long x;
    cin>>n>>x;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a, a+n);
    long long he = 0;
    for(i=0; i<n; i++){
        he += a[i];
        if(he >= x)
            break;
    }
    int ans;
    if(i == n){
        if(he == x)
            ans = n;
        else
            ans = n-1;
    }
    else{
        if(he == x)
            ans = i+1;
        else
            ans = i;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 888
import heapq
N,M=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
    
for i in range(0,M):
    tmp=heapq.heappop(A)
    heapq.heappush(A,-int(-tmp/2))
print(-sum(A))

Measured memory_bytes: 14180
#include<stdio.h>
int main(void){
	while(1){
		int l,m,n,r=0,cnt=0;
		scanf("%d",&l);
		if(l==0)return 0;
		int i;
		for(i=0;i<12;i++){
			scanf("%d%d",&m,&n);
			r+=(m-n);
		    
			if(r>=l&&cnt==0)cnt=i+1;
		}
		if(cnt!=0)printf("%d\n",cnt);
		else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,s=0;
  vector<int> v;
  cin>>n;
  v.resize(n);
  for(int i=0;i<n;i++){cin>>v[i];v[i]-=i+1;}
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)s+=abs(v[i]-v[n/2]);
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    S = N * L + N * (N - 1) // 2
    if L <= 0 and N + L -1 >= 0:
        print(S)
    elif L > 0:
        print(S-L)
    else:
        print(S-(N + L - 1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int t[15][15];
int n,m;

int check(int a,int b,int c,int d){
	if(c-a<2 || d-b<2)return -1;
	int i,j,k;
	int p,q,r;//min_edge max_inter sum
	p=100,q=-1,r=0;
	for(i=a;i<=c;i++){
		for(j=b;j<=d;j++){
			if(a<i && i<c && b<j && j<d){
				if(q<t[i][j])q=t[i][j];
				r+=t[i][j];
			}else if(t[i][j]<p)p=t[i][j];
		}
	}
	if(p<=q)return -1;
	return p*(c-a-1)*(d-b-1)-r;
}


int main(){
	int i,j,k,l;
	int a,b,c;
	int s=0;
	while(cin>>n>>m){
		if(!n)break;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				cin>>t[i][j];
			}
		}
		s=0;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				for(k=0;k<n;k++){
					for(l=0;l<m;l++){
						a=check(i,j,k,l);
						if(s<a)s=a;
					}
				}
			}
		}
		cout<<s<<endl;
	}
}



Measured memory_bytes: 3088
#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;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int x;
	cin >> x;
	
	if(x >= 400 && x < 600)cout << "8";
	else if(x < 800)cout << "7";
	else if(x < 1000)cout << "6";
	else if(x < 1200)cout << "5";
	else if(x < 1400)cout << "4";
	else if(x < 1600)cout << "3";
	else if(x < 1800)cout << "2";
	else cout << "1";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


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

using namespace std;

const int N = 1004;

int n, a[N];

int main(){

    scanf("%d", &n);

    int sum = 0;
    for(int i = 0; i < n; i++) scanf("%d", a+i), sum += a[i];


    int ans = 0;

    for(int i = 0; i < n; i++){
        if(abs(n*a[i] - sum) < abs(n*a[ans]-sum)){
            ans = i;
        }
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

bool check(int x, vector<int>& as, int k)
{
	static vector<int> bs;

	bs = as;
	const int n = as.size();

	for(int i = 0; i < n; i++) {
		bs[i] = bs[i] % x;
	}
	sort(bs.begin(), bs.end());

	int lo_k = k, hi_k = k;
	int lo_c = 0, hi_c = 0;

	while(lo_c < n) {
		int b = bs[lo_c];
		if(b > lo_k) {
			break;
		}
		lo_c += 1;
		lo_k -= b;
	}

	while(hi_c < n) {
		int b = x - bs[n - 1 - hi_c];
		if(b > hi_k) {
			break;
		}
		hi_c += 1;
		hi_k -= b;
	}

	return lo_c + hi_c >= n;
}

int main()
{
	int n, k;
	vector<int> as;
	int s = 0;

	scanf("%d%d", &n, &k);
	as.resize(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &as[i]);
		s += as[i];
	}

	int ans = 1;

	for(int x = 1; x * x <= s; x++) {

		int y = s / x;

		if(s % x == 0 && check(x, as, k)) {
			ans = max(ans, x);
		}
		if(s % y == 0 && check(y, as, k)) {
			ans = max(ans, y);
		}
	}

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

	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static void recurse(ArrayList<ArrayList<Integer>> adj, int[] dp,int[] visited, int v){

        visited[v]=1;

        for(int i=0;i<adj.get(v).size();i++){
            if(visited[adj.get(v).get(i)]!=1){
                recurse(adj,dp,visited,adj.get(v).get(i));
            }
            dp[v]=Math.max(dp[v],dp[adj.get(v).get(i)]+1);

        }
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n = Reader.nextInt();
        int m = Reader.nextInt();
        ArrayList<ArrayList<Integer> > adj = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {
            adj.add(new ArrayList<>());
        }
        for(int i=0;i<m;i++){
            int[] edge = Reader.nextIntArray(2);
            adj.get(edge[0]-1).add(edge[1]-1);
        }
        int maxVal = 0;
        int[] dp=new int[n];
        int[] visited = new int[n];
        for(int i=0;i<n;i++){
            if(visited[i]==0){
                recurse(adj,dp,visited,i);
            }
        }
        for(int i=0;i<n;i++){
            maxVal = Math.max(maxVal,dp[i]);
        }
        System.out.println(maxVal);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}



Measured memory_bytes: 73412
#include <stdio.h>

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

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, d, x;
    cin >> n >> k;
    vector<ll> a(n+1, 0);
    for(ll i = 1; i <= k; i++){
        cin >> d;
        for(int j = 1; j <= d; j++){
            cin >> x;
            a[x]++;
        }
    }
    ll ans = 0;
    for(ll i=1; i<=n; i++){
        if(a[i]== 0) ans++;
    }
    cout << ans;
    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M);//M個の道路の始点の配列
  vector<int> B(M);//M個の道路の終点の配列
  vector<int> C(N,0);//N個の都市の道路の数
  
  for(int i=0;i<M;i++){
    cin >> A.at(i) >> B.at(i);
  }
  for(int i=0;i<M;i++){
    C.at(A.at(i)-1)++;
    C.at(B.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def build(raw_data):
    bit = raw_data.copy()
    for i in range(len(bit)):
        j = i + (i & (-i))
        if j < len(bit):
            bit[j] += bit[i]
    return bit


@njit((i8[:], i8), cache=True)
def get_sum(bit, i):
    s = 0
    while i:
        s += bit[i]
        i -= i & -i
    return s


@njit((i8[:], i8, i8), cache=True)
def add(bit, i, x):
    while i < len(bit):
        bit[i] += x
        i += i & -i


@njit((i8[:], i8), cache=True)
def find_kth_element(bit, k):
    N = len(bit)
    x, sx = 0, 0
    dx = 1
    while 2 * dx < N:
        dx *= 2
    while dx:
        y = x + dx
        if y < N:
            sy = sx + bit[y]
            if sy < k:
                x, sx = y, sy
        dx //= 2
    return x + 1

@njit((i8, i8[:]), cache=True)
def main(N, AB):
    A, B = AB[::2], AB[1::2]
    Q = len(A)

    bit = np.zeros(N + 1, np.int64)  # 長方形の右上になる x 座標集合を管理
    bit_raw = np.zeros(N + 1, np.int64)
    H = np.zeros(N + 1, np.int64)  # 長方形の高さを管理
    H[0] = 2 * 10**13 + 10
    bit_raw[N] = 1
    add(bit, N, 1)

    for i in range(Q):
        a, b = A[i], B[i]
        n = get_sum(bit, a - 1)
        h = H[find_kth_element(bit, 1 + n)]
        if not bit_raw[a]:
            bit_raw[a] = 1
            add(bit, a, 1)
            H[a] = h
        r = a

        while b:
            l = 0 if n == 0 else find_kth_element(bit, n)
            n -= 1
            area = (H[l] - H[r]) * (r - l)
            if area <= b:
                b -= area
                if l:
                    bit_raw[l] = 0
                    add(bit, l, -1)
                H[l], H[r] = 0, H[l]
                continue
            k = b // (r - l)
            b -= k * (r - l)
            H[r] += k
            if b:
                m = l + b
                bit_raw[m] = 1
                add(bit, m, 1)
                H[m] = H[r] + 1
                b = 0
    for n in range(N, 0, -1):
        H[n - 1] = max(H[n - 1], H[n])
    return H[1:N + 1]

N, Q = map(int, readline().split())
AB = np.array(read().split(), np.int64)

ans = main(N, AB)
print('\n'.join(map(str, ans.tolist())))

Measured memory_bytes: 119856
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public class Area
	{
		public int Right{get;set;}
		public int Left{get;set;}
		public char C{get;set;}
	}
	
	public static void Main(string[] args)
	{
		int n = Console.ReadLine().ToInt();
		var str = Console.ReadLine();
		char c = str[0];
		int right = 0;
		
		var areas = new List<Area>();
		for(int i = 0; i < n; i++)
		{
			if(c != str[i])
			{
				areas.Add(new Area(){Left = right, Right = i-1, C = str[i-1]});
				right = i;
			}
			c = str[i];
		}
		areas.Add( new Area(){Right = right, Left = n-1, C = str[n-1]} );
		
		if(areas.Count == 1)
		{
			Console.WriteLine(0);
			return;
		}
		
		right = n-1;
		int left = 0;
		long wa = 0;
		while(true)
		{
			while(str[right] == 'W' && right > 0) right--;
			while(str[left] == 'R' && left < n-1) left++;
			if(right > left)
			{
				wa++;
				right--;
				left++;
			}
			else
			{
				break;
			}
		}
		
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 33320
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int A = sc.nextInt();
    long B = sc.nextLong();
    long ans = 1;
    if(A >= B){
      ans += K;
    }else if(B-A == 1){
      ans += K;
    }else{
      K -= A-1;
      ans += A-1;
      ans += (K/2)*(B-A);
      if(K%2 == 1){
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21972
#include<iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  bool flag=false;
  for(int i=0; i<3; i++){
    if(S[i]==S[i+1]){
      flag=true;
      break;
    }
  }
  if(flag==true)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 504
#include <cstdio>
using namespace std;

int main()
{
  bool f[100001];
  int c[100001];

  for (int i = 0; i <= 100000; i++)
  {
    f[i] = false;
    c[i] = 0;
  }

  for (int i = 2; i <= 100000; i++)
    if (!f[i])
      for (int j = i + i; j <= 100000; j += i)
        f[j] = true;

  for (int i = 3; i <= 100000; i += 2)
    if (!f[i] && !f[(i + 1) / 2])
      c[i]++;

  for (int i = 3; i <= 100000; i++)
    c[i] += c[i - 1];

  int q, l, r;
  scanf("%d", &q);

  for (int i = 0; i < q; i++)
  {
    scanf("%d%d", &l, &r);
    printf("%d\n", c[r] - c[l - 1]);
  }

  return 0;
}


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

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max() / 2);
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max() / 2);
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max() / 2;
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

long long N, X[200009], Y[200009]; vector<pair<long long, long long>>E;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i]; if (X[i] > Y[i]) swap(X[i], Y[i]);
		E.push_back(make_pair(X[i], Y[i]));
	}
	sort(E.begin(), E.end());

	RangeMin<long long> LX(N + 2), LY(N + 2), RX(N + 2), RY(N + 2);

	for (int i = 0; i < N; i++) {
		X[i] = E[i].first; Y[i] = E[i].second;
		LX.update(i, X[i]); LY.update(i, Y[i]);
		RX.update(i, -X[i]); RY.update(i, -Y[i]);
	}
	long long ans = (1LL << 60);
	for (int i = 0; i < N; i++) {
		long long LA = min(LX.query(0, i), LY.query(i, N));
		long long RA = min(RX.query(0, i), RY.query(i, N)) * -1LL;
		long long LB = min(LY.query(0, i), LX.query(i, N));
		long long RB = min(RY.query(0, i), RX.query(i, N)) * -1LL;
		ans = min(ans, (RA - LA)*(RB - LB));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23788
#include <cstdint>
#include <iostream>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

} // namespace null_null

#include <vector>

namespace null_null {

void main_() {
  usize N;
  std::cin>>N;
  std::vector<i32>H(N),dp(N,1);
  for(usize i=0;i<N;i++){
    std::cin>>H[i];
  }

  for(usize i=N-1;i>=1;i--){
    if(H[i-1]>=H[i]){
      dp[i-1]+=dp[i];
    }
  }

  i32 ans=0;
  for(usize i=0;i<N;i++){
    ans=std::max((i32)ans,(i32)dp[i]);
  }

  std::cout<<ans-1<<std::endl;
}

} // namespace null_null

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  null_null::main_();
  return 0;
}

Measured memory_bytes: 1792