akhauriyash/Code-Regression huggingface dataset:
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(n):
  # 配るdp
  if i+1<=n-1: dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
  if i+2<=n-1: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2])) 
print(dp[n-1])

Measured memory_bytes: 53448
// 161-C Replacing Integer

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return -1 * (*(int*)a - *(int*)b);
}


int main() {

    int i;
    int alp_list[26] = { 0 };
    char word[100001];

    scanf("%s", &word);

    for (i = 0; i < strlen(word); i++) {
        alp_list[word[i] - 'a'] = 1;
    }
    
    for (i = 0; i < sizeof(alp_list) / sizeof(int); i++) {
        if (alp_list[i] == 0) {
            printf("%c",'a'+i);
            return 0;
        }
    }
    printf("None");
    return 0;
}

Measured memory_bytes: 256
k_n = list(map(int,input().split()))
a = list(map(int,input().split()))
dis = []
total_dis = 0
max_dis = 0
for i in range(k_n[1]):
  if(i < (k_n[1]-1)):
    dis.append(a[i+1] - a[i])
  else:
    dis.append(k_n[0] - a[i] + a[0])
  
  if(max_dis <= dis[i]):
    max_dis = dis[i]
    
  total_dis+= dis[i]

total_dis -= max_dis
print(total_dis)

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

int main()
{

  int n ;
  cin >> n ;
  string s;
  cin >> s  ;
  
  int ans = 0 ;

  for(int i=0;i+1<s.size();i++){
      if(s[i]!=s[i+1]){
          ans++;
      }
  }

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



Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

#define VMAX 100

struct OwnEdge
{
	int f, t, flow, cap,cost;
	OwnEdge(int f, int t, int flow, int cap,int cost) :f(f), t(t), flow(flow), cap(cap),cost(cost) {}
};

vector<OwnEdge> G[VMAX];
int h[VMAX], tod[VMAX], prevv[VMAX], preve[VMAX];

int solve(int n, int src, int dest, int F)
{
	int ans = 0;
	while (F > 0)
	{
		fill(tod, tod + VMAX, INF);
		priority_queue<pii, vector<pii>, greater<pii>> pq;
		tod[src] = 0;
		pq.push(make_pair(0, src));
		while (!pq.empty())
		{
			pii temp = pq.top();
			pq.pop();
			if (tod[temp.second] < temp.first)
			{
				continue;
			}
			for (int i = 0; i != G[temp.second].size(); i++)
			{
				if (G[temp.second][i].cap <= G[temp.second][i].flow)
				{
					continue;
				}
				if (tod[G[temp.second][i].t] + h[G[temp.second][i].t]>temp.first + h[temp.second] + G[temp.second][i].cost)
				{
					tod[G[temp.second][i].t] = tod[temp.second] + h[temp.second] + G[temp.second][i].cost - h[G[temp.second][i].t];
					prevv[G[temp.second][i].t] = temp.second;
					preve[G[temp.second][i].t] = i;
					pq.push(make_pair(tod[G[temp.second][i].t], G[temp.second][i].t));
				}
			}
		}

		if (tod[dest] == INF)
		{
			return -1;
		}

		for (int i = 0; i < n; i++)
		{
			h[i] += tod[i];
		}
		int td = F;
		for (int i = dest; i != src; i = prevv[i])
		{
			td = min(td, G[prevv[i]][preve[i]].cap - G[prevv[i]][preve[i]].flow);
		}
		F -= td;
		ans += td*h[dest];
		for (int i = dest; i != src; i = prevv[i])
		{
			G[prevv[i]][preve[i]].flow += td;
			G[i][G[prevv[i]][preve[i]].f].flow -= td;
		}
	}
	return ans;
}

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

	int V, E, F;
	cin >> V >> E >> F;

	for (int i = 0; i < E; i++)
	{
		int u, v, c, d;
		cin >> u >> v >> c >> d;

		int tus = G[u].size(), tvs = G[v].size();

		G[u].push_back(OwnEdge(tvs, v, 0, c, d));
		G[v].push_back(OwnEdge(tus, u, c, c, -d));
	}

	cout << solve(V, 0, V - 1, F) << endl;

	return 0;
}


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

int main()
{
    int a[3],k;
    while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&k)==4)
    {
        int res;
        sort(a,a+3);
        res=a[0]+a[1];
        for(int i=0;i<k;i++)
            a[2]*=2;
        res+=a[2];
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   string s;
   cin>>s;
   int d=s.length();
   if(s[d-1]=='s'){
    cout<<s<<"es"<<"\n";
   }else{
    cout<<s<<'s'<<"\n";
   }



}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int exp(int a, int b)
{
    if (b == 0)
    {
        return 1;
    }
    return a * exp(a, b - 1);
}

