akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
E = []
for i in range(M):
    L, R, C = map(int, input().split())
    E.append([L-1, R-1, C])

E = sorted(E)

# N_はN以上の2べき数
N_ = 2**(len(bin(N))-2)
INF = 10**15 # 10**10 
seg = [INF] * (2*N_-1)

# k番目(0index)をaに更新
def update(k, a):
    k += N_-1
    seg[k] = a

    while k > 0:
        k = (k-1)//2
        seg[k] = min(seg[k*2+1], seg[k*2+2])

# 開区間！！！[a, b)の最小値を求める
def query(a, b, k, l, r):
    if r <= a or b <= l:
        return INF
    if a <= l and r <= b:
        return seg[k]
    else:
        vl = query(a, b, k*2+1, l, (l+r)//2)
        vr = query(a, b, k*2+2, (l+r)//2, r)
        return min(vl, vr)



# 初期化
update(0, 0)

for i in range(M):
    new = query(E[i][0], E[i][1], 0, 0, N_) + E[i][2]
    if new < seg[E[i][1] + N_-1]:
        update(E[i][1], new)

if seg[N-1+N_-1] == INF:
    print(-1)
else:
    print(seg[N-1+N_-1])

Measured memory_bytes: 105692
#include <bits/stdc++.h>
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define ll long long

using namespace std;

int main() {
    ll hp;
    cin >> hp;
    ll i = 0;
    while ( pow(2,i) <=hp){
        i++;
    }
    ll ans = pow(2,i)-1;
    cout << ans;

  }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int N,ans=0;
  cin >> N;
  vector<int> L(N);
  int i,j,l,r,p;
  for(i=0;i<N;i++)cin >> L[i];
  L.push_back(1001);
  sort(L.begin(),L.end());
  for(i=0;i<N-2;i++) {
    for(j=i+1;j<N-1;j++) {
      l=j+1;
      r=N;
      while(r-l>=1) {
        p = (l+r)/2;
        if(L[p]>=L[i]+L[j] && L[p-1]<L[i]+L[j])l=r;
        else if(L[p] < L[i]+L[j]) {
          l=p+1;
          p=l;
        } else r=p;
      }
      ans += p-j-1;
    }
  }
  cout << ans << endl;
}

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

inline int Get(int x){ return x*(x-1)>>1;}

int num[3],n,m,ans=1<<30,uu,vv,col[N],now;
bool f[N][N],g[N][N];

bool dfs(int x,int c){
	col[x]=c,num[c]++;
	
	for(int i=1;i<=n;i++) if(!g[x][i])
	    if(!col[i]){ if(!dfs(i,3-c)) return 0;}
	    else if(col[i]==c) return 0;
	
	return 1;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	    scanf("%d%d",&uu,&vv),g[uu][vv]=g[vv][uu]=1;
	
	f[0][0]=1;
	for(int i=1;i<=n;i++) g[i][i]=1;
	
	for(int i=1;i<=n;i++) if(!col[i]){
		num[1]=num[2]=0;
		if(!dfs(i,1)){ puts("-1"); return 0;}
		
		now++;
		for(int j=0;j<=n;j++) if(f[now-1][j]) f[now][j+num[1]]=f[now][j+num[2]]=1;
	}
	
	for(int i=0;i<=n;i++) if(f[now][i]) ans=min(ans,Get(i)+Get(n-i));
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    ll cnt0 = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        if(a%2 == 0) {
            cnt0++;
        }
    }

    ll x = 1;
    rep(i, n) {
        x *= 3;
    }

    ll y = 1;
    rep(i, cnt0) {
        y *= 2;
    }
    
    out(x - y);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
    int points_count;
    int dimension;
    vector<vector<int> > points;

    cin >> points_count >> dimension;
    
    for(int i = 0; i < points_count; i++){
        vector<int> point;
        for(int j = 0; j < dimension; j++){
            int c;
            cin >> c;
            point.push_back(c);
        }
        points.push_back(point);
    }
    
    int int_dist_count = 0;
    for(int i = 0; i < points_count - 1; i++){
        for(int j = i + 1; j < points_count; j++){
            int double_dist = 0;
            for(int k = 0; k < dimension; k++){
                int dist = abs(points[i][k] - points[j][k]);
                double_dist += dist * dist;
            }
            if((int)sqrt(double_dist) * (int)sqrt(double_dist) == double_dist){
                int_dist_count++;
            }
        }
    }

    cout << int_dist_count << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF=10**18
s=[-INF] + [int(input()) for i in range(A)] + [INF]
t=[-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)
#copy code.

Measured memory_bytes: 12812
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	long long ans=1e18;
	for(int i=1;i<n;++i){
		long long s1=(long long)i*m;
		long long s2=(long long)(n-i)*(m/2);
		long long s3=(long long)(n-i)*(m-m/2);
		long long t=max(max(s1,s2),s3)-min(min(s1,s2),s3);
		if(t<ans)ans=t;
	}
	for(int i=1;i<n;++i){
		long long s1=(long long)i*m;
		long long s2=(long long)(n-i)/2*m;
		long long s3=(long long)(n-i-(n-i)/2)*m;
		long long t=max(max(s1,s2),s3)-min(min(s1,s2),s3);
		if(t<ans)ans=t;
	}
	for(int i=1;i<m;++i){
		long long s1=(long long)n*i;
		long long s2=(long long)(n/2)*(m-i);
		long long s3=(long long)(n-n/2)*(m-i);
		long long t=max(max(s1,s2),s3)-min(min(s1,s2),s3);
		if(t<ans)ans=t;
	}
	for(int i=1;i<m;++i){
		long long s1=(long long)n*i;
		long long s2=(long long)n*((m-i)/2);
		long long s3=(long long)n*(m-i-(m-i)/2);
		long long t=max(max(s1,s2),s3)-min(min(s1,s2),s3);
		if(t<ans)ans=t;
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> field(H);  
  for (int i = 0; i < H; i++) {
      cin >> field.at(i);
  }
  
  vector<vector<string>> field_after(H, vector<string>(W, "#")); 

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field.at(i).at(j) == '#') {
        field_after.at(i).at(j) = "#";
      }
      else {
        int count = 0;

        if (i > 0 && j > 0 && field.at(i-1).at(j-1) == '#')
          count++;
        if (i > 0 && field.at(i-1).at(j) == '#')
          count++;
        if (i > 0 && j < W-1 && field.at(i-1).at(j+1) == '#')
          count++;
        if (j > 0 && field.at(i).at(j-1) == '#')
          count++;
        if (j < W-1 && field.at(i).at(j+1) == '#')
          count++;
        if (i < H-1 && j > 0 && field.at(i+1).at(j-1) == '#')
          count++;
        if (i < H-1 && field.at(i+1).at(j) == '#')
          count++;
        if (i < H-1 && j < W-1 && field.at(i+1).at(j+1) == '#')
          count++;      

        field_after.at(i).at(j) = to_string(count);
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << field_after.at(i).at(j);
    }
    cout << endl;
  }  

}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int train;
	int bus;
	if (a < b) {
		train = a;
	} else {
		train = b;
	}
	if (c < d) {
		bus = c;
	} else {
		bus = d;
	}
	int ans = train + bus;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s;
 	cin>>s;
 	ll n=s.size();
 	for(ll i=0;i<n/2;i++)
 	{
 		if(s[i]!=s[n-1-i])
 		{
 			cout<<"No"<<endl;
 			return 0;
 		}
 	}
 	s=s.substr(0,n/2);
 	n=s.size();
 	for(ll i=0;i<n/2;i++)
 	{
 		if(s[i]!=s[n-1-i])
 		{
 			cout<<"No"<<endl;
 			return 0;
 		}
 	}
 	cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        string input= Console.ReadLine();
        Console.WriteLine(700+(input.Length-input.Replace("o","").Length)*100);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

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

