akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>

struct node { ll x,y; }a[100010];

int n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll gcd(ll x,ll y) { return (!y)?x:gcd(y,x%y); }

inline bool cmp(const node &x,const node &y) { return max(x.x,x.y)>max(y.x,y.y); }

inline pll check(pll x,pll y) { return (x.first*y.second>x.second*y.first)?x:y; }

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) a[i].x=rd(),a[i].y=rd();
	ll sum=0;
	for (int i=1;i<=n;i++) sum+=a[i].x;
	sort(a+1,a+n+1,cmp);
	int id=0;ll s=0;
	for (int i=1;i<=n;i++)
	{
		if (s+max(a[i].x,a[i].y)>sum) break;
		s+=max(a[i].x,a[i].y);id=i;
	}
	if (id==n) { puts("0 1");return 0; }
	pll ans(0,1);
	for (int i=1;i<=n;i++)
	{
		if (i>id)
		{
			if (s+a[i].y>=sum) ans=check(ans,pll(a[i].y-sum+s,a[i].y));
		}
		else
		{
			ll now=s-max(a[i].x,a[i].y)+max(a[id+1].x,a[id+1].y);
			if (now+a[i].y>=sum) ans=check(ans,pll(a[i].y-sum+now,a[i].y));
		}
	}
	ans.first+=ans.second*(n-id-1);ans.second*=n;
	ll hh=gcd(ans.first,ans.second);
	printf("%lld %lld\n",ans.first/hh,ans.second/hh);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long N;
  string S;
  cin >> N >> S;
  
  int T[N];
  long long num=0;
  int ans=0;
  int one, two, three;
  for(int i=0;i<N;i++)
  {
    T[i]=S[N-1-i]-'0';
  }
  for(int i=0;i<1000;i++)
  {
    one=-1; two=-1; three=-1;
    for(int n=2;n<N;n++)
    {
      if(T[n]==i/100) one=n;
    }
    if(one==-1) continue;
    for(int n=1;n<one;n++)
    {
      if(T[n]==(i%100)/10) two=n;
    }
    if(two==-1) continue;
    for(int n=0;n<two;n++)
    {
      if(T[n]==i%10) three=n;
    }
    if(three!=-1) ans++;
  }
  
  //cout << T[0] <<" "<< T[1]<<" " << T[2]<<" " << T[3]<<" " << T[4] << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int rank = 0;
            String input = System.Console.ReadLine();
            int rating = int.Parse(input);

            if (rating >= 400 && rating <= 599)
            {
                rank = 8;
            }
            if (rating >= 600 && rating <= 799)
            {
                rank = 7;
            }
            if (rating >= 800 && rating <= 999)
            {
                rank = 6;
            }
            if (rating >= 1000 && rating <= 1199)
            {
                rank = 5;
            }
            if (rating >= 1200 && rating <= 1399)
            {
                rank = 4;
            }
            if (rating >= 1400 && rating <= 1599)
            {
                rank = 3;
            }
            if (rating >= 1600 && rating <= 1799)
            {
                rank = 2;
            }
            if (rating >= 1800 && rating <= 1999)
            {
                rank = 1;
            }

            Console.WriteLine(rank);
        }
    }
}


Measured memory_bytes: 27524
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    int64_t n,m;
    cin>>n>>m;
    
    int64_t sum=0;
    for(int i=0;i<m;i++){
        int64_t a;
        cin>>a;
        sum+=a;
    }

    if(n-sum>=0)
        cout<<n-sum<<endl;
    else
        cout<<-1<<endl;

    return 0;
}  

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n, m; cin >> n >> m;
  const int nmax = 50;
  char a[nmax][nmax], b[nmax][nmax];

  for(int y = 0; y < n; ++y) {
    for(int x = 0; x < n; ++x) {
      cin >> a[y][x];
    }
  }

  for(int y = 0; y < m; ++y) {
    for(int x = 0; x < m; ++x) {
      cin >> b[y][x];
    }
  }
  bool exist = false;

  for(int ly = 0; ly < n; ly++) {
    for(int lx = 0; lx < n; ++lx) {
      if(ly+m-1 >= n or lx+m-1 >= n)  continue;

      bool match = true;
      for(int y = 0; y < m; ++y) {
        for(int x = 0; x < m; ++x) {
          if(a[ly+y][lx+x] != b[y][x]) match = false;
        }
      }
      if(match) exist = true;
    }
  }

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

  return 0;
}


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

