akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  
  int64_t ans = 0;
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(i>=1) {
      ans += max(0, a[i-1]-a[i]);
      if(a[i-1]-a[i]>0) a[i] = a[i-1];
    }
  } 
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3952
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

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




int main() {
  string str1;
  cin >> str1;
  int num_R = 0;
  int ans = 0;
  rep(i,3){
    if(str1.at(i)=='R'){
      num_R++;
    }else{
      ans = max(ans, num_R);
      num_R = 0;
    }
  } 
  ans = max(ans, num_R);
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 3708
#include<iostream>
#include<set>

using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  static char s[300001];
  cin>>s;
  unsigned long long B=100000007;
  unsigned long long h=B;
  static unsigned long long a[300000];
  static unsigned long long rnk[300000];
  for(int i=0;i<n;i++){
    rnk[n-1-i]=h;
    a[i]=h*s[i];
    h*=B;
  }
  unsigned long long ch=a[0];
  int l=0,r=0;
  set<unsigned long long> st;
  while(m--){
    char q[4];
    cin>>q;
    if(q[0]=='R'){
      if(q[1]=='+'){
	ch+=a[++r];
      }else{
	ch-=a[r--];
      }
    }else{
      if(q[1]=='+'){
	ch-=a[l++];
      }else{
	ch+=a[--l];
      }
    }
    st.insert(ch*rnk[l]);
  }
  cout<<st.size()<<endl;
}

Measured memory_bytes: 20232
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << (x) << endl
#define IOS ios::sync_with_stdio(false); cin.tie(NULL)
// Greate commom divisor
#define gcd(a, b) __gcd(a, b) 
#define ll long long