using namespace std;

void dfs(int s, vector<int>* adj, int* longestPath, bool* visited) {

	if (visited[s]) {
		return;
	}
	longestPath[s] = 0;
	visited[s] = true;
	for (int i = 0; i < adj[s].size(); i++) {
		dfs(adj[s][i], adj, longestPath, visited);
		longestPath[s] = max(longestPath[s], longestPath[adj[s][i]] + 1);
	}

}

int main() {

	int n, m;
	cin >> n >> m;

	vector<int> adj[n];
	int longestPath[n];
	bool visited[n] = {0};

	for (int i = 0; i < m; i++) {

		int x, y;
		cin >> x >> y;

		x--;
		y--;

		adj[x].push_back(y);

	}

	int output = -1;
	for (int i = 0; i < n; i++) {
		if (visited[i] == false) {
			dfs(i, &(adj[0]), &(longestPath[0]), &(visited[0]));
		}
		output = max(output, longestPath[i]);
	}
	cout << output << endl;

}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

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

    bool ok = 0;
    for (int i=1; i<n-1; i++){
        ok |= (a[i-1]==b[i-1] && a[i]==b[i] && a[i+1]==b[i+1]);
    }

    cout<<(ok?"Yes":"No")<<endl;

    return 0;
}





Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int a,b; cin >>a >>b;
  cout <<6-a-b <<endl;
}