int main(){
	int a,b,keta[300] = {0},kcor = 0;
	while(cin >> a){
		cin >> b;
		if(a+b == 0){
			keta[kcor] = 1;
		}
		else{
			keta[kcor] = log10(double(a+b))+1;
		}
		kcor++;
	}
	for(int i = 0;i < kcor;i++){
		cout << keta[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#include<map>
#include<set>
using namespace std;

map<int, int> cnt;
set<int> exist;

int main() {
    int n;
    scanf("%d", &n);
    long long s1 = 0;
    long long s2 = 0;

    int p = 0;
    int l = 0;
    int r = 0;
    for(int i = 0; i < n; i++) {
        int q;
        scanf("%d",&q);
        
        if(q == 1) {
            int x, b;
            scanf("%d %d", &x, &b);
            s2 += b;

            if(i == 0) p = x;

            cnt[x]++;
            exist.insert(x);
            s1 += abs(p - x);

            if(x < p) l++;
            if(x > p) r++;

            int c = cnt[p];
            if(l >= c + r) {
                int next = *(--exist.lower_bound(p));

                s2 -= (l - c - r) * (long long) abs(p - next);
                l -= cnt[next];
                r += cnt[p];
                p = next;
            } else if(r > c + l) {
                int next = *(exist.upper_bound(p));
                
                s2 -= (r - c - l) * (long long) abs(p - next);
                l += cnt[p];
                r -= cnt[next];
                p = next;
            }
        }
        if(q == 2) {
            printf("%d %lld\n", p, s1 + s2);
        }
    }
    return 0;
}

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

long long ceil_div(long long a, long long b)
{
    return (a + b - 1) / b;
}

int main()
{
    int k, q;
    cin >> k >> q;

    vector<long long> d(k);
    for (long long &dd : d)
    {
        cin >> dd;
    }

    long long n, x, m;
    for (int i = 0; i < q; i++)
    {
        cin >> n >> x >> m;
        long long ans = n - 1;
        long long sum = x;
        for (int i = 0; i < k; i++)
        {
            long long diff = d[i] % m;
            if (diff == 0)
            {
                ans -= ceil_div(n - i - 1, k);
            }
            sum += ceil_div(n - i - 1, k) * diff;
        }
        cout << ans - (sum / m - x / m) << endl;
    }
}


Measured memory_bytes: 384
// "header" {{{
#pragma GCC optimize("Ofast")

#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define double long double
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int64_t mod1 = 1000000007;
constexpr int64_t mod2 = 998244353;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); }
inline int square(int a){ return a * a; }

int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
// }}}

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

    int n,k;
    cin >> n >> k;
    vector<int> v(n);

    rep(i,n){
        cin >> v[i];
    }

    int maxv = 0;
    for(int i = 0;i <= min(n,k);++i){
        for(int j = 0;j <= i;++j){
            vector<int> tmp;
            int sum = 0;
            for(int l = 0;l < j;++l){
                tmp.emplace_back(v[l]);
                sum += v[l];
            }
            for(int l = 1;l <= i-j;++l){
                tmp.emplace_back(v[n-l]);
                sum += v[n-l];
            }
            sort(all(tmp));
            rep(l,min(k-i,i)){
                if(tmp[l] < 0) sum -= tmp[l];
                else break;
            }
            chmax(maxv,sum);
        }
    }

    cout << maxv << '\n';

    return 0;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  const ll n = 100010;
  vector<ll> cnt(n, 0);
  rep(i, 1, n) {
    for (ll j = i; j < n; j += i) {
      cnt[j]++;
    }
  }
  rep(i, n) cnt[i] = (cnt[i] + 1) / 2;
  vector<ll> S(n, 0);
  rep(i, 2, n+1) {
    ll d = cnt[i] >= 3 ? 1 : 0;
    S[i+1] = S[i] + d;
  }
  ll Q; cin >> Q;
  rep(q, Q) {
    ll x; cin >> x;
    cout << S[x+1] << endl;
  }
}



Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int ans=a*x+b*y;
  int na=x,nb=y;
  while(min(na,nb)>0){
    chmin(ans,ans+2*c-a-b);
    na--;nb--;
  }
  while(max(na,nb)>0){
    int k=(na>0?a:b);
    chmin(ans,ans+2*c-k);
    if(na>0) na--;
    else nb--;
  }
  

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
int n, p[N];
vector <int> v[N];

