akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N;

int main() {

	cin >> N;

	string ans;

	while (N) {
		ans += (N - 1) % 26 + 'a';
		if (N % 26 == 0) N--;
		N /= 26;
	}

	for (auto i = ans.rbegin(); i != ans.rend(); ++i)
		cout << *i;
	cout << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main() {
    ll l, r;
    cin >> l >> r;
    if(r-l >2222){
        cout << 0 << endl;
        return 0;
    }
    vector<bool> contained(2019, false);
    for(int i = l; i <= r; i++){
        contained[i%2019] = true;
    }
    ll ans = 2019;
    int n = 2019;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(contained[i] && contained[j]){
                ans = min(ans, ll(i*j)%n);
            }
        }
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;
const int INF = 2147483647;
const int MAX = 200000;


int main() {
	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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,m,k,ans=0;
    cin>>n>>m>>k;
    ll a[n+1]={0},b[m+1]={0};
    for(ll i=1;i<=n;i++) cin>>a[i],a[i]+=a[i-1];
    for(ll i=1;i<=m;i++) cin>>b[i],b[i]+=b[i-1];
    for(ll i=0;i<=n;i++) if(k>=a[i]) ans=max(ans,upper_bound(b+1,b+1+m,k-a[i])-b-1+i);
    cout<<ans;
}


Measured memory_bytes: 6740
package main

import (
	"fmt"
	"sort"
)

func main() {
	s := make([]int, 3)
	fmt.Scan(&s[0], &s[1], &s[2])
	sort.Ints(s)

	ans := "No"
	if s[0] == s[1] && s[1] != s[2] {
		ans = "Yes"
	} else if s[1] == s[2] && s[0] != s[1] {
		ans = "Yes"
	}

	fmt.Println(ans)

}


Measured memory_bytes: 512
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("op.txt","w",stdout);
	#endif

	clock_t startTime=clock();

	ll n;
	cin>>n;
	map<string,ll> mp;
	rep(i,0,n)
	{
		string s;
		cin>>s;
		mp[s]++;
	}

	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3856
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    
    int cnt = 0;
    for(int i = 0; i <= 3000; i++){
        for(int j = 0; j <= 3000; j++){
            if((N-i*R-j*G) % B == 0 && (N-i*R-j*G) / B >= 0){
                cnt++;
            }
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
A,B,C=map(int,input().split())

cnt=0
lp=0
ls=set()
a=A
b=B
c=C
ls.add((a,b,c))
while not(a%2==1 or b%2==1 or c%2==1 or lp==1):
    a=int((A+B+C-a)/2)
    b=int((A+B+C-b)/2)
    c=int((A+B+C-c)/2)
    cnt+=1
    if ((a,b,c) in ls):
        lp=1
if lp==1:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 38384
def ans(n):
    tmp=0
    for i in range(N):
        tmp+=abs(a[i]-a[n-1])
    return tmp


N=int(input())
a=list(map(int,input().split()))

a=[a[i]-i-1 for i in range(N)]
a=sorted(a)



print(ans(N//2) if N%2==0 else ans(N//2+1))

Measured memory_bytes: 26360
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int n;
vint G[100001];
void add_edge(int x,int y){
	G[x].PB(y);
	G[y].PB(x);
}
ll dp_w[100001],dp_b[100001];

pint dfs(int s, int par){
	ll ans_w=1,ans_b=1;
	for(int t:G[s]){
		if(t==par) continue;
		pint p=dfs(t,s);
		(ans_w*=(p.first+p.second))%=MOD;
		(ans_b*=p.first)%=MOD;
	}
	return pint(ans_w,ans_b);
}

int main(){
	cin>>n;
	FOR(i,0,n-1){
		int x,y;
		cin>>x>>y;
		x--; y--;
		add_edge(x,y);
	}
	pint ans=dfs(0,-1);
	co((ans.first+ans.second)%MOD);
}


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

int main() {
  int S;
  cin >> S;
  int s = S % 60;
  S = (S - s) / 60;
  int m = S % 60;
  int h = (S - m) / 60;
  cout << h << ":" << m << ":" << s << endl;

  return 0;
}


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

int main()
{
    long long n,mul=1,a[100005],i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==0)
        {
           cout<<0;
           return 0;
        }

    }
    for(i=0;i<n;i++)
    {
        if(a[i]>1000000000000000000/mul)
        {
            cout<<-1;
            return 0;
        }
        else
            mul*=a[i];
    }
    cout<<mul;
    return 0;
}


Measured memory_bytes: 4352
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n-1):a[i+1]+=a[i]
for i in range(m-1):b[i+1]+=b[i]
from bisect import bisect_left,bisect_right
ans=bisect_right(b,k)
for i in range(n):
  if a[i]>k:break
  ans=max(ans,i+1+bisect_right(b,k-a[i]))
print(ans)

Measured memory_bytes: 40756
n=list(input())
#print(n)
min=9999999999999999
for i in range(len(n)-2):
    num=100*int(n[i])+10*int(n[i+1])+int(n[i+2])
    if abs(num-753)<min:
        min=abs(num-753)
        #print(min)


print(min)


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  int n;
  cin >>n;
  VI a(n-1);
 
  for(int i=0;i<n-1 ;i++) cin >> a.at(i);
  map<int,int> num;
  for(int x:a){
    if(num.count(x)){
      num.at(x)++;
    }
    else{
      num[x]=1;
    }
  }
  for(int i=1;i<=n;i++){
    if(num.count(i)){
		cout << num.at(i) << endl;
    }
    else{
      cout << 0 << endl;
    }
  }
      
}

Measured memory_bytes: 13136
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const S = list[1].split(' ').map(Number);
const q = Number(list[2]);
const T = list[3].split(' ').map(Number);

const search = (target, value) => {
  let l = 0;
  let r = target.length;
  while (l < r) {
    const index = Math.floor((l + r) / 2);
    if (target[index] < value) {
      l = index + 1;
    } else if (target[index] > value) {
      r = index;
    } else {
      return true;
    }
  }
  return false;
}

let count = 0;
T.forEach((t) => {
  if (search(S, t)) {
    count++;
  }
});
console.log(count);



Measured memory_bytes: 32576
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String S = in.next();

            HashSet<Integer> used = new HashSet<Integer>();
            for (int i = 0; i < S.length(); i++) {
                used.add((int) S.charAt(i));
            }

            for (int i = 'a'; i <= 'z'; i++) {
                if (used.contains(i)) {
                    continue;
                }

                System.out.println((char) i);
                return;
            }

            System.out.println("None");
        }
    }
}


