akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
  int i, j, n, getnm, nm, k=0;
  int C[10001];

  for(i = 0; i < 10001; i++){
    C[i] = 0;
  }
 
  scanf("%d", &getnm);

  for(i = 0; i < getnm; i++){
    scanf("%d", &nm);
    C[nm]++;
  }

  for(i = 0; i < 10001; i++){
    for(j = 0; j < C[i]; j++){
      if(k == getnm-1) printf("%d\n", i);
      else {
	printf("%d ", i);
	k++;
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 2072
import math
a, b, h, m = map(int, input().split())
s_radius = m * 6
m_radius = h * 30 + 30 * (m/60)
a_radius = abs(s_radius - m_radius)
ans = math.sqrt(a**2+b**2 - 2*a*b*math.cos(math.radians(a_radius)))
print(ans)


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

int main(){
  int n,a;

  for(;;){
    scanf("%d",&n);
    if(!n)break;

    vector<int> color;
    vector<int> num;
    for(int i=1;i<=n;i++){
      scanf("%d",&a);
      if(color.empty()){
	color.push_back(a);
	num.push_back(1);
      }else{
	if(!(i&1) && color.back()!=a){
	  color[(int)color.size()-1] = a;
	  num[(int)num.size()-1]++;
	  if(color.size()>1){
	    num[(int)num.size()-2] += num[(int)num.size()-1];
	    color.erase(color.begin()+(int)color.size()-1);
	    num.erase(num.begin()+(int)num.size()-1);
	  }
	}else{
	  if(color.back()==a)num[(int)num.size()-1]++;
	  else{
	    color.push_back(a);
	    num.push_back(1);
	  }
	}
      }
    }
    int ans = 0;
    for(int i=0;i<(int)color.size();i++)
      if(!color[i])ans += num[i];
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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;
}
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int N;
long long a[100010][3];
long long dp[100010][3];

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  rep(i,N) rep(j,3) cin >> a[i][j];
  for(int i=0;i<N;i++)
  {
    for(int j=0;j<3;j++)
    {
      for(int k=0;k<3;k++)
      {
        if(j==k) continue;
        chmax(dp[i+1][k],dp[i][j] + a[i][k]);
      }
    }
  }
  long long res = 0;
  rep(j,3) chmax(res,dp[N][j]);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=2147483547;
int n;
#define Maxn 1000010
char S[Maxn];
int sum[Maxn],at[Maxn],cnt=0;
int le[Maxn],ri[Maxn];

inline int D(int x){
    if(x>0)return x;
	return -x;	
}
inline bool Judge(int mid){
	le[0]=0;ri[0]=mid;
	for(int i=1;i<=cnt;++i){
		le[i]=-inf;ri[i]=inf;
	}
	for(int i=0;i<=n;++i){
		le[at[i]]=max(le[at[i]],-sum[i]); 
		ri[at[i]]=min(ri[at[i]],mid-sum[i]);
	}
	if(le[0]>ri[0])return false;
	int l,r,ty;
	if(le[0]==ri[0]){
		l=r=le[0];
		ty=(D(le[0])%2);
	}else{
		l=le[0];r=ri[0];
		ty=2;
	}
	for(int i=1;i<=cnt;++i){
		if(ty==2){
			l--;r++;
			l=max(l,le[i]);r=min(r,ri[i]);
			if(l>r)return false;
			if(l==r){
				ty=(D(l)%2);
				continue;
			}
			continue;
		}
		l--;r++;
		l=max(l,le[i]);r=min(r,ri[i]);
		if(l>r)return false;
		int g=(D(l)%2);
		ty^=1;
		if(l+(g^ty)>r)return false;
	}
	return true;
}

int main(){
	scanf("%s",S+1);n=strlen(S+1);
	cnt=0;
	for(int i=1;i<=n;++i){
		sum[i]+=sum[i-1];
	    if(S[i]=='1')
	       sum[i]++;	
	    if(S[i]=='0')
		sum[i]--;
		if(S[i]=='?')cnt++;
		at[i]=cnt; 
	}
	int l=0,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(Judge(mid))r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 19696
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a, T b) { return a<b?(a=b,true):false; }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define bs2int(bs) (int)((bs).to_ulong())
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

int n,k;

int main() {
  cin>>n>>k;
  ll c=1;
  REP(i,n)
  {
    if (c*2<c+k) c*=2;
    else c+=k;
  }
  cout << c << endl;
}


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    string a; cin >> a;
    ll n = a.size();
    ll ans = 1 + n*(n-1)/2;
    vector<ll> num(26,0);
    rep(i, n) {
        ll tmp = ll(a[i]-'a');
        num[tmp]++;
    }

    rep(i, 26) {
        ans -= num[i]*(num[i]-1)/2;
    }
    cout << ans << endl;
    
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3608
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (i == N - 1) {
            if (x == a[i]) {
                ans++;
            }
        } else {
            if (x >= a[i]) {
                ans++;
                x -= a[i];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100000

int partition(int A[],int p,int r){
  int x,i,j,temp;
  
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  
  return i+1;
  
}

int main(){
  int m,A[N];
  int i,x;
  
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&A[i]);
  }
  x=partition(A, 0, m-1);
  
  for(i=0;i<m;i++){
    if(i==x) printf("[%d]",A[x]);
    else printf("%d",A[i]);
    if(i<m-1) printf(" ");
  }
  
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[52];
    int sum=0,temp;
    int a,k;
    cin>>a>>k;
    for(int i=0;i<a;i++){
        cin>>arr[i];
    }
    for (int i=0;i<a;i++)
    {
        for (int j=i+1;j<a;j++)
        {
            if (arr[i]<arr[j])
            {

                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
    for (int i=0;i<k;i++)
    {
        sum+=arr[i];
    }
    cout << sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[] a = new int[n];
		Arrays.setAll(a, i -> sc.nextInt() - 1);
		sc.close();
		
		int cnt = 0;
		int button = 0;
		boolean[] pushed = new boolean[n];
		pushed[0] = true;
		
		while (true) {
			button = a[button];
			cnt++;
			
			if (pushed[button]) {
				System.out.println(-1);
				return;
			}
			
			if (button == 1) break;
			
			pushed[button] = true;
		}
		System.out.println(cnt);
	}
}




Measured memory_bytes: 51152
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<tuple>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	ll n,a,b;
	cin >> n >> a >> b;
	if(n==1){
		cout << (a==b?1:0) << "\n";
	}else{
		if(a>b){
			puts("0");
		}
		else{
			cout << (b-a)*(n-2)+1 << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	vi C(3);
	REP(i, 3)C[i] = IN();
	sort(ALL(C));
	YesNo(C[0] + C[1] == C[2]);
	return 0;
}

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

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

using namespace std;

int main(){
	int n; cin>>n;
	int hist[26];
	rep(c,26) hist[c]=100;
	rep(i,n){
		string s; cin>>s;
		int tmp[26]={};
		for(char c:s) tmp[c-'a']++;
		rep(c,26) hist[c]=min(hist[c],tmp[c]);
	}

	rep(c,26) cout<<string(hist[c],'a'+c);
	cout<<'\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, k;
        in >> n >> k;
        ll ans = k;
        for (int i = 1; i < n; i++) {
            ans *= k - 1;
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 N, K;
  cin >> N >> K;

  i64 cnt = (N - 1) * (N - 2) / 2 - K;
  if(cnt < 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<i64, i64>> vec;
  for(int i = 2;i <= N;i++) {
    vec.push_back({1, i});
  }
  for(int i = 2;i <= N && cnt > 0;i++) {
    for(int j = i + 1;j <= N && cnt > 0;j++) {
      vec.push_back({i, j});
      cnt--;
    }
  }
  cout << vec.size() << endl;
  for(auto p: vec) {
    cout << p.first << " " << p.second << endl;
  }
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

bool cmp(const string& s, const string& t, int a) {
	for (int i = 0; i < (int)s.length(); i++) {
		if (s[i] != t[a+i]) return false;
	}
	return true;
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	string s, t;
	cin >> s >> t;
	t = t + t;
	for (int i = 0; i < (int)s.length(); i++) {
		if (cmp(s, t, i)) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int division(int N) {
    int n = 0;
    for (int j = 1; j <= N; j++) {
        if(j%2 == 0) continue;
        int count = 0;
        for (int i = 1; i <= j; i++)
            if (j%i == 0)
                count++;
        if (count == 8)
            n++;
    }
    return n;
}

int main() {
    int N;
    cin >> N;
    cout << division(N) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const ll mod = 1e9 + 7;


int main(){

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

  int sum=0;
  for(int i=1;i<=a*b;i++){
    if(i%b==c&&i%a==0){
      out("YES");
      return 0;
    }
  }
  out("NO");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int k, n, maxN = 0;
    cin >> k >> n;
    vector<int> vect(n);
    for(int i = 0; i < n; i++){
        cin >> vect[i];
    }
    vect.push_back(vect[0]+k);
    for (int i = 0; i < n; ++i) {
        maxN = max(maxN, vect[i+1] - vect[i]);
    }
    int res = k - maxN;
    cout << res << endl;
    return 0;
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

const int mod = 1e9 + 7;

template< class T >
struct ConvexHullTrickAddQueryMonotone {
  deque< pair< T, T > > L;
  int isdec;

  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}

  inline T getX(const pair< T, T > &a, const T &x) {
    return (a.first * x + a.second);
  }

  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c) {
    return ((b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first));
  }

  inline bool empty() { return (L.empty()); }

  void add(T a, T b) {
    pair< T, T > line(a, b);

    if(isdec == -1 && !L.empty()) {
      if(a < L[0].first) isdec = 1;
      else if(a > L[0].first) isdec = 0;
    }

    if(isdec == 1) {
      if(!L.empty() && L.back().first == a) {
        line.second = min(line.second, L.back().second);
        L.pop_back();
      }
      while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
      L.emplace_back(line);
    } else {
      if(!L.empty() && L.front().first == a) {
        line.second = min(line.second, L.front().second);
        L.pop_front();
      }
      while(L.size() >= 2 && check(line, L[0], L[1])) L.pop_front();
      L.emplace_front(line);
    }
  }

  T getMinimumQuery(T x) {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }

  T getMinimumQueryMonotone(T x) {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }
};


int main() {
  int N;
  int64 C;
  int64 H[200000];

  cin >> N >> C;
  for(int i = 0; i < N; i++) cin >> H[i];
  ConvexHullTrickAddQueryMonotone< int64 > conv;
  conv.add(-2 * H[0], H[0] * H[0]);
  for(int i = 1; i < N; i++) {
    int64 uku = conv.getMinimumQueryMonotone(H[i]) + H[i] * H[i] + C;
    if(i + 1 == N) {
      cout << uku << endl;
    }
    conv.add(-2 * H[i], uku + H[i] * H[i]);
  }
}


Measured memory_bytes: 3968
using System;

namespace ABC168B
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b;
            string s = Console.ReadLine();
            b= s.Length;
            if (a < b)
            {
                for (int i = 0; i < a; i++)
                {
                    Console.Write(s.Substring(i, 1));
                }   Console.Write("...");
            }

            else
                Console.Write(s);
         
        }
    }
}


Measured memory_bytes: 17612
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((s (read-line))
         (data (make-array 26 :element-type 'uint32 :initial-element 0)))
    (map () (lambda (c) (incf (aref data (- (char-code c) 97)))) s)
    (println (- (+ 1 (floor (* (length s) (- (length s) 1)) 2))
                (reduce #'+ data
                        :key (lambda (x)
                               (declare (uint31 x))
                               (floor (* x (- x 1)) 2)))))))

#-swank(main)


Measured memory_bytes: 20452
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
const ld pi = 3.14159265358979323846;
//ll MOD = 1e9 + 7;
ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll x,y;
    cin>>x>>y;
    ll t = y - 2*x;
    ll c = 4*x - y;
    if(t%2 == 0 && c%2 == 0 && t>=0 && c>=0){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    
}





int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";


}


Measured memory_bytes: 3780
fn main(){
    let _raw = input();
    let words: Vec<_> = _raw.split(' ').collect();
    let mut num = [0; 2];
    num[0] = words[0].parse().unwrap();
    num[1] = words[1].parse().unwrap();
    
    println!("{}", (num[0] * num[1]))
}

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

Measured memory_bytes: 2080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<ll> A(N);
    for(auto& in:A) cin >> in;

    ll Low = 1;
    res += A[0] -1;
    for(int i = 1; i < N; i++){
        if(Low+1==A[i]){
            Low++;
            continue;
        }

        ll P = Low+1;

        ll get_cnt = (A[i] + P - 1)/P - 1;
        A[i] -= P*get_cnt;

       //  cout << i << " : " << Low << " " << P << " " << A[i] << endl;
        res += get_cnt;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	priority_queue<int>q;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		q.push(a);
	}
	int ans=0;
	while(q.size()>1){
		int a1=q.top(); q.pop();
		int a2=q.top();
		if(a1==a2){
			if(ans){
				cout<<1L*ans*a1<<"\n"s;
				return 0;
			}
			else ans=a1;
			q.pop();
		}
	}
	cout<<"0\n"s;
}


Measured memory_bytes: 3808
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var x = nextstr();
  var bc = 1;
  for(var i = 0; i < n; i++)if(x[i] === "1")bc++;
  var ans = xArray(0,n);
  var m1 = 0;
  for(var i = 0; i < n; i++){
    m1 *= 2;
    m1 += +x[i];
    m1 %= bc;
  }
  var c = 1;
  for(var i = n; i--;){
    if(x[i] === "0"){
      ans[i] = 1;
      var t = m1+c;
      t %= bc;
      while(t){
        t %= bitcount(t);
        ans[i]++;
      }
    }
    c = c*2%bc;
  }
  bc -= 2;
  if(bc < 1)return ans.join("\n");
  m1 = 0;
  for(var i = 0; i < n; i++){
    m1 *= 2;
    m1 += +x[i];
    m1 %= bc;
  }
  c = bc-1;
  for(var i = n; i--;){
    if(x[i] === "1"){
      ans[i] = 1;
      var t = m1+c;
      t %= bc;
      while(t){
        t %= bitcount(t);
        ans[i]++;
      }
    }
    c = c*2%bc;
  }
  return ans.join("\n");
}

function bitcount(bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

Measured memory_bytes: 42480
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;

int main(){
    //std::stack<int> stack;
    int n,m;
    cin >> n >> m;
    
    
    cout << n*m << endl;
     return 0;
}





Measured memory_bytes: 3632
n = gets.chomp!.to_i
h = {
  'AC' => 0,
  'WA' => 0,
  'TLE' => 0,
  'RE' => 0,
}
n.times do
  h[gets.chomp!] += 1
end
h.each do |k, v|
  puts "#{k} x #{v}"
end

Measured memory_bytes: 14372
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define INF (INT_MAX >> 1)

using namespace std;

int main() {
    int N;
    cin >> N;

    map<int, int> s;

    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        if (s.count(a) == 0)
            s[a] = 1;
        else
            s.erase(a);
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 4864
def main():
    n = int(input())
    info = [[int(x) for x in input().split()] for _ in range(n - 1)]
    answer = [0 for _ in range(n)]
    for i in range(n - 2, -1, -1):
        now = info[i][1]
        for j in range(i, n - 1):
            if j > i and now % info[j][2]:
                now += info[j][2] - now % info[j][2]
            now = max(now, info[j][1])
            now += info[j][0]
        answer[i] = now
    print("\n".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

ll MOD = 1000000007;
ll lcm(ll a, ll b) { return (a / __gcd(a, b) * b); }

bool check(int d, const vector<bool>& available) {
  string s = to_string(d);
  rep(i, s.size()) {
    if (!available[s[i] - '0']) {
      return false;
    }
  }
  return true;
}

int main() {
  //
  int n, k;
  cin >> n >> k;
  vector<bool> available(10, true);
  rep(i, k) {
    int d;
    cin >> d;
    available[d] = false;
  }
  REP(x, n, 10 * n + 1) {
    if (check(x, available)) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i=0;i<26;i++) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    for (int i=0;i<D;i++){
        for (int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    //初期t[i]の決定
    for (int i=0;i<D;i++) {
        t[i] = i % 26;
    }

    ll oldsum = 0;
    vector<int> ans = t;
    for (int m=0;m<1000;m++){
        //ここでt[i]を更新していく
        int dd = rand()%365;
        int qq = rand()%26;
        int oldval = t[dd];
        t[dd] = qq;
        //=======================
        ll sum = 0;
        vector<int> last(26);
        for (ll i=0;i<D;i++){
            sum += s[i][t[i]];
            last[t[i]] = i+1;
            for (int j=0;j<26;j++){
                sum -= 1LL*c[j]*(i+1-last[j]);
            }
        }
        if (sum > oldsum) {
            oldsum = sum;
            ans[dd] = qq;
        } else {
            t[dd] = oldval;
        }
    }
    for (int i=0;i<D;i++){
        cout << ans[i]+1 << "\n";
    }
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int dp[505][505][10][3][2];
int m;
int M = 10000;

int solve(string s){
	int n = s.size();
	rep(i,n+1) rep(j,m) rep(k,10) rep(l,3) rep(o,2) dp[i][j][k][l][o] = 0;
	dp[0][0][0][1][0] = 1;
	rep(i,n){
		int c = s[i] - '0';
		rep(j,m){
			rep(k,10){
				rep(l,10){
					if(k+l == 0) dp[i+1][j][0][1][0] += dp[i][j][0][1][0];
					else if(l == 0){
						if(i == 0){
							if(k <= c) dp[i+1][(j*10+k)%m][k][1][(k<c)] += dp[i][j][0][1][0];
						}else{
							dp[i+1][(j*10+k)%m][k][1][1] += dp[i][j][0][1][0];
						}
					}else{
						if(k==l) continue;
						if(k<c) rep(o,2) dp[i+1][(j*10+k)%m][k][(k<l)*2][1] += dp[i][j][l][1][o];
						else if(k==c) rep(o,2) dp[i+1][(j*10+k)%m][k][(k<l)*2][o] += dp[i][j][l][1][o];
						else dp[i+1][(j*10+k)%m][k][(k<l)*2][1] += dp[i][j][l][1][1];
					}
					if(k == l) continue;
					if(k<c) rep(o,2) dp[i+1][(j*10+k)%m][k][(k<l)*2][1] += dp[i][j][l][(k>l)*2][o];
					else if(k==c) rep(o,2) dp[i+1][(j*10+k)%m][k][(k<l)*2][o] += dp[i][j][l][(k>l)*2][o];
					else dp[i+1][(j*10+k)%m][k][(k<l)*2][1] += dp[i][j][l][(k>l)*2][1];
					rep(o,3) rep(p,2) dp[i+1][(j*10+k)%m][k][o][p] %= M;
				}
			}
		}
	}
	ll ans = 0;
	rep(i,10) rep(j,3) rep(k,2){
		ans += dp[n][0][i][j][k];
		ans %= M;
	}
	ans = (ans - 1 + M) % M;
	return ans;
}

int main(){
	string a,b; cin >> a >> b;
	cin >> m;
	if(a.back() != '0') a.back()--;
	else{
		for(ll i=a.size()-1; i>=0; i--){
			if(a[i] != '0'){
				a[i]--;
				break;
			}
			a[i] = '9';
		}
		if(a[0] == '0') a.erase(a.begin());
	}
	cout << (solve(b) - solve(a) + M) % M << "\n";
}


Measured memory_bytes: 62420
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,h=0,w=0;
	char d;
	while(cin>>a>>d>>b>>d>>c){
		if(a==b)
			h++;
		if(a*a+b*b==c*c)
			w++;
	}
	cout<<w<<endl;
	cout<<h<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    double a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    set<double> s1,s2;
    rep(i,f+1){
        rep(j,f+1){
            double now = 100.0*i*a+100.0*j*b;
            if(now <= f){
                s1.insert(now);
            }
        }
    }
    rep(i,f+1){
        rep(j,f+1){
            double now = c*i + d*j ;
            if(now <= f){
                s2.insert(now);
            }
        }
    }
    double ans = 0;
    int ans1 = 0,ans2 = 0;
    for(auto u : s1){
        for(auto v : s2){
            if(v/(u+v) <= e/(100+e)){
                if(ans<=v/(u+v) && u+v<=f){
                    ans1 = u;
                    ans2 = v;
                    ans = v/(u+v);
                }
            }
        }
    }
    cout<<ans1+ans2<<" "<<ans2<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main() {
    int n, x;
    cin >> n >> x;
    int l[110];
    int d[110];
    for(int i = 0; i < n; i++) cin >> l[i];
    int count = 0;
    for(int i = 0; i < n+1; i++){
        if(i == 0) d[i] = 0;
        else d[i] = d[i-1] + l[i-1];
    }

    for(int i = 0; i < n+1; i++){
        if(d[i] <= x) count++;
    }
    cout << count << endl;
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    string str;
    for (int i = 1; i <= n; ++i) {
        str = to_string(i);
        if (str.length() % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
v_list = input().split()
c_list = input().split()
sum = 0
for i in range(0,n):
    v = int(v_list[i])
    c = int(c_list[i])
    if v - c > 0:
        sum += v - c
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
    Phuong_;
    ll a,b,k;
    cin >> a >> b >> k;
    ll t=a;
    a=max(a-k,0LL);
    if (a==0)
    {
        k-=t;
        b=max(b-k,0LL);
    }
    cout << a << ' ' << b;
    return 0;
}



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

int main(void) {
    int N,A,B;
    cin>>N>>A>>B;
    string S;
    cin>>S;
    int yosen = 0;
    int yosen_oversea = 0;
    for (int i = 0; i < N; i++) {
        char c = S[i];
        if (c == 'a') {
            if (yosen < A + B) {
                cout << "Yes" << endl;
                yosen++;
            } else {
                cout << "No" << endl;
            }
        } else if (c == 'b') {
            yosen_oversea++;
            if (yosen < A + B && yosen_oversea <= B) {
                cout << "Yes" << endl;
                yosen++;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

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

using namespace std;

#define LENGTH 200000

int main(){
    int N;
    cin >> N;

    vector<string> words;
    rep(i,N){
        string tmp;
        cin >> tmp;
        words.push_back(tmp);
    }

    sort(words.begin(),words.end());
    words.erase(unique(words.begin(),words.end()),words.end());

    cout<<words.size();
}

Measured memory_bytes: 11664
#include <bits/stdc++.h>
const int maxn=1e5+10,mod=998244353;
typedef long long ll;
using namespace std;
int n,m,k,t;
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    ll a,b;
    ll n;
    scanf("%lld%lld%lld",&n,&a,&b);
    if((b-a)%2==0)printf("%lld\n",(b-a)/2);
    else
    {
        ll ret1=(a+b)/2;
        a=n-a+1,b=n-b+1;
        printf("%lld\n",min(ret1,(a+b)/2));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, m, k, a, cnt[40];

int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		for(cin >> k; k > 0; k--)
		{
			cin >> a;
			cnt[a]++;
		}
	}

	int ans = 0;
	for(int i = 1; i <= m; i++)
		ans += (cnt[i] == n ? 1 : 0);

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,T = map(int,readline().split())
m = map(int,read().split())
AB = sorted(zip(m,m))

can_add = [0] * N
for n in range(N-1,0,-1):
    x = can_add[n]
    y = AB[n][1]
    can_add[n-1] = x if x > y else y

dp = np.zeros(T,np.int64)

answer = 0
for i,(a,b) in enumerate(AB):
    np.maximum(dp[a:], dp[:-a].copy() + b, out = dp[a:])
    x = dp.max() + can_add[i]
    if answer < x:
        answer = x

print(answer)

Measured memory_bytes: 14432
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    int h,w,ans=0;
    char s[2010][2010];
    int U[2010][2010],D[2010][2010],R[2010][2010],L[2010][2010];
    cin>>h>>w;
    rep(i,h)rep(j,w){
        cin>>s[i][j];
    }
    rep(i,h){
        int cur=0;
        rep(j,w){
            if(s[i][j]=='#') cur=0;
            else cur++;
            L[i][j]=cur;
        }
    }
    rep(i,h){
        int cur=0;
        repr(j,w){
            if(s[i][j]=='#') cur=0;
            else cur++;
            R[i][j]=cur;
        }
    }
    rep(i,w){
        int cur=0;
        rep(j,h){
            if(s[j][i]=='#') cur=0;
            else cur++;
            U[j][i]=cur;
        }
    }
    rep(i,w){
        int cur=0;
        repr(j,h){
            if(s[j][i]=='#') cur=0;
            else cur++;
            D[j][i]=cur;
        }
    }
    rep(i,h)rep(j,w){
        if(s[i][j]!='#'){
            int a=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
            ans =max(ans,a);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 67200
import java.io.*;
import java.util.*;
import java.util.Map.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int c = sc.nextInt();

		int[][] d = new int[c][c];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < c; j++) {
				d[i][j] = sc.nextInt();
			}
		}
		int[][] cc = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cc[i][j] = sc.nextInt() - 1;
			}
		}

		List<Map<Integer, Integer>> clist = new ArrayList<>(3);
		for (int i = 0; i < 3; i++) {
			clist.add(new HashMap<>());
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				Map<Integer, Integer> hmtmp = clist.get((i + j) % 3);
				if (hmtmp.containsKey(cc[i][j])) {
					hmtmp.put(cc[i][j], hmtmp.get(cc[i][j]) + 1);
				} else {
					hmtmp.put(cc[i][j], 1);
				}
			}
		}

		long min = Integer.MAX_VALUE;
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < c; j++) {
				if (i == j) {
					continue;
				}
				for (int k = 0; k < c; k++) {
					if (k == i || k == j) {
						continue;
					}

					int tmp = 0;
					for (Entry<Integer, Integer> e : clist.get(0).entrySet()) {
						tmp += d[e.getKey()][i] * e.getValue();
					}
					for (Entry<Integer, Integer> e : clist.get(1).entrySet()) {
						tmp += d[e.getKey()][j] * e.getValue();
					}
					for (Entry<Integer, Integer> e : clist.get(2).entrySet()) {
						tmp += d[e.getKey()][k] * e.getValue();
					}

					min = Math.min(min, tmp);
				}
			}
		}

		pr.println(min);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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


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

  int r;
  cin >> r;
  cout << r*r << endl;
  
  return 0;
    

}


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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;


int main() {
    long long n;
    cin >> n;
    long long ans = INF;
    for (int x = 1; 1ll * x * x <= n; x++) {
        if (!(n % x)) {
            ans = min(ans, x + n / x - 2);
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace _1_3_B {
    class Program {
        static void Main(string[] args) {
            var list = new List<int>();
            while (true) {
                var num = int.Parse(Console.ReadLine());
                if (num == 0)
                    break;
                list.Add(num);
            }

            int i = 1;
            foreach (var x in list) {
                Console.WriteLine($"Case {i}: {x}");
                i++;
            }
        }
    }
}



Measured memory_bytes: 15912
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

inline int ctoi(const char c)
{
	return c >= '0'&&c <= '9' ? c - '0' : -1;
}

int main()
{
	string s, t;

	cin >> s;
	cin >> t;

	if (s == t) {
		cout << "Yes" << endl;
		return 0;
	}

	int i;
	for (i = 1; i < s.size(); i++) {
		if (s.substr(s.size() - i) + s.substr(0, s.size() - i) == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL A, B, C, D;
    cin >> A >> B >> C >> D;
    LL lc = LCM(C, D);
    LL bres = B - (B / C + B / D - B / lc);
    --A;
    LL ares = A - (A / C + A / D - A / lc);
    cout << bres - ares << endl;

    return 0;
}



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

import sys
sjobs = sorted(jobs, key=lambda x:x[1])

now = 0
for delta, limit in sjobs:
    now += delta
    if now > limit:
        print("No")
        sys.exit()
print("Yes")

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

const int N = (1e5) + 5;
char s[N];
int ans[N];
int cnt_L[N], cnt_R[N];

// claudio van
int main() {
  scanf("%s", s);
  int n = strlen(s);
  if (s[n - 1] == 'R') {
    cnt_R[n - 1] = 1;
  }
  for (int i = n - 2; i >= 0; --i) {
    cnt_R[i] = (s[i] == 'R'? cnt_R[i + 1] + 1 : 0);
  }
  if (s[0] == 'L') {
    cnt_L[0] = 1;
  }
  for (int i = 1; i < n; ++i) {
    cnt_L[i] = (s[i] == 'L'? cnt_L[i - 1] + 1 : 0);
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      if ((cnt_R[i] + 1) % 2 == 0) {
        ans[i + cnt_R[i] - 1]++;
      } else {
        ans[i + cnt_R[i]]++;
      }
    } else {
      if ((cnt_L[i] + 1) % 2 == 0) {
        ans[i - cnt_L[i] + 1]++;
      } else {
        ans[i - cnt_L[i]]++;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i != 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1664