Measured memory_bytes: 256
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(2);
  
  lin(N);
  map<ll, ll> f = factor(N);
  ll res = 0;
  auto iter = f.begin();

  rep(i, f.size()){
    ll k = (*iter).second;
    for(ll n = 1; true; n++){
      res++;
      if(n * (n + 1) / 2 <= k && k < (n+1)*(n+2) / 2) break;
    }
    iter++;
  }

  cout << res << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
int h ,w;
cin>>h>>w;

vector<pair<int,int> >fst;
vector<pair<int,int> >scnd;

int grid[h][w];
int sum = 0;
for(int i=0 ; i<h ; i++){
    for(int j=0 ; j<w ; j++){
        cin>>grid[i][j];
        sum += grid[i][j];
    }
}


for(int i=0 ; i<h ; i++){
    if(i%2==0){
    for(int j=0 ; j<w-1 ; j++){
       if(grid[i][j] % 2){
        grid[i][j+1] += grid[i][j];
        fst.push_back({i+1 , j+1});
        scnd.push_back({i+1, j+2});
       }
    }
    if(grid[i][w-1]%2 && i+1<h){
        grid[i+1][w-1] += grid[i][w-1];
        fst.push_back({i+1 , w});
        scnd.push_back({i+2 ,w});
    }
    }

    else{
    for(int j=w-1 ; j>=1 ; j--){
        if(grid[i][j] % 2){
        grid[i][j-1] += grid[i][j];
        fst.push_back({i+1 , j+1});
        scnd.push_back({i+1, j});
       }
    }
    if(grid[i][0]%2 && i+1<h){
        grid[i+1][0] += grid[i][0];
        fst.push_back({i+1 , 1});
        scnd.push_back({i+2 ,1});
    }

    }

}

/*for(int i=0 ; i<h ; i++){
    for(int j=0 ; j<w; j++){
        cout<<grid[i][j]<<" ";
    }
    cout<<endl;
}


cout<<endl<<endl;*/


cout<<fst.size()<<endl;
for(int i=0 ; i<fst.size() ; i++){
    cout<<fst[i].first<<" "<<fst[i].second<<" ";
    cout<<scnd[i].first<<" "<<scnd[i].second<<endl;
}

}


