akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;


const int MAXN = 10000001;

ll FAC2[MAXN] = {0};
ll FAC[MAXN] = {0};
ll IFAC[MAXN] = {0};

ll upp(ll i, ll j){
    if(j == 0)return 1;
    ll h = upp(i,j/2);
    if(j%2 == 0)return (h*h)%big;
    return (i*((h*h)%big))%big;
}

ll DP[5002][5002] = {0};

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n >> m;

    ll nf = 1;
    ll nf2 = 1;

    rep(c1,0,n){
        FAC2[c1] = nf2;
        nf2 *= ll(n-c1);
        nf2 %= big;
        FAC[c1] = nf;
        nf *= ll(c1+1);
        nf %= big;
    }

    rep(c1,0,m+1){
        IFAC[c1] = upp(FAC[c1], big-2);
    }

    ll no_self = 0;
    ll t = 1;
    for(ll s = 0; s <= m; s++){
        ll bin = (((FAC[m]*IFAC[s])%big)*IFAC[m-s])%big;
        no_self += t * (bin*(((m-s) * FAC[n-s-1])%big))%big;
        if(no_self < 0)no_self += big;
        if(no_self >= big)no_self -= big;

        t *= -1;
    }

    ll ans = no_self;


    ll self_cyc = 0;


    for(ll M = m; M >= 0; M--){
        for(ll x = 0; x <= m; x++){
            if(n-M-x-2 < 0){
                DP[M][x] = 0;
                continue;
            }
            if(x == 0){
                DP[M][x] = FAC[n-M-2];
                continue;
            }
            if(M == m){
                DP[M][x] = 0;
                for(ll b = 0; b <= x; b++){
                    DP[M][x] += IFAC[x-b]*((FAC[n-M-b-2] * FAC[x])%big);
                    DP[M][x] %= big;
                }
                continue;
            }
            DP[M][x] = x*DP[M+1][x-1] + FAC[n-M-2];// + FAC[n-M-2-x] * FAC[x];
            DP[M][x] %= big;
        }
    }

    for(ll x = 2; x <= m; x++){

        ll t = 1;
        for(ll s = 0; s < x-1; s++){
            ll ts = big+t;
            ts *= (x-1-s);
            ts %= big;
            ts *= FAC[x-1];
            ts %= big;
            ts *= IFAC[s];
            ts %= big;
            ts *= IFAC[x-1-s];
            ts %= big;

            ans += ts*DP[s][m-x];
            ans %= big;

            t *= -1;
        }

    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 355388
#include<bits/stdc++.h>
using namespace std;
#define in(a, n) for(int i=0;i<n;i++)
#define oo 1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
int a[100009],b[100009],c[100009];
int n,k;
// 1 = swim // 2 = catch // 3 = HW
int dp[100009][4];
int solve(int j, int pr)
{
    if(j==n)
        return 0;
    if(dp[j][pr]!=-1 ) return dp[j][pr];
    int p=0,p1=0,p2=0;
    if(pr!=1)
        p=a[j]+solve(j+1,1);
    if(pr!=2)
        p1=b[j]+solve(j+1,2);
    if(pr!=3)
        p2=c[j]+solve(j+1,3);
    return dp[j][pr]=max({p1,p,p2});


}
void flush(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
int main()
{
    flush();
    cin>>n;
    setdp;
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    cout<<solve(0,0);
}


Measured memory_bytes: 12612
n = gets.to_i
v = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
res = Array.new(n,0)
n.times{|i| res[i] = v[i]-c[i]}
ans = 0
n.times{|i| ans += res[i] if res[i] > 0}
puts ans


Measured memory_bytes: 1788
coin = [500,100,50]
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i_500 in range(a+1):
    for i_100 in range(b+1):
        for i_50 in range(c+1):
            if x==i_500*500+i_100*100+i_50*50:
                ans += 1
print(ans)


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

S = input().rstrip()
N = len(S)
mod = 10**9+7

# dp[i][0] -> A
# dp[i][1] -> AB
# dp[i][2] -> ABC
dp = [0, 0, 0]
k = 1
for i in range(N):
    if S[i] == "A":
        dp[0] += k
    elif S[i] == "B":
        dp[1] += dp[0]
    elif S[i] == "C":
        dp[2] += dp[1]
    else:
        dp[2] = 3*dp[2] + dp[1]
        dp[1] = 3*dp[1] + dp[0]
        dp[0] = 3*dp[0] + k
        k = k*3%mod
    
    dp[0] %= mod
    dp[1] %= mod
    dp[2] %= mod

print(dp[2])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int N,T; cin >> N >> T;
  int cost = 2000;
  rep(i,N) {
    int c,t; cin >> c >> t;
    if(t <= T) cost = min(cost, c);
  }
  if(cost==2000) puts("TLE");
  else cout << cost << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// input
	var w, h, n int
	fmt.Scan(&w, &h, &n)
	x := make([]int, n)
	y := make([]int, n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i], &y[i], &a[i])
	}

	// set x,y max&min
	var xmin int = 0
	var xmax int = w
	var ymin int = 0
	var ymax int = h
	for i := 0; i < n; i++ {
		switch a[i] {
		case 1:
			if xmin < x[i] {
				xmin = x[i]
			}
		case 2:
			if x[i] < xmax {
				xmax = x[i]
			}
		case 3:
			if ymin < y[i] {
				ymin = y[i]
			}
		case 4:
			if y[i] < ymax {
				ymax = y[i]
			}
		}
	}

	// calculate area
	if xmax <= xmin || ymax <= ymin {
		fmt.Println(0)
	} else {
		fmt.Println((xmax - xmin) * (ymax - ymin))
	}
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