int main()
{
    int D, N;
    cin >> D >> N;
    if (N != 100)
    {
        cout << exp(100, D) * N << endl;
    }
    else
    {
        cout << exp(100, D) * (N + 1) << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var list = new Dictionary<int, int>();

            for (int i = 0; i < n; i++)
            {
                list.Add(i, int.Parse(Console.ReadLine()));
            }

            var min = list[0];
            var max = int.MinValue;

            for (int i = 1; i < n; i++)
            {
                max = max > (list[i] - min) ? max : list[i] - min;
                min = min < list[i] ? min : list[i];
            }

            Console.WriteLine(max);
        }
    }
}

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

int main() {

    while(1){
        int n, x;
        cin >> n >> x;

        if(n==0) return 0;

        int res = 0;
        for(int a = 1; a <= n-2; ++a){
            for(int b = a+1; b <= n-1; ++b){
                for(int c = b+1; c <= n; ++c){

                    if(a+b+c == x) ++res;
                }
            }
        }

        cout << res << endl;

    }

    return 0;
}


Measured memory_bytes: 3056
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

void _yn(bool p) {
	p ? _y() : _n();
}

void _YN(bool p) {
	p ? _Y() : _N();
}


LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




/*****************************************************************************/

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

	int n;
	cin >> n;
	vi a(5);
	int m = ll_INF;
	f(i, 0, 5) {
		cin >> a[i];
		m = min(m, a[i]);
	}
	if (m == 1) {
		cout << 4 + n / m;
	}
	else {
		cout << 5 + n / m;
	}
	return 0;
}

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

int main()
{
    int n, q;
    std::cin >> n >> q;

    std::string s;
    std::cin >> s;

    std::vector<int> pos_ac;
    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            pos_ac.push_back(i);
        }
    }

    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            pos_ac.push_back(i + n);
        }
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        std::cin >> l >> r;
        l--;
        r--;

        auto l_itr = lower_bound(pos_ac.begin(), pos_ac.end(), l);
        auto r_itr = lower_bound(pos_ac.begin(), pos_ac.end(), r);

        int count = r_itr - l_itr;

        std::cout << count << std::endl;
    }
}


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

vector<ll> enumDivisors(ll x) {
  vector<ll> res;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res.push_back(i);
      if (i * i != x) res.push_back(x / i);
    }
  }
  return res;
}

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

  // n の約数についてチェック
  int ans = 0;
  for (ll x : enumDivisors(n)) {
    if (x == 1) continue;
    ll tmp = n;
    while (tmp % x == 0) tmp /= x;
    if (tmp % x == 1) ans++;
  }

  // n - 1 の約数は条件を満たす
  ans += enumDivisors(n - 1).size() - 1;

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

Measured memory_bytes: 3708
#include <iostream>

namespace myspace{
	
	class vector{
	public:
		void push_back(int);
		int size();
		int &operator[](int);
		vector();
	private:
		int s;
		int box[100];
	};
	
	vector::vector()
	{
		s = 0;
	}
	
	int &vector::operator[](int i)
	{
		return box[i];
	}
	
	int vector::size()
	{
		return s;
	}
	
	void vector::push_back(int input)
	{
		box[s] = input;
		s++;
	}
}//??????????????????myspac

using namespace myspace;
using namespace std;

void Output(vector A)
{
    int i;
    for(i=0;i<A.size()-1;i++){
        cout << A[i] << " ";
    }
    cout << A[i] << endl;
}
 
void InsertionSort(vector A,int n)
{
    for(int i=0;i<n;i++)
    {
        int v = A[i];
        int j = i - 1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        Output(A);
    }
}
 
int main()
{   
    int n;
    cin >> n;
     
    vector A;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
    InsertionSort(A, n);
     
    return 0;
}

Measured memory_bytes: 1160
#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))
#define all(v) v.begin(), v.end()