Measured memory_bytes: 30496
#include<bits/stdc++.h>
using namespace std;
#define db(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define rep(i,b)for(auto i=0;i<(b);++i)
#define fo(i,a,b)for(auto i=(a);i<=(b);++i)
#define ford(i,a,b)for(auto i=(a);i>=(b);--i)
#define vv vector
#define pb push_back
template<typename X>void MA(X&a,X b){a=max(a,b);}template<typename X>void MI(X&a,X b){a=min(a,b);}
template<typename X>void clr(X&x,int a){memset(x,a,sizeof(a));};typedef long long ll;typedef long double ld;
int cond=0,multi=0,gcj=0;
#define vi vector<int>

ll COEF[1<<18];
ll SUM[1<<18];

void push(int x,int l, int r){
  if(COEF[x]>=0){
    if(l==r){
      return;
    }
    int mid=(l+r)/2;
    SUM[2*x]+=SUM[x];
    COEF[2*x]+=COEF[x];

    SUM[2*x+1]+=SUM[x]+COEF[x]*(mid-l+1);
    COEF[2*x+1]+=COEF[x];

    COEF[x]=0;
    SUM[x]=0;
  }
}

ll res=-1;
ll tadd(int x,int a,int b,int l,int r,int coef){
  //db(x<<" "<<a<<" "<<b<<" "<<l<<" "<<r<<" "<<coef);
  if(b<l||a>r)return 0;
  push(x,l,r);
  if(a<=l&&r<=b){
    if(coef>=0){
      SUM[x]+=coef;
      COEF[x]+=1;
    }

    res=SUM[x];
    return r-l+1;
  }
  push(x,l,r);

  if(l==r){
    assert(0);
    res=SUM[x];

    return 1;
  }
  int mid=(l+r)/2;

  if(l<=mid)coef+=tadd(2*x,a,b,l,mid,coef);
  if(mid+1<=r)coef+=tadd(2*x+1,a,b,mid+1,r,coef);
  //pull();
  return coef;
}