int dfs(int node) {
	dbg(node);
	vector <int> dpt;

	for(auto i : v[node])
		dpt.push_back(dfs(i));

	sort(dpt.begin(), dpt.end(), greater <int>());
	int ret = 1;
	for(int i = 0; i < dpt.size(); i++)
		ret = max(ret, dpt[i] + i + 1);
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 2; i <= n; i++) {
		cin >> p[i];
		v[p[i]].push_back(i);
	}

	cout << dfs(1) - 1;
}	

	

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind() { s = 0; }
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[fx]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

// ----

int h, w;
int id(int i, int j) { return w * i + j; }
pair<int, int> ij(int v) { return MP(v / w, v % w); }

string s[400];

int main() {
	cin >> h >> w;
	inc(i, h) { cin >> s[i]; }
	
	UnionFind uf(h * w);
	inc(i, h) {
	inc(j, w) {
		if(i > 0 && s[i][j] != s[i - 1][j]) { uf.unite(id(i, j), id(i - 1, j)); }
		if(j > 0 && s[i][j] != s[i][j - 1]) { uf.unite(id(i, j), id(i, j - 1)); }
	}
	}
	
	LL ans = 0;
	inc(i, h * w) {
		LL x = 0, y = 0;
		inc(j, uf.v[i].size()) {
			auto p = ij(uf.v[i][j]);
			(s[p.FI][p.SE] == '#' ? x : y) += 1;
		}
		ans += x * y;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    if(s[0]>='a'&&s[0]<='z'){
        cout<<"a"<<endl;
    }else{
        cout<<"A"<<endl;
    }

    return 0;
}

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

using namespace std;

#define INF 10000000

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

	vector<int> d(m);
	vector<int> dp(n + 1, INF);

	for (vector<int>::size_type i = 0; i < m; i++)
	{
		cin >> d[i];
	}

	dp[0] = 0;

	for (unsigned i = 1; i <= n; i++)
	{
		for (vector<int>::size_type j = 0; j < m; j++)
		{
			if (i >= d[j])
			{
				if (dp[i] >= dp[i - d[j]] + 1)
				{
					dp[i] = dp[i - d[j]] + 1;
				}
			}
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1292
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int n, i = 0, k = 0, game = 0, flag = 0;
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		int[][] member = new int[n + 1][3];
		int[] point = new int[n + 1];
		for(i = 0; i < n; i++){
			for(game = 0; game < 3; game++){
				member[i][game] = scan.nextInt();
			}
		}
		for(game = 0; game < 3; game++){
			for(i = 0; i < n; i++){
				flag = 0;
				for(k = i + 1; k < n; k++){
					if(member[i][game] == member[k][game]){
						member[k][game] = 0;
						flag = 1;
					}
				}
				if(flag == 1){
					member[i][game] = 0;
				}
			}
			for(i = 0; i < n; i++){
				point[i] += member[i][game]; 
			}
		}
		scan.close();
		for(i = 0; i < n; i++){
			System.out.println(point[i]);
		}
	}
}

Measured memory_bytes: 20892
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
char s[maxn],t[maxn];
int main()
{
	scanf("%s%s",s,t);
	int lens=strlen(s),lent=strlen(t),ans=0;
	for(int i=0;i+lent<=lens;i++)
	{
		int cnt=0;
		for(int j=0;j<lent;j++)
			cnt+=(s[i+j]==t[j]);
		ans=max(ans,cnt);
	}
	printf("%d\n",lent-ans);
}	

Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;


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

string s, t;
int dp[3030][3030] = {0};

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

    cin >> s >> t;

    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(s[i] == t[j]){
                chmax(dp[i+1][j+1], dp[i][j]+1);
                chmax(dp[i+1][j+1], dp[i+1][j]);
                chmax(dp[i+1][j+1], dp[i][j+1]);
            }else{
                chmax(dp[i+1][j+1], dp[i+1][j]);
                chmax(dp[i+1][j+1], dp[i][j+1]);
            }
        }
    }


    string ans(dp[s.size()][t.size()], 'a');
    int i = s.size();
    int j = t.size();
    int index = dp[s.size()][t.size()]-1;

    while(i > 0 && j > 0){

        if(s[i-1] == t[j-1]){
            ans[index] = s[i-1];
            i--;
            j--;
            index--;
        }else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        }else{
            j--;
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 2e5 + 10;
using namespace std;

int main() {
    IO;
    int n;
    cin >> n;
    map<string, int> cnt;
    cnt["AC"] = 0;
    cnt["WA"] = 0;
    cnt["TLE"] = 0;
    cnt["RE"] = 0;
    while (n--) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    cout << "AC" << " x " << cnt["AC"] << endl;
    cout << "WA" << " x " << cnt["WA"] << endl;
    cout << "TLE" << " x " << cnt["TLE"] << endl;
    cout << "RE" << " x " << cnt["RE"] << endl;


}


Measured memory_bytes: 3664
n = gets.to_i
Dish = Struct.new(:a, :b, :id)
dishes = []

n.times do |i|
  a, b = gets.split.map(&:to_i)
  dishes << Dish.new(a, b, i)
end

# example
# a1 b1
# a2 b2
# 高橋君がa1をとったときの総和
# a1 - b2
# 高橋君がa2をとったきの総和
# a2 - b1
# 高橋君がa1をとるべきなのは
# a1 - b2 >= a2 - b1
# => a1 + b1 >= a2 + b2

dishes.sort_by! {|d| -(d.a + d.b) }

ans = 0
n.times do |i|
  d = dishes.shift
  if (i % 2) == 0
    ans += d.a
  else
    ans -= d.b
  end
end

p ans


Measured memory_bytes: 14712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
 			var A = cin.ReadInt;
			var B = cin.ReadInt;
			var S = cin.Read;

			for(int i = 0; i < S.Length; i++)
			{
				if (i == A)
				{
					if(S[i] != '-')
					{
						Console.WriteLine("No");
						return;
					}
				}
				else
				{
					int n_s;
					if(int.TryParse(S[i].ToString(),out n_s))
					{
						if (!(0 <= n_s && n_s <= 9))
						{
							Console.WriteLine("No");
							return;
						}
					}
					else
					{
						Console.WriteLine("No");
						return;
					}
				}
			}
			Console.WriteLine("Yes");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	string str;
	cin>>str;
	int sum = 0;
	for(int i = 0; i < str.length(); i++){
		int num = str[i] - '0';
		sum += num;
	}
	if( sum % 9 == 0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	long long int n;
	cin >> n;
	long long int ans = 0;
	if (n == 1) {
		cout << 0 << endl;
	}
	else {
		cout << n * (n - 1) / 2 << endl;
	}
	return 0;
}

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

const int MOD = 998244353;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<vector<ll> > dp(c + 1, vector<ll>(d + 1, 0));

    dp[a][b] = 1;

    for (int i = a; i <= c; i++)
        for (int j = b; j <= d; j++)
            if (i != a || j != b)
                dp[i][j] = ((dp[i - 1][j] * j) % MOD + (dp[i][j - 1] * i) % MOD - (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD + MOD) % MOD;

    cout << dp[c][d] << '\n';
    return 0;
}


Measured memory_bytes: 73636
#include <bits/stdc++.h>
using namespace std;
int a, b;
string s;
bool sol () {
  cin >> a >> b;
  cin >> s;
  if (s.size() != a + b + 1) {
    return false;
  }

  for(int i = 0; i < a; ++i) {
    if (s[i] < '0' || s[i] > '9') return false;
  }

  if (s[a] != '-') return false;
  for(int i = a + 1; i < a + b + 1; ++i) {
    if (s[i] < '0' || s[i] > '9') return false;
  }
  return true;
}

int main () {
  if (sol()) {
    cout << "Yes";
  } else cout << "No";
}

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

// 解説を証明するのが大変(なにこれ)(でもすき)
// 上からガッツリ抑えて, それを構築可能であることが言える, すごい

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    ll a, b; cin >> a >> b;
    if(a > b) swap(a, b);
    if(a == b) {
      cout << 2 * (a - 1) << endl;
    } else if (a + 1 == b) {
      cout << 2 * (a - 1) << endl;
    } else {
      ll c = sqrt(a * b);
      if(c * c == a * b) c--;
      if(c * (c + 1) < a * b) {
        cout << 2 * c - 1 << endl;
      } else {
        cout << 2 * c - 2 << endl;
      }
    }
  }
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v);

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

	int A;
	int B;
	int C;
	cin >> A >> B >> C;

	int remA = A % B;
	if (remA == C) {
		cout << "YES" << ENDL;
		return 0;
	}

	bool flag = false;
	int t = (remA + A) % B;
	while (t != remA) {
		if (t == C) {
			flag = true;
			break;
		}
		t = (t + A) % B;
	}
	
	if (flag) {
		cout << "YES" << ENDL;
	}
	else {
		cout << "NO" << ENDL;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;
int main(){
  string S;
  cin>>S;
  int L = S.length();
  int *N = new int[L];
  int p=0;
  int i=0;
  rep(o,0,L) N[o]=0;
  rep(l,0,L){
    p=i;
    while(S[p]!='L') p++;
    if((p-i)%2){//奇数
      N[p-1]+=(p-i-1)/2+1;
      N[p]+=(p-i-1)/2;
    }else{//偶数
      N[p-1]+=(p-i)/2;
      N[p]+=(p-i)/2;
    }
    
    i=p;
    while(S[i]!='R'&&i<L) i++;
    if((i-p)%2){//奇数
      N[p-1]+=(i-p-1)/2;
      N[p]+=(i-p-1)/2+1;
    }else{//偶数
      N[p-1]+=(i-p)/2;
      N[p]+=(i-p)/2;
    }
    if(i==L) break;
  }

    rep(i,0,L) cout<<N[i]<<" ";
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//



Measured memory_bytes: 1024
n, k = map(int, input().split())
p = list(map(int, input().split()))

pe = [1] * max(p)
for i in range(1, len(pe)):
    pe[i] += (pe[i-1] + i)

for i in range(1, len(pe)):
    pe[i] *= 1/(i+1)

ans = sum([pe[pi-1] for pi in p[0:k]])
s = ans
for i, t in enumerate(range(k, n)):
    s = s + pe[p[t]-1] - pe[p[i]-1]
    ans = max(ans, s)

print(ans)

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

void print(string str, int a, int b) {
    for (int i = a; i <= b; i++) cout << str[i];
    cout << endl;
}

string reverse(string str, int a, int b) {
    string after = "";
    for (int i = 0; i < a; i++) after += str[i];
    for (int i = b; i >= a; i--) after += str[i];
    for (int i = b + 1; i < str.size(); i++) after += str[i];
    return after;
}

string replace(string str, int a, int b, string p) {
    string after = "";
    for (int i = 0; i < a; i++) after += str[i];
    after += p;
    for (int i = b + 1; i < str.size(); i++) after += str[i];
    return after;
}

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

    string str;
    cin >> str;

    int loop;
    cin >> loop;

    rep(qi, loop) {
        string query;
        cin >> query;
        int a, b;
        cin >> a >> b;

        if (query == "replace") {
            string p;
            cin >> p;
            str = replace(str, a, b, p);
        } else if (query == "reverse") {
            str = reverse(str, a, b);
        } else if (query == "print") {
            print(str, a, b);
        }
    }
    return 0;
}


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

int main() {
	ll n;
	ll x, m;
	cin >> n >> x >> m;
	map<ll,ll> mp;
	vector<ll> a,ind(m+1);
	ll cnt=0;
	ll ai = x;
	mp[ai]++;
	a.push_back(ai);
	ind[ai]=cnt;
	ll st=0, ed=n-1;
	bool circlep = false;
	for(ll i=2; i < n+1;i++) {
		ll now = ll(ai*ai) % m;
		if (mp[now]==1){
			// now 既出
			circlep = true;
			ed = cnt;
			st = ind[now];
			break;
		} else if (now == 0) {
			ed = cnt;
			break;
		}
		mp[now]++;
		a.push_back(now);
		cnt++;
		ind[now]=cnt;
		ai = now;
	}
	ll sum = 0;
	if (circlep) {
		ll sumc = 0;
		ll suma = 0;
		rep(i,st) {
			sum += a[i];
		}
		for(ll i= st;i<=ed;i++){
			sumc += a[i];
		}
		ll nshow=(n-st)/(ed-st+1);
		ll amari=(n-st)%(ed-st+1);
		for(ll i= st;i< st+amari;i++){
			suma += a[i];
		}
		sum += suma;
		sum += sumc*nshow;
	} else {
		for(ll i= st;i<=ed;i++){
			sum += a[i];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 7476
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<int> v;
int main(){
    string s;cin>>s;
    for(int i=0;i<(int)s.size();){
        char c=s[i];
        int cnt=0;
        while(s[i]==c){
            cnt++;
            i++;
        }
        v.push_back(cnt);
    }
    int id=0;
    vector<int> ans((int)s.size(),0);
    for(int i=0;i<(int)v.size();i+=2){
        id+=v[i];
        ans[id-1]=v[i]/2+v[i+1]/2+((v[i]&1)?1:0);
        ans[id]=v[i]/2+v[i+1]/2+((v[i+1]&1)?1:0);
        id+=v[i+1];
    }
    for(int i=0;i<(int)s.size();i++){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1528
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sa := nextLine()
	sb := nextLine()
	sc := nextLine()
	next := byte('a')
	for {
		if next == 'a' {
			if len(sa) <= 0 {
				fmt.Println("A")
				break
			}
			next = sa[0]
			sa = sa[1:]
		} else if next == 'b' {
			if len(sb) <= 0 {
				fmt.Println("B")
				break
			}
			next = sb[0]
			sb = sb[1:]
		} else {
			if len(sc) <= 0 {
				fmt.Println("C")
				break
			}
			next = sc[0]
			sc = sc[1:]
		}
	}
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;

typedef pair<int, int> P;

int a[100000];
P card[100000];

int max(int a,int b){return a > b ? a : b;}

int main() {
    int n, m;
    scanf("%d %d",&n, &m);

    for(int i = 0; i < n; i++)scanf("%d", &a[i]);
    for(int i = 0; i < m; i++) {
        int c, b;
        scanf("%d %d", &c, &b);
        card[i] = P(b, c);
    }

    sort(a, a + n);
    sort(card, card + m);
    reverse(card, card + m);

    int t = 0;
    for(int i = 0; i < m; i++) {
        P p = card[i];
        int b = p.first;
        int c = p.second;
        for(int j = 0; j < c; j++) {
            a[t] = max(a[t], b);
            t++;

            if(t == n) break;
        }

        if (t == n) break;
    }

    long long s = 0;
    for(int i = 0; i < n; i++) s += a[i];
    printf("%lld\n", s);
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
int main() {
	int x=100,y=100, ans=0;
	for (int i = 0; i < 4; i++) {
		int a;
		std::cin >> a;
		if (a < x) {
			x = a;
		}
		ans += a;
	}
	for (int i = 0; i < 2; i++) {
		int a;
		std::cin >> a;
		if (a < y) {
			y = a;
		}
		ans += a;
	}
	std::cout << ans - x - y << std::endl;
}


Measured memory_bytes: 3100
N = int(input()) #入力する整数
A = list(map(int,input().split())) #入力する数列A
SUMA = sum(A) #数列の和
MOD = 10**9 + 7 # mod
C = [0] * (N-1) #累積和数列
for i in range(N-1): #\sum_{j = i+1}^{N}を求めて数列に代入する
  SUMA -= A[i]
  C[i] = SUMA
ans = 0 #求める答え
for i in range(N-1):
  ans += A[i]*C[i]
  ans %= MOD #その都度modで割った余りにする
print(ans) #答えを出力する

Measured memory_bytes: 31396
from math import gcd
import numpy
N, M = map(int, input().split())
S = input()
T = input()
def func(m, n):
    return (m * n) // gcd(m, n)
ans = func(N, M)
var1 = ans//N
var2 = ans//M
for i in range(1, ans+1, var1*var2):
    varS = (i - 1) // var1
    varT = (i - 1) // var2
    if S[varS] != T[varT]:
        ans=-1
print(ans)

Measured memory_bytes: 27304
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

M = I()
dc = [IL() for i in range(M)]

num = 0
cnt = 0
for d,c in dc:
  num += d*c
  cnt += c

print(cnt - 1 + math.ceil(num/9) - 1)

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

int main(){
    string ans = "No";
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    while (k > 0) {
        if (a >= b) {
            b *= 2;
            k--;
        } else if (b >= c) {
            c *= 2;
            k--;
        } else {
            c *= 2;
            k--;
        }
    }
    
    if (a < b && b < c) {
        ans = "Yes";
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h, n;
	cin >> h >> n; 
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		h -= a;
	}
	cout << (h<=0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int A;
int B;

scanf("%d",&A);
scanf("%d",&B);
if(A==1 ) A=14;
if(B==1) B=14;

if(A>B) printf("Alice");

else if(A<B) printf("Bob");

else printf("Draw");

return 0;
}

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

int main()
{

    int N;
    string s;
    cin >> N >> s;

    int red_total = 0;
    int blue_total = 0;

    for (int n = 0; n < N; n++)
    {
        if (s[n] == 'R')
        {
            red_total++;
        }
        else
        {
            blue_total++;
        }
    }
    if (red_total > blue_total){
        cout << 'Y' << 'e' << 's' << endl;
    }
    else
    {
        cout << 'N' << 'o' << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

int mn = 110;
string s;

int main () {
	cin >> s;
	for (char i = 'a'; i <= 'z'; i++) {
		int mx = 0, l = 0;
		for (int j = 0; j < SZ(s); j++) {
			if (s[j] == i) {
				mx = max(mx, j-l);
				l = j+1;
			}
		}
		mx = max(mx, SZ(s)-l);
		mn = min(mn, mx);
		//printf("%c %d\n", i, mx);
	}
	printf("%d\n", mn);
	return 0;
}


Measured memory_bytes: 256
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class Main {

	class Operation127D {
		private long B, C;

		Operation127D (long B, long C) {
			this.B = B;
			this.C = C;
		}

		long getC() {
			return C;
		}
	}

	static Main instance = new Main();

	public static void main(String[] args) throws Exception {
		int N = in.i(), M = in.i();
		long[] A = new long[N];
		for (int i = 0; i < N; i++)
			A[i] = in.l();

		ArrayList<Operation127D> operations = new ArrayList<>(M);
		for (int i = 0; i < M; i++) {
			Operation127D op = instance.new Operation127D(in.i(), in.i());
			operations.add(op);
		}

		// smaller -> greater
		Arrays.sort(A);
		// greater -> smaller
		operations.sort(Comparator.comparingLong(Operation127D::getC).reversed());



		long acc = 0;
		int op_i = 0;
		Operation127D op = operations.get(0);
		for ( long a : A ) {
			if (op != null && op.B == 0) {
				if (M - 1 == op_i) {
					op = null;
				} else {
					op = operations.get(++op_i);
				}
			}

			if (op == null) {
				acc += a;
			} else {
				if ( a >= op.C ) {
					acc += a;
				} else {
					acc += op.C;
					op.B--;
				}
			}
		}

		out.println(acc);
	}

	static PrintStream out = System.out;
	static FastReader in = new FastReader();
}

class FastReader {
	final private int BUF_SIZE = 1 << 16;
	private DataInputStream din = new DataInputStream(System.in);
	private byte[] buffer = new byte[BUF_SIZE];
	private int bufferPointer, bytesRead;

	String s() throws IOException {
		return s(64);
	}

	String s(int capacity) throws IOException {
		byte[] buf = new byte[capacity];
		int cnt = 0, c;
		while ((c = c()) != -1) {
			if (c == '\n') break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	int i() throws IOException {
		int ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	long l() throws IOException {
		long ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	double d() throws IOException {
		double ret = 0, div = 1;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		if (c == '.')
			while ((c = c()) >= '0' && c <= '9')
				ret += (c - '0') / (div *= 10);
		return neg ? -ret : ret;
	}

	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUF_SIZE);
		if (bytesRead == -1) buffer[0] = -1;
	}

	byte c() throws IOException {
		if (bufferPointer == bytesRead) fillBuffer();
		return buffer[bufferPointer++];
	}
}



Measured memory_bytes: 33764
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    int m, d;
    cin >> m >> d;
    int count=0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= d; j++)
        {
            int d1 = j % 10;
            int d2 = (j - d1)/10;
            //int g=0;
            //cout<<d1<<" "<<d2<<endl;
            if(d1>=2&&d2>=2&&d1*d2==i){
                count++;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import math
import bisect
from queue import Queue
from collections import deque

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [1000000000 for _ in range(n)]

dp[0] = 0

for i in range(1,n):
    if(i == 1):
        dp[i] = abs(h[i]-h[i-1])
    else:
        for j in range(1,min(k+1,i+1)):
            dp[i] = min(dp[i],abs(h[i]-h[i-j]) + dp[i-j])

print(dp[n-1])

Measured memory_bytes: 61672
N = int(input())
X = list(map(int, input().split()))

m = min(X)
M = max(X)

min_val = 100 * 100 * 100
for p in range(m, M+1):
    score = 0
    for x in X:
         score += (x-p)*(x-p)
    if score < min_val: min_val = score
print(min_val)


Measured memory_bytes: 3060
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[2005][12];
int v[2005][12]={};
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	vector<int>vec[12];
	for(int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		vec[b].pb(a);
	}
	for(int i=1;i<=10;i++) sort(vec[i].begin(),vec[i].end(),greater<int>());
	for(int i=1;i<=10;i++)
	{
		for(int j=0;j<vec[i].size();j++)
		{
			v[j+1][i]=v[j][i]+vec[i][j];
		}
	}
	
	for(int i=0;i<2005;i++)for(int j=0;j<12;j++)dp[i][j]=0;
	
	dp[0][0]=0;
	for(int i=1;i<=10;i++)
	{
		for(int j=0;j<=vec[i].size();j++)
		{
			for(int l=0;l<=k-j;l++)
			{
				dp[j+l][i]=max(dp[j+l][i],dp[l][i-1]+v[j][i]+j*(j-1));
			}
		}
	}
	printf("%d\n",dp[k][10]);
}

Measured memory_bytes: 1412
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n+1), b(n+1);
	REP(i, n)cin >> a[i+1];
	REP(i, n)cin >> b[i];
	a[0] = 0; b[n] = 0;
	vl tmpa(n), tmpb(n);
	REP(i, n) {
		if (a[i] < a[i+1]) {
			tmpa[i] = -a[i+1];
		}
		else {
			tmpa[i] = a[i+1];
		}
	}
	RREP(i, n) {
		if (b[i] > b[i + 1]) {
			tmpb[i] = -b[i];
		}
		else {
			tmpb[i] = b[i];
		}
	}
	ll ans = 1;
	REP(i, n) {
		if (tmpa[i] < 0) {
			if (tmpb[i] < 0) {
				if (tmpa[i] != tmpb[i]) {
					ans = 0;
				}
			}
			else {
				if (-tmpa[i] > tmpb[i]) {
					ans = 0;
				}
			}
		}
		else {
			if (tmpb[i] < 0) {
				if (-tmpb[i] > tmpa[i]) {
					ans = 0;
				}
			}
			else {
				ans *= min(tmpa[i], tmpb[i]);
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 2560
// package com.company;

import java.util.*;
import java.io.*;

public class Main {
    static Scanner input = new Scanner(System.in);


    public static void main(String[] args) {
        String ans = "";
        int n = input.nextInt();
        int p = input.nextInt();

        while (n != 0 || p!= 0) {
            int[] arr = new int[n];
            Arrays.fill(arr, 0);

            int index = 0;
            int stones = p; // stones in the glass
            while (arr[index] < p) {
                if (stones > 0) {
                    arr[index]++; // ứng viên đc nhận thêm 1 viên đá và chuyển cốc cho ng kế tiếp
                    if (arr[index] == p) break;
                    stones --;
                } else {
                    // Neu coc rong, ung vien phai bo het da vao coc
                    stones = arr[index];
                    arr[index] = 0;
                }
                index ++; // chuyen coc cho ng ke ben
                if (index ==  n) index = 0;
            }
            ans += "" + index + "\n";
            n = input.nextInt();
            p = input.nextInt();
        }
        
        System.out.println(ans.trim());
    }
}


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

int main() {
	int n,cnt=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		long long k,old;
		old=k;
		cin>>k;
		if(old>=k){
			cnt++;
		}else{
			ans=max(ans,cnt);
			cnt=0;
		}
		old=k;
	}
	ans=max(ans,cnt);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long

int a,b,c;

int main(){	
	cin>>a>>b>>c;

	for(int i=1;i<=100000;i++){
		if(a*i%b==c){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int x,i,j,k,a,b,c,ans=0;
	cin>>a>>b>>c>>x;
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				if(500*i+100*j+50*k==x)ans++;
			}
		}
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int main() {
  ll n;
  cin >> n;
  string s;
  while (n > 0) {
    s = char('a' + (n - 1) % 26) + s;
    n = (n - ((n - 1) % 26)) / 26;
  }
  cout << s << endl;
}

Measured memory_bytes: 3568
n = int(input())

A = list(map(int, input().split()))


total_ = 0
m = 100000000000000000000000000000000000

for i in range(100):
    for j in A:
        total_ += (j - i)**2
    if total_ < m:
        m = total_
    total_ = 0
print(m)
    

Measured memory_bytes: 38896