void dfs(vector<vector<int>> &tree,vector<int> &res, vector<int> &vis,int fir,int depth)
{
//    printf("%d %d\n",fir,depth);
    res[fir]=depth;
    forn(i,(int)tree[fir].size())
    {
//        printf("%d\n",tree[fir][i]);
        if(vis[tree[fir][i]]==0)
        {
           vis[tree[fir][i]]=1;
           dfs(tree,res,vis,tree[fir][i],depth+1);
        }
    }
}

int main()
{
    int n,v,u;
    scanf("%d%d%d",&n,&u,&v);
    u--;
    v--;
    vector<vector<int>> tree(n);
    forn(i,n-1)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        tree[x-1].pb(y-1);
        tree[y-1].pb(x-1);
    }
    vector<int>fir(n),sec(n);
    vector<int>vis(n);
    vis[v]=1;
    dfs(tree,fir,vis,v,0);
    forn(i,n)vis[i]=0;
    vis[u]=1;
    dfs(tree,sec,vis,u,0);
    forn(i,n)vis[i]=0;
    int maxx=0;
    forn(i,n)
    {
        if(fir[i]>sec[i])maxx=max(maxx,fir[i]-1);
    }
    printf("%d\n",maxx);
    return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int n,a[N],sum;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
	if(sum%10){
		cout<<sum;
		return 0;
	}
	sort(a+1,a+n+1);
	int i=1;
	while(!(a[i]%10)&&i<=n) i++;
	sum-=a[i];
	if(i==n+1) sum=0;
	cout<<sum;
}

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

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