void solve(){
  rep(i,1<<18)COEF[i]=0;
  int N,M;cin>>N>>M;
  vi A(N+2);
  fo(i,1,N)cin>>A[i];

  ll sofar=0;
  fo(i,1,N-1){
    ll a=A[i],b=A[i+1];
    db(a<<" "<<b);
    if(a<b){
      tadd(1,a+1,b,1,M,0);
      sofar+=b-a;
    }
    else {
      if(a+1<=M)
        tadd(1,a+1,M,1,M,0);
      tadd(1,1,b,1,M,M-a);
      sofar+=M-a+b;
    }
    if(cond){
      fo(ii,1,M){
        tadd(1,ii,ii,1,M,-1);
        cerr<<res<<" ";
      }
      cerr<<endl;
    }
  }
  db(sofar);
  ll ans=sofar;
  fo(i,1,M){
    tadd(1,i,i,1,M,-1);
    db(i<<" "<<res);
    ans=min(ans,sofar-res);
  }
  cout<<ans<<"\n";
}

























































int main(int argc,char** argv){
  ios::sync_with_stdio(false),cin.tie(0),cond=argc>=2&&argv[1][0]=='q'?1<<30:0;
  cout.setf(ios::fixed),cout.precision(10);int t;if(multi||gcj)cin>>t;else t=1;
  fo(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    solve();
  }return 0;}