Measured memory_bytes: 6340
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define FORi(N) for(int i = 0; i < N; ++i)
#define FORj(N) for(int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll logk = log2(K);
    ld p = 0;
    if(K <= N) {
        p += 1.0l * (N - K +1) / N;
    }
    ld pp = 0;
    for(ll i = 1; i <= N; ++i) {
        if(i >= K) {
            // p+=1.0l/N;
            break;
        } else {
            ll logi = log2(i);
            ll di = (K-1) / i ;
            //cout<<di<<endl;
            //cout<<log2(di+1)+1<<endl;
            pp += 1.0l / N / pow(2, (ll)(log2(di)+1));
            /*for(int ii=i,num=1;;ii*=2,num++){
              if(K<ii){
                p+=1.0l/N/pow(2,num);
              }
            }*/
        }
    }
    p += pp;
    // cout<<p;
    printf("%.12llf\n", p);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> kazu(n);
  for(int i = 0; i < n; i++){
    cin >> kazu.at(i);
  }
  int kosuu = n;
  int min = kazu[0];
  for(int i = 0; i < n; i++){
    if(min > kazu.at(i)) min = kazu.at(i);
    if(min != kazu.at(i)) kosuu--;
  }
  cout << kosuu << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<limits>
#include <bitset>      
#include<cstring>


#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF numeric_limits<int>::max()



using namespace std;


int dp[3030][3030];


int main(){

    string s, t;
    cin >> s >> t;

    int n, m;
    n = s.length();
    m = t.length();


    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
          }
       }
    
    
    string ans;
    int i = n, j = m;

    while(i > 0 && j > 0){
           if(s[i-1] == t[j-1]){
                ans.pb(s[i-1]);
                i--;j--;
             }
           else if(dp[i][j-1] > dp[i-1][j]){
                 j--;
               }
          else{
                 i--;
               }          
       }


       for(int k = ans.size()-1; k >= 0; k--){
            cout << ans[k];
         }


    
    return 0;
}






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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    char b;
    cin >> b;
    switch (b) {
    case 'A':
        cout << 'T' << endl;
        break;
    case 'T':
        cout << 'A' << endl;
        break;
    case 'C':
        cout << 'G' << endl;
        break;
    case 'G':
        cout << 'C' << endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 3548
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
ll a[10000],ans,anss,n,i,l,r,b,delta,mid,t;
bool cmp(ll x,ll y)
{
	return x>y;
}
int main ()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+1+n,cmp);
	if (a[1]<=n-1) 
	{
		printf("0\n");
		return 0;
	}
	while (1)
	{
		sort(a+1,a+1+n,cmp);
	//	pr(anss);
		//pr(ans);
		//for (i=1;i<=n;i++) printf("a[%lld]=%lld\n",i,a[i]+delta);
		if (a[1]+delta<=n-1) break;
		l=0,r=10000000000000000;
		ans=0;
		while (l<=r)
		{
			mid=(l+r)/2;
			if (a[1]+delta-n*mid>n-1) 
			{
				l=mid+1;
				ans=mid;
			}
			else 
			{
				r=mid-1;
			}
		}
		delta+=ans;
		a[1]-=n*ans;
		a[1]-=ans;
		anss+=ans;
		if (ans==0) break;
	}
	while (1)
	{
		sort(a+1,a+1+n,cmp);
		if (a[1]+delta<=n-1) break;
		delta++;
		a[1]=a[1]-n-1;
		anss++;
	}
	printf("%lld\n",anss);
}

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

