akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int h, w;
int par[160000];   //親
int rank1[160000]; //木の深さ
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        rank1[i] = 0;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
//併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (rank1[x] < rank1[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (rank1[x] == rank1[y])
            rank1[x]++;
    }
}
bool same(int x, int y)
{
    return find(x) == find(y);
}
int size(int x)
{
    return -par[find(x)];
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    vector<string> s;
    for (int i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    init(h * w);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (i == h - 1 && j == w - 1)
            {
            }
            else if (i == h - 1)
            {
                if (s[i][j] != s[i][j + 1])
                    unite(i * w + j, i * w + j + 1);
            }
            else if (j == w - 1)
            {
                if (s[i][j] != s[i + 1][j])
                    unite(i * w + j, (i + 1) * w + j);
            }
            else
            {
                if (s[i][j] != s[i + 1][j])
                    unite(i * w + j, (i + 1) * w + j);
                if (s[i][j] != s[i][j + 1])
                    unite(i * w + j, i * w + j + 1);
            }
        }
    }
    map<int, ll> bcount;
    map<int, ll> wcount;
    for (int i = 0; i < h * w; i++)
    {
        //cout << par[i] << "\n";
        if (s[i / w][i % w] == '#')
            bcount[find(i)]++;
        else
            wcount[find(i)]++;
    }
    ll ans = 0;
    for (auto iter = bcount.begin(); iter != bcount.end(); iter++)
    {
        ans += bcount[iter->first] * wcount[iter->first];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, n;
  cin >> x >> n;
  map<int, int> mp;
  rep(i, n) {
    int p;
    cin >> p;
    mp[p]++;
  }
  int mn = INF, ans;
  rep(i, 110) {
    if (mp.find(i) != mp.end())
      continue;
    if (chmin(mn, abs(i-x)))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
a=3.times.map{gets.split.map(&:to_i)}.flatten
gets.to_i.times{
  i=a.index(gets.to_i)
  a[i]=0 if i
}
["111000000",
  "000111000",
  "000000111",
  "100100100",
  "010010010",
  "001001001",
  "100010001",
  "001010100"].map{|s|
  if s.chars.each_with_index.all?{|c,i|c==?0||a[i]==0}
    puts "Yes"
    exit
  end
}
puts "No"

Measured memory_bytes: 1788
import bisect

n = int(input())
l = list(map(int, input().split()))  

l.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        idx = bisect.bisect_left(l,l[i]+l[j])
        ans += idx-1-j
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
long long k,n;
cin>>k>>n;
long long a[n];
for(long long i=0;i<n;i++){
  cin>>a[i];
}
long long ans=a[n-1]-a[0];
for(long long i=1;i<n-1;i++){
  ans=min(ans,k-a[i]+a[i-1]-a[0]+a[0]);
  ans=min(ans,a[i]+k-a[n-1]+a[n-1]-a[i+1]);
}

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


Measured memory_bytes: 1792
import math
import collections
import sys

input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

n=input()
if n[0]!=str(7) and n[1]!=str(7) and n[2]!=str(7):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 65104
#include "bits/stdc++.h"
using namespace std;

long gcd(long a,long b){
	if(b==0) return a;
	if(a<b) swap(a,b);
	return gcd(b,a%b);
}
int main() {
	int n; cin >> n;
	vector<long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	int res = 0;
	for(int i = 0; i < n; i++) res = gcd(a[i],res); 
	cout << res << endl;
}



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

int main() {
double R,G;
cin >> R;
cin >> G;
// (R + ?)/2 = G
//R/2 + ?/2 = G
//?/2 = G - R/2
//? = 2G - R
cout << G*2 - R <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int sum(ll x){
    if (x == 0) return 1e9;
    int ret = 0;
    while (x){
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

const int N = 100000;
// int dp[N], k, visit[N];

// int calc(int x){
//     if (dp[x] >= 0) return x;
//     visit[x] = 1;
//     int ret = sum(x);
//     REP(i,10){
//         int y = x + i * k;
//         if (visit[y/10] && dp[y/10] == -1) continue;
//         ret = min(ret, (y % 10) + calc(y/10));
//     }
//     cout << x << " " << ret << endl;
//     return dp[x] = ret;
// }
#define INF 1e15

struct edge{ll to,cost;};
 
void dijkstra(VL &d, vector<vector<edge> > graph){
    fill(ALL(d), INF);
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(make_pair(0, 0));
    while (!q.empty()){
        P a = q.top();
        q.pop();
        int now = a.second;
        if(d[now] < a.first) continue;
        REP(i,graph[now].size()){
            edge e = graph[now][i];
            int next = e.to;
            if (d[next] > d[now] + e.cost){
                d[next] = d[now] + e.cost;
                q.push(make_pair(d[next], next));
            }
        }
    }
}

vector<vector<edge> > eg(N+10);

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

    REP(i,N){
        REP(j,10){
            int x = i + j * k;
            eg[i].push_back((edge){x/10, x%10});
        }
        eg[i].push_back((edge){N+1, sum(i)});
    }

    VL d(N+10);
    dijkstra(d, eg);

    cout << d[N+1] << endl;

    // REP(i,10) cout << d[i] << endl;



    // REP(i,N) dp[i] = -1;
    // cout << calc(0) << endl;

    // int ans = 1e9;
    // FOR(i,1,300000){
    //     ans = min(ans, sum((ll)k * i));
    //     // if (sum((ll)k*i) == 7) cout << i << endl;
    // }
    // cout << ans << endl;

    return 0;
}


Measured memory_bytes: 53240
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

signed main(void)
{
	while (1) {
		int N, M, P;
		cin >> N >> M >> P;
		M--;
		if (N == 0) break;
		int x[100];
		ll sum = 0;
		rep(i, N) {
			cin >> x[i];
			sum += x[i];
		}
		sum = sum*100*(100 - P) / 100;
		if (x[M] == 0) {
			cout << 0 << endl;
		}
		else {
			cout << sum / x[M] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

long long  ggd(long long  a,long long  b){
  if(b==0) return a;
  return ggd(b, a%b);
}

int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long gcdnum = ggd(D, C);
  long long CD = C*D/gcdnum;
  long long bc = B/C, ac=(A-1)/C, bd = B/D, ad = (A-1)/D, bcd = B/CD, acd = (A-1)/CD;
  long long c=bc-ac, d=bd-ad, cd=bcd-acd;
  long long ans = B-A+1 -(c+d-cd);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
X = int(input())

if 100 <= X <= 111:
  n = 111
elif X <= 222:
  n = 222
elif X <= 333:
  n = 333
elif X <= 444:
  n = 444
elif X <= 555:
  n = 555
elif X <= 666:
  n = 666
elif X <= 777:
  n = 777
elif X <= 888:
  n = 888
elif X <= 999:
  n = 999
else:
  print("error")

print(n)

Measured memory_bytes: 3060
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> K(N);
    vector<vector<int>> A(N);
    rep(i, N) {
        cin >> K.at(i);
        rep(j, K.at(i)) {
            int tmp;
            cin >> tmp;
            A.at(i).push_back(tmp);
        }
    }

    vector<int> preferences(M, 0);

    rep(i, N) {
        for(auto a : A.at(i)) {
            preferences[a - 1]++;
        }
    }

    int count = 0;
    rep(i, M) {
        if (preferences.at(i) == N) count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define reg register
#define reset(a) memset(a,0,sizeof(a))
using namespace std;
typedef pair<int,int> par;
const int N=1e5+5;
struct E
{
	int to,nxt;
}edge[N*50];
struct node
{
	int x,id;
	inline friend bool operator < (node a,node b) {return a.x<b.x;}
}c[N];
int n,m,num,head[N],a[N],dfn[N],low[N],bel[N];
int cnt,tim,tot,stack[N],top,idx[N];
bool exist[N];
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
inline void add_edge(int from,int to)
{
	edge[++num]=(E){to,head[from]};
	head[from]=num;
}
inline void clear()
{
	reset(dfn); reset(low); reset(bel);
	reset(exist); reset(head); reset(idx);
	num=cnt=tot=top=0; tim=n<<1;
}
void tarjan(int k)
{
	int temp;
	dfn[k]=low[k]=++cnt;
	stack[++top]=k; exist[k]=1;
	for (reg int i=head[k];i;i=edge[i].nxt)
	{
		int v=edge[i].to;
		if (!dfn[v])
		{
			tarjan(v);
			low[k]=min(low[k],low[v]);
		}
		else if (exist[v])
		  low[k]=min(low[k],dfn[v]);
	}
	if (dfn[k]==low[k])
	{
		++tot;
		do
		{
			temp=stack[top--];
			exist[temp]=0;
			bel[temp]=tot;
		}while (temp!=k);
	}
}
void build(int l,int r,int now)
{
	idx[now]=++tim;
	if (now>1) add_edge(idx[now>>1],tim);
	if (l==r) {add_edge(idx[now],c[l].id>n?c[l].id-n:c[l].id+n); return;}
	int mid=(l+r)>>1;
	build(l,mid,now<<1); build(mid+1,r,now<<1|1);
}
void change(int L,int R,int l,int r,int now,int x)
{
	if (l>R||r<L) return;
	if (l>=L&&r<=R) {add_edge(x,idx[now]); return;}
	int mid=(l+r)>>1;
	if (mid>=R) change(L,R,l,mid,now<<1,x);
	else if (mid<L) change(L,R,mid+1,r,now<<1|1,x);
	else
	{
		change(L,mid,l,mid,now<<1,x);
		change(mid+1,R,mid+1,r,now<<1|1,x);
	}
}
inline par query(int p,int k)
{
	par ret; ret.first=ret.second=p;
	int l=1,r=p,pos=p;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (c[p].x-c[mid].x<k) pos=mid,r=mid-1;
		else l=mid+1;
	}
	ret.first=pos; l=p,r=m,pos=p;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (c[mid].x-c[p].x<k) pos=mid,l=mid+1;
		else r=mid-1;
	}
	ret.second=pos; return ret;
}
inline bool check(int k)
{
	clear(); build(1,m,1);
	for (reg int i=1;i<=m;i++)
	{
		par now=query(i,k);
		change(now.first,i-1,1,m,1,c[i].id);
		change(i+1,now.second,1,m,1,c[i].id);
	}
	for (reg int i=1;i<=m;i++) if (!dfn[i]) tarjan(i);
	for (reg int i=1;i<=n;i++)
	  if (bel[i]==bel[i+n]) return 0;
	return 1;
}
int main()
{
	n=read();
	for (reg int i=1;i<=n;i++)
	{
		a[i]=read(),a[i+n]=read();
		c[++m]=(node){a[i],i};
		c[++m]=(node){a[i+n],i+n};
	}
	sort(c+1,c+m+1);
	int l=0,r=1e9,ans=0;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12288
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
for a in range(n-k):
    if t[k+a] == t[a]:
        t[k+a] = 0
x = t.count('r') * p + t.count('s') * r + t.count('p') * s
print(x)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int Div[N];
 
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	for (int i = 1; i < N; ++i)
		for (int j = i; j < N; j += i)
			++Div[j];
	int n; cin >> n;
	long long ans = 0;
	for (int c = 1; c < n; ++c)
		ans += Div[n-c];
	cout << ans << '\n';
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
int vis[N];
vector<vector<int>>adj(N);


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
void dfs(int x){
    vis[x]=1;
    for(auto i:adj[x]){
        if(!vis[i])
            dfs(i);
    }
}


void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<(n^1)<<endl;
    }
    return 0;
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846


    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
    long long minu(long long a, long long b){
        return mod(mod(a)-mod(b));
    }
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
int main()
{
    int n;
    cin>>n;
    if(n<=1)
    {


        cout<<"0\n";
        return 0;
        }
    if(n==2)
    {
        cout<<2;
        return 0;
    }
     ll ans=minu(add(modPow(10LL,n),modPow(8LL,n)),mul(2LL,modPow(9LL,n)));
        cout<<ans;

}


Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

ll ans;
vector<ll> patti(51);
vector<ll> total(51);

void solve(ll N, ll x){
  if(N == 1) {
    if(x >= 5){
      ans += 3;
    } else {
      ans = ans + x - 1;
    }
    
    return;
  }
  if(total[N]/2 + 1 <= x) { // 半分以上はいる場合
    x = x - total[N]/2 - 1;
    ans += patti[N-1] + 1;
  }
  else {
    x--; // 1番目のバンズを外す
  }
  if(x <= 0) return;
  solve(N-1, x);
}

int main() {
  ll N, x;
  cin >> N >> x;
  
  patti[0] = 1;
  total[0] = 1;
  for(int i = 1; i <= 50; i++){
    patti[i] = 1 + patti[i-1]*2;
    total[i] = 3 + total[i-1]*2;
  }

  ans = 0;
  solve(N, x);
  
  print(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a[200000], b[200000];
int main() {
  ll n, k, l, r, mid, cnt;
  cin >> n >> k;
  for (ll i = 0LL; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  l = 0;
  r = 1000000000000000LL;
  while (l <= r) {
    mid = (l + r) / 2LL;
    cnt = 0LL;
    for (int i = 0; i < n; i++) {
      if (mid < a[i] * b[n - 1 - i]) {
        cnt += a[i] - mid / b[n - 1 - i];
      }
    }
    if (cnt <= k) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {

  long long int N, M, count; 

  cin >> N;
  cin >> M;
  
  if(2*N > M){
    if(N < M/2)
      cout << N;
    else
      cout << M/2;
  }
  else {
    count = N;
    M -= 2*N;
    count += M/4;
    cout << count;
  } 
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  string s;
  ll ans = 0,c=0;
  cin >> s;
  for(auto ch:s){
    if(ch=='S') c = 0;
    else c++;
    ans = max(c,ans);
  }
  cout << ans << endl;
}


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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n+10);
  vector<ll> b(n+10);
  vector<ll> c(m+10);
  vector<ll> d(m+10);
  ll ans[n+10][m+10];
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,m) cin >> c[i] >> d[i];
  rep(i,n){
    rep(j,m){
        ans[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
    }
  }
  vector<ll> e(m);
  rep(i,n){
    rep(j,m){
      e[j] = ans[i][j];
    }
    ll min = *min_element(e.begin(),e.end());
    rep(j,m){
      if(min == e[j]){
        cout << j+1 << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
main(){
   
  int a,b;
   
  scanf("%d%d",&a,&b);
   
  if(a < b) printf("a < b\n");
  else if(a > b) printf("a > b\n");
  else printf("a == b\n");
   
  return 0;
}

  

Measured memory_bytes: 580
// ABC 079 D Wall  ワーシャルフロイド
// https://atcoder.jp/contests/abc079/tasks/abc079_d
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int H, W;
    cin >> H >> W;
    int cost[10][10];
    for(int i = 0; i <= 9; i++) {
        for(int j = 0; j <= 9; j++) {
            cin >> cost[i][j];
        }
    }

    for(int k = 0; k <= 9; ++k) {
        for(int i = 0; i <= 9; ++i) {
            for(int j = 0; j <= 9; ++j) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
  
    int count=0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int input;
            cin >> input;
            if(input>=0){
                count+=cost[input][1];
            }
        }
    }
    cout << count <<endl;
    return 0;
}


Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    auto S = sread();
    long N = S.length;
    if (N == 1)
    {
        writeln(S);
        return;
    }
    auto cnt = new long[][](10, 10);
    foreach (x; 1 .. S.to!long + 1)
    {
        auto s = x.text;
        // dprint(s[0] - '0', s[$ - 1] - '0');
        cnt[s[0] - '0'][s[$ - 1] - '0']++;
    }
    long ans;
    foreach (i; 1 .. 10)
        foreach (j; 1 .. 10)
        {
            // dprint(i, j, cnt[i][j], cnt[j][i]);
            ans += cnt[i][j] * cnt[j][i];
        }
    writeln(ans);
}


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

int r, D, x;

int main()
{
	scanf("%d %d %d", &r, &D, &x);

	for(int i = 0; i < 10; i++)
	{
		int ans = r * x - D;
		printf("%d\n", ans);
		x = ans;
	}
}

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

int main() {
  string S;
  string T;
  int c=0;
  cin>>S>>T;
  
  for(int i=0; i<3; i++){
  		if(S.at(i)==T.at(i)){
        	c+=1;
        }
  }
  cout<<c;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;
int A,B;
int main()
{
    scanf("%d%d",&A,&B);
    int k=B-A;
    printf("%d",(k+1)*k/2-B);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef vector<int> Vi;
const int INF = (1<<25);
const int MAX_V = 101;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int w, h, f, m;
int c[10][10];

struct State {
  int x, y, l, r, oxy, cost;
  State(int x_, int y_, int l_, int r_, int oxy_, int cost_) {
    x=x_; y=y_; l=l_; r=r_; oxy=oxy_; cost=cost_;
  }
  State(){}
};

bool operator<(const State& a, const State& b) {
  return a.cost > b.cost;
}

int d[10][10][10][10][51];

int solve(int o) {
  if( o < 2 ) return INF;

  for(int y=0; y<10; y++) {
    for(int x=0; x<10; x++) {
      for(int l=0; l<10; l++) {
	for(int r=0; r<10; r++) {
	  for(int m=0; m<51; m++) {
	    d[y][x][l][r][m] = INF;
	  }
	}
      }
    }
  }

  priority_queue<State> q;
  for(int x=0; x<w; x++) {
    int cost = -1 * min(c[0][x], 0);
    int oxy = min(m, o - 1 + max(c[0][x], 0));
    d[0][x][x][x][oxy] = cost;
    q.push(State(x, 0, x, x, oxy, cost));
  }

  int res = INF;
  while( !q.empty() ) {
    State p = q.top(); q.pop();
    int x = p.x, y = p.y, l = p.l, r = p.r;
    int oxy = p.oxy, cost = d[y][x][l][r][oxy];

    if( oxy == 0 ) continue;
    if( f < cost ) return INF;
    if( y == h-1 ) {
      res = cost; 
      break;
    }
    if( oxy == 1 ) continue;

    for(int dx=-1; dx<=1; dx+=2) {
      int mx = x + dx;
      if( mx < 0 || w <= mx ) continue;

      int l_ = min(l, mx), r_ = max(r, mx);
      int next_cost = cost, next_oxy;
      if( l_ == l && r_ == r ) {
	next_oxy = oxy -1;
      }
      else {
	next_cost += -1 * min(c[y][mx], 0);
	next_oxy = min(m, oxy - 1 + max(c[y][mx], 0));
      }
      if( next_cost < d[y][mx][l_][r_][next_oxy] ) {
	d[y][mx][l_][r_][next_oxy] = next_cost;
	q.push(State(mx, y, l_, r_, next_oxy, next_cost));
      }
    }

    if( y < h-1 ) {
      int next_cost = cost + -1 * min(c[y+1][x], 0);
      int next_oxy = min(m, oxy - 1 + max(c[y+1][x], 0));
      if( next_cost < d[y+1][x][x][x][next_oxy] ) {
	d[y+1][x][x][x][next_oxy] = next_cost;
	q.push(State(x, y+1, x, x, next_oxy, next_cost));
      }
    }
  }
  if( f < res ) return INF;
  return res;
}

int main() {
  while( cin >> w >> h, w || h ) {
    int o;
    cin >> f >> m >> o;
    for(int y=0; y<h; y++) {
      for(int x=0; x<w; x++) {
	cin >> c[y][x];
      }
    }

    int ans = solve(o);
    if( ans == INF ) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 3324
n=int(input())
a=list(map(int,input().split()))
q=int(input())
l=[0]*q
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    l[i]=(b,c)
book={}
for i in a:
    if i in book:
        book[i]+=1
    else:
        book[i]=1

for i in range(q):
    if l[i][0] in book:
        if l[i][1] in book:
            ans+=(l[i][1]-l[i][0])*book[l[i][0]]
            book[l[i][1]]+=book[l[i][0]]
            book[l[i][0]]=0
        else:
            ans+=(l[i][1]-l[i][0])*book[l[i][0]]
            book[l[i][1]]=book[l[i][0]]
            book[l[i][0]]=0
    print(ans)

Measured memory_bytes: 89272
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> ra(MX,0);
vector<int> par(MX,0);


int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(ra[x]<ra[y]) {
        par[x] = y;
    }else {
        par[y] = x;
        if(ra[x]==ra[y]) ra[x]++;
    }

}

bool same(int x, int y) {
    return find(x) == find(y);
}

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

    vector<int> p(n,0);
    vector<vector<int>> xy(m, vector<int>(2)); 
    
    for (size_t i = 0; i < n; i++)
    {
        cin >> p[i];
        p[i]-=1;
        par[i] = i;
    }

    for (size_t i = 0; i < m; i++)
    {
        int x,y;
        cin >> x >> y;
        unite(x-1,y-1);
    }

    int ans=0;
    for (size_t i = 0; i < n; i++)
    {
        if(same(p[i],i)) ans++;
    }

    cout << ans << endl;
    


    
    
}

Measured memory_bytes: 22144
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)

Measured memory_bytes: 40304
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let x: usize = input();
    let mut sum = 0;
    for i in 1..x + 1 {
        sum += i;
        if sum >= x {
            println!("{}", i);
            return;
        }
    }
}

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

// #define fi first
#define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define WHITE 0  // 未訪問
#define BLACK 1  // 訪問ずみ

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
const int N=100000;
//const ll M = 1000000000+7;


int main(){
  ll n,p,ans;
  ans = 0;
  cin>>n>>p;

  string s;
  cin>>s;

  //sort(ALL(s));
  vector<ll> v(n+1);
  v[n] = 0;
  ll keta = 1;

  if(10%p==0) {
    rep(i, n){
      if((s[i]-'0')%p==0) ans+=i+1;
    }
    cout << ans <<endl;
    return 0;
  }

  map<ll, ll> m;
  for(int i=n-1;i>=0;i--){
    v[i] =  ((s[i] - '0') * keta) % p ;
    v[i] = (v[i]+v[i+1] )% p;
    //cout << v[i] <<endl;
    m[v[i]]++;
    keta *=10; keta  %= p;
  }
  //m[0]++;
  for(map<ll,ll>::iterator mi=m.begin();mi!=m.end();mi++){
    //rep(i,p+1){
  //cout  <<"# "  <<mi->second<<endl;   keta = ke   keta = keta * 10 % p;ta * 10 % p;

     ans += mi->se*(mi->se-1)/2;
  }
  //  cout << ans <<endl;

  
  ans += m[0];


  cout << ans <<endl;
    return 0;

}
 


Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define ss                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define li                list<int>
#define pii               pair<int,int>
#define vi                vector<int>
#define mii               map<int ,int>
#define setbits(x)        _builtin_popcountll(x)
#define zrobits(x)        _builtin_ctzll(x)
#define mod               1000000007
#define inf               1e18
#define ps(x,y)           fixed<<setprecision(y)<<x
#define mk(arr,n,type)    type *arr=new type(n);
#define w(x)              int x; cin>>x; while(x--)
#define all(x)            (x).begin(), (x).end()
#define PI                3.14159265358979
void c_p_c()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("ou.txt", "w", stdout);
#endif
}
// int fact(int n)
// {
// 	if (n == 1)return 1;
// 	return (n * (fact(n - 1))) % mod;
// }
// int power(int x, unsigned int y, int mo)
// {
// 	int res = 1;

// 	while (y > 0)
// 	{
// 		if (y & 1)
// 			res = (res * x) % mo;
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % mo; // Change x to x^2
// 	}
// 	return res % mo;
// }


//int a[111111111], b[111111111], c[1111111];
void solve()
{
	int a; cin >> a;
	cout << a + (a * a) + (a * a * a);

}
int32_t main()

{
	c_p_c();
	solve();
}

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

int main(){
  int n;
  cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    num[x-1]=i+1;
  }for(int i=0;i<n;i++){
    cout<<num[i]<<' ';
  }cout<<endl;
}

Measured memory_bytes: 1152
import collections

N = int(input())

if N == 1:
  print(1 if int(input()) != 1 else 0)
  exit()

a = [int(x) for x in input().split()]

b = list(collections.Counter(a).items())

c = 0
for i in b:
  if i[1] - i[0] < 0:
    c += i[1]
  else:
    c += i[1] - i[0]

print(c) 
 


Measured memory_bytes: 21232
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e7))
#define pi (2*acos(0))
#define mp make_pair
#define M ((int)(1e9 + 7))
#define xx first
#define yy second
#define NN ((int)(5e5+2))
#define N ((int)(2e5 + 2))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int lu;

typedef tree < int ,  null_type ,  less < int > ,  rb_tree_tag ,  tree_order_statistics_node_update > o_set;

int main()
{
    int n;
    scanf("%d",&n);
    if(n==3){
        printf("2 5 63\n");
        return 0;
    }
    int x = min(15000,n-2);
    n -= x;
    if(n%2==1){
        n++;
        x--;
    }
    if(x%3==1){
        printf("%d ",2*(x+2));
        x--;
    }
    for(int i = 1; i<=x; i++) printf("%d ",i*2);
    for(int i = 1; i<=n; i++) printf("%d ",3*(2*i-1));
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    ll X, K, D; cin >> X >> K >> D;

    X = abs(X);
    
    ll cnt = min(K, X / D);
    K -= cnt;
    X -= cnt * D;

    if (K % 2 == 0) {
        cout << abs(X) << endl;
    } else {
        cout << abs(X - D) << endl;
    }

    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1] -= 'A'-'a';
    cout<<s<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            if (n == (i+1) * (j+1)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3612
import math


def sosu(x):
    if x <= 3:
        return True
    else:
        n = math.ceil(math.sqrt(x))
        for i in range(2, n):
            if x % i == 0:
                return False
        return True


X = int(input())
while True:
    if sosu(X):
        break
    else:
        X += 1
print(X)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse2")
 
    #include <bits/stdc++.h>
    #include <vector> 
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
 
    #define int         long long
    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define mp          make_pair
    #define all(a)      (a).begin(),(a).end()
    #define FF           first
    #define SS           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define rep(i,a,b)  for(int i=a;i<b;i++)
     ll hell=1000000007;



   
  
    int solve(){  
       
       int  n;
       cin>>n;

       int ans=0;
       rep(i,1,n)
       ans+=(n-1)/i;
       cout<<ans<<endl;

     return 0;
        
        }


    signed main()
    {       


  
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
 
    int t=1,k=1;                                                                                                                  
    //cin>>t;
   
    while(t--)
    {
     
     // cout<<"Case #"<<k++<<": ";
     solve();
     //cout<<endl;
    }
    return 0;
    } 

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

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  if (A + (K - 1) < B - (K - 1)) {
    for (int i = 0; i < K; ++i) {
      cout << A + i << endl;
    }
    for (int i = K - 1; 0 <= i; --i) {
      cout << B - i << endl;
    }
  } else {
    for (int i = A; i <= B; ++i) {
      cout << i << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}

vector<vi> calcNext(string s){
  int n=s.size();
  vector<vi> res(n+1,vi(26,n));
  rrep(i,n-1){
    rep(j,26) res[i][j]=res[i+1][j];
    res[i][s[i]-'a']=i;
  }

  return res;
}


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

  string s;
  cin>>s;
  int n=s.size();

  vector<vi> next=calcNext(s);

  vi dp(n+1,inf);
  vector<pair<char,int>> recon(n+1,{'?',n});

  dp[n]=1;
  
  rrep(i,n-1){
    rep(j,26){ 
      if(next[i][j]==n){
        if(dp[i]>1){
          dp[i]=1;
          recon[i]={'a'+j,n};
        }
      }else if(dp[i]>dp[next[i][j]+1]+1){
        dp[i]=dp[next[i][j]+1]+1;
        recon[i]={'a'+j,next[i][j]+1};
      }
    }
  }

  
  string ans="";
  int it=0;
  while(it<n){
    auto p=recon[it];
    ans+=p.F;
    it=p.S;
    
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 53584
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=r;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long n,p,i,a[131072],r[2]={0,0},res,k;
    scanf("%lld%lld",&n,&p);
    for(i = 1;i <= n;i++){scanf("%lld",&a[i]);if(a[i]%2){r[1]++;}else{r[0]++;}}
    res=0;
    k=0;
    for(i=0;i<=r[0];i++){
        res+=(llnCr(r[0],i));
    }
    for(i=p;i<=r[1];i+=2){
        k+=(llnCr(r[1],i));
    }
    printf("%lld\n",res*k);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	map<int, int> m;
	vi v(n);
	rep(i, n){
		cin >> v[i];
		m[v[i]]++;
	}
	
	vector<pi> p;
	if(n < 10){
		rep(i, n) rep(j, n) if(i != j && v[i] >= v[j]) p.emplace_back(v[i], v[j]);
	}
	else rep(i, n){
		ll diff = 1e18;
		int x = 0;
		auto j = m.lower_bound(v[i] / 2);
		
		if(diff > abs(2ll * j->first - v[i])){
			diff = abs(2ll * j->first - v[i]);
			x = j->first;
		}
		
		if(j != m.begin()){
			--j;
			if(diff > abs(2ll * j->first - v[i])){
				diff = abs(2ll * j->first - v[i]);
				x = j->first;
			}
		}
		
		if(x <= v[i]) p.emplace_back(v[i], x);
	}
	
	//dbg(p);
	
	double mx = -1;
	pi mxp;
	rep(i, p.size()){
		int n = p[i].first, k = p[i].second;
		double d = lgamma(n + 1) - lgamma(k + 1) - lgamma(n - k + 1);
		if(mx < d) mx = d, mxp = p[i];
	}
	cout << mxp.first << " " << mxp.second << endl;
	
	return 0;
}

Measured memory_bytes: 6524
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long a = 26;
		
		char[] al = new char[26];
		String[] alp = new String[26]; 
		ArrayList<String> alph = new ArrayList<String>();
		for(int i = 0; i<26;i++) {
			al[i] = (char)(97+i);
			alp[i] = String.valueOf(al[i]);
			alph.add(alp[i]);
		}
		
		ArrayList<String> list = new ArrayList<String>();
		
		//141167095653375
		
		while(true) {
			if(n < 27) {
				list.add(alph.get((int)n-1));
				break;
			}
			long end = n % a;
			
			if(end == 0) {
				end = 26;
			}
			//System.out.println(end);
			list.add(alph.get((int)end-1));
			long ans = (n-end) / a;
			//System.out.println(ans);
			if(ans < 27) {
				list.add(alph.get((int)ans-1));
				break;
			}
			n = ans;
				
		}
		Collections.reverse(list);
		for(String item:list) {
			System.out.print(item);
		}
	}

}


Measured memory_bytes: 35876
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    fast;
    int n, w;
    cin >> n >> w;
    vpl v(n);
    cin >> v;
    ll sum = 0;
    for (auto x : v)
        sum += x.second;
    vl dp(sum + 1, 1e18);
    dp[0] = 0;
    loop(i, n)
    {
        for (int j = sum; j >= v[i].second; j--)
            if (dp[j - v[i].second] + v[i].first <= w)
                dp[j] = min(dp[j], dp[j - v[i].second] + v[i].first);
    }
    rep(i, sum + 1, 1) if (dp[i] <= w)
    {
        cout << i << endl;
        return 0;
    }
#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 1024