/*
stringstream io;
#define cin io
int init(){
  io<<1<<endl;
  int N=500000;
  io<<N<<" "<<N<<endl;
  fo(i,1,N-1)io<<i-1<<" ";io<<endl;
  fo(i,0,N-1)io<<i%2<<" ";io<<endl;
  fo(i,0,N-1)io<<(N-1-i)/2<<" ";io<<endl;

  return 0;
}
int xx=init();
*/


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n<1200){
    cout<<"ABC"<<endl;
    }
  else if(1200<=n&&n<2800){
    cout<<"ARC"<<endl;
    }
  else{
    cout<<"AGC"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  vvi A(3,vi(3));
  rep(i,3) {
    rep(j,3) {
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vi b(N);
  rep(i,N) {
    cin >> b[i];
  }
  vv(bool) ok(3,v(bool)(3,false));
  rep(ni,N) {
    int x = b[ni];
    rep(i,3) {
      rep(j,3) {
        if(A[i][j] == x) {
          ok[i][j] = true;
        }
      }
    }
  }
  bool ans = false;
  rep(i,3) {
    bool o = true;
    rep(j,3) {
      if(!ok[i][j]) o = false;
    }
    if(o) ans = true;
  }
  rep(j,3) {
    bool o = true;
    rep(i,3) {
      if(!ok[i][j]) o = false;
    }
    if(o) ans = true;
  }
  if(ok[0][0] && ok[1][1] && ok[2][2]) ans = true;
  if(ok[2][0] && ok[1][1] && ok[0][2]) ans = true;
  if(ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
typedef long long ll;

int n, q;
const int maxn = 300000;
vector<ll> node[maxn];
ll val[maxn];
bool visit[maxn];

ll next(ll pos, ll c)
{
    for (int i = 0; i < node[pos].size(); i++)
    {
        int ni = node[pos][i];
        if (!visit[ni])
        {
            val[ni] += c;
            visit[ni] = true;
            next(ni, val[ni]);
        }
    }
}

int main(void)
{
    cin >> n >> q;
    REP(i, n)
    {
        val[i] = 0;
        visit[i] = false;
    }
    REP(i, n - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }
    REP(i, q)
    {
        ll p, x;
        cin >> p >> x;
        p--;
        val[p] += x;
    }

    visit[0] = true;
    next(0, val[0]);

    REP(i, n)
    {
        if (i != 0)
        {
            cout << " ";
        }
        cout << val[i];
    }
    cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i<n; i++) cin >> S[i];
  long long M = 0, A=0, R=0, C=0, H=0;
  for (int i = 0; i < n; i++) {
    if (S[i][0] == 'M') M++;
    if(S[i][0] == 'A') A++;
    if(S[i][0] == 'R') R++;
    if(S[i][0] == 'C') C++;
    if(S[i][0] == 'H') H++;
  }
  long long cnt = M * A * R + M * A * C + M * A * H + M * R * C + M * R * H + M * C * H + A * R * C + A * R * H + R * C * H + A * C * H;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6368
//=================================
// Created on: 2018/09/21 23:10:45
//=================================
#include <bits/stdc++.h>
using ll = long long;
int main()
{
    ll N;
    std::cin >> N;
    std::vector<ll> A(N);
    ll S = 0;
    for (int i = 0; i < N; i++) { std::cin >> A[i], S += A[i]; }
    const ll NUM = N * (N + 1) / 2;
    if (S % NUM != 0) { return std::cout << "NO" << std::endl, 0; }
    const ll TIM = S / NUM;
    std::vector<ll> imos(N);
    for (int i = 0; i < N; i++) { imos[i] = A[i] - (i == 0 ? 0LL : A[i - 1]); }
    for (int i = 0; i < N; i++) { imos[i] -= TIM; }
    ll sum = 0;
    for (ll i = 1; i < N; i++) {
        if (imos[i] > 0 or (-imos[i]) % N != 0) { return std::cout << "NO" << std::endl, 0; }
        sum += (-imos[i]) / N;
        imos[0] -= (N - i) * (-imos[i] / N);
    }
    std::cout << (imos[0] == 0 and sum <= TIM ? "YES" : "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var V = G;
		var C = G;
		var ans = 0;
		for (var i = 0; i < N; i++) if (V[i] > C[i]) ans += V[i] - C[i];
		WriteLine(ans);
	}
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left,int mid,int right){
  int n1 = mid-left;
  int n2 = right-mid;

  for(int i=0;i<n1;i++) L[i] = A[left+i];
  for(int i=0;i<n2;i++) R[i] = A[mid+i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0,j = 0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(int A[],int n,int left,int right){
  if(left+1 < right){
    int mid = (left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){
  int A[MAX],n;
  cnt = 0;

  cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];

  mergeSort(A,n,0,n);

  for(int i=0;i<n;i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 6920
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define MOD 1000000007
using ll=long long;

int main(){
  ll N;
  cin>>N;
  map<ll,ll> m;
  ll n=N;
  ll i=2;
  while(i*i<=N){
    if(n%i==0){
      m[i]++;
      n/=i;
    }else{
      i++;
    }
  }
  if(n>1){
    m[i]++;
  }

  ll ans=0;
  for(auto p:m){
    ll left=1;
    ll right=100;
    while(left+1<right){
      ll x=(left+right)/2;
      if(x*(x+1)/2<=p.second){
        left=x;;
      }else{
        right=x;
      }
    }
    ans+=left;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3628
from collections import deque
from itertools import permutations

N,M = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(M)]

graph = [[False]*(N+1) for _ in range(N+1)]
for i in l:
    graph[i[0]][i[1]] = True
    graph[i[1]][i[0]] = True

cnt = 0

for i in permutations(range(1,N+1)):
    if i[0] != 1:
        continue
    isJoin = True
    for j in range(1,N):
        if not graph[i[j-1]][i[j]]:
            isJoin = False
            break
    if isJoin:
        cnt += 1
print(cnt)
            


Measured memory_bytes: 39920
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    ll n, m;    cin >> n >> m;
    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int factor2 = -1;
    for(int i = 0; i < n; i++){
        int tmpFactor2 = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            tmpFactor2++;
        }
        if(factor2 == -1){
            factor2 = tmpFactor2;
        }
        else if(factor2 != tmpFactor2){
            cout << 0 << endl;
            return 0;
        }
    }

    ll x = 1;
    while(factor2 > 0){
        x *= 2;
        factor2--;
    }
    for(int i = 0; i < n; i++){
        x = lcm(x, a[i]);
    }

    cout << (m / x + 1) / 2;

    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> p(n);
	rep(i, n)cin>>p[i];
	int x, y, z;
	x = y = z = 0;
	rep(i,n){
		if(p[i] <= a) x++;
		else if(p[i] <= b) y++;
		else z++;
	}
	cout << min({x,y,z}) << endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,pint> p3;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  ll h,w;
  cin>>h>>w;
  map<pint,int> mp;
  int n;cin>>n;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    REP(j,-1,2)REP(k,-1,2){
      int nx=a+j,ny=b+k;
      if(1<nx&&nx<h&&1<ny&&ny<w)
        mp[{nx,ny}]++;
      }
    }
  ll ans[10];
  rep(i,10)ans[i]=0;
  ans[0]=(h-2)*(w-2);
  for(auto x:mp){
    ans[x.second]++;
    ans[0]--;
    }
  rep(i,10)cout<<ans[i]<<endl;
  return 0;
  }

Measured memory_bytes: 56448
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int> ,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
long long arr[3005];
long long arr2[3005];
long long dp[2][3001];
int n;
int main()
{
   // memset(dp,-1,sizeof dp);
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = n;i >= 1;i--)
        arr2[i] = arr[n-i+1];
    //cout << solve(n,n,1);
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            if(i+j <= n)
                continue;
            dp[i%2][j] = 0;
            if((i+j)%2 == (n+n)%2)
                dp[i%2][j] = max(arr2[i] + dp[(i-1)%2][j],arr[j] + dp[i%2][(j-1)]);
            else
                dp[i%2][j] = min(-arr2[i] + dp[(i-1)%2][j],-arr[j] + dp[i%2][(j-1)]);
        }
    }
    cout << dp[n%2][n];
    return 0;
}


Measured memory_bytes: 384
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define NMAX 100000

int K = 1;
vector<vector<int>> tree(NMAX);
int colors[NMAX];

void dfs(int p, int p_color){
	int color = 1;
	for(int c:tree[p]){
		if(colors[c]) continue;
		colors[c] = color==p_color? ++color: color;
		K = max(K, color);
		dfs(c, color++);
	}
}

int main(){
	int N; cin>>N;
	int C[N-1];
	for(int i=0; i<N-1; ++i){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
		tree[C[i]].push_back(p);
	}
	colors[0] = NMAX;
	dfs(0, -1);
	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}

Measured memory_bytes: 7680
#include<iostream>
#include<vector>
#include<algorithm>
#include <iterator>
#include<queue>
#include <functional>
#include <string>
#include <numeric>
using namespace std;

int DelCheck(vector<int> &Line, bool &flag){
  int a = 0, score = 0;
  if (Line[2] == 0)return 0;
  if (Line[a] == Line[a + 1]){
    if (Line[a + 1] == Line[a + 2]){
      if (Line[a + 2] == Line[a + 3]){
        if (Line[a + 3] == Line[a + 4]){
          score = accumulate(Line.begin(), Line.end(), 0);
          fill(Line.begin(), Line.end(), 0);
          flag = true;
          return score;
        }
        else{
          score = accumulate(Line.begin(), Line.end() - 1, 0);
          fill(Line.begin(), Line.end() - 1, 0);
          flag = true;
          return score;
        }
      }
      else{
        score = accumulate(Line.begin(), Line.end() - 2, 0);
        fill(Line.begin(), Line.end() - 2, 0);
        flag = true;
        return score;
      }
    }
  }
  if (Line[a + 1] == Line[a + 2]){
    if (Line[a + 2] == Line[a + 3]){
      if (Line[a + 3] == Line[a + 4]){
        score = accumulate(Line.begin() + 1, Line.end(), 0);
        fill(Line.begin() + 1, Line.end(), 0);
        flag = true;
        return score;
      }
      else{
        score = accumulate(Line.begin() + 1, Line.end() - 1, 0);
        fill(Line.begin() + 1, Line.end() - 1, 0);
        flag = true;
        return score;
      }
    }
  }
  if (Line[a + 2] == Line[a + 3]){
    if (Line[a + 3] == Line[a + 4]){
      score = accumulate(Line.begin() + 2, Line.end(), 0);
      fill(Line.begin() + 2, Line.end(), 0);
      flag = true;
      return score;
    }
  }
  return 0;
  
}

int main(){
  while (1){
    int n;
    int Total=0;
    cin >> n;
    if (!n)return 0;
    vector<vector<int>> Field(n);
    for (int i = 0; i < n; ++i){
      
      int a, b, c, d, e;
      cin >> a >> b >> c >> d >> e;
      Field[i].push_back(a); Field[i].push_back(b);
      Field[i].push_back(c); Field[i].push_back(d);
      Field[i].push_back(e);
    }
    bool flag = true;
    while (flag){
      flag = false;
      for (int i = 0; i < n; ++i){
        Total += DelCheck(Field[i],flag);
      }
      for (int i = n-1; i >=0; --i){
        for (int j = 0; j < 5; ++j){
          for (int l = 0; l < n-1+1; ++l){
            if (Field[i][j] == 0){
              for (int k = i; k >0; --k){
                Field[k][j] = Field[k-1][j];
                Field[k - 1][j] = 0;
              }
            }
          }
        }
      }
    }
    cout << Total << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] A = new int[n];
    for (int i = 0; i < n; i++){
      A[i] = Integer.parseInt(sc.next());
    }
    int ans = Integer.MAX_VALUE;
    int count = 0;
    for (int a: A){
      count = 0;
      while ((a%2) == 0){
        count += 1;
        a /= 2;
      }
      ans = Math.min(ans,count);
    }
    System.out.println(ans);

  }
}


Measured memory_bytes: 35872
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	int n;
	ll x;
	cin >> n >> x;
	ll arr[n];
	ll count = 1;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
		if (sum <= x)
			count++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  string s;
  cin>>s;
  string P[100]={};
  int a=s.length();
  for(int i=0;i<a;i++){
      P[i]=s[i];
  }
  cout<<P[0];
  cout<<a-2;
  cout<<P[a-1]<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int H, A;
    cin >> H >> A;

    int ans = (H+A-1) / A;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0]*(N+1) # 足場iにたどり着くまでの最小コスト
for i in range(2,N+1):
  dp[i] = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(1,K+1):
    if i-j > 0:
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])

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

    int main(){
        ll q , l , r;
        vector<ll> v , v2;
        set<ll> s;
        bool flg;
        s.insert(2);
        for(int i = 3 ; i <= 100000 ; i += 2){
            flg = true;
            for(int j = 2 ; j * j <= i ; j++){
                if(i % j == 0 ){
                    flg = false;
                }
            }
            if(flg){
                v.push_back(i);
                s.insert(i);
            }
        }
        for(int i = 0 ; i < v.size() ; i++ ){
            if(s.count((v[i]+1) / 2 )){
                v2.push_back(v[i]);
            }
        }
        //cout << v2[0] << ":" << v2[1] << ":" << v2[2] << ":" << v2[3] << ":" << v2[v2.size()-1] ; 
         
        cin >> q;
        ll ans;
        for(ll i = 0 ; i < q ; i++){
            cin >> l >> r;
            auto itr1 = lower_bound(v2.begin() , v2.end() , l);
            auto itr2 = upper_bound(v2.begin() , v2.end() , r);
            ans = itr2 - itr1;
            cout << ans << endl;
        }
        
        return 0;
    }