int main(int argc, char const *argv[])
{
    IOS;
    ll x, ans = 0;
    cin >> x;
    debug(x);
    ans = ((ll) x/500)*1000;
    debug(ans);
    x = x%500;
    debug(x);
    ans = ans + (((ll) x/5)*5);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N,M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for(int i = 0;i < M;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        A--;
        B--;
        if(uf.issame(A,B)) {
            if(uf.diff(A,B) != C) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(A,B,C);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1536
def main():
    n = int(input())
    vs = [1]
    v = 6
    while v <= n:
        vs.append(v)
        v *= 6
    v = 9
    while v <= n:
        vs.append(v)
        v *= 9
    vs.sort()
    nums = [1 << 30] * (n + 1)
    nums[0] = 0
    for i in range(0, n):
        for v in vs:
            j = i + v
            if j > n:
                break
            nums[j] = min(nums[j], nums[i] + 1)
    print(nums[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
/************************************************
* Author        :somniloquy
* Created Time  :2015/10/30 16:15:09
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int hw_max = 1000 + 5;
char graph[hw_max][hw_max];
int sign[hw_max][hw_max];
int h, w, n, ans;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
struct node
{
	int x;
	int y;
	int time;
} start;

void BFS(node op, char ed)
{
	queue <node> process;
	process.push(op);
	sign[op.x][op.y] = 1;
	while(!process.empty())
	{
		node now = process.front();
		process.pop();
		for(int i = 0; i < 4; i ++)
		{
			node next = now;
			next.x += dx[i];
			next.y += dy[i];
			next.time ++;
			if(next.x >= 0 && next.x < h && next.y >= 0 && next.y < w && graph[next.x][next.y] != 'X' && !sign[next.x][next.y])
			{
				if(graph[next.x][next.y] == ed)
				{
					ans += next.time;
					next.time = 0;
					start = next;
				       	return;
				}
				else
				{
					process.push(next);
					sign[next.x][next.y] = 1;
				}
			}
		}
	}
}

int main()
{
	while(~scanf("%d %d %d", & h, & w, & n))
	{
		getchar();
		for(int i = 0; i < h; i ++)
		{
			for(int j = 0; j < w; j ++)
			{
			       scanf("%c", & graph[i][j]);
			       if(graph[i][j] == 'S')
			       {
					start.x = i;
					start.y = j;
					start.time = 0;
			       }
			}
			getchar();
		}
		ans = 0;
		for(int i = 1; i <= n; i ++)
		{
			memset(sign, 0, sizeof(sign));
			BFS(start, '0' + i);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 6144
N = int(input())
clues = [ input().split() for _ in range(N) ]

restaurant = {}
for i in range(N):
  S, P = clues[i]
  score = restaurant.get(S, {})
  score[i] = int(P)
  restaurant[S] = score

for S in restaurant:
  score = restaurant[S]
  restaurant[S] = sorted(score.items(), key=lambda x:x[1], reverse=True)

restaurant = sorted(restaurant.items(), key=lambda x:x[0])

for S in restaurant:
  for i in S[1]:
    print(i[0] + 1)

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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> b[i];
    }
    a[0] = b[0];
    a[1] = b[0];
    for (int i = 1; i < n - 1; i++) {
        a[i] = min(a[i], b[i]);
        a[i + 1] = b[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int N;
    cin >> N;
    int sum = 0;
    int maxi = 0;
    int tmp;
    for(int i = 0;i < N;i++)
    {
        cin >> tmp;
        sum += tmp;
        maxi = max(maxi,tmp);
    }
    if(maxi < sum - maxi)
        cout << "Yes\n";
    else
        cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int ans,used[100010];
vector<P>in[100010];
int n,m;
 
void check(int pos){
  if(used[pos]||!ans)return;
  used[pos]=1;
  for(int i=0;i<in[pos].size();i++){
    int nx=in[pos][i].first,idx=in[pos][i].second;
    if(used[nx])ans=0;
    in[pos].erase(in[pos].begin()+i);
    in[nx].erase(in[nx].begin()+idx);
    check(nx);
    i=-1;
  }
}
 
int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<=n;i++)in[i].clear(),used[i]=0;
 
    ans=1;
    for(int i=0,a,b;i<m;i++){
      cin>>a>>b;
      in[a].push_back(P(b,in[b].size()));
      in[b].push_back(P(a,in[a].size()-1));
      if(in[a].size()/3||in[b].size()/3) ans=0;
    }
     
    for(int i=1;i<=n;i++) check(i);
    cout <<(ans? "yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 10608
//https://atcoder.jp/contests/cf17-final/tasks/cf17_final_a
//A - AKIBA
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    string s; cin>>s;

    vector<string> chk;
    auto get=[&](vector<ll> um){
        string akb="AKIHABARA";
        string ret;
        ll pt=0;
        for(auto c:akb){
            if(c=='A'){
                if(um.at(pt++)) continue;
            }
            ret.push_back(c);
        }
        return ret;
    };
	REP(i, 2) {
		REP(j, 2) {
			REP(k, 2) {
				REP(l, 2) {
                   chk.emplace_back(get({i,j,k,l})); 
                }
			}
		}
	}

	for(const auto& t:chk){
        if(t==s) {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
#include <math.h>
int main(void) 
{ 
    int x, b=1, p, n, m=0;
    
    scanf("%d", &x);
    
    if(x==1){
        printf("1\n");
        return 0;
    }
    
    while(1){
        b++;
        p=2;
        while(x>=pow(b,p)){
            n=pow(b,p);
            p++;
        }
        if(n>m) m=n;
        if(p==2) break;
    }
    printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 2448
#include <iostream>
#include <string>

using namespace std;

int main(){

    int n, k;
    int r, s, p;
    string t;
    long long int ans = 0;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    for(int i = 0; i < t.length(); i++){
        if(t[i] == 'r'){
            if(i - k < 0){
                ans += p;
            }
            else{
                if(t[i] != t[i-k]){
                    ans += p;
                }
                else{
                    t[i] = 'n';
                }
            }
        }
        else if(t[i] == 's'){
            if(i - k < 0){
                ans += r;
            }
            else{
                if(t[i] != t[i-k]){
                    ans += r;
                }
                else{
                    t[i] = 'n';
                }
            }
        }
        else{
            //t[i] == 'p'
            if(i - k < 0){
                ans += s;
            }
            else{
                if(t[i] != t[i-k]){
                    ans += s;
                }
                else{
                    t[i] = 'n';
                }
            }
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];

vector<string> card;

map<string,int> mp;

int main()
{
    int n,m,k,a,b,c,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    string S;

    for(int i=1;i<=n;i++){
        cin>>S;
        mp[S]++;
        card.push_back(S);
    }
    cin>>m;

    for(int i=1;i<=m;i++){
        cin>>S;
        mp[S]--;
        card.push_back(S);
    }

    mx = 0;

    for(int i=0;i<n+m;i++)
        mx = max(mx,mp[card[i]]);

    cout<<mx<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-7
#define endl "\n"
/*ll gcd(ll a,ll b)
{
    if(a==0){return b;}
    return gcd(b%a,a);
}*/
ll modexp(ll x,ll y,ll p)
{
    ll res=1;x%=p;
    while(y>0)
    {   if(y%2==1){res=(res*x)%p;}
        y=y>>1;x=(x*x)%p;
    }return res;
}
int n,k;
ll fact[10001];
ll modin(ll x)
{
    return modexp(x,MOD-2,MOD);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    int r=n-k;
    int b=k;
    fact[0]=1;
    rep(i,1,10000)
    {
        fact[i]=(fact[i-1]*i)%MOD;
    }
    rep(i,1,k)
    {
        if((r+1-i)<0)
        {
            cout<<"0"<<"\n";
            continue;
        }
        ll ans=fact[r+1];
        ans=(ans*modin(fact[i]))%MOD;
        ans=(ans*modin(fact[r-i+1]))%MOD;
        ll ans1=fact[b-1];
        ans1=(ans1*modin(fact[i-1]))%MOD;
        ans1=(ans1*modin(fact[b-i]))%MOD;
        ll ans0=ans*ans1;
        ans0=ans0%MOD;
        cout<<ans0<<"\n";
    }
    return 0;

    /*check for long long or int*/
}


Measured memory_bytes: 384
n = int(input())
c = [[int(i) for i in input().split()] for i in range(n)]
z = []
w = []
for i in range(n):
    z.append(c[i][0] + c[i][1])
    w.append(c[i][1] - c[i][0])
ans = max(max(z)-min(z), max(w)-min(w))
print(ans)

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

int main(){
    ll n;
    cin >> n;
    ll l = 0, r = n;
 
    cout << l << endl;
    string t, u = " ";
    cin >> t;
    if (t == "Vacant") exit;
    else u = t;
 
    while (r - l  > 1){
        ll y = (l + r) / 2;
        cout << y << endl;
        string s;
        cin >> s;
        if (s == "Vacant") break;
        else{
            if (((y - l + 1) % 2 == 0 && u != s) || ((y - l + 1) % 2 != 0 && u == s)){
                l = y;
                u = s;
            }
            else r = y;
        }
    }
}

Measured memory_bytes: 852
M = 10 ** 9 + 7

x, y = map(int, input().split())

r = 0
if (x + y) % 3 == 0:
  a, b = (2 * y - x) // 3, (2 * x - y ) // 3
  if a >= 0 <= b:
    n = a + b + 1
    f = [1] * n
    for i in range(1, n):
      f[i] = f[i - 1] * i % M
    r = f[a + b] * pow(f[a] * f[b], M - 2, M) % M
print(r)


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

using namespace std;

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

bool used[26];

int main()
{
	memset(used, false, sizeof(used));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string S; cin >> S;

	int n = (int)S.length();

	string res = "";
	if (n < 26){
		rep (i, n){
			used[(int)(S[i] - 'a')] |= true;
		} // end rep
		res = S;
		rep (j, 26){
			if (!used[j]){
				res += (char)('a' + j);
				break;
			} // end if
		} // end rep
	}else{ // if (n == 26){
		for (int i = 26 - 1; i > 0; --i){
			used[(int)(S[i] - 'a')] |= true;
			if (S[i-1] < S[i]){
				rep (j, 26){
					if (used[j] && (char)('a' + j) > S[i-1]){
						res = S.substr(0, i - 1);
						res += (char)('a' + j);
						break;
					} // end if
				} // end rep
				if (!res.empty())  break;
			} // end if
		} // end for
	} // end if

	if (res.empty()){
		cout << -1 << endl;
	}else{
		cout << res << endl; 
	} // end if
								
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin >> a;
	int m=0,count=0;
	for(int i=0;i<a.length();i++){
		if(a[i]=='R') count++;
		else count = 0;
		m = max(m,count);
	}	
	cout << m << '\n';	
	return 0;
}

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

using namespace std;

int main() {

	int n, m, d;
	cin >> n >> m >> d;
	vector<string> s(n, "");
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	int counter = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m-d+1; j++) {
			bool countflg = true;
			for (int k = 0; k < d; k++) {
				if (s[i][j + k] == '#') { countflg = false; break; }
			}
			if (countflg) { counter++; }
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n - d+1; j++) {
			bool countflg = true;
			for (int k = 0; k < d; k++) {
				if (s[j+k][i] == '#') { countflg = false; break; }
			}
			if (countflg) { counter++; }
		}
	}
	cout << counter << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int r, g;
    cin >> r >> g;

    cout << 2 * g - r << endl;
    return 0;
}


Measured memory_bytes: 3548
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long price[] = {sc.nextLong(), sc.nextLong(), sc.nextLong(), sc.nextLong()};
		int pow[] = {8, 4, 2, 1};
		long best[] = new long[2];
		for(int i = 0; i < 2; i ++) {
			best[i] = price[0] * pow[i];
			for(int j = 0; i + j < 4; j ++) {
				best[i] = Math.min(best[i], price[j] * pow[i + j]);
			}
		}
		long need = sc.nextLong();
		System.out.println(need / 2 * best[0] + need % 2 * best[1]);
	}
}

Measured memory_bytes: 23764
#include <stdio.h>

#define N 1000

int main()
{
  int i, j, k;
int n;
int A[N];
int v;

 scanf("%d",&n);
 for(i=0;i<n;i++){
   scanf("%d",&A[i]);
 }

 for (i=1; i < n; i++) { 
   for (k=0; k < n; k++) { 
     if(k==n-1){
       printf("%d\n", A[k]);
       break;
     }
     printf("%d ", A[k]);
   }
   v=A[i];
   j = i-1; 

   while ((j >= 0) && (A[j] > v)) {
     A[j+1] = A[j];
     j--;
   }
   A[j+1] = v;
 }
 
 for (i=0; i < n; i++) { 
   if(i==n-1){
     printf("%d\n", A[i]);
     break;
     }
   printf("%d ", A[i]);
 }
 return 0;
}

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

using namespace std;

#define INF (1<<29)

struct P{
    int t, c, nt;
    P(){}
    P(int t, int c, int nt) :
        t(t), c(c), nt(nt) {}

    bool operator < (const P &p) const {
        if (t != p.t) {
            return t < p.t;
        }
        return c > p.c;
    }
};


int main()
{
    int n;
    while (cin >> n, n) {
        vector<P> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i].t >> v[i].c;
            v[i].nt = v[i].t;
            v[i].c *= 2;
        }
        sort(v.begin(), v.end());
        queue<P> Q[2];
        for (int i = 0; i < n; i++) {
            Q[0].push(v[i]);
        }
        int res = 0;
        while (!Q[0].empty() || !Q[1].empty()) {          
            int f = INF;            
            if (!Q[0].empty()) {
                f = Q[0].front().nt;
            }
            if (!Q[1].empty()) {
                f = min(f, Q[1].front().nt);
            }

            res += f;
            queue<P> nQ[2], nQ2[2];
            for (int i = 0; i < 2; i++) {
                vector<P> v;
                while (!Q[i].empty()) {
                    P p = Q[i].front(); Q[i].pop();
                    if (p.nt-f == 0) {
                        p.nt = p.t;
                        if (--p.c > 0) {
                            v.push_back(p);   
                        }
                    } else {
                        p.nt -= f;
                        nQ[i].push(p);
                    }
                }
                sort(v.begin(), v.end());
                for (int j = 0; j < (int)v.size(); j++) {
                    nQ2[1-i].push(v[j]);
                }
            }
            for (int i = 0; i < 2; i++) {
                while (!nQ2[i].empty()) {
                    nQ[i].push(nQ2[i].front());
                    nQ2[i].pop();
                }
            }

            for (int i = 0; i < 2; i++) {
                int nt = 0;
                while (!nQ[i].empty()) {
                    P p = nQ[i].front(); nQ[i].pop();                  
                    nt = p.nt = max(nt, p.nt);
                    Q[i].push(p);
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3012
a, b, c = gets.split.map(&:to_i)
k = gets.to_i
[0, 1, 2].repeated_combination(k).each do |p|
  red = a * 2 ** p.count(0)
  green = b * 2 ** p.count(1)
  blue = c * 2 ** p.count(2)
  if red < green && green < blue
    puts 'Yes'
    exit 0
  end
end
puts 'No'


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

int main() {
    string S;
    int alphabet[26] = {};
    cin >> S;
    for (int i=0; i < S.size(); i++) {
        alphabet[(int)S[i] - 97]++;
    }
    for (int i=0; i<26; i++) {
        if (alphabet[i] == 0) {
            cout << char('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long a,b,c=1,k,i,n,j,ans,temp,p,m,ex1,ex2,ex3,ex4,x,y;
	    cin>>x>>y>>n;
	    int arr[n][3];
	    for(i=0;i<n;i++)
	    {
	        for(j=0;j<3;j++)
	        {
	            cin>>arr[i][j];
	        }
	    }
	    ex1=0;
	    ex2=x;
	    ex3=0;
	    ex4=y;
	    for(i=0;i<n;i++)
	    {
	        if(arr[i][2]==1)
	        {
	            if(arr[i][0]>=ex1)
	            {
	                ex1=arr[i][0];
	            }
	        }
	        if(arr[i][2]==2)
	        {
	            if(arr[i][0]<=ex2)
	            {
	                ex2=arr[i][0];
	            }
	        }
	        if(arr[i][2]==3)
	        {
	            if(arr[i][1]>=ex3)
	            {
	                ex3=arr[i][1];
	            }
	        }
	        if(arr[i][2]==4)
	        {
	            if(arr[i][1]<=ex4)
	            {
	                ex4=arr[i][1];
	            }
	        }
	    }
	    if(ex2-ex1>=0)
	    cout<<max(long(0),(ex2-ex1)*(ex4-ex3));
	    else cout<<0;
	   
	    
    }
    
}


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

int main() {
	int n,m;
	cin>>n>>m;
	char arr[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>arr[i][j];
		}
	}
	for(int i=0;i<m+2;i++) cout<<'#';
	cout<<'\n';
	for(int i=0;i<n;i++){
		cout<<'#';
				for(int j=0;j<m;j++){
			cout<<arr[i][j];
		}
		cout<<"#\n";
	}
		for(int i=0;i<m+2;i++) cout<<'#';
	cout<<'\n';
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc134/tasks/abc134_e

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    //差分が小さくなるように重ねる
    cin >> n;
    multiset<int> mp;
    REP(i, n) {
        cin >> t;
        auto it = mp.upper_bound(-t);
        // 検索値より小さい値が見つかったら削除する
        if (it != mp.end()) {
            mp.erase(it);
        }
        mp.insert(-t);
    }
    cout << mp.size() << endl;

    return 0;
}


Measured memory_bytes: 4992
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 09/Nov/19 06:41:36 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on

const int mod = 998244353;
const int N = 1e5 + 5;
int arr[N], d[N];
int n;

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);

	cin >> n;
	fr (i, 1, n + 1) {
		cin >> arr[i];
		d[arr[i]]++;
		d[arr[i]] %= mod;
	}
	auto power = [&] (int a, int b) {
		int ans = 1;
		while (b) {
			if (b & 1) {
				ans = ans * a;
				ans %= mod;
			}
			a *= a;
			a %= mod;
			b >>= 1;
		}
		return ans;
	};

	int ans = 1;
	bool f = 0;
	if (arr[1] or d[0] > 1) {
		pr (0);
		return 0;
	}
	fr (i, 1, N) {
		if (!d[i]) {
			f = 1;
			continue;
		}
		if (f) {
			pr (0);
			return 0;
		}

		ans *= power (d[i - 1], d[i]);
		ans %= mod;
	}
	pr (ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    //input
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));

    for(int i = 0;i < n; i++) {
            cin >> c[i];
        for(int j = 0; j < m ; j++){
            cin >> a[i][j];
    }
    }

    //compute
    int cost = 0;
    int counter = 0;
    for(int i = 0;i < n; i++)cost += c[i];
    vector<int> r(m,0);

    for (int bit = 0; bit < (1<<n); ++bit) {
        int flag = 1;
        vector<int> skill(m,0);
        int tcost = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                tcost += c[i];
                for (int j = 0; j < m; ++j){
                    skill[j] += a[i][j];
                }
            }
        }

        for (int i = 0; i < m; ++i) {
            if(skill[i] < x){
                flag = 0;
                break;
            }
        }

        if(flag == 1){
                counter++;
                cost = min(cost,tcost);
        }
    }

    //output
    if(counter == 0){
        cout << -1 << endl;
    }else{
        cout << cost << endl;
    }
}

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

