akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    char s[1000000];
    int n,m;
    while(cin>>n,n){
        cin>>m>>s;
        int ans = 0;
        for(int i=0;i<m-n*2;++i){
            if(s[i]=='I'){
                for(int j=0;j<n;++j){
                    if(s[i+2*j+1]!='O'||s[i+2*j+2]!='I') break;
                    if(j==n-1) ++ans;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3976
#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 ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



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

    int T=1;
    //cin >> T;
    while(T--){
        ll n;
        cin>>n;
        string s[4] = {"AC", "WA", "TLE", "RE"};
        string z;
        int cnt[4]={0};
        rep(i,n){
            cin>>z;
            rep(j,4){
                if(z==s[j]) cnt[j]++;
            }
        }
        rep(i,4){
            cout<<s[i]<<" x "<<cnt[i]<<el;
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

int main(){

    char s[4];
    int i,j,cont2=0,cont3=0;

    for(i=0;i<3;i++){
        cin >> s[i];
    }
    s[i]='\n';

    for(j=0;j<3;j++){
        if(s[j]=='R' && s[j+1]=='R'){
            cont2++;
        }
        if(s[j]=='R'){
            cont3++;
        }
    }
    if(cont3==0){
        cout << "0\n";
        return 0;
    }
    if(cont2==0){
        cout << "1\n";
        return 0;
    }
    else{
        cout << cont2+1 << endl;
        return 0;
    }
    
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    int cnt_s[26] = {};
    int cnt_t[26] = {};
    int N = S.size();
    rep(i,0,N){
        int num = S[i] - 'a';
        cnt_s[num]++;
        num = T[i] - 'a';
        cnt_t[num]++;
    }
    sort(cnt_s, cnt_s + 26);
    sort(cnt_t, cnt_t + 26);
    rep(i,0,26){
        if(cnt_s[i] != cnt_t[i]){
            print("No");
            return 0;
        }
    }
    print("Yes");

}


Measured memory_bytes: 916
#include<stdio.h>

void insertionSort(int A[], int N);
int A[100];
int main(void){

    int N, i, y;

    scanf("%d",&N);

    for(i = 0 ; i < N; i++){
        scanf("%d",&y);
        A[i] = y;
        if(i > 0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");


    insertionSort(A, N);
    return 0;

}

void insertionSort(int A[], int N){
    int i, j, k, v;

    for(i = 1; i < N; i++){
        v = A[i];
        j = i - 1;

        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }

        for(k = 0;k < N; k++){
            if(k > 0) printf(" ");
            printf("%d",A[k]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 604
room = [[[0]*10 for i in range (0,3)] for k in range (0,4)]

#print(room)

N = int(input())

for loop in range(N):

    b, f, r, v = map(int, input().split())

    room[b-1][f-1][r-1] += v

    #print(room)

for i in range(0,4):
    for j in range(0,3):
        for k in range(0,10):
            print(" %d"%room[i][j][k],end = "")
        print("")
    if i < 3:
        print("#"*20)



Measured memory_bytes: 5620
n=int(input())
import math
ans=0
def yakusu(n):
  ans_local=set()
  for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
      ans_local = ans_local | set([i,n//i]) #setなので平方数でもOK
  return list(ans_local)  #必要に応じてsort
for i in range(1,n+1,2):
    if len(yakusu(i))==8:
        ans+=1
print(ans)

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

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

    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());

        mp[str]++;
    }

    long long res = 0;
    for (const auto& element : mp) {
        res += (long long)element.second * (element.second - 1) / 2;
    }
    

    cout << res << endl;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t q;
    cin >> q;

    for (auto _ : irange(0L, q)) {
        int64_t a, b;
        cin >> a >> b;

        if (a > b) {
            swap(a, b);
        }

        auto c = a * b;

        int64_t s = sqrt(a * b);
        while ((s + 1) * (s + 1) <= c) {
            ++s;
        }

        int64_t ans = 2 * s;

        if (s * s == c) {
            ans -= 2;
            --s;
        } else if (s * (s + 1) >= c) {
            --ans;
        }

        if (a <= s) {
            --ans;
        }

        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
import java.util.*;

/*
説明
*/
public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        
        double ans = n * n * n;

        // ans = ans * ans * ans;
        // if (!first.equals(saigo)) {
        //     ans = "No";
        // }
        System.out.println(String.format("%.12f", ans/27));
    }
}

Measured memory_bytes: 20816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long long> L(N);
    for (int i = 0; i < N; ++i) cin >> L[i];
    sort(L.begin(), L.end()); // L をソートしておく (二分探索に必要)

    long long res = 0;
    
    // a と b を固定
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            // c の動ける範囲の右端を求める
            int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

            // c の動ける範囲は、[j+1, k)
            res += max(k - (j+1), 0);
        }
    }
    cout << res << endl;
}
  
 

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

ll W,H;
vector<pair<ll,bool> > r;//コスト,縦か横(0=縦)

int main(){
  cin >> W >> H;
  rep(i,W){
    ll ptmp;
    cin >> ptmp;
    r.push_back(make_pair(ptmp,1));
  }

  rep(i,H){
    ll qtmp;
    cin >> qtmp;
    r.push_back(make_pair(qtmp,0));
  }

  sort(all(r));

  ll yok=0,tat=0;
  ll ans=0;

  rep(i,H+W){
    if(r[i].second){//横の辺なら
      ans += r[i].first*(H+1-tat);
      yok++;
    }else{
      ans += r[i].first*(W+1-yok);
      tat++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	long long n;
	int k, x, ans;
	k = 0;
	scanf("%lld", &n);
	n++;
		while (n > 0){
			x = (n % 10);
			n = n / 10;
			k++;
		}
		ans = x + (9 * k) - 10;
		printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
 

int main(void)
{

	double  x1, y1, x2, y2,X,Y,D;
	double distance;
	
	scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2);
	
	X = pow(x2-x1,2);
	Y = pow(y2-y1,2);

	D = X + Y;

	distance = sqrt(D);
	
	printf("%f\n",distance);

	return 0;

}

Measured memory_bytes: 652
open Batteries
let n,k = Scanf.sscanf (read_line()) "%d %d" (fun n k -> n,k)
let p = read_line()|>String.split_on_char ' ' |> List.map int_of_string |> List.sort compare
let _ = (List.fold_left (fun a b -> a + b) 0 (List.init k @@ fun o -> List.nth p o)) |> Printf.printf "%d\n"

Measured memory_bytes: 5716
#include <stdio.h>
#include <string.h>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int a, b, hit, blow; const int power[4] = { 1, 10, 100, 1000 };
int main() {
	while (true) {
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) break;
		hit = 0; blow = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if ((a / power[i]) % 10 == (b / power[j]) % 10) {
					if (i == j) {
						hit++;
					}
					else {
						blow++;
					}
				}
			}
		}
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,c=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<=n-3;i++)
	{
	    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
	    c++;
	}
	cout<<c<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=sz(s);
    
    int ans=n;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            ans=min(ans,max(i+1,n-1-i));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main(){
    fast;
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    
    ll brr[n+1]={0}, crr[n+1];
    
    for(ll i=0;i<n;i++)
        brr[arr[i]]++;
    
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        crr[i] = (brr[i]*(brr[i]-1))/2;
        ans += crr[i];
    }
    
    for(ll i=0;i<n;i++)
        cout<<ans - (brr[arr[i]]-1)<<endl;
    
    
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	
	int a[50], b[50], c[50], d[50];
	int N, M;
	cin >> N >> M;
	int ans[50], m[50];
	for(int i = 0; i < N; i++){
		cin >> a[i] >> b[i];
		ans[i] = -1;
		m[i] = 1000000000;
	}
	for(int i = 0; i < M; i++){
		cin >> c[i] >> d[i];
	}
	
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			if(m[i] > abs(a[i] - c[j]) + abs(b[i] - d[j])){
				m[i] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j + 1;
			}
		}
	}
	for(int i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//problem link: 


#include<bits/stdc++.h>

#define PI 3.1415926535897932384626
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,a,b) for(i=a;i<b;i++)
#define ll long long
#define pb push_back
#define popb pop_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ini(a) memset(a,-1,sizeof(a))
#define M (long long)(1e9+7)

#define chk(a) cout << endl << #a << " : " << a << endl
#define chk2(a,b) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;


using namespace std;

typedef pair<int, int>	pi;
typedef pair<int,pi>    pii;
typedef pair<ll, ll>	pl;
typedef pair<ll,pl>     pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pi>		vpi;
typedef vector<pii>     vpii;
typedef vector<pl>		vpl;
typedef vector<pll>     vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

//========================================================================



void solve(){

	int n,x,t;
	cin>>n>>x>>t;
	cout<<((n/x)+(n%x!=0))*t<<endl;
	

}



int main(){

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

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int n;
    cin >> n;
	int c[1000] = {},s[1000] = {},f[1000] = {};
	rep(i,0,n-1)cin >> c[i] >> s[i] >> f[i];

	rep(i,0,n-1){
        int t = 0;
        t = s[i]+c[i];
    
        rep(j,i+1,n-1){
            if(t < s[j])t = s[j];
            else{
                int tt = s[j];
                /*while(tt < t){
                    tt += f[j];
                }
                t = tt;*/

                t = tt + f[j] * ((t-tt+f[j]-1)/f[j]);
            }
            t += c[j];
        }
        P(t);
	}
	P(0);
	return  0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n
 
    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]
 
    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
 
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count_member(self, x):
        return -self.p[self.find(x)]

n,m=map(int,input().split())
uf=UnionFind(n+1)
ans=n

for i in range(m):
  x,y,z=map(int,input().split())
  if not(uf.same(x,y)):
    uf.union(x,y)
    ans-=1
  uf.union(x,y)

print(ans)



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

void cal_div(int m, vector<int>& divisors) {
  for (int i = 1; i*i <= m; ++i) {
    if (m % i == 0) {
      divisors.push_back(i);
      if (i*i != m) divisors.push_back(m/i);
    }
  }
}

bool cal(int tmax, vector<int> a) {
  rep(i, n) a[i] %= tmax;
  sort(a.begin(), a.end());
  int m = accumulate(a.begin(), a.end(), 0) / tmax;

  return accumulate(a.begin(), a.begin()+n-m, 0) <= k;
}

int main() {
  cin >> n >> k;
  vector<int> a(n), divisors;
  rep(i, n) cin >> a[i];
  int sum = accumulate(a.begin(), a.end(), 0);
  
  cal_div(sum, divisors);
  sort(divisors.begin(), divisors.end(), greater<int>() );
  for (int i : divisors) if (cal(i, a)) {
    cout << i << endl;
    break;
  }
  return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  if(n == 1 && m == 1) ans = 1;
  else if(n == 1 || m == 1) ans = (ll)n*m - 2;
  else if(n > 2 && m > 2)ans = (ll)(n-2)*(m-2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#define INF 0x3f3f3f3f
#define NO 1000005
#define MO 10005
#define P 1000000007
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define lln putchar('\n')
typedef long long ll;
typedef double db;
using namespace std;
typedef pair<db, pair<int, int> > pii;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

int n, m, MAX[NO];
pii a[NO];
//variable

void build(int o, int l, int r)
{
	if (l == r)
		MAX[o] = r;
	else
	{
		int mid = l + r >> 1;
		build(o << 1, l, mid);
		build(o << 1 | 1, mid + 1, r);
		MAX[o] = max(MAX[o << 1], MAX[o << 1 | 1]);
	}
}
void add(int o, int l, int r, int pos)
{
	if (l == r && l == pos)
		MAX[o] = -INF;
	else
	{
		int mid = l + r >> 1;
		if (pos > mid)
			add(o << 1 | 1, mid + 1, r, pos);
		else
			add(o << 1, l, mid, pos);
		MAX[o] = max(MAX[o << 1], MAX[o << 1 | 1]);
	}
}
int query(int o, int l, int r, int L, int R)
{
	if (l >= L && r <= R)
		return MAX[o];
	else
	{
		int mid = l + r >> 1, rr = -INF;
		if (L <= mid)
			rr = max(rr, query(o << 1, l, mid, L, R));
		if (R > mid)
			rr = max(rr, query(o << 1 | 1, mid + 1, r, L, R));
		return rr;
	}
}
void init()
{
	n = read(), m = read();
    for (int i = 1; i <= n; i++)
    	a[i].se.se = read(), a[i].se.fi = read();
    sort(a + 1, a + n + 1);
	build(1, 1, m + 1);
    ll ans = 0;
    for (int i = n; i >= 1; i--)
    {
    	//cout << a[i].fi << ' ';
    	if (a[i].se.se > m)
    		continue;
    	int p = query(1, 1, m + 1, 1, m - a[i].se.se + 1);
    	//cout << p << endl;
		if (p == -INF)
    		continue;
    	ans += a[i].se.fi, add(1, 1, m + 1, p);
	}
	cout << ans << endl;
}
//functions

int main()
{
	init();
	return 0;
}
//main

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vll l(100);
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i < 100; ++i) {
        l[i] = l[i-1] + l[i-2];
    }
    cout << l[n] << endl;
}

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


int main(){
  int N;
  cin >> N;
  double count = 0.0;
  for (int i = 1; i < N + 1; i++){
    if (i % 2 == 1){
      count++;
    }
  }
  double p = count / N;
  cout << fixed << setprecision(10);
  cout << p << endl;
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i+1<=N-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i+2<=N-1:
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const long long mod = 1000000007;

int main(){
    string l;
    cin >> l;
    int n = sz(l);
    vector<vll> dp(n+1, vll(2));
    dp[0][0] = 1;
    rep(i, n) {
        if (l[i] == '1') {
            dp[i+1][1] = (dp[i+1][1] + dp[i][0] + dp[i][1]) % mod;
            dp[i+1][1] = (dp[i+1][1] + dp[i][1] * 2) % mod;
            dp[i+1][0] = (dp[i+1][0] + dp[i][0] * 2) % mod;
        }
        else {
            dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % mod;
            dp[i+1][1] = (dp[i+1][1] + dp[i][1] * 2) % mod;
            dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % mod;
        }
    }
    ll ans = (dp[n][1] + dp[n][0]) % mod;
    cout << ans << endl;
    return 0;
}


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

int main(){
	int N;
	int B[101];
	int A[101];

	cin >> N;

	for( int i = 1; i < N; i++ ){
		cin >> B[i];
	}
	
	A[1] = B[1];
	A[2] = B[1];
	for( int i = 2; i < N; i++ ){
		A[i+1] = B[i];
		if( B[i] < A[i] ) A[i] = B[i];
	}

	int sum = 0;
	for( int  i = 1; i <= N; i++ ){
		sum += A[i];
	}

	cout << sum << endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<bool> Ans(N);
  vector<int> pena(N);
  rep(i, M)
  {
    int p;
    string s;
    cin >> p >> s;
    if(Ans.at(p-1))
      continue;
    if(s=="AC"){
      Ans.at(p-1) = true;
    }else{
      pena.at(p-1)++;
    }
  }
  int num = 0,p=0;
  rep(i,N){
    if(Ans.at(i)==true){
      p += pena.at(i);
      num++;
    }
  }
  cout << num <<" " <<p<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	ll n,m;cin>>n>>m;
	ll ans=0,x;
	if(m>=2*n){
		x=(m-2*n)/4;
		ans=x+n;
	}
	else ans=m/2;
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
N = int(input())
A = []
neg = 0
for i in map(int,input().split()):
    if i < 0:
        A.append(-i)
        neg += 1
    else:
        A.append(i)
ans = 0
if neg % 2 == 0:
    ans = sum(A)
else:
    ans = sum(A) - 2 * min(A)
print(ans)

Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

double pi=acos(-1);

int main(){
    double a,b,x;
    cin>>a>>b>>x;

    if(2*x>a*a*b){
        double z=2*b-2*x/(a*a);
        double s=atan(a/z);
        double ans=s*180/pi;
        ans=90-ans;
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    else{
        double y=2*x/(a*b);
        double s=atan(y/b);
        double ans=s*180/pi;
        ans=90-ans;
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }

}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(auto& v: a) scanf("%d", &v);
	sort(begin(a), end(a), std::greater<>());

	i64 ans = a[0];
	for(int i = 1; i < (n - 1) / 2 + 1; i++) ans += a[i] * 2;
	if(n & 1) ans -= a[(n - 1) / 2];
	
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4032
o=input()
e=input()

if len(o)-len(e)==1:
  s=["a"]*(2*len(e)+1)
else:
  s=["a"]*(2*len(e))

for i in range(len(o)):
  s[i*2]=o[i]

for j in range(len(e)):
  s[j*2+1]=e[j]

for k in s:
  print(k,end="")

print("")

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

int main() {
	int k, n, a0; cin >> k >> n >> a0;
	int d[200009], m = -1, da = a0;
	for (int i = 0; i < n - 1; i++) {
		int  a; cin >> a;
		d[i] = a - da; //cout << d[i] << " ";
		if (d[i] > m) m = d[i];
		da = a;
	}
	d[n - 1] = a0 + k - da; //cout << d[n - 1] << " ";
	if (d[n - 1] > m) m = d[n - 1];

	cout << k - m << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

int h, w;
bool ever[400][400];
string field[400];
ll cnt[160000][2];
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };

void dfs(int i, int x, int y) {
    ever[x][y] = 1;
    cnt[i][field[y][x] == '.']++;
    FOR(j, 0, 4) {
        int _x = x + dx[j], _y = y + dy[j];
        if (_x < 0 || _x >= w || _y < 0 || _y >= h)continue;
        if (ever[_x][_y])continue;
        if (field[y][x] == field[_y][_x])continue;
        dfs(i, _x, _y);
    }
}

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

    cin >> h >> w;
    FOR(i, 0, h)cin >> field[i];

    int i = 0;
    FOR(y, 0, h)FOR(x, 0, w) {
        if (ever[x][y])continue;
        dfs(i++, x, y);
    }

    ll ans = 0;
    for (int i = 0; i < 160000; i++) {
        if (cnt[i][0] == 0 && cnt[i][1] == 0)break;
        ans += cnt[i][0] * cnt[i][1];
    }

    cout << ans << "\n";
}

Measured memory_bytes: 18048
import sys
input = sys.stdin.readline
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    dist = abs(A-B)
    ans = V * T - W * T
    if ans >= dist:
        print("YES")
    else:
        print("NO")
if __name__ == "__main__":
    main()

Measured memory_bytes: 61716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define degrees(a) a * 180.0 / M_PI;
#define radians(a) a * M_PI / 180.0;
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll A, B;
  cin >> A >> B;
  string ans;
  if (A > 0) {
    ans = "Positive";
  } else if (A <= 0 && B >= 0) {
    ans = "Zero";
  } else if (A % 2 == B % 2) {
    ans = "Negative";
  } else {
    ans = "Positive";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

int main() {
	optimizar_io
	int n;

	cin >> n;
	cout << 1 - n << "\n";
	return 0;
}

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

#define mod 1000000007

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> A(n);
  rep(i,n){
    cin >> A[i].first;
    A[i].second = i+1;
  }

  sort(A.begin(), A.end());
  rep(i, n) cout << A[i].second << endl;

  return 0;
}


Measured memory_bytes: 3964
import java.util.Scanner;
 
class Main {
    @SuppressWarnings("resource")
    public static void main(String[] args) {
    	//??£?¨?, ?????????
        StringBuilder sb=new StringBuilder("");
         
        Scanner n=new Scanner(System.in);
          
        int a=n.nextInt();
        int b=n.nextInt();
    	//????????¨???         
        //????????¶??°?????????#??????????§??????????????\???°?????????. ??????
        //????????¶??°??¨?\???°??§?????????  #  ??¨ . ????????????
        while (a!=0 || b!=0){
        	
        	for (int c = 0; c < a ; c++){
                for (int d = 0 ; d < b ; d++){
                	//????????¶??°
                    if(c % 2 == 0){
                    	//????????¶??°
                    	if(d % 2 == 0){
                        	sb.append("#");
                        //???????\???°
                        } else if(d % 2 == 1){
                        	sb.append(".");
                        }
                    //???????\???°
                    } else if(c % 2 == 1){
                    	//????????¶??°
                    	if(d % 2 == 0){
                        	sb.append(".");
                        //???????\???°
                        } else if(d % 2 == 1){
                        	sb.append("#");
                        }
                    }
                }
                //??????
                sb.append("\n");  
            }
            
            //??????
            System.out.println(sb);
            a=n.nextInt();
            b=n.nextInt();
            sb=new StringBuilder("");
        }
    }
}

Measured memory_bytes: 27820
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>

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

using namespace std;

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

    set<string> item;
    rep(i, n)
    {
        string val;
        cin >> val;
        item.insert(val);
    }
    cout << item.size() << endl;
    return 0;
}


Measured memory_bytes: 19124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k; cin>>n>>k;
    vector<int> v(n);
    rep(i,n)cin>>v.at(i);

    int ans=0;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=i; j++){
            if(j>n or 2*j<i)continue;
            for(int l=0; l<=j; l++){
                vector<int> tmp;
                for(int o=0; o<l; o++)tmp.push_back(v.at(o));
                for(int o=0; o<j-l; o++)tmp.push_back(v.at(n-1-o));
                sort(all(tmp),greater<int>());
                int sum=0;
                rep(o,2*j-i)sum+=tmp.at(o);
                chmax(ans,sum);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
class Main
  def self.run
    frames = read_inputs
    puts frames.map(&:draw).join("\n")
    puts "\n"
  end

  private

  def self.read_inputs
    frames = []
    while true do
      h, w = gets.split(" ").map(&:to_i)
      case [h, w]
        when [0, 0] then break
        else frames << Frame.new(h, w)
      end
    end
    frames
  end
end

class Frame
  def initialize(height, width)
    @height, @width = height, width
  end

  def draw
    output = "#{border}\n"
    (1..inner_height).each {|i|
      output << "##{"." * inner_width}#\n"
    }
    output << "#{border}\n"
  end

  def border
    "#" * @width
  end

  def inner_height
    @height - 2
  end

  def inner_width
    @width - 2
  end
end

Main.run

Measured memory_bytes: 8784
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))

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

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    int ans = 0;

    for(int i = 0; i < S.size(); i++) {
        if(S.at(i) == '0')ans++;
    }
    
    cout << 2*min(ans,((int)S.size() - ans)) << endl;

    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <string.h>

using namespace std;

#define DIFF_ASCII  0x20		// ASCIIの差分

int main()
{
	string inputStr;
	int strLength = 0;
	
	// 文字列の入力と文字列長の計算
	getline(cin, inputStr);
	strLength = inputStr.size();
	
	// 大文字小文字の変換
	// ASCIIでの大文字小文字は、大文字の方が小さい
	for(int i = 0; i < strLength; i++)
	{
		// 大文字から小文字
		if( ('A' <= inputStr[i]) && ('Z' >= inputStr[i]) )
		{
			inputStr[i] += DIFF_ASCII;
		}
		// 小文字から大文字
		else if( ('a' <= inputStr[i]) && ('z' >= inputStr[i]) )
		{
			inputStr[i] -= DIFF_ASCII;
		}
		// それ以外
		else
		{
			// 何もしない
		}
	}
	
	cout << inputStr << endl;
	
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int x;
  cin >> x;
  if (x == 0){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;

}


Measured memory_bytes: 3648
x = int(input())
if x <= 599:
    print(8)
elif x <= 799:
    print(7)
elif x <= 999:
    print(6)
elif x <= 1199:
    print(5)
elif x<= 1399:
    print(4)
elif x <= 1599:
    print(3)
elif x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9116
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, c, x[109], y[109], p[109], ch[109], par[109];
int cross(int p0, int p1, int p2) {
	return (x[p1] - x[p0]) * (y[p2] - y[p0]) - (x[p2] - x[p0]) * (y[p1] - y[p0]);
}
int root(int pos) {
	if (par[pos] == pos) return pos;
	return par[pos] = root(par[pos]);
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		p[i] = i;
		par[i] = i;
	}
	sort(p, p + n, [](int i, int j) { return x[i] != x[j] ? x[i] < x[j] : y[i] < y[j]; });
	c = 2;
	ch[0] = p[0];
	ch[1] = p[1];
	for (int i = 2; i < n; ++i) {
		while (c >= 2 && cross(ch[c - 1], p[i], ch[c - 2]) < 0) --c;
		ch[c++] = p[i];
	}
	for (int i = n - 2; i >= 0; --i) {
		while (c >= 2 && cross(ch[c - 1], p[i], ch[c - 2]) < 0) --c;
		ch[c++] = p[i];
	}
	--c;
	double dist = 0.0;
	for (int i = 0; i < c; ++i) {
		dist += hypot(x[ch[i]] - x[ch[i + 1]], y[ch[i]] - y[ch[i + 1]]);
		par[root(ch[i])] = root(ch[i + 1]);
	}
	vector<int> va(m), vb(m), perm(m);
	for (int i = 0; i < m; ++i) {
		cin >> va[i] >> vb[i];
		--va[i];
		--vb[i];
		perm[i] = i;
	}
	sort(perm.begin(), perm.end(), [&](int i, int j) { return hypot(x[va[i]] - x[vb[i]], y[va[i]] - y[vb[i]]) < hypot(x[va[j]] - x[vb[j]], y[va[j]] - y[vb[j]]); });
	for (int i = 0; i < m; ++i) {
		if (root(va[perm[i]]) != root(vb[perm[i]])) {
			par[root(va[perm[i]])] = root(vb[perm[i]]);
			dist += hypot(x[va[perm[i]]] - x[vb[perm[i]]], y[va[perm[i]]] - y[vb[perm[i]]]);
		}
	}
	cout << fixed << setprecision(15) << dist << endl;
	return 0;
}


Measured memory_bytes: 3344
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (lst)
  (labels ((f (x)
             (do ((x x (ash x -1))
                  (res 0 (1+ res)))
                 ((oddp x) res))))
    (reduce #'+ (mapcar #'f lst))))

(let ((n (read)))
  (princ (main (read-times n))))


Measured memory_bytes: 60604
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,cnt=0,val,sum=0,tmp=0,tmp2=100000;
	cin>>N>>val;
	cnt += N;
	int arr[N];
	for(int i=0;i<N;i++)cin>>arr[i];
	for(int i=0;i<N;i++)sum += arr[i];
	tmp = val-sum;
	for(int i=0;i<N;i++){
		if(tmp2 > arr[i])tmp2 = arr[i];
	}
	tmp = tmp/tmp2;
	cnt += tmp;
	cout<<cnt<<endl;
	return 0;
}

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

int main()
{
    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;

    vector<pii> cost_num;
    cost_num.emplace_back(q*8, 0);
    cost_num.emplace_back(h*4, 1);
    cost_num.emplace_back(s*2, 2);
    cost_num.emplace_back(d, 3);

    sort(cost_num.begin(), cost_num.end());
    
    ll ans;
    if (cost_num[0].second == 3)
    {
        // cout << n << ' ' << cost_num[0].first <<' ' << cost_num[0].second << ' ' << (n / 2) * cost_num[0].first<< endl;
        if (n % 2 == 0)
            ans = n / 2 * d;
        else
            ans = (n / 2) * d + cost_num[1].first/2;
    }
    else 
        ans = cost_num[0].first / 2 * n;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int w,n;
  int a[40];
  for(int i=0; i<40; i++){
    a[i] = i;
  }
  cin >> w >> n;
  for(int i=0; i<n; i++){
    int s,t;
    char c;
    cin >> s >> c >> t;
    swap(a[s],a[t]);
  }
  for(int i=1; i<=w; i++){
    cout << a[i] << endl;
  }
  return 0;
}

  

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

using namespace std;

typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define mp(p, q) make_pair(p, q)
//３つ以上の値をセットに(3より多いときはカッコ内を増やす)\
sort -> p -> q -> r
#define mt(p, q, r) make_tuple(p, q, r)
#define all(a) a.begin(), a.end()

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

//配列を反転
template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Down(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end(), greater<ll>()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b, greater<ll>()));
  }
}

  void Main()
  {
    vll a(5); V(a);
    vll b(5); rep(i, 5) {b[i] = a[i] % 10; if(b[i] == 0) continue; else b[i] = 10 - b[i];}
    vpll ans(5); rep(i, 5) {ans[i] = mp(b[i], a[i]);}
    Sort(ans);
    ll A = 0; rep(i, 4) {ans[i].second += ans[i].first;}
    rep(i, 5) {A += ans[i].second;}
    fin(A);
  }

  int main()
  {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20); //高精度少数表示
    Main();
    return 0;
  }

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */

#include <iostream>
#include <fstream>

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

class BBuffet {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<int> a(n),b(n),c(n-1);
        rep(i,n){
            in >> a[i];
            a[i]--;
        }
        int ans=0;
        rep(i,n){
            in >> b[i];
            ans+=b[i];
        }
        rep(i,n-1){
            in >> c[i];
        }
        for(int i=0;i<n-1;i++){
            if(a[i]==a[i+1]-1){
                ans+=c[a[i]];
            }
        }
        out << ans << endl;
	}
};


int main() {
	BBuffet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#define ll long long
using namespace std;

int n,tmp[30];
map <string,int> ma;
ll ans=0,sum=0;
char c[15];

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c>'9'||c<'0')&&c!='-')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		memset(tmp,0,sizeof(tmp));
		scanf("%s",c+1);
		for(int j=1;j<=10;j++)
		tmp[c[j]-'a'+1]++;
		string s;
		for(int j=1;j<=26;j++){
			for(int k=1;k<=tmp[j];k++)
			s+=(j+'a'-1);
		}
		ma[s]++;
		ans+=ma[s]-1;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 12800
# 	The program took 8s to solve 36 cases.
# 	The program itself did not take long, because
# I have done it before.

input1 = input().split()
N = int(input1[0]) # No. of items
W = int(input1[1]) # Upper limit of weight

item = [[0]*2 for i in range(N)]
for i in range(N):
	input2 = input().split()
	item[i][0] = int(input2[0])
	item[i][1] = int(input2[1])

v = [[0]*(W+1) for i in range(N)]
for i in range(N):
	for c in range(W+1):
		if (i < 0 or c <= 0):
			v[i][c] = 0
		elif (c-item[i][1] < 0):
			v[i][c] = v[i-1][c]
		else:
			v[i][c] = max(item[i][0] + v[i-1][c-item[i][1]], v[i-1][c])
			
print(v[N-1][W])

Measured memory_bytes: 41988
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String str = sc.next();
        char t = ' ';
        int ans = 0;
        for(int i=0;i<N;i++){
            char a = str.charAt(i); 
            if(a != t){
                ans++;
            }
            t = a;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26068