Measured memory_bytes: 1152
N = int(input())
xyr = [list(map(int, input().split())) for _ in range(N)]


def m():
    tmpx, tmpy, tmpr = 0, 0, 0
    for a,b,c in xyr:
        if c != 0:
            tmpx = a
            tmpy = b
            tmpr = c
            break

    for cx in range(0, 101):
        for cy in range(0, 101):
            h = max(0, tmpr + abs(tmpx - cx) + abs(tmpy - cy))
            f = 0
            for x, y, r in xyr:
                if not (r == max(h - abs(x - cx) - abs(y - cy), 0)):
                    f = 1
                    break
            if f == 0:
                return "{} {} {}".format(cx, cy, h)


print(m())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

double temp(int t, int h) {
    double s = t-h*0.006;
    return s;
}

int main() {
    int n;
    cin >> n;
    string nn = to_string(n);
    int sum = 0;
    rep(i,nn.size()) {
        sum += nn[i]-'0';
    }
    if (n%sum == 0) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}


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

#define int        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<int>
#define v2d        vector<vector<int>>
#define vip        vector<pair<int,int> >
#define v1s        vector<string>
#define pa         pair<int,int>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<"\n";
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define endl       "\n"
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

void azmuth(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    // #ifndef ONLINE_JUDGE
    //      freopen("input.txt",  "r",  stdin);
    //      freopen("output.txt", "w", stdout);
    // #endif
}
int lb = 1000000000;