ll gcd(ll a, ll b) {
  if (b > a) {
    swap(a, b);
  }
  ll r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

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



signed main() {
  int n;
  cin >> n;
  vi a(n);
  rep (i, n) cin >> a[i];

  int now = 1;
  int ans = 0;
  rep (i, n) {
    if (a[i] == now) now++;
    else ans++;
  }
  if (ans == n) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i,a,n) for(ll i = a;i < n; i++)
#define REP(i,n) for(ll i = 0;i < n; i++)
const ll INF= 1LL << 60;
struct song{
    string s;
    int t;
};
int main(){
    int n;
    string x;
    cin >> n;
    vector<song> A(n);
    REP(i,n) cin >> A[i].s >> A[i].t;
    cin >> x;
    int cnt= 0;
    int flag= 0;
    REP(i,n){
        if(flag) cnt+= A[i].t;
        if(A[i].s==x) flag= 1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, R = map(int, input().split())

if N >= 10 :
  print (R)
else :
  print (R+(100*(10-N)))





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

int main()
{
	long long q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	printf("%lld",(n%2==0)?(min(min(min(q*8,h*4),s*2),d)*n/2):(min(min(q*4,h*2),s)+min(min(min(q*8,h*4),s*2),d)*(n-1)/2));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    string w, x;
    int n, i=0, count=0, judge=1;

    cin >> w;

    sort(w.begin(), w.end());

    n = w.size();

    while(i<n){
        count = 0;

        x = w[i];
        
        while(w[i] == x[0]){
            i++;
            count++;
        }

        if(count % 2 != 0){
            judge = 0;
        }
    }

    if(judge==1){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
from heapq import heappop as hpp, heappush as hp
h = []
for num in a:
    hp(h, -num)
for _ in range(m):
    val = hpp(h)
    val *= -1
    hp(h, -(val//2))
ans = -sum(h)
print(ans)

Measured memory_bytes: 91436
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, m, x;
  cin >> n >> m >> x;
  ll c[n], a[n][m];
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  
  ll ans=INF;
  rep(i, 1LL<<n) {
    ll money=0;
    vl skill(m, 0);
    rep(j, n) if(i & 1LL<<j) {
      money += c[j];
      rep(k, m) skill[k] += a[j][k];
    }
    ll min_skill=x;
    rep(j, m) chmin(min_skill, skill[j]);
    if(min_skill==x) chmin(ans, money);
  }
  if(ans<INF) cout << ans << newl;
  else cout << -1 << newl;
  return 0;
}

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

string s;
int K;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> s >> K;
    REP(i, s.size()) {
        char& c = s[i];
        if (c == 'a') continue;

        if ('z' - c + 1 <= K) {
            K -= ('z' - c + 1);
            c = 'a';
        }
        if (K == 0) break;
    }
    char& c = s[s.size() - 1];
    c += (K % 26);
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	double a[8];
	while(cin >> a[0]){
		for(int i=1;i<8;i++) cin >> a[i];
		bool b = true;
		if(a[0]>a[6]) b = false;
		if(a[1]>a[7]) b = false;
		if(a[4]>a[2]) b = false;
		if(a[5]>a[3]) b = false;
		if(b) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long

const ll mod=1e9+7;

int main()
{
    int n;
    sfi(n)

    ll arr[n+1];
    f(i,1,n+1)
    	sfl(arr[i])

    ll dp[n+1][n+1];

    memset(dp,0,sizeof(dp));

    for(int i=n;i>0;i--)
    {
    	f(j,i,n+1)
    	{
    		if(i==j)
    			dp[i][j]=arr[i];
    		else
    		{
    			dp[i][j]=max((arr[i]-dp[i+1][j]),(arr[j]-dp[i][j-1]));
    		}
    	}
    }

    pfln(dp[1][n])

    return 0;
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<ll> cnt(60);
    int i,j;
    for(i=0; i<n; i++) {
        ll tmp;
        scanf("%lld", &tmp);
        for(j=0; j<60; j++) {
            if(tmp & ((ll)1<<j)) {
                cnt[j]++;
            }
        }
    }

    ll ans=0;
    for(i=0; i<60; i++) {
        ll tmp=cnt[i]*(n-cnt[i])%MOD;
        for(j=0; j<i; j++) {
            tmp=tmp*2%MOD;
        }
        ans=(ans+tmp)%MOD;
    }
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k = sc.nextInt();
        System.out.println(a[k - 1]);
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=0;
    rep(i,min(x,y)) ans+=min(a+b,2*c);
    if(x>=y)  rep(i,abs(x-y)) ans+=min(a,2*c);
    else rep(i,abs(x-y)) ans+=min(b,2*c);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void)
{
	int n,x;
	int i,j,k,a;

	while(1){
		a = 0;
		scanf("%d %d",&n,&x);
		if(n == 0 && x == 0)
		break;
		for (i = 1; i <= n;i++){
			for(j = i+1;j<=n;j++){
				for(k = j+1;k<=n;k++){
					if(i + j +k == x)
					a++;
				}
			}
		}
		printf("%d\n",a);
					
	}
	return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>

using namespace std;

int main(int argc, const char * argv[]){
    int n,x;
    scanf("%d",&n);

    for(int i = 1; i<= n; i++)
    {
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
        if(x%10 == 3){
            printf(" %d",i);
            break;
            }
            x /=10;
            }
            while(x);
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

string s;
int p[30][100005];

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>s;
	int n=s.size();
	p[s[0]-'a'][0]=1;
	for(int i=1;i<n;++i){
		p[s[i]-'a'][i]=1;
		for(int j=0;j<26;++j) p[j][i]+=p[j][i-1];
	}
	for(int i=0;i<n;++i) for(int j=0;j<26;++j) p[j][i]=2*p[j][i]-i;
	for(int i=0;i<26;++i){
		int tmp=1,pos=-1;
		if(p[i][0]<tmp) tmp=p[i][0],pos=0;
		for(int j=1;j<n;++j){
			if(p[i][j]>tmp&&pos+1<j){
				cout<<pos+2<<' '<<j+1;
				return 0;
			}
			if(p[i][j]<tmp){
				tmp=p[i][j];
				pos=j;
			}
		}
	}
	cout<<"-1 -1";
}

Measured memory_bytes: 10704
#include <bits/stdc++.h>
#define INT long long int
#define N 3
#define PA pair<INT, INT>
#define oo 9876543219876543
#define MOD 1000000007
using namespace std;
INT T, n, m, k, x, y, z, a[500050], b[500040], c[500050], ans, Z, Y, dt[1000010][2][2];
set<INT> u, d;
string s, t;

INT dp(int x, int y, int z)
{
    if( x == n ) return y and z;
    if( ~dt[x][y][z] ) return dt[x][y][z];
    INT &ret = dt[x][y][z] = 0;
    ret = (dp(x+1, 1, z) + dp(x+1, y, 1) + 8*dp(x+1, y, z))%MOD;
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    T = 1; //cin>>T;
    while( T-- )
    {
        memset(dt, -1, sizeof(dt));
        cin>>n;
        cout<<dp(0, 0, 0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 97224
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
8
insert 30
insert 88
insert 12
insert 1
insert 20
insert 17
insert 25
print

output: in_order + pre_order
1 12 17 20 25 30 88
30 12 1 20 17 25 88

"""

import sys


class Node(object):
    def __init__(self, data):
        self.data = data
        self.left, self.right = None, None

    def insert(self, data):
        """
        insert data according to BST rules
        """
        if data < self.data:
            if self.left is None:
                self.left = Node(data)
            else:
                self.left.insert(data)
        else:
            if self.right is None:
                self.right = Node(data)
            else:
                self.right.insert(data)

        return None

    def pre_order(self, node):
        if node is not None:
            print('', node.data, end='')
            self.pre_order(node.left)
            self.pre_order(node.right)
        return None

    def in_order(self, node):
        if node is not None:
            self.in_order(node.left)
            print('', node.data, end='')
            self.in_order(node.right)
        return None


def action(command, content):
    if command.startswith('in'):
        tree_root.insert(data=int(content))

    if command.startswith('pr'):
        tree_root.in_order(node=tree_root)
        print('')
        tree_root.pre_order(node=tree_root)
        print('')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    command_list = list(map(lambda x: x.split(), _input[1:]))
    # assert len(command_list) == array_length
    # print(array_length, *command_list)

    flag, tree_root = False, None
    for each in command_list:
        command, content = each[0], each[-1]
        if (not flag) and command.startswith('in'):
            tree_root = Node(data=int(content))
            flag = True
            continue
        action(command=command, content=content)

Measured memory_bytes: 288668
private const val MOD = 1e9.toLong() + 7

private class Comb {

    val n = 2000002

    val fact = LongArray(n + 1)
    val factInv = LongArray(n + 1)

    init {
        fact[0] = 1L
        for (i in 1..n) {
            fact[i] = fact[i - 1] * i % MOD
        }
        factInv[n] = inv(fact[n])
        for (i in n downTo 1) {
            factInv[i - 1] = factInv[i] * i % MOD
        }
    }

    private fun pow(base: Long, exp: Long): Long {
        if (exp == 0L) return 1L
        var a = pow(base, exp shr 1)
        a *= a
        a %= MOD
        if (exp and 1L == 0L) return a
        return base * a % MOD
    }

    private fun inv(x: Long): Long {
        return pow(x, MOD - 2)
    }

    fun comb(n: Int, k: Int): Long {
        if (k !in 0..n) return 0L
        return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD
    }

}

fun main(args: Array<String>) {
    val cb = Comb()

    val (r1, c1, r2, c2) = readLine()!!.split(' ').map { it.toInt() }

    var ans = 0L

    ans += cb.comb(r2 + c2 + 2, r2 + 1) - 1
    ans %= MOD

    ans += MOD
    ans -= cb.comb(r2 + c1 + 1, r2 + 1) - 1
    ans %= MOD

    ans += MOD
    ans -= cb.comb(r1 + c2 + 1, c2 + 1) - 1
    ans %= MOD

    ans += cb.comb(r1 + c1, r1) - 1
    ans %= MOD

    println(ans)
}


Measured memory_bytes: 71012
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<char> C(3);
  for(int i=0;i<3;i++){
    cin >> C.at(i);
  }
  if((C.at(0) == C.at(1))||(C.at(0) == C.at(2))||(C.at(2) == C.at(1))){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


int main() {
  int n;
  cin >> n;
  while(n--) {
    int s,g;
    cin >> s >> g;
    vector<int> v;
    if (s<g)
      for (int i=s;i<=g;i++)
        v.push_back(i);
    else if (s<6&&g<6) {
      for (int i=s;i>=g;i--)
        v.push_back(i);
    } else if (g<6&&s>=6) {
      for (int i=s;i<=9;i++) {
        v.push_back(i);
      }
      for (int i=5;i>=g;i--) {
        v.push_back(i);
      }
    } else if (s>=6&&g>=6) {
      for (int i=s;i<=9;i++) {
        v.push_back(i);
      }
      for (int i=5;i>=0;i--) {
        v.push_back(i);
      }
      for (int i=1;i<=g;i++)
        v.push_back(i);
    }
    REP(i,v.size()) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
import Control.Monad
import Data.List

solve :: [Bool] -> String
solve [_] = "No"
solve (a11:a12:a13:a21:a22:a23:a31:a32:a33:aa) | all (==True) [a11,a12,a13] = "Yes"
                                               | all (==True) [a21,a22,a23] = "Yes"
                                               | all (==True) [a31,a32,a33] = "Yes"
                                               | all (==True) [a11,a21,a31] = "Yes"
                                               | all (==True) [a12,a22,a32] = "Yes"
                                               | all (==True) [a13,a23,a33] = "Yes"
                                               | all (==True) [a11,a22,a33] = "Yes"
                                               | all (==True) [a13,a22,a31] = "Yes"
                                               | otherwise = "No"

main = do
    aij <- replicateM 3 (map read . words <$> getLine) :: IO [[Int]]
    n <- readLn :: IO Int
    bn <- map read <$> replicateM n getLine :: IO [Int]
    putStrLn $ solve $ map (\x -> elem x bn) $ concat aij


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N;
  cin >> N;
  cout << ((N+1)/2)/((double)N)  << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define rep(i,a,b) for(auto i=(a);i<=(b);++i)
#define per(i,a,b) for(auto i=(a);i>=(b);--i)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define root 1,cnum,1
#define Pr pair<int,int>
#define Prd pair<double,double>
#define Prl pair<LL,LL>
#define Prc pair<char,char>
#define fi first
#define se second
#define Abs(x) (x>0?x:x*-1)
#define lowbit(x) (x&(-x))
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF = 0x7FFFFFFF;
const LL LINF = 0x7FFFFFFFFFFFFF;
void guan() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

const int maxn = 1010101;
const int mod = 1e9+7;
const double eps = 1e-12;
int a[maxn];
int fa[maxn], fb[maxn];

int main() {
    guan();
    int T, Case = 0;
    int n;
    string s;
    while(cin >> n >> s) {
        mst(fa,0); mst(fb,0);
        int cnta = 0, cntb = 0;
        for(int i = 0;i < s.length();++i) {
            fa[s[i]]++;
            if(fa[s[i]]==1) cnta++;
        }
        int ans = 0, cnt = 0;
        for(int i = -1+s.length();i >= 0;--i) {
            fb[s[i]]++;
            fa[s[i]]--;
            if(fb[s[i]]==1&&fa[s[i]]) cnt++;
            else if(fb[s[i]]>=2&&fa[s[i]]==0) cnt--;
            ans = max(ans,cnt);
        }
        cout << ans << endl;
    } return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>

int main(){
	int n,m,l;	//最初に入力される変数
	
	scanf("%d %d %d",&n,&m,&l);	//最初の入力
	
	int A[n][m];		//行列Aの定義
	int B[m][l];		//行列Bの定義
	long int C[n][l];	//行列Cの定義
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			scanf("%d",&A[i][j]);//行列Aに要素を格納
		}
	}
	
	for(int i = 0;i < m;i++){
		for(int j = 0;j < l;j++){
			scanf("%d",&B[i][j]);//行列Bに要素を格納
		}
	}
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < l;j++){
			C[i][j] = 0;//行列cの初期化
		}
	}
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			for(int k = 0;k < l;k++){
				C[i][k] += (long)A[i][j] * (long)B[j][k];
			}
		}
	}
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < l;j++){
			printf("%ld",C[i][j]);//出力
			if(j != l - 1){
				printf(" ");
			}
		}
		printf("\n");//行毎に改行
	}
	
	return 0;
}



Measured memory_bytes: 2108
package main

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

func main() {
	A, B, K := ReadInt(), ReadInt(), ReadInt()
	for i := A; i < B+1; i++ {
		if i < A+K || B+1-K <= i {
			fmt.Println(i)
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1868
/**************** Geometrical Library ****************/

#include<cmath>
#include<vector>
#include<algorithm>

#define	EPS	1e-8

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(const Point &cc,double rr) : c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

double cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}

int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	for(Point a,b,c,p;~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&p.x,&p.y);){
		int cnt=0;
		cnt+=ccw(a,b,p);
		cnt+=ccw(b,c,p);
		cnt+=ccw(c,a,p);
		puts((cnt==3*CCW || cnt==3*CW)?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
N, M = map(int,input().split())

v = list(range(1,N+1))
edges = [[] for _ in range(N+1)]
for _ in range(M):
  a, b = map(int,input().split())
  edges[a] += [b]
  edges[b] += [a]

def dfs(v, e):
  for x in v:
    if(len(e[x]) == 1):
      t = e[x][0]
      e[x] = []
      e[t].remove(x)
      v.remove(x)
      return dfs(v, e)+1
  return 0

print(dfs(v, edges))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <numeric>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int inf = TEN(18) * 3;

int N;
int Sum[200010];

int evaluate(int l, int m, int r)
{
	return abs((Sum[r] - Sum[m]) - (Sum[m] - Sum[l]));
}

signed main()
{
	cin >> N;

	rep1(i, N) cin >> Sum[i];
	rep1(i, N) Sum[i] += Sum[i - 1];

	int ans = inf;

	int lmid = 1, rmid = 3;

	range(mid, 2, N - 2 + 1) {
		while (evaluate(0, lmid, mid) > evaluate(0, lmid + 1, mid)) lmid++;
		while (evaluate(mid, rmid, N) > evaluate(mid, rmid + 1, N)) rmid++;

		vi v({Sum[N] - Sum[rmid], Sum[rmid] - Sum[mid], Sum[mid] - Sum[lmid], Sum[lmid]});

		sort(all(v));

		chmin(ans, v[3] - v[0]);
	}

	cout << ans << endl;
}




Measured memory_bytes: 1792
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    tmd = collections.defaultdict(list)
    tmdc = collections.defaultdict(int)
    for i in range(n-1):
        tma, tmb, tmc = list(map(int, input().rstrip('\n').split()))
        tmd[tma-1] += [tmb-1]
        tmd[tmb-1] += [tma-1]
        tmdc[tma-1, tmb-1] = tmc
        tmdc[tmb-1, tma-1] = tmc

    ql = [[0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    ql.append([cost + tmdc[tmp, tmv], tmv])
                    fq[tmv] = (cost + tmdc[tmp, tmv]) % 2
        else:
            break
    for i in range(n):
        print(fq[i])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 115036
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int x = 0;
	for (int i = 0 ; i < s.length() ; i++) {
		if (s[i] == 'g') x++;
		else x--;
	} 
	cout << x / 2;
}

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

int main(){
    int x; cin>>x;
    if (x <= 599) printf("8");
    else if (x <= 799) printf("7");
    else if (x <= 999) printf("6");
    else if (x <= 1199) printf("5");
    else if (x <= 1399) printf("4");
    else if (x <= 1599) printf("3");
    else if (x <= 1799) printf("2");
    else printf("1");
}


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

int sum(int min,int max){
    return ((max+min)*(max-min+1))/2;
}

int main(){
    int N,L;
    cin>>N>>L;
    int result;
    if(L>0){
        result=sum(L+1,L+N-1);
    }
    else if((L<=0)&&(L+N-1>=0)){
        result=sum(L,L+N-1);
    }
    else{
        result=sum(L,L+N-2);
    }
    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef deque<ll> dqll;

vector<ll> cst;
vector<vector<P>> lst;

const ll mod = 1000000007;
ll fact[10200200];
ll invfact[10200200];

inline ll take_mod(ll a) { return (a % mod + mod) % mod; }

inline ll add(ll a, ll b) { return take_mod(a + b); }

inline ll sub(ll a, ll b) { return take_mod(a - b); }

inline ll mul(ll a, ll b) { return take_mod(a * b); }

inline ll pow(ll x, ll n) {
  ll res = 1LL;
  while (n > 0) {
    if (n & 1) res = mul(res, x);
    x = mul(x, x);
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x) { return pow(x, mod - 2); }

void make_fact(ll n) {
  fact[0] = 1;
  ll res = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = res;
    res = mul(res, i + 1);
  }
}

void make_invfact(ll n) {
  invfact[0] = 1;
  invfact[n] = mod_inv(fact[n]);
  for (int i = n - 1; i >= 1; i--) {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
}

ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); }

ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); }

int main() {
  ll X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  ll dai, sho;
  dai = max(X, Y);
  sho = min(X, Y);

  if(dai > 2*sho){
    cout << 0 << endl;
    return 0;
  }

  ll mNum = (dai + sho) / 3;

  ll kk = 1;
  for (ll i = 0; i <= mNum; i++) {
    if(i + 2*(mNum - i) == sho){
      kk = i;
      break;
    }
  } // i

  make_fact(10000000);
  make_invfact(10000000);

  ll ans = comb(mNum, kk);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 158080
from decimal import *
import re
def solve2(m, n):
    maxlen = 80
    PREC=200
    getcontext().prec = PREC
    x = Decimal(m) / Decimal(n)
    s = x.to_eng_string()
    if len(s) < PREC:
        return(s[2:],'')
    rep = 1
    while True:
        r = r'(.{%d})\1{%d,}' % (rep, int(maxlen/rep))  #ex. '(.{6})\\1{13,}'
        a=re.search(r, s)
        if a:
            break
        rep += 1
        if rep > maxlen:
            raise ValueError('This cannot happen.rep=%d' % rep)

    u = s[2:a.start()+len(a.group(1))]
    v = (' '*PREC + '^'*len(a.group(1)))[-len(u):]
    return(u,v)

while True:
    try:
        m,n = map(int, input().strip().split())
        s,t = solve2(m, n)
        print(s)
        if t!='':
            print(t)
    except EOFError:
        break

Measured memory_bytes: 10020
#include <stdio.h>
int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	
	h=S/3600;
	m=S/60-h*60;
	s=S-m*60-h*3600;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mpl;
mpl m;
vll v;
void Solve()
{
     ll sum=0,n,k;
     cin>>n>>k;
     rep(i,0,n)
     {
         ll a,b;
         cin>>a>>b;
         m[a]+=b;
     }
     rep(j,0,100001)
    {
         sum+=m[j];
         v.pb(sum);

     }
     cout<<lb(v,k)-v.begin()<<endl;

}
int main()
{
    Solve();
    return 0;
}

Measured memory_bytes: 7284
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    string S, T;
    cin >> S;
    cin >> T;
    int counter = 0;
    for (int i=0; i<S.length(); ++i){
        if(S[i] != T[i]){
            ++counter;
        }
    }

    cout << counter << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

template <class T>
class SegTree {
  int n;                       // 葉の数
  vector<T> data;              // データを格納するvector
  T def;                       // 初期値かつ単位元
  function<T(T, T)> operation; // 区間クエリで使う処理
  function<T(T, T)> update;    // 点更新で使う処理

  // 区間[a,b)の総和。ノードk=[l,r)に着目している。
  T _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return def; // 交差しない
    if (a <= l && r <= b)
      return data[k]; // a,l,r,bの順で完全に含まれる
    else {
      T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
      T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
      return operation(c1, c2);
    }
  }

 public:
  // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
  // _update:更新関数
  SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
    : def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n) {
      n *= 2;
    }
    data = vector<T>(2 * n - 1, def);
  }

  // 場所i(0-indexed)の値をxで更新
  void change(int i, T x) {
    i += n - 1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)の区間クエリを実行
  T query(int a, int b) {
    return _query(a, b, 0, 0, n);
  }

  // 添字でアクセス
  T operator[](int i) {
    return data[i + n - 1];
  }
};

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b) {
  // Eucledean algorithm
  while (a) {
    if (a < b) {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

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

  if (n == 2) {
    cout << max(a[0], a[1]) << endl;
  } else {
    ll def = gcd(a[0], a[1]);
    chmax(def, gcd(a[1], a[2]));
    chmax(def, gcd(a[0], a[2]));

    SegTree<ll> st(
      n, def, [](long long a, long long b) { return gcd(a, b); }, [](long long a, long long b) { return b; });

    rep(i, n) {
      st.change(i, a[i]);
    }

    ll ans = st.query(1, n);
    rep(i, n) {
      ll a = st.query(0, i);
      ll b = a;
      if (i != n - 1) {
        b = st.query(i + 1, n);
      }
      chmax(ans, gcd(a, b));
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	s+=s;
	int n=s.size();
	vector<bool> dp(n+10,false);
	dp[0]=true;
	rep(i,n){
		if(!dp[i]) continue;
		if(s.substr(i,5)=="dream") dp[i+5]=true;
		if(s.substr(i,7)=="dreamer") dp[i+7]=true;
		if(s.substr(i,5)=="erase") dp[i+5]=true;
		if(s.substr(i,6)=="eraser") dp[i+6]=true;
	}
	if(dp[n]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 620
import math

n = int(input())

ans = 0

for i in range(1, int(math.sqrt(n)) + 1):
            if n % i == 0:
                ans = i

if n/ans > ans:
    ans = int(n/ans)

digit =0
while ans >= 1:
    ans /= 10
    digit +=1

print(digit)


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

typedef long long ll;
typedef long double ld;

#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ALL(v)      v.begin(), v.end()
#define PB          push_back
#define MP          make_pair
#define UB          upper_bound
#define LB          lower_bound
#define PI          2*acos(0.0)
#define MOD         1000000007
#define GCD(a, b)   __gcd(a, b)
#define LCM(a, b)   ((a)*(b)) / GCD(a, b)
#define INPUT       freopen("input.txt", "r", stdin);
#define OUTPUT      freopen("output.txt", "w", stdout);
#define PRINT(a)    for(auto i : a) cout << i << " "; cout << endl;
#define PRINTS(s)   for(auto i=s.begin(); i!=s.end(); i++) cout << *i << " "; cout << endl;
#define PRINTM(m)   for(auto i=m.begin(); i!=m.end(); i++) cout << i->first << " " << i->second << endl;

int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
string lowerCase = "abcdefghijklmnopqrstuvwxyz";
string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/// Graph moves
const int fxKing[] = {+1,+1,+0,-1,-1,-1,+0,+1}; /// King's move
const int fyKing[] = {+0,+1,+1,+1,+0,-1,-1,-1}; /// King's move
const int fxKnight[] = {+2,+1,-1,-2,-2,-1,+1,+2}; /// Knight's move
const int fyKnight[] = {+1,+2,+2,+1,-1,-2,-2,-1}; /// Knight's move

ll q, t, a, b, c, d, m, n, k;
ll cnt, Mn, Mx, sum, sum1, sum2, ck;
ll arr1[1000], arr2[1000];

map <ll, ll> mp1, mp2;
set <ll> st1, st2;
vector <ll> vec1, vec2;
string str1, str2, str3;

int main()
{
    FIO;
    t = 1;
    while(t--)
    {
        cin >> n ;
        cout << n * n << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N; cin >> N;
  vector<ll> A(3*N); for(ll i = 0; i < 3*N; i++){ cin >> A[i];}
  
  vector<ll> sum_front(3*N,0);
  vector<ll> sum_back(3*N,0); //仕切りがkの時に、sum_front[k]とsum_back[k]をたす
  
  //まずは前半から求める  
  priority_queue<ll,vector<ll>, greater<ll>> Q; ll sum = 0LL;
  for(ll k = N; k <= 2*N; k++){
    
    if( k == N){ 
      for(ll j = 0; j < N; j++){ Q.push(A[j]); sum += A[j];}}
    else{ Q.push(A[k-1]); sum += A[k-1]; sum -= Q.top(); Q.pop();}
      
      sum_front[k-1] = sum; }
  
  priority_queue<ll> Q2; ll sum2 = 0LL;
  
  for(ll k=2*N; k >= N; k--){
    
    if( k == 2*N){
      for(ll j = 2*N; j < 3*N; j++){ Q2.push(A[j]); sum2 += A[j];}}
    else{ Q2.push(A[k]); sum2 += A[k]; sum2 -= Q2.top(); Q2.pop();}
    
    sum_back[k] = sum2;}
  ll ans = -1LL << 60;
  for(ll k = N; k <= 2*N; k++){
    
    ans = max( ans, sum_front[k-1]-sum_back[k]);}
  cout << ans << endl; return 0;}
      
    
    

Measured memory_bytes: 9588