int main(void){
	int n,a;
	cin>>n;
	vector<int> A;
	rep(i,n){
		cin>>a;
		A.push_back(a);
	}
	sort(all(A));
	int bi=0,ei=n-1;
	vector<int> m1,m2;
	while(bi <= ei){
		m1.push_back(A[bi]);
		bi++;
		if(bi>ei) break;
		m1.push_back(A[ei]);
		ei--;
	}
	bi=0;ei=n-1;
	while(bi <= ei){
		m2.push_back(A[ei]);
		ei--;
		if(bi>ei) break;
		m2.push_back(A[bi]);
		bi++;
	}
	int tmp = m1[m1.size()-1];
	REPS(i,n){
		m1[i] = m1[i-1];
	}
	m1[0] = tmp;


	tmp = m2[m2.size() -1];
	REPS(i,n){
		m2[i] = m2[i-1];
	}
	m2[0] = tmp;
	ll ans1=0,ans2=0;
	rep(i,n-1){
		//cout<<m1[i]<<endl;
		ans1 += abs(m1[i+1] - m1[i]);
		ans2 += abs(m2[i+1] - m2[i]);
	}

	cout<<max(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define MOD(x) ((x) >= mod ? (x) - mod : (x))
#define ll long long
using namespace std;
const int maxn = 510, inf = 1e9 + 233, mod = 998244353;
int n, m, ans, cnt;
int a[maxn], b[maxn][maxn];

template<typename T>
inline void read(T &k)
{
	int f = 1; k = 0; char c = getchar();
	while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
	while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
	k *= f;
}

inline int power(int a, int b)
{
	int ans = 1; 
	for (; b; b >>= 1, a = 1ll * a * a % mod)
		if (b & 1) ans = 1ll * ans * a % mod;
	return ans;
}

int main()
{
	read(n); read(m); 
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			read(a[j]);

		bool flag = 1;
		for (int j = 1; j <= m; j++)
			if (a[j])
			{
				if (b[j][0])
				{
					for (int k = 1; k <= m; k++)
						a[k] ^= b[j][k];
				}
				else
				{
					b[j][0] = 1;
					for (int k = 1; k <= m; k++)
						b[j][k] = a[k];

					flag = 0;
					break;
				}
			}

		cnt += flag;
	}

	ans = power(2, n) - power(2, cnt) + mod; ans = MOD(ans);
	printf("%lld\n", 1ll * ans * power(2, m - 1) % mod);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int N;
vector<vector<pair<int, int>>> b;
vector<char> ans;
vector<bool> seen;

void dfs(int a, int p, bool c) {
    if (seen[a]) {
        return;
    }
    
    seen[a] = true;
    ans[a] = (c ? '1' : '0');
    
    rep(i, b[a].size()) {
        dfs(b[a][i].first, a, ((b[a][i].second % 2 == 0) ? c : !c));
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N;
    ans.resize(N);
    b.resize(N);
    seen.resize(N, false);
    
    rep(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        
        b[u].push_back(pair<int, int>(v, w));
        b[v].push_back(pair<int, int>(u, w));
    }
    
    dfs(0, -1, false);
    
    rep(i, N) {
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;
 
#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())
 
ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

void mod_add(ll &a, ll b) {
  a += b;
  if(a > mod) a -= mod;
}
void mod_sub(ll &a, ll b) {
  a -= b;
  if(a < 0) a += mod;
}

//only for variables and vectors; 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);

  ll t, n, m, i, j, k, q, u, v;
  // cin >> t;
  // ll tc = t;
  t = 1;
  while (t--)
  {
    cin >> n;
    m = n + 1 >> 1;
    
    printf("%.9lf", (double)m / n);
    // cout << "Case #" << tc - t << ": ";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=400+10,maxm=1e5+10;
int n,m,x[maxm],y[maxm];
bool ok[maxn],S[maxn][maxn];
bool check(int i,int j)
{
	for (int k=1;k<=n;k++)
	    if (S[i][k]&&S[j][k])
	        return 0;
	return 1;
}
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++) scanf("%d%d",&x[i],&y[i]);
	for (int i=1;i<=n;i++)
	{
	    ok[i]=1;
	    S[i][i]=1;
		for (int j=m;j>=1;j--)
		{
		    if (S[i][x[j]]&&S[i][y[j]])
		    {
		    	ok[i]=0;break;
			}
			if (S[i][x[j]]&&!S[i][y[j]])
			    S[i][y[j]]=1;
			if (!S[i][x[j]]&&S[i][y[j]])
			    S[i][x[j]]=1;
		}
	}
	int ans=0;
	for (int i=1;i<=n;i++)
	    for (int j=i+1;j<=n;j++)
	        if (ok[i]&&ok[j]&&check(i,j))
	            ans++;
	cout<<ans;
	return 0;
}

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

struct node {
	int ch[30];
	int cnt;
};

node trie[2000000];
int nextid = 1;

void print(int nid) {
	cout << "#" << nid << ": " << trie[nid].cnt << endl;
	for (char c = 'a'; c <= 'z'; ++c) {
		if (trie[nid].ch[c-'a']!=0) {
			cout << c << " " << trie[nid].ch[c-'a'] << endl;
		}
	}
	for (char c = 'a'; c <= 'z'; ++c) {
		if (trie[nid].ch[c-'a']!=0) {
			print(trie[nid].ch[c-'a']);
		}
	}
}


int main() {
	int N;
	cin >> N;
	vector<string> strs(N);
	for (auto& s : strs) {
		cin >> s;
		reverse(begin(s), end(s));

		int nid = 0;
		for (int i = 0; i < s.size(); ++i) {
			if (trie[nid].ch[s[i]-'a'] == 0) {
				trie[nid].ch[s[i]-'a'] = nextid++;
			}
			nid = trie[nid].ch[s[i]-'a'];
		}
		trie[nid].cnt++;
	}
	// print(0);
	int64_t ans = 0;
	unordered_map<string, int> cnts; 
	for (auto& s : strs) {
		map<char, int> last;
		set<char> rem;
		for (int i = 0; i < s.size(); ++i) {
			last[s[i]] = i;
			rem.insert(s[i]);
		}
		int nid = 0;
		for (int i = 0; i < (int)s.size()-1; ++i) {
			for (char c : rem) {
				if (trie[nid].ch[c-'a'] == 0)
					continue;
				// cout << s.substr(0, i) << " " << c << " " << trie[trie[nid].ch[c-'a']].cnt << endl;
				ans += trie[trie[nid].ch[c-'a']].cnt;
			}
			if (trie[nid].ch[s[i]-'a'] == 0)
				break;
			nid = trie[nid].ch[s[i]-'a'];
			if (last[s[i]] == i)
				rem.erase(s[i]);
		}
		ans += cnts[s];
		cnts[s]++;
		// cout << s << " " << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 126872
#include<bits/stdc++.h>
using namespace std;
int n,k,a[55];
int ans;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=n;i>=n-k+1;i--)ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<int> h(n);

  for (int i=0; i<n; i++) cin>>h[i];
  int hmax = -1;
  for (int i=0; i<n; i++) {
    if (hmax <= h[i]) ans++;
    hmax = max( hmax, h[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
using namespace std;
int main(){
     int a,b,c,x,y;
     cin >> x >> y >> a >> b >> c;
     vector<long long> p(a),q(b),r(c);
     for(int i=0;i<a;i++){
         cin >> p[i];
     }
     for(int k=0;k<b;k++){
         cin >> q[k];
     }
     for(int i=0;i<c;i++){
         cin >> r[i];
     }
     sort(p.begin(),p.end());
     sort(q.begin(),q.end());
     reverse(p.begin(),p.end());
     reverse(q.begin(),q.end());
     vector<long long> as;
     for(int i=0;i<x;i++)as.push_back(p[i]);
     for(int i=0;i<y;i++)as.push_back(q[i]);
     for(int i=0;i<c;i++)as.push_back(r[i]);
     sort(as.begin(),as.end());
     reverse(as.begin(),as.end());
     long long ans=0;
     for(int i=0;i<x+y;i++){
         ans = ans + as[i];
     }
     cout << ans; 
}


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

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  
  rep(i,n) a[i]--;
  
  int ans = 0;
  
  rep(i,n){
    ans += b[a[i]];
  }
  rep(i,n-1){
    if(a[i]+1==a[i+1]) ans += c[a[i]];
  }
  cout << ans << endl;
}
  
  


Measured memory_bytes: 256
PROGRAM-ID.                      ABC_999_A.
ENVIRONMENT                      DIVISION.
INPUT-OUTPUT                     SECTION.
FILE-CONTROL.
    SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

DATA                             DIVISION.
FILE                             SECTION.
    FD  SYSIN.
        01 INDATA PIC X(110000).

WORKING-STORAGE                  SECTION.
    01 INP     PIC X(110000).

    01 N       PIC 9(5).
    01 maxlen  PIC 9(6) VALUE 110000.
    01 cur     PIC 9(6) VALUE 1.
    01 i       PIC 9(18) VALUE 1.
    01 j       PIC 9(18).
    01 len     PIC 9(6).
    01 ans     PIC X(6).
    01 a       PIC 9(10).

    01 r       PIC 9(1).
    01 num     PIC 9(2).
    01 sm      PIC 9(6).

    01 ZS      PIC Z(6)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT N.

    OPEN INPUT SYSIN.

    READ SYSIN INTO INP.

    CLOSE SYSIN.

    MOVE N TO maxlen.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO a

        PERFORM GETNUM

        ADD num TO sm

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    MOVE sm TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.

GETNUM                           SECTION.
    MOVE ZERO TO num

    PERFORM UNTIL ZERO = a
        DIVIDE 2 INTO a GIVING a REMAINDER r
        IF ZERO = r THEN
            ADD 1 TO NUM
        ELSE
            EXIT PERFORM
        END-IF
    END-PERFORM.


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

vector<long long> A(51);
vector<long long> P(51);

long long func(long long N, long long X) {
  if(N==0) {
    return 1;
  }
  
  if(X==1) {
    return 0;
  
  } else if(X>=2 && X<=1+A[N-1]) {
    return func(N-1, X-1);
  
  } else if (X==2+A[N-1]) {
    return P[N-1] + 1;
    
  } else if (X>=3+A[N-1] && X<=2+2*A[N-1]) {
    return func(N-1, X-2-A[N-1]) + 1 + P[N-1];
  
  } else if(X==A[N]){
    return P[N];
  }
}

int main() {
  long long N, X;
  cin >> N >> X;
  
  A[0] = 1;
  P[0] = 1;
  for(int i=1; i<=50; i++) {
    A[i] = A[i-1]*2+3;
    P[i] = P[i-1]*2+1;
  }
  
  cout << func(N, X) << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
def min_frog(N,H):
    dp = [0] * (N)
    dp[1] = abs(H[1] - H[0])
    if N > 2:
        for i in range(N-2):
            dp[i+2] = min(dp[i+1] + abs(H[i+2]-H[i+1]), dp[i] + abs(H[i+2] - H[i]))
    return dp[N-1]

print(min_frog(N,H))

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;cin>>a;
  int l=a/100,r=a%100;
  bool ym=true,my=true;
  if(l>12||l<=0)my=false;
  if(r>12||r<=0)ym=false;
  string ans;
  if(ym&&my)ans="AMBIGUOUS";
  if(ym&&!my)ans="YYMM";
  if(!ym&&my)ans="MMYY";
  if(!my&&!ym)ans="NA";
  cout<<ans<<endl;
}

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int x; cin >> x;
    if(x < 600) cout << 8 << endl;
    else if(x < 800) cout << 7 << endl;
    else if(x < 1000) cout << 6 << endl;
    else if(x < 1200) cout << 5 << endl;
    else if(x < 1400) cout << 4 << endl;
    else if(x < 1600) cout << 3 << endl;
    else if(x < 1800) cout << 2 << endl;
    else if(x < 2000) cout << 1 << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main() {
    int H, W,j,k;
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        for(j = 0; j < H;j++){
            for(k = 0;k < W; k++){
                if(j == 0 || j == H-1 || k == 0 || k == W - 1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	rep(i,5){
		int a; cin >> a;
		if(a == 0) cout << i+1 << endl;
	}
} 


Measured memory_bytes: 3648
/*
 * ID: adityaaaaaaaaaaaaaaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define y1 asdgh
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#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

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 1e9 + 7;
int n , k;

signed main() {
    
    fio;
    cin >> n >> k;
    n = (n + 1) / 2;
    if(n >= k){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{     int h[10][3][4];
    for (int i=0;i<10;++i){
        for(int j=0;j<3;++j){
            for (int k=0; k<4;++k){
                h[i][j][k]=0;
            }
        }
    }
    int n;
    int b,f,r,v;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> b >> f >> r >> v;

        h[r-1][f-1][b-1]+=v;

    }

     for (int k=0;k<4;++k){
        for (int j=0;j<3;++j){
            for (int i=0;i<10;++i){
                 cout << " ";
                cout << h[i][j][k];


            }
            cout << endl;
        }
       if(k<3) {cout << "####################"<<endl;}

     }
     return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    vector<P> po;
    map<P, int> mp;
    for (int i = 0, y = 0, x = 0, w = 0; i < N; i++) { cin >> y >> x >> w, po.push_back({y, x}), mp[{y, x}] += w; }
    int ans = 0;
    for (const auto& p : po) {
        const int y = p.first, x = p.second;
        ans = max(ans, mp[{y, x}] + mp[{y - 1, x}] + mp[{y, x - 1}] + mp[{y - 1, x - 1}]);
        ans = max(ans, mp[{y, x}] + mp[{y + 1, x}] + mp[{y, x - 1}] + mp[{y + 1, x - 1}]);
        ans = max(ans, mp[{y, x}] + mp[{y - 1, x}] + mp[{y, x + 1}] + mp[{y - 1, x + 1}]);
        ans = max(ans, mp[{y, x}] + mp[{y + 1, x}] + mp[{y, x + 1}] + mp[{y + 1, x + 1}]);
    }
    cout << ans << " / " << 1 << endl;
    return 0;
}



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

int main() {
    int N, M;
    cin >> N >> M;
    set<int> A;
    set<int> B;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        if (a == 1) {
            A.insert(b);
        }
        if (b == N) {
            B.insert(a);
        }
    }
    rep(i, N) {
        if (A.count(i+1) && B.count(i+1)) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    vector<int> xx(a), yy(a);
    for (int j = 0; j < a; ++j) {
      cin >> xx.at(j) >> yy.at(j);
      --xx.at(j);
    }
    x.at(i) = xx;
    y.at(i) = yy;
  }
  
  int ans = 0;
  for (int i = 1; i <= (1 << n) - 1; ++i) {
    bool ok = true;
    for (int j = 0; j < n; ++j) {
      if (i & (1<<j)) {
        for (int k = 0; k < x.at(j).size(); ++k) {
          if (((i >> x.at(j).at(k)) & 1)  != y.at(j).at(k)) {
            ok = false;
            break;
          }
        }
        if (!ok) {
          break;
        }
      }
    }
    if (ok) {
      int tmp = 0;
      for (int j = 0; j < n; ++j) {
        tmp += ((i & (1 << j)) >> j);
      }
      ans = max(tmp, ans);
    }
  }
  cout << ans << endl;
  return 0;
}
    


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

long int dfs(long int x, long int y)
{
    if (x % y == 0)
        return (2 * x) - y;
    else
        return (x / y) * y * 2 + dfs(y, x % y);
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int n,x;
    cin >> n >> x;
    long int ans = n;
    n -= x;
    ans += dfs(max(n, x), min(n, x));
    cout << ans << endl;
	return 0; 
} 


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
map<ll,ll>::iterator itr ;
ll ans ;
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  cin>>n ;
  ll arr[n] ;
  for(i=0;i<n;i++)
  cin>>arr[i] ;
  sort(arr,arr+n) ;
  cnt=1 ;
  for(i=0;i<n;i++)
  {  if(arr[i]==0)
       {
          cout<<"0\n" ;
          return 0;
      }
        
        if(arr[i]>(inf/cnt))
      {
          cout<<"-1\n" ;
          return 0;
      }
      cnt=(cnt*arr[i]) ;

  }
  cout<<cnt ;
  return 0; }


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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0;

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

    if(A > B){
        ans += A;
        A--;
    }
    else {ans += B;
    B--;
    }
    }

    cout << ans << endl;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned 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 (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n) {
    cin>>a[i];
    a[i]--;
  }
  vi idx(n);
  rep(i,n) idx[a[i]]=i;
  set<int> s;
  ll ans=0;
  rrep(x,n){
    int i = idx[x];
    ll c=0;
    s.insert(i);
    vi l(2,-1);
    vi r(2,n);
    auto it=s.find(i);
    rep(j,2){
      if(it==s.begin())break;
      --it;
      l[j]=*it;
    }
    it=s.find(i);
    rep(j,2){
      ++it;
      if(it==s.end())break;
      r[j]=*it;
    }
    vi ls(2);
    ls[0]=i-l[0];
    ls[1]=l[0]-l[1];
    vi rs(2);
    rs[0]=r[0]-i;
    rs[1]=r[1]-r[0];
    c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];
    
    ans+=c*(x+1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  std::string S; std::cin >> S;
  int N = S.length();

  LL count = 0;
  LL bc_count = 0;
  for (int i = N - 1; i >= 0; --i) {
#if DEBUG
    std::cout << S[i] << ":";
#endif
    if (S[i] == 'C') {
      if (i>0 && S[i - 1] == 'B') {
        ++bc_count;
        --i;
      } else {
        bc_count = 0;
      }
    } else if (S[i] == 'B') {
      bc_count = 0;
    } else {  // S[i] == 'A'
      count += bc_count;
    }
#if DEBUG
    std::cout << bc_count << std::endl;
#endif
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll ans=hell;
        ll A,B,M;
        cin>>A>>B>>M;
        vi a(A);
        vi b(B);
        rep(i,0,A)cin>>a[i];
        rep(i,0,B)cin>>b[i];
        rep(i,0,M)
        {
            ll x,y,c;
            cin>>x>>y>>c;
            x--;
            y--;
            ans=min(ans,max(a[x]+b[y]-c,0ll));
        }
        sort(all(a));
        sort(all(b));
        ans=min(ans,a[0]+b[0]);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: u32,
        a: [i64; n],
    }

    let mut sunuke: i64 = a.iter().sum();
    let mut raccoon: i64 = 0;
    let mut ans = std::i64::MAX;
    for i in 0..n - 1 {
        sunuke -= a[i as usize];
        raccoon += a[i as usize];
        if (sunuke - raccoon).abs() < ans {
            ans = (sunuke - raccoon).abs();
        }
    }
    println!("{}", ans);
}


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

typedef long long ll;

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

    unsigned long long k = 0, n = 0;
    cin >> n >> k;

    vector<int> v(n + 1, 0);
    vector<int> visited(n + 1, 0);
    int king_pos = 1;
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }

    for(int i = 1; i <= min(n + 5, k); i++) {
        king_pos = v[king_pos];

        if(visited[king_pos] > 0) {
            int l = i - visited[king_pos];
            int r = (k - visited[king_pos])%l;
            for(int j = 0; j < r; j++) {
                king_pos = v[king_pos];
            }

            cout << king_pos << endl;
            return 0;
        }
        visited[king_pos] = i;
    }

    cout << king_pos << endl;


    return 0;
}

Measured memory_bytes: 4744
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

A, B = map(int, input().split())

if B == 1:
    print(0)
    exit()

if A >= B:
    print(1)
    exit()

count = 2
B -= (A-1)
while True:
    if A >= B:
        print(count)
        exit()

    count += 1
    B -= (A-1)


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

#define pb push_back

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	for (int i = 1; i <= 5; i++) {
		int a; cin >> a;
		if (a == 0) {
			cout << i;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3536
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

// 約数のvectorを返す
vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }
    return ret;
}

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

    ll n;
    cin >> n;

    int ans = 0;
    auto div = divisor(n);

    for (ll d : div) {
        if (d == 1) continue;

        ll quotient = n;
        while (quotient % d == 0) {
            quotient /= d;
        }

        if (quotient == 1) {
            ans++;
        } else {
            quotient--;
            if (quotient % d == 0) {
                ans++;
            }
        }
    }

    div = divisor(n - 1);
    ans += div.size() - 1;

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;cin>>N;
  vector<int>V(N);
  for(int i=0;i<N;i++){
    cin>>V.at(i);
  }
  sort(V.begin(),V.end());
  double ans=V.at(0);
  
  for(int i=1;i<N;i++){
    ans+=V.at(i);
    ans=ans/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char s[4];
	scanf("%s", s);

	int n = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == '1') {
			n++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

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

	int n;
	cin>>n;
	string ans="";

	//97->122
	while(n){
		n-=1;
		ans = ans + (char)((int)'a'+n%26);
		n/=26;
	}

	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>

#include <cstdio>
#include <cstdlib>

int main(int argc,char** argv){
  int N;
  int K;
  std::cin >> N >> K;
  bool A[N];
  for(int i=0;i<N;i++) A[i] = true;
  for (int i=0;i<K;i++){
    int d;
    std::cin >> d;
    for(int j=0;j<d;j++){
      int tmp;
      std::cin >> tmp;
      A[tmp-1] = false;
    }
  }
  int ret = 0;
  for(int i=0;i<N;i++) if(A[i]) ret++;
  std::cout << ret << std::endl;
  return 0;
}


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

class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		String input = reader.readLine();
		String str[] = input.split(" ");
		int height = Integer.parseInt(str[0]);
		int width = Integer.parseInt(str[1]);
		int area = height * width;
		int roundSpan = (height + width) * 2;

		System.out.println(area + " " + roundSpan);

	}
}

Measured memory_bytes: 24232
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int N;
	cin>>N;
	vector<int> a(N);
	ll ans = 0;
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	for(int i = 0; i < N; i++){
		if( ((i+1) % 2 == 1 )&& (a[i] % 2 == 1)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-12,pi=acos(-1);
int n,ans;
double ang,x,y,dx,dy=1;
int main()
{
	scanf("%d",&n);
	ang=n/180.0*pi;
	while (true)
	{
		x+=dx;
		y+=dy;
		ans++;
		if (fabs(x)<eps && fabs(y)<eps) break;
		double tmp=dx*sin(ang)+dy*cos(ang);
		dx=dx*cos(ang)-dy*sin(ang);
		dy=tmp;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3956
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
using namespace std;

int n;
long long k;
long long a[120000];
long long s[50][2];
long long p[60];
long long allS[60];
long long f[60];
bool flg[60];

void init() {
    p[0] = 1;
    for (int i = 1; i <= 55; ++i) {
        p[i] = p[i - 1] * 2;
    }
}

long long dp(int loc)
{
    if (loc < 0) return 0;
    if (flg[loc]) return f[loc];
    flg[loc] = 1;
    if ((p[loc]&k) == 0)
        f[loc] = (s[loc][0] + dp(loc-1));
    if ((p[loc] & k) > 0)
        f[loc] = max(s[loc][1] + dp(loc - 1), s[loc][0]+((loc == 0)?0:allS[loc - 1]));
    return f[loc];
}

int main()
{
    init();
    scanf("%d",&n);
    scanf("%lld",&k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld",&a[i]);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 50; ++j) {
            if ((p[j]&a[i])) {
                s[j][0] += p[j];
            } else {
                s[j][1] += p[j];                
            }
        }
    }
    for (int i = 0; i < 50; ++i) {
        if (i>0) allS[i] = allS[i-1];
        allS[i]+=max(s[i][0],s[i][1]);
    }
    cout<<dp(49)<<endl;
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;
std::vector<P> assignment;

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

  std::cin >> N >> M;

  if(N % 2 == 1){
      int s = 1, t = N - 1;

      while(M > 0 && s < t){
          assignment.emplace_back(s, t);
          M -= 1;
          s += 1;
          t -= 1;
      }
  }else{
      int s = 1, t = N;

      for(int i=N/2-1;i>0&&M>0;--i){
          if(i % 2 == 1){
              assignment.emplace_back(s, s + i);
              s += 1;
          }else{
              assignment.emplace_back(t - i, t);
              t -= 1;
          }
          M -= 1;
      }
  }

  for(auto &p : assignment){
      int a, b;
      std::tie(a, b) = p;

      std::cout << a << " " << b << std::endl;
  }
}


Measured memory_bytes: 4160
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  bool ans=true;
  vvl c(3,vl(3));
  rep(i,3){
    rep(j,3){
      cin>>c[i][j];
    }
  }
  rep(i,2){
      if(!(c[i+1][0]-c[i][0]==c[i+1][1]-c[i][1] &&c[i+1][1]-c[i][1]==c[i+1][2]-c[i][2]))ans=false;
  }
  rep(i,2){
    if(!(c[0][i+1]-c[0][i]==c[1][i+1]-c[1][i]&& c[1][i+1]-c[1][i]==c[2][i+1]-c[2][i]))ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

Measured memory_bytes: 256
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
    Mbak Seulgi Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int p[1000010];
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    cin >> n;
    ll chaeng = 0;
    for(i=1;i<=1000000;i++) {
        for(j=i;j<=1000000;j+=i) {
            p[j]++;
        }
    }
    for(i=1;i<n;i++) {
        chaeng += p[i];
    }
    cout << chaeng << endl;
    return 0;
}


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

int main() {
    ll n, keta = 0;
    cin >> n;
    if(n<=9) {cout << n << endl; return 0;}
    n++;
    ll temp = n;
    while(temp/10){
        keta++;
        temp/=10;
    }
    ll ans= 0;
    rep(i,keta){
        ans+=9;
    }
    ans+=(temp-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
n,k=map(int, input().split())

array={}
for _ in range(n):
    a,b=map(int, input().split())
    if a not in array:
        array.setdefault(a, b)
    else:
        array[a]+=b
    
array=sorted(array.items())

count=0
for array_ele in array:
    count+=array_ele[1]
    if count>=k:
        print(array_ele[0])
        break

Measured memory_bytes: 14564
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

jumps = 0
point = 1
arrived = [False] * (N + 1)
history = [0] * (N * 2)
arrived[1] = True
history[0] = 1
warped = False

while jumps < K:
    next_point = A[point]
    if not warped and arrived[next_point]:
        last_jump = 0
        while history[last_jump] != next_point:
            last_jump += 1
        loop_num = jumps - last_jump + 1
        jumps += ((K - jumps) // loop_num - 1) * loop_num
        warped = True

    arrived[point] = True
    if jumps < N * 2:
        history[jumps] = point
    point = next_point
    jumps += 1

print(point)

Measured memory_bytes: 32292