//____________________________________________________________________________________


void solve(){
    int n,W;cin>>n>>W;
    v1d dp(W+5,0);
    for(int i=0;i<n;i++){
        int w,v;cin>>w>>v;
        for(int j=W;j>=w;j--){
            dp[j] = max(dp[j],dp[j-w]+v);
        }
        // print(dp);
    }
    int ans = 0;
    for(auto i:dp)ans = max(ans,i);
    cout<<ans<<"\n";
}

int32_t main(){
    azmuth();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
    }
    int ans=0;
    int cnt=1;
    int next=a[0];
    while(cnt<=n){
        if(next==2){
            cout<<cnt<<endl;
            return 0;
        }
        else{
            next=a[next-1];
        }
        cnt++;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 640
use std::io;

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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn str_cmp(str1: &str, str2: &str) {
    let vec1: Vec<char> = str1.chars().collect();
    let vec2: Vec<char> = str2.chars().collect();

    let l1 = vec1.len() as usize + 1;
    let l2 = vec2.len() as usize + 1;

    let mut length = vec![vec![0; l1]; l2];

    for j in 1..l2 {
        for i in 1..l1 {
            if vec1[i - 1] == vec2[j - 1] {
                length[j][i] = length[j - 1][i - 1] + 1;
            } else {
                length[j][i] = std::cmp::max(length[j][i - 1], length[j - 1][i]);
            }
        }
    }
    println!("{:?}", length[l2 - 1][l1 - 1]);
}

fn main() {
    let n: i32 = read();
    for i in 0..n as usize {
        let str1: String = read();
        let str2: String = read();

        let str1 = str1.as_str();
        let str2 = str2.as_str();
        str_cmp(&str1, &str2);
    }
}



Measured memory_bytes: 9104
n, t = map(int, input().split())
a = [int(x) for x in input().split()]
mx = [0] * n
mx[-1] = a[-1]
for i in range(n - 2, -1, -1):
  mx[i] = max(mx[i + 1], a[i])
d = 0
c = 0
for i in range(n - 1):
  cur = a[i]
  can = mx[i + 1]
  dd = can - cur
  if dd > d:
    d = dd
    c = 1
  elif dd == d:
    c += 1
print(c)

Measured memory_bytes: 20144
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()


int main(int argc, char const *argv[])
{
    ll k;
    cin >> k;
    queue<ll> q;
    for (ll i = 1; i <= 9; i++)
    {
        q.push(i);
    }

    ll ans = 0;
    for (ll i = 0; i < k; i++)
    {
        ans = q.front();
        q.pop();
        if (ans % 10 != 0)
        {
            q.push(10 * ans + (ans % 10) - 1);
        }
        q.push(10 * ans + (ans % 10));
        if (ans % 10 != 9)
        {
            q.push(10 * ans + (ans % 10) + 1);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<set>
#include<iostream>
using namespace std;
int main(){
  int i=2,N,h,m;
  set<pair<int, int>> t;
  while(i--&&cin>>N)
    while(N--&&cin>>h>>m)
      t.insert(make_pair(h,m));
  for(auto i=t.begin();i!=t.end();)
    printf("%d:%02d",i->first,i->second),cout<<(++i!=t.end()?" ":"");
  cout<<endl;
}

Measured memory_bytes: 1228
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007

ll O[60];

int main(){
	int N; cin>>N;
	rp(i,0,N){ ll a; scanf("%lld",&a); rp(j,0,60) O[j]+=a>>j&1; }
	ll ans = 0;
	rp(i, 0, 60) ans = (ans + (O[i]*(N-O[i]) % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<< ans <<endl;
}

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B;
cin>>A>>B;
int ans;
if(B%A==0)ans=A+B;
else ans=B-A;
cout<<ans<<endl;

//system("pause");
return 0;
}

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

vector<int> ans(200005, 0);

void dfs (int u, vector<vector<int>> &tree, int p = -1) {
  for (int t : tree.at(u)) {
    if (t == p) continue;
    ans.at(t) += ans.at(u);
    dfs(t, tree, u);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  
  vector<int> a(n-1), b(n-1);
  for (int i = 0; i < n-1; i++) {
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  
  vector<int> p(q), x(q);
  for (int i = 0; i < q; i++) {
    cin >> p.at(i) >> x.at(i);
    p.at(i)--;
  }

  vector<vector<int>> tree(n);
  for(int i = 0; i < n-1; i++) {
    tree.at(a.at(i)).push_back(b.at(i));
    tree.at(b.at(i)).push_back(a.at(i));
  }
  
  for(int i = 0; i < q; i++) {
    ans.at(p.at(i)) += x.at(i);
  } 
    
  dfs(0, tree);
  for(int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}

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

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> v(N, 0);
        int ba = 0;
        char c;
        int k = 0;
        for (int i=0; i<100; ++i) {
            cin >> c;
            if (c == 'M') {
                ++ v[k];
            } else if (c == 'S') {
                ba += 1 + v[k];
                v[k] = 0;
            } else {
                v[k] += 1 + ba;
                ba = 0;
            }
            k = (k + 1) % N;
        }
        sort(v.begin(), v.end());
        for (int i=0; i<N; ++i) {
            cout << v[i] << " ";
        }
        cout << ba << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
 
int main(){
	
	int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;
	if(m2>=m1){
		cout << (h2-h1)*60+(m2-m1)-k<<endl;
	}
	else cout << (h2-h1-1)*60+(m2+60-m1)-k<<endl;
	
	
	
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
int main()
{
 int a,b,ans;
 scanf("%d %d",&a,&b);
 if(abs(a - b) % 2 == 0)
 {
  ans = (a + b) / 2;
  printf("%d\n",ans);
 }
 else
  printf("IMPOSSIBLE\n");
 return 0;
}

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

#define MAX_N 100000

int bit[MAX_N + 1], n;

int sum(int i) {
  int s = 0;
  while(i > 0) {
	s += bit[i];
	i -= i & -i;
  }
  return s;
}

void add(int i, int x) {
  while(i <= n) {
	bit[i] += x;
	i += i & -i;
  }
}

int main() {
  int q;
  int com, x, y;
  cin >> n >> q;
  while(q--) {
	cin >> com >> x >> y;
	if(com == 0) {
	  add(x, y);
	}
	else {
	  cout << sum(y) - sum(x-1) << endl;
	}
  }
  return 0;
}

Measured memory_bytes: 1548
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    long long H, W;
 
    cin >> H >> W;
 
    long long a, b;

    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }

    if(H%2 == 1 && W%2 == 1){
        cout << H*W/2+1 << endl;
        return 0;
    }

    if(H%2 == 0 || W%2 == 0){
        cout << H*W/2 << endl;
        return 0;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

double logn(int base, double antilog) {
    return log(antilog) / log((double)base);
}

int main(void){
  int n,count = 0;
  double d;
  scanf("%d %lf",&n,&d);
  d = logn(10,d);
  double p,q,x[n],y[n];
  rep(i,0,n){
    scanf("%lf %lf",&p,&q);
    x[i] = logn(10,p*p+q*q)/2;
  }
  rep(i,0,n){
    if(x[i] <= d){
	count++;
      }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 4028
n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
    row = list(map(int, input().split()))
    c.append(row[0])
    a.append(row[1:])

import itertools

ans = float('inf')
for r in range(n+1):
    for idxs in itertools.combinations(range(n), r=r):
        price = [0]*m
        for idx in idxs:
            for i in range(m):
                price[i] += a[idx][i]
        
        if all(price[i] >= x for i in range(m)):
            ans = min(ans, sum(c[idx] for idx in idxs))

if ans == float('inf'):
    print(-1)
else:
    print(ans)

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int digits(ll n){
  return log10(n) + 1;
}

int N = 1000000;
int isPrime[1000000];

void sieve(){
    isPrime[0] = isPrime[1] = 1;    //0- prime, 1 - nonrprime
    for (int i = 2; i*i <= N; i++){
        if(isPrime[i] == 0){
            for (int j = i * i; j <= N ; j += i)
                isPrime[j] = 1;
        }
    }
}

int main(){
  FAST();

  sieve();

  int x;
  cin >> x;
  while(isPrime[x] != 0)
    x++;
  cout << x << endl;



  return 0;
}


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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector< string > S(H);
  for(int i = 0; i < H; i++) cin >> S[i];

  vector< int > row(H), col(W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }
  for(int i = 0; i < H; i++) {
    bool output = false;
    for(int j = 0; j < W; j++) {
      if(row[i] && col[j]) {
        cout << S[i][j];
        output = true;
      }
    }
    if(output) cout << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		String str2 = sc.next();
		String str3 = sc.next();
		
		String result = "" + (char)(str1.charAt(0) - 'a' + 'A')
							+ (char)(str2.charAt(0) - 'a' + 'A')
							+ (char)(str3.charAt(0) - 'a' + 'A');
		System.out.println(result);
		
		sc.close();
	}

}


Measured memory_bytes: 21844