int main(void){
	int x = 0;	int res = 0;	int n;
	string s;	cin >> n >> s;
	for (char c : s) {
		if (c == 'I') {
			x++;
		} 
      	else {
			x--;
		}
		res = max(res, x);
	}
	cout << res;
}



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

int tile[21][21]={0};
int d[21][21]={0};
int lapse=0;
int W,H;
char a;
pair<int,int> person;
int answer=0;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

bool valid(int x,int y){
    return (x>=0 && x<H && y>=0 && y<W && tile[x][y]==1);
}

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

void dfs(int x,int y){
    ++answer;
    d[x][y]=1;
    //cout<<"visited ("<<x+1<<","<<y+1<<")\n";

    for(int i=0;i<4;++i){
        if(valid(x+dx[i],y+dy[i]) && d[x+dx[i]][y+dy[i]]==0){
            dfs(x+dx[i],y+dy[i]);
        }
    }
}

int main(){
    
    
    while(cin>>W>>H && W!=0){
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                cin>>a;
                if(a=='.'){
                    tile[i][j]=1;
                }
                else if(a=='@'){
                    person.first=i;
                    person.second=j;
                }
            }
        }

        dfs(person.first,person.second);

        cout<<answer<<"\n";
        answer=0;
        Fill(tile,0);
        Fill(d,0);
    }
}

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47516
from sys import stdin