int main(){
int N,a[100001];
cin>>N;
for(int i=1;i<N+1;i++){
  cin>>a[i];
}

int count,b;
for(int i=1;i<N+1;i++){
   b=a[i];
   if(i==a[b]){count++;}
}
cout<<count/2;



return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif

set<int> primes{2,3};
template<class T>
void prime_factors(T n, map<T, int>&out) {
    if(n == 1) { // n=1 の素因数分解は n^1
        //out[n] = 1;
        //return out;
        return;
    }
    for(T i:primes){
        while(n % i == 0) {
            ++out[i]; // 素数i^{out[i]}
            n /= i;
        }
    }
    if(n!=1){
        for(T i = *(primes.rbegin()), _n = n; i*i <= _n; i+=2) {
            if(n%i==0){
                primes.insert(i);
                while(n % i == 0) {
                    ++out[i]; // 素数i^{out[i]}
                    n /= i;
                }
            }
        }
    }
    if(n != 1) out[n] = 1;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    map<int,int> f;
    map<int,int> buf;
    REP(i,2,n+1){
        buf.clear();
        cerr<<__LINE__<<endl;
        prime_factors(i,buf);
        cerr<<__LINE__<<endl;
        for(auto&& b:buf){
            f[b.F]+=b.S;
        }
        cerr<<__LINE__<<endl;
    }
    ll ans=1;
    for(auto&& b:f){
        (ans*=b.S+1)%=MOD;
    }
    cout<ans<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int ans=0;
ans=max(ans,10*a+b+c);
ans=max(ans,10*b+a+c);
ans=max(ans,10*c+b+a);
cout<<ans<<endl;}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int r,b;
	r=0;b=0;
	rep(i,n){
		if(s[i] == 'R'){
			r++;
		}else{
			b++;
		}
	}
	s[0] = 'A';
	cout<<(r>b?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<utility>
#include<string>
#include<string.h>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
#include<algorithm>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,q;
    ll k;
    int a[100005]={};
    int p[100005]={};
    scanf("%d%lld%d",&n,&k,&q);
    REP(i,q){
        scanf("%d",&a[i]);
        p[a[i]-1]++;
    }
    REP(i,n){
        int min=q-p[i];
        if(min<k)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

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

using namespace std;
#define ll long long
#define inf 998244353

ll fun(ll n,ll m)
{
    ll s=1;
    while(m)
    {
        if(m&1)
        {
            s=s*n%inf;
        }
        n=n*n%inf;
        m=m/2;
    }
    return s;
}

int main()
{
    string s, t1, t2, t, t3, t4;
    cin >> s;
    int l=s.length();
    int left=(l-1)/2;
    int lr=(l+3)/2;
    t=s;
    reverse(t.begin(),t.end());
    t1=s;
    t1.erase(left);
    t2=s;
    t2.erase(0,left+1);
    t3=t1;
    t4=t2;
    reverse(t3.begin(),t3.end());
    reverse(t4.begin(),t4.end());
    if(s==t&&t1==t3&&t2==t4)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位


int c[51][51];	//nCr->c[n][r];
long double ave[51];

vector<pair<int,int>> G[100000];
bool visited[1000000];
vector< pair<int,int> > v,w;
vector<int> x, y;

signed main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int xi, yi;
		cin >> xi >> yi;
		x.push_back(xi);
		y.push_back(yi);
	}

	//

	int ans = LL_MAX;
	for (int x1 = 0; x1 < N; x1++) {
		for (int x2 = 0; x2 < N; x2++) {
			for (int y1 = 0; y1 < N; y1++) {
				for (int y2 = 0; y2 < N; y2++) {
					int up = max(y[y1], y[y2]), down = min(y[y1], y[y2]), left = min(x[x1], x[x2]), right = max(x[x1], x[x2]);
					int count = 0;
					for (int i = 0; i < N; i++) {
						if (x[i] <= right && x[i] >= left && y[i] <= up && y[i] >= down) count++;
					}
					if (count >= K) {
						int space = (up - down)*(right - left);
						if (space < ans) ans = space;
					}
				}

			}
		}
	}



	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long 

signed main(){
    int K,A,B;
    cin >> K >> A >> B;
    if(A+2 >= B) cout << K + 1 << endl;
    else if(K <= A) cout << K + 1 << endl;
    else cout << (B-A)*(((K-A+1)/2)-1) + B + ((K-A+1) % 2) << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long

using namespace std;

const int N = 3e5 + 7;
const int mod = 1e7;

int w[107], v[107], dp[107][N];

int32_t main() {
    speed;
    int n, W;
    cin >> n >> W;
    for ( int i = 1; i <= n; i++ ) {
        cin >> w[i] >> v[i];
    }
    for ( int i = 0; i <= n; i++ ) {
        for ( int j = 1; j < N; j++ ) {
            dp[i][j] = 1e12;
        }
    }
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            dp[i][j] = dp[i - 1][j];
            if ( v[i] <= j ) {
                dp[i][j] = min( dp[i][j], dp[i - 1][j - v[i]] + w[i] );
            }
        }
    }
    int mx = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( dp[n][i] <= W ) {
            mx = i;
        }
    }
    cout << mx;
}


Measured memory_bytes: 240264
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
LL CNT[26];
int main(){
  string s;cin>>s;LL ans=1;
  for(int i=0;i<s.size();i++){
    CNT[s[i]-'a']++,ans+=i+1-CNT[s[i]-'a'];
  }
  lldout(ans);
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
struct point {
	long long a, b, e, t;
	bool operator <(const point &p)const {
		return t < p.t;
	}
}w[101000];
long long X;
int n;
int main() {
	int i, j;
	scanf("%d%lld", &n,&X);
	long long ss = 0;
	for (i = 1; i <= n; i++) {
		scanf("%lld%lld%lld", &w[i].a, &w[i].b, &w[i].e);
		w[i].t = (X - w[i].a) * w[i].e + w[i].b*w[i].a;
		ss -= w[i].b*w[i].a;
	}
	sort(w + 1, w + n + 1);
	long long res = 0, rr = 1e18;
	for (i = n; i >= 1; i--) {
		if (ss + w[i].t < 0) {
			res += X;
			ss += w[i].t;
		}
		else {
			ss = -ss;
			long long Mn = 1e18;
			for (j = 1; j <= i; j++) {
				Mn = min(Mn, (ss + w[j].b - 1) / w[j].b);
				Mn = min(Mn, (ss + (w[j].e - w[j].b)*w[j].a + w[j].e - 1) / w[j].e);
			}
			rr = min(rr, res + Mn);
			break;
		}
	}
	ss = 0;
	for (i = 1; i <= n; i++) {
		ss += w[i].e*(X - w[i].a);
	}
	res = X*n;
	for (i = 1; i <= n; i++) {
		if (ss - w[i].t > 0) {
			res -= X;
			ss -= w[i].t;
		}
		else {
			long long Mx = 0;
			for (j = i; j <= n; j++) {
				Mx = max(Mx, ss / w[j].e);
				long long t = ss - (w[j].e - w[j].b)*(X - w[j].a);
				if (t > 0) {
					Mx = max(Mx, t / w[j].b);
				}
			}
			rr = min(rr, res - Mx);
			break;
		}
	}
	printf("%lld\n", rr);
}

Measured memory_bytes: 3328
#include <stdio.h>

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

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);

  int ans = 0;
  int MAX = max(max(a,b),c);

  while(MAX-a >= 2){
    a += 2;
    ans++;
  }
  while(MAX-b >= 2){
    b += 2;
    ans++;
  }
  while(MAX-c >= 2){
    c += 2;
    ans++;
  }

  int cnt = 0;
  if(MAX == a) cnt++;
  if(MAX == b) cnt++;
  if(MAX == c) cnt++;

  if(cnt == 1) ans++;
  if(cnt == 2) ans += 2;

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
As = [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]
K = int(input())
print(As[K-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

int main(){
    int n;
    vlai p={10,50,100,500,0};
    while(cin>>n,n){
        vlai c(0,4);
        cin>>c[0]>>c[1]>>c[2]>>c[3];
        int b=(p*c).sum()-n;
        rrep(i,4) while(b>=p[i]){ b-=p[i]; c[i]--;}
        if(p[4]++)cout<<endl;
        rep(i,4){
            if(c[i]>0)cout<<p[i]<<" "<<c[i]<<endl;
        }
    }
}

Measured memory_bytes: 2988
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

int main()
{
	string s;
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		for(int j=i+1;j<s.size()+1;j++)
		{
			bool f=true;
			for(int k=i;k<j;k++)
			{
				if(!(s[k]=='A' || s[k]=='C' || s[k]=='G' || s[k]=='T'))
					f=false;
			}
			if(f)
				ans=max(ans,j-i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

constexpr ll MAX = (ll)(1E+10);

string str;
ll N;

void calc(vll& hoge){
  ll tmp = 1;
  ll pos = 0;
  vvll hoge_vec(1, hoge);
  while(tmp<MAX){
    vll hoge_tmp(N,0);
    REP(i,N) hoge_tmp[i] = hoge_vec[pos][hoge_vec[pos][i]];
    hoge_vec.pb(hoge_tmp);
    tmp<<=1;
    pos++;
  }

  vll ans(N,0);
  REP(i,N) ans[i] = i;

  ll fuga=0;
  ll max_val = MAX;
  while(max_val>0){
    if(max_val%2==1){
      REP(i,N) ans[i] = hoge_vec[fuga][ans[i]];
    }
    max_val>>=1;
    fuga++;
  }
  hoge = ans;
  return;
}

int main(){
  IN(str);
  N = str.size();

  vll hoge(N, 0);
  REP(i,N){
    if(str[i]=='L') hoge[i]=i-1;
    else            hoge[i]=i+1;
  }

  calc(hoge);
  calc(hoge);

  vll ans(N, 0);
  REP(i,N) ans[hoge[i]]++;
  REP(i,N){
    printf("%d ", ans[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 29424
n = gets.chomp.to_i

def gcd3(a,b,c)
  d = a.gcd(b)
  d.gcd(c)
end

result1 = 0
result2 = 0
(1..n).each do |i|
  result1 += gcd3(i,i,i)
end

(1..n).each do |i|
  (1..n).each do |j|
    (1..n).each do |k|
      next if (i == j && j == k)
      result2 += gcd3(i,j,k)
    end
  end
end

puts result1 + result2

Measured memory_bytes: 14340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ll(1e18)
int main()
{
	int n;
	cin>>n;
	ll pr=1;
	int flag=0;
	for(int i=0; i<n; i++){
		ll num;
		cin>>num;
		ll var=inf/pr;
		if(num==0){
			pr=0;
			flag=0;
			break;
		}
		if(num>var){
			flag=1;
		}
		else if(flag==0)
		 pr*=num;
	}
	if(flag)
	 cout<<"-1";
	else
	 cout<<pr;
	return 0;
	
}

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

int main() {
    char a , b;
    cin >> a >> b;
    if ( a == 'H' && b == 'H') {
        cout << 'H' << endl;
    }
    if ( a == 'H' && b == 'D') {
        cout << 'D' << endl;
    }
    if ( a == 'D' && b == 'H') {
        cout << 'D' << endl;;
    }
    if ( a == 'D' && b == 'D') {
        cout << 'H' << endl;
    }
}

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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int n = Integer.parseInt(strArr[0]);
            int m = Integer.parseInt(strArr[1]);
            int ans[] = new int[n];
            for (int i = 0; i < m; i++) {
                strArr = br.readLine().split(" ");
                int a = Integer.parseInt(strArr[0]);
                ans[a - 1]++;
                int b = Integer.parseInt(strArr[1]);
                ans[b - 1]++;
            }
            for (int i = 0; i < n; i++) {
                System.out.println(ans[i]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 24532
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 200500, mod = 998244353;
string s;
int n, cnt[26], z, suf[maxn];
int getlen() {
	memset(cnt, 0, sizeof cnt), z = 26;
	int ans = 1;
	for(int i = n; i--;) {
		if(cnt[s[i]-'a']++ == 0) z--;
		if(z == 0) {
		memset(cnt, 0, sizeof cnt), z = 26;
			ans++;
		}
		suf[i] = ans;
	}
	return ans;
}
vi pos[26];
void purge(int x) {
	for(auto &i : pos) {
		while(!i.empty()&&i.back()<=x) i.pop_back();
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s, n = s.size();
	int len = getlen();
	for(int i = n; i--;) pos[s[i]-'a'].pb(i);
	string ans(len, ' ');
	for(int i = 0; i < len; i++) {
		for(int j = 0; j < 26; j++) {
			if(!pos[j].empty()&&suf[1+pos[j].back()]>=len-i) continue;
			ans[i] = 'a'+j;
			if(!pos[j].empty()) purge(pos[j].back());
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 2196
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

int x, ans;

int main() {
	cin >> x;
	ans = x;
	bool flg = false;
	while (!flg) {
		flg = true;
		for (int i = 2;i*i <= ans;i++) {
			if (ans%i == 0) {
				flg = false;
				break;
			}
		}
		if (!flg)ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  if n-k+1 < i or k < i:
    print(0)
  else:
    print((C[n-k+1][i] * C[k-1][i-1])%mod)



Measured memory_bytes: 83472
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

input = sys.stdin.readline
#import numpy as n



def main():

    N = int(input())
    ans =0
    for i in range(1,N+1):
        num =  int(N/i)
        ans += int(num*(num+1)/2 *i)

    print(ans)





if __name__ == "__main__":
    main()

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = (int)s.size();
    for (int i = 1; i < n; i++) {
        string c = s.substr(n - i);
        if ((n - i) & 1) continue;
        bool can = true;
        for (int j = 0; j < (n - i) / 2; j++) {
            if (s[j] != s[j + (n - i) / 2]) {
                can = false;
                break;
            }
        }
        if (can) {
            cout << (n - i) << '\n';
            exit(0);
        }
    }
    cout << 0 << '\n';
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int testVal = -1;
    int i = 1;
    while ((testVal = sc.nextInt()) != 0) {
      System.out.println(String.format("Case %d: %d", i, testVal));
      i++;
    }
  }
}

Measured memory_bytes: 59832
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int H[2],M[2],K;

void solve() {
    REP(i,2)cin>>H[i]>>M[i];
    cin>>K;
    int s = H[0]*60+M[0];
    int e = H[1]*60+M[1]-K;
    cout << e-s << endl;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;
void io(string s="file"){freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);}


signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;
    if(s.back()=='s'){
        s+="es";
    }else s+="s";
    cout<<s;
}



Measured memory_bytes: 3636
n = int(input())
x = list(map(int, input().split()))

x1 = sorted(x)
tmp1 = n // 2
tmp2 = (n // 2) - 1
val1 = x1[tmp1]
val2 = x1[tmp2]

for i in range(len(x)):
    if x[i] < val1:
        print(val1)
    else:
        print(val2)


Measured memory_bytes: 93780
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vi data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    int ans = 1;
    int num = data.at(0);
    for (int i = 1; i < N; i++) {
        if (data.at(i) < num) {
            ans++;
            num = data.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
#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 = 3001;
const char newl = '\n';

ll modpow(ll n) {
  if(n==0) return 1;
  else if(n%2==0) return modpow(n/2)*modpow(n/2)%MOD;
  else return 2*modpow(n-1)%MOD;
}

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

  ll n, s;
  cin >> n >> s;
  
  ll a, start = modpow(n-1), inv2 = modpow(MOD-2);
  
  vvl dp(n+1, vl(s+1, 0));
  rep(i, n) {
    cin >> a;
    if(a<=s) dp[i+1][a] = start;
    rep2(j, s) {
      dp[i+1][j] += dp[i][j];
      if(j-a>=0) dp[i+1][j] += dp[i][j-a]*inv2;
      dp[i+1][j] %= MOD;
    }
  }
  cout << dp[n][s] << newl;
  return 0;
}

Measured memory_bytes: 73612
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std

int plus(int n) {
    if(n == (int)1e9) {
        return 1;
    } else {
        return n + 1;
    }
}

void solve() {
    int n, k, s;
    std::cin >> n >> k >> s;
    std::vector<int> ans(n);
    rep(i, k) {
        ans[i] = s;
    }
    repeat(i, k, n) {
        ans[i] = plus(s);
    }
    rep(i, n) std::cout << ans[i] << " \n"[i == n - 1];
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 1664