N = int(stdin.readline())
H = list(map(int, stdin.readline().split()))

current_count = 0
max_count = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        current_count+=1
    else:
        if max_count < current_count:
            max_count = current_count
        current_count = 0

if max_count < current_count:
    max_count = current_count

print(max_count)

Measured memory_bytes: 14252
#include <iostream>
#define rep(i, n) for (int i = 1; i <= n; ++i)

using namespace std;

int main() {
	int n;
	cin >> n;
	
	n %= 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon\n";
	else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon\n";
	else cout << "bon\n";
	
	return 0;
}

Measured memory_bytes: 3640
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [MAP() for _ in range(N)]

fin = False
for cx in range(101):
	for cy in range(101):
		tmp = 10**9+7
		for a in A:
			x, y, h = a
			if h != 0:
				H = abs(cx-x)+abs(cy-y)+h
				if tmp == 10**9+7:
					tmp = H
				else:
					if tmp != H:
						break
			else:
				if tmp == 10**9+7: continue
				if tmp > abs(cx-x)+abs(cy-y):
					break
		else:
			X ,Y ,CH = cx, cy, H
			fin = True
print(X, Y, CH)

Measured memory_bytes: 42480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,mod,sz[100005];
ll f[100005],ans[100005];
vector<int> v[100005];
vector<ll> qzh[100005],hzh[100005];
void dfs(int x,int fa)
{
	f[x]=1;
	for(int i=0;i<sz[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		dfs(y,x);
		f[x]=f[x]*(f[y]+1)%mod;
	}
	//printf("f(%d)=%lld\n",x,f[x]);
}
void dfs2(int x,int fa,int sum)
{
	ans[x]=f[x]*sum%mod;
	//printf("dfs2(%d,%d,%d)\n",x,fa,sum);
	qzh[x].resize(sz[x]),hzh[x].resize(sz[x]);
	int last=1;
	for(int i=0;i<sz[x];i++)
	{
		int y=v[x][i];
		if(y==fa) 
		{
			qzh[x][i]=last;
			continue;
		}
		qzh[x][i]=(f[y]+1)*last%mod;
		last=qzh[x][i];
	}
	last=1;
	if(sz[x])
	{
		for(int i=sz[x]-1;i>=0;i--)
		{
			int y=v[x][i];
			if(y==fa) 
			{
				hzh[x][i]=last;
				continue;
			}
			hzh[x][i]=(f[y]+1)*last%mod;
			last=hzh[x][i];
		}
	}
	for(int i=0;i<sz[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		int nxs=sum;
		if(i>0) nxs=nxs*qzh[x][i-1]%mod;
		if(i<sz[x]-1) nxs=nxs*hzh[x][i+1]%mod;
		dfs2(y,x,nxs+1);
	}
}
int main()
{
	scanf("%d%d",&n,&mod);
	for(int i=1;i<=n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=n;i++) sz[i]=v[i].size();
	dfs(1,0);
	dfs2(1,0,1);
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 26240
from collections import defaultdict
S = str(input())
N = len(S)
mod = 10 ** 9 + 7

dp = [[0 for _ in range(13)] for _ in range(N)]
if S[0] == '?':
    for j in range(10):
        dp[0][j] = 1
else:
    dp[0][int(S[0])] = 1

residualDict = defaultdict(list)
for s in range(0, 10):
    for j in range(0, 13):
        for k in range(0, 13):
            if (10 * k + s) % 13 == j:
                residualDict[s].append([j, k])

for i in range(1, N):
    if S[i] == '?':
        for s in range(0, 10):
            tmpList = residualDict[s]
            for j, k in tmpList:
                dp[i][j] += dp[i - 1][k]
    else:
        s = int(S[i])
        tmpList = residualDict[s]
        for j, k in tmpList:
            dp[i][j] += dp[i-1][k]

    for j in range(13):
        dp[i][j] %= mod

print(dp[N-1][5])


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define INF             1e9
#define INFL            8e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define READ            freopen("D:\\moidda CPP\\alu.txt", "r", stdin)
#define WRITE           freopen("D:\\moidda CPP\\vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MASK(x)         for(int i = 0; i < 8; i++){ if(x&(1<<i)){ cout << i << " "; } } cout << endl;

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pff;

const int MAX = 1e5 + 2;
const int MAXLOG = log2(MAX) + 2;
const int MAXN = 200 + 2;
const int MOD = 1e9 + 7;
const double PY = acos(-1.0);
const double EPS = 1E-9;

int32_t main()
{
#ifndef ONLINE_JUDGE
//    READ;
//    WRITE;
#endif

    FASTIO;

    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for(ll x = k; x <= n+1; x++){
        ll t = (x*n)%MOD;
        t -= (x*(x-1))%MOD;
        t += MOD;
        t %= MOD;
        t++;
        t %= MOD;
        ans = (ans+t)%MOD;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int m[1000005];
int d[1000005];
int main() {
	int x,n;
	scanf("%d",&n);
	int a[n+1];
	for(int i=0;i<=1000000;i++) 
	m[i] = 0,d[i] = 0;
	int tot = 0;
	for(int i=0;i<n;i++)scanf("%d",&a[i]),m[a[i]]++;;
	for(int i=1;i<=1e6;i++) {
		if(!m[i]) continue;
		for(int j=i*2;j<=1e6;j+=i) {
			if(m[j] && !d[j]) {
				d[j] = 1;
				//printf("%d\n",j);
				tot+=m[j];
			}
		}
	}
	for(int i=1;i<=1e6;i++) {
		if(d[i]) continue;
		if(m[i]>1) tot+=m[i];
	}
	printf("%d\n",n-tot);
}

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

int main(void){
    string s;
    cin >> s;
    int n = s.size();
    int a[n];
    for(int i=0;i<n;i++) a[i] = s[i]-'A';
    sort(a,a+n);
    string ans;
    if(a[0] == a[1] && a[2] == a[3] && a[1] != a[2]) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
value = []
weight = []

for i in range(N):
    vi, wi = map(int, input().split())
    value.append(vi)
    weight.append(wi)

# dp[i+1][w]:i番目までの品物を入れたとき、wを超えない最大価値

dp = [[0]*(10**4+10) for _ in range(110)]
def rec(i,w):
    dp[i+1][w] = dp[i][w] #i番目は入れない

    if w-weight[i] >= 0:
        dp[i+1][w] = max(dp[i+1][w-weight[i]] + value[i], dp[i][w])

for i in range(N):
    for j in range(W+1):
        rec(i,j)
print(dp[N][W])


Measured memory_bytes: 42676
/**
 * @author      : omgursocute
 * @created     : 27/01/2020
 * @task        : D
 */

// ===== TEMPLATE STARTS HERE ===== //

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define FORa(i, a, b) for(ll i = (a); i <= (b); ++i)
#define FORb(i, a, b, c) for(ll i = (a); i <= (b); i += (c))
#define FORn(i, n) for(ll i = 0; i < (n); ++i)
#define FORra(i, a, b) for(ll i = (a); i >= (b); --i)
#define FORrb(i, a, b, c) for(ll i = (a); i >= (b); i -= (c))
#define FORrn(i, n) for(ll i = ((n)-1); i >= 0; --i)
#define NUMARGC(_1, _2, _3, _4, NAME, ...) NAME
#define FOR(...) NUMARGC(__VA_ARGS__, FORb, FORa, FORn)(__VA_ARGS__)
#define RFOR(...) NUMARGC(__VA_ARGS__, FORrb, FORra, FORrn)(__VA_ARGS__)

#define XFOR(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define RXFOR(i, x) for(__typeof((x).rbegin()) i = (x).rbegin(); i != (x).rend(); ++i)

#define pll pair<ll, ll>
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range(x, a, b) ((x).begin()+a), ((x).begin()+b)
#define pb push_back

#define sqr(x) 1ll*(x)*(x)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << '[' << #x << ']' << " = " << x << '\n'
#else
#define debug(x) "cute"
#endif

namespace io {
	void Speed() {
		ios::sync_with_stdio(false);
		cin.tie(NULL); cout.tie(NULL);
	}
#ifndef ONLINE_JUGDE
	void In(string s) {freopen(s.c_str(), "r", stdin);}
	void Out(string s) {freopen(s.c_str(), "w", stdout);}
	void setIO(string s) {In(s + ".inp"); Out(s + "out");}
#endif
}

// ======= TEMPLATE ENDS HERE ======= //

int main() {
	io::Speed();
	
	ll n;
	cin >> n;
	
	ll ct = 0;
	ll x = 1;

	while(n != 0) {
		n >>= 1;
		ct += x;
		x <<= 1;
	}

	cout << ct;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    string s,t;
    cin >> s >> t;
    vector<pair<char,char>> vc1(s.size()),vc2(s.size());
    rep(i,s.size()){
        vc1[i]=P{s[i],t[i]};
        vc2[i]=P{t[i],s[i]};
    }
    sort(vc1.begin(),vc1.end());
    sort(vc2.begin(),vc2.end());
    int now = 0;
    while(now<s.size()){
        // int cnt = 0;
        char cur_f = vc1[now].first;
        char cur_s = vc1[now].second;
        while(now<s.size()&&vc1[now+1].first==cur_f){
            if(cur_s==vc1[now+1].second)now++;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        ++now;
    }
    now = 0;
    while(now<s.size()){
        // int cnt = 0;
        char cur_f = vc2[now].first;
        char cur_s = vc2[now].second;
        while(now<s.size()&&vc2[now+1].first==cur_f){
            if(cur_s==vc2[now+1].second)now++;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        ++now;
    }
    cout << "Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1544
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 998244353
def solve():
    n, q = getList()
    s = input().strip()
    acc = [0]
    tmp = 0
    pred = ""
    for c in s:
        if pred == "A" and c == "C":
            tmp += 1
        acc.append(tmp)
        pred = c

    for i in range(q):
        l, r = getList()
        print(acc[r] - acc[l])

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Measured memory_bytes: 77228
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repa(i,n) for(ll i=n;i>=0;i--)
#define repx(i,x,n) for(ll i=x;i<n;i++)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define PI       3.14159265358979323846
#define fastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
const ll MAX=1e5+5;
const ll INF=2e18;
int ans=0,l1,l2;
#define INPUT_OUTPUT {\
    freopen("input.txt","r",stdin);\
    freopen("output.txt","w",stdout);\
}

// logical code of program starts here.
void solve()
{
    string s,t;
    cin>>s>>t;
    l1=s.length();
    l2=t.length();
    int dp[l1+1][l2+1];
    rep(i,l1+1)
    {
        rep(j,l2+1)
        {
            if(i == 0 or j == 0)
                dp[i][j] = 0;
            else if(s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    string ans;
    int i=l1,j=l2;
    while(i>0 and j>0)
    {
        if(s[i-1] == t[j-1])
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else j--;
    }
    reverse(all(ans));
    cout<<ans<<endl;
}


// mian function 
int main()
{
    //INPUT_OUTPUT;//file handling
    fastIO;// fast input output
    clock_t start, end; 
    start = clock();
    int t;
    t=1;
    //cin>>t;
    w(t) solve();
    end = clock();   
    double time_taken = double(end - start)/double(CLOCKS_PER_SEC); 
    clog << "Time taken by program is : " << fixed 
    << time_taken << setprecision(5); 
    clog << " sec " << endl;
    return 0;
}

Measured memory_bytes: 38916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(buff.readLine());
		String[] box = buff.readLine().split(" ");
		int[] num_box = new int[N];
		for(int i = 0; i < N; ++i){
			num_box[i] = Integer.parseInt(box[i]);
		}
		int alice = 0, bob = 0;
		boolean flag = true;
		while(N-- > 0){
			int max = 0, max_indx = 0;
			for(int i = 0; i < num_box.length; ++i){
				if(max < num_box[i]){
					max_indx = i;
					max = num_box[i];
				}
			}
			num_box[max_indx] = 0;

			if(flag){
				alice += max;
			} else {
				bob += max;
			}
			flag = !flag;
		}

		System.out.println(alice - bob);
	}

	static long f() {
		long ans = 0;


		return ans;
	}
}

Measured memory_bytes: 23252
a,b= map(int,input().split())
N = list(map(int,input().split()))
S =[]
key = 0
while(1):
	if a-key in N:
		if a +key in N:
			key +=1
		else:
			print(a+key)
			break
		
	else:
		print(a-key)
		break

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

int getX(int n) {
  return n * (n+1) / 2;
}

int test(int x) {
  int a = (int)sqrt((int)0x7FFFFFFF);
  int SUM[1000000];
  SUM[0] = 0;
  for(int i=1;i<a;i++) {
    SUM[i] = SUM[i-1] + i;
  }

  for(int i=0;i<a;i++) {
    if(SUM[i] >= x) {
      return i;
    }
  }

  return -1;
}

int main() {

  int X;
  scanf("%d", &X);

  printf("%d\n", test(X));

  return 0;
}


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

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  int n;
  cin >> n;
  vl a(n);
  rep (i, n) cin >> a[i];
  sort(all(a));
  int ok = n, ng = -1;
  while (ng + 1 < ok) {
    int mid = (ok + ng) / 2;
    ll x = a[mid];
    bool flag = true;
    rep (i, n) {
      if (i == mid) continue;
      if (2 * x >= a[i]) x += a[i];
      else flag = false;
    }

    if (flag) ok = mid;
    else ng = mid;
  }

  cout << n - ok << endl;
}

Measured memory_bytes: 1024