akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,a,b,c] <- getIntList
    ls <- replicateM n getInt
    let zs = map (\g -> zip g ls) gs
            where gs = sequence $ replicate n [0..3]
    let ans = minimum $ map (solve a b c) zs
    print ans

solve a b c z | check = m1 + m2 + m3 + g1 + g2 + g3
              | otherwise = 100000
    where s1 = map snd $ filter ((==1).fst) z
          s2 = map snd $ filter ((==2).fst) z
          s3 = map snd $ filter ((==3).fst) z
          m1 = (10 *) $ (length s1) - 1
          m2 = (10 *) $ (length s2) - 1
          m3 = (10 *) $ (length s3) - 1
          g1 = abs $ a - (sum s1)
          g2 = abs $ b - (sum s2)
          g3 = abs $ c - (sum s3)
          check = all (not . null) [s1,s2,s3]

Measured memory_bytes: 7680
using System;
using System.Collections.Generic;
using System.Linq;


namespace Library
{
    public class Miscelleneous
    {
        public static void print(object j){Console.WriteLine(j.ToString());}
        
        public static void Main(){
            string s;
            int[] I=new int[100];
            int k;
            while(true){
                s=Console.ReadLine();
                if(string.IsNullOrEmpty(s))break;
                k=int.Parse(s);
                I[k-1]++;
            }
            
            int M=I.Max();
            
            for(int i=0;i<100;i++)
                if(I[i]==M)print(i+1);
        }
    }
}

Measured memory_bytes: 9248
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
import numpy as np
a = [0] + a
b = [0] + b
sa = np.cumsum(a)
sb = np.cumsum(b)
ans = 0
r = m
for i in range(n+1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i+r)

print(ans)

Measured memory_bytes: 47440
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String[] arr = new String[n];
    for(int i=0;i<n;i++){
      String type = scan.next();
      arr[i] = type;
    }
    int AC = 0;
    int WA= 0;
    int TLE = 0;
    int RE = 0;
    for(String a:arr){
      if(a.equals("AC")){
        AC++;
      }else if(a.equals("WA")){
        WA++;
      }else if(a.equals("TLE")){
        TLE++;
      }else if(a.equals("RE")){
        RE++;
      }
    }
    System.out.println("AC x " + AC);
    System.out.println("WA x " + WA);
    System.out.println("TLE x " + TLE);
    System.out.println("RE x " + RE);
  }
}

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

vector<int> d(100), f(100);
vector<vector<int>> G(100);
int cnt = 1;

void dfs(int i) {
    d[i] = cnt++;
    for (auto v : G[i]) {
        if (d[v] == 0) dfs(v);
    }
    f[i] = cnt++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[u - 1].push_back(v - 1);
        }
    }
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) dfs(i);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size(); i++) cout << 'x';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = abc162d()

fun abc162d() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val counts = LongArray(3)
    s.forEach { counts[it.toInt() % 3]++ }

    var removeCount = 0L

    for (left in 0 until n) {
        for (mid in left + 1 until n) {
            val right = mid + (mid - left)
            if (right !in s.indices) break
            if (setOf(s[left], s[mid], s[right]).size == 3) removeCount++
        }
    }

    val answer = counts[0] * counts[1] * counts[2] - removeCount

    println(answer)
}


Measured memory_bytes: 55692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
 
int main() {
  
  int X, N;
  cin >> X >> N;
  
  if(100 < X) {
    cout << X << endl;
    return 0;
  }
  
  unordered_map<int, bool> p = unordered_map<int, bool>();
  REP(i, N) {
    int pp;
    cin >> pp;
    p[pp] = true;
  }
  
  int r = X;
  int i = 0;
  
  while(true) {
    if(!p[X - i]) {
      r = X - i;
      break;
    }
    if(!p[X + i]) {
      r = X + i;
      break;
    }
    i++;
  }
  
  cout << r << endl;
  
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
const int maxn=200;
char g[maxn+5][maxn+5];
int dis[maxn+5];
int n;
queue<int> q;
int bfs(int S)
{
    while(!q.empty()) q.pop();
    for(int i=1;i<=n;++i) dis[i]=0;
    q.push(S);
    dis[S]=1;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int v=1;v<=n;++v)
        {
            if(g[u][v]=='0') continue;
            if(dis[v]==0)
            {
                dis[v]=dis[u]+1;
                q.push(v);
            }
            else
                if(dis[v]==dis[u]-1) ;
                else
                if(dis[v]!=dis[u]+1) return -1;
        }
    }
    int mx=0;
    for(int i=1;i<=n;++i) mx=max(mx,dis[i]);
    return mx;
}
int solve()
{
    int ans=-1;
    for(int i=1;i<=n;++i) ans=max(ans,bfs(i));
    return ans;
}
int main()
{

    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%s",g[i]+1);
    cout<<solve()<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
char t3[1510];
int main(){
	int n;
	int a,b;
	int i,j;
	char t;
	scanf("%s",&t1);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",&t3);
		if(strcmp(t3,"replace")==0){
			scanf("%d %d %s",&a,&b,&t2);
			for(j=0;j<b-a+1;j++){
				t1[a+j]=t2[j];
			}
		}
		else if(strcmp(t3,"reverse")==0){
			scanf("%d %d",&a,&b);
			while(a<b){
				t=t1[a];
				t1[a]=t1[b];
				t1[b]=t;
				a++;
				b--;
			}
		}
		else if(strcmp(t3,"print")==0){
			scanf("%d %d",&a,&b);
			for(j=a;j<b+1;j++){
				printf("%c",t1[j]);
			}
			puts("");
		}
	}
	return 0;
}


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

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define endl			"\n"

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

	while(n){
		if(n%10 == 7){
			cout<<"Yes";
			return 0;
		}
		n /= 10;
	}

	cout<<"No";

	return 0;
}


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

//#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
ll mod=1e9+7;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	ll a[n],pref[n+1];
	pref[0]=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		pref[i+1]=pref[i]+a[i];
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ll val=pref[n]-pref[i+1];
		val=val%mod;
		val=(val*a[i])%mod;
		ans+=val;
		ans=ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6764
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;

class Base {
public:
    virtual void f() {
        cout << "base" << endl;
    }
};
class Derive : public Base {
public:
    virtual void f() {
        cout << "derive" << endl;
    }
};
void solve() {
    string s;
    cin >> s;
    if(s[0] == s[2]) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
}

int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var A = IO.GetIntList();

            var ans = A.Sum() >= str[0] ? "Yes" : "No";

            Console.WriteLine(ans);
        }

    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

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

const int base = 1e9 + 7;

int main() {
    int n;
    scanf("%d", &n);

    vector< int> v(n);
    for (int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        v[a]++;
    }

    if (n & 1) {
        if (v[0] != 1) return !printf("0\n");
        for (int i = 2; i < n; i += 2) if (v[i] != 2) return !printf("0\n");
    } else {
        for (int i = 1; i < n; i += 2) if (v[i] != 2) return !printf("0\n");
    }

    n /= 2;
    int res = 1;
    while (n--) {
        (res *= 2) %= base;
    }

    cout << res << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
int a[100005];

int main(){

	scanf("%d ",&n);
	FORI(0, n) {
		scanf("%d ", &a[i]);
		a[i]--;
	}
	int x = 0;
	FORI(0, 100000) {
		if (x == 1) {
			cout << i << endl;
			return 0;
		}
		x = a[x];
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iostream>
#include <set>
#include <map>

const int maxN = (int)2e5 + 10;
using LL = long long;

int N, A[maxN];
LL pref[maxN];

void input()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
        scanf("%d", A + i);
}

std::map<LL, int> map;

void initSet()
{
    pref[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        pref[i] = pref[i - 1] + A[i];
        if (map.find(pref[i]) != map.end())
            map[pref[i]] += 1;
        else
            map.emplace(pref[i], 1);
    }
}

LL solve()
{
    initSet();
    LL ans = 0;
    for (int i = 1; i <= N; i++)
    {
        auto it = map.find(pref[i - 1]);
        if (it != map.end())
            ans += it->second;

        it = map.find(pref[i]);
        if (it->second == 1)
            map.erase(it);
        else
            it->second -= 1;
    }
    return ans;
}

int main()
{
    input();
    std::cout << solve();
    return 0;
}


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

int main() {
  string S;
 
  int count = 0;
  cin >> S;
 vector<char> rS(S.size());

  for (int i = 0; i < S.size(); i++)
  {
    rS.at(i)=S.at(i);
  }
  
 reverse(rS.begin(),rS.end());
  
    for (int i = 0; i < S.size(); i++) {
       if(S.at(i) != rS.at(i))
       {count++;}
    }
  
  cout << count/2 << endl;
  
  
  
}

Measured memory_bytes: 256
X = int(input())
ans = []
def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
    else:
        return 50000

for i in range(1, 45000):
    ans.append(move(X, i))

print(min(ans))


Measured memory_bytes: 43852
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<queue>
#define int long long
using namespace std;
int test[123456], uiop[123456];
signed main() {
	int n, m, k, a, b = 100000000000, ans = 0; string s, t; cin >> n >> m;
	if (n == m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define INF 200001
using namespace std;
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&n);
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);   
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
      }   
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

struct apple {
  ll v;
  ll c;
};

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<apple> vec(a + b + c);
  ll cnt = 0;
  for (auto &v : vec) {
    ll tmp;
    cin >> tmp;
    v = {tmp, (cnt < a) ? 0 : (cnt < a + b) ? 1 : 2};
    ++cnt;
  }

  sort(vec.begin(), vec.end(),
       [](auto &lhs, auto &rhs) { return lhs.v > rhs.v; });

  ll ans = 0;
  ll cnt_c = 0;
  for (auto &v : vec) {
    if (x + y - cnt_c <= 0) {
      break;
    } else if (v.c == 0 && 0 < x) {
      ans += v.v;
      --x;
    } else if (v.c == 1 && 0 < y) {
      ans += v.v;
      --y;
    } else if (v.c == 2) {
      ans += v.v;
      ++cnt_c;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7992
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int64 mpow(int64 mm, int64 xx)
{
	if(xx == 0)
	{
		return 1;
	}
	int64 tmp = mpow(mm, xx / 2);
	tmp *= tmp;
	tmp %= mod;
	if(xx % 2 == 1)
	{
		tmp *= mm;
		tmp %= mod;
	}
	return tmp;
}

int main()
{
	int64 nn, tmp, ans = 1;
	bool zero = false;
	cin >> nn;
	vector<int64> dd(nn + 1, 0);
	cin >> tmp;
	if(tmp != 0)
	{
		cout << 0 << endl;
		return 0;
	}
	dd[tmp]++;
	for(int64 ii = 1;ii < nn;ii++)
	{
		cin >> tmp;
		if(tmp == 0)
		{
			cout << 0 << endl;
			return 0;
		}
		dd[tmp]++;
	}
	for(int64 ii = 1;ii <= nn;ii++)
	{
		if(dd[ii] != 0 && zero)
		{
			cout << 0 << endl;
			return 0;
		}
		if(dd[ii] == 0)
		{
			zero = true;
		}
		ans *= mpow(dd[ii - 1], dd[ii]);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include <iostream>
using namespace std ;
int main ()
{
    int A , B , sum , substract , multi ;
    cin >> A >> B ;
    sum = A + B ;
    substract = A - B ;
    multi = A * B ;

    if (sum >= substract && sum >= multi )
        cout << sum ;
    else if (multi >= sum && multi >= substract)
        cout << multi ;
    else
        cout << substract ;
    return 0 ;




}


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

int main() {
    static const double pi = 3.141592653589793;
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double theta, phi;
    theta = 2.0*pi * (60.0*H + M) / (12.0 * 60.0);
    phi = 2.0*pi * M / 60.0;

    double diff = abs(theta - phi);

    if (diff > pi) diff = 2 * pi - diff;
    double ans = sqrt(A*A + B*B - 2.0*A*B * cos(diff));
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 4172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] num = new int[r][c];
		int sumAll = 0;
		int[] sumR = new int[r];
		int[] sumC = new int[c];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				num[i][j] = Integer.parseInt(in.next());
				sumR[i] += num[i][j];
				sumC[j] += num[i][j];
				sumAll += num[i][j];
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				System.out.print(num[i][j] + " ");	
			}
			System.out.println(sumR[i]);
		}
		for (int j = 0; j < c; j++) {
			System.out.print(sumC[j] + " ");
		}
		System.out.println(sumAll);
		in.close();
	}
}	


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

int main() {
  string s;
  cin >> s;
  int x = s.size();
  int count = 0;
  for (int i=0; i<x/2; i++) {
      if (s[i] != s[x-1-i]) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3628
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
time =0
amin = min(a,b,c,d,e)
time=(n//amin+1 if n%amin != 0 else n/amin)+4
print(int(time))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

		long X = s.nextLong();
		long Y = s.nextLong();
		int count = 1;

		while (X < Y) {
			X = X * 2;
			if (X <= Y) {
				count++;
			} else {
				break;
			}
		}

		System.out.println(count);

	}
}


Measured memory_bytes: 21972
sx,sy,tx,ty = map(int, raw_input().split())
r = ""
r += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
r += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
r += "U"*(ty-sy)+"R"*(tx-sx)
r += "D"*(ty-sy)+"L"*(tx-sx)
print r

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

int main() {
  int N;
  cin >> N;
    
  for(int i = 0; i < N; i++) {
  string S;
  cin >> S;
    if (S == "Y") {
    cout << "Four" << endl;
    break;
    }
    if (i == (N - 1))
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
char tmp[maxn];
string s;

bool read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

void solve() {
  long long res = 0;
  int cnt = 0;
  for (int i = n - 1; i >= 0;) {
    if (i && s[i - 1] == 'B' && s[i] == 'C') {
      cnt++;
      i -= 2;
      continue;
    }
    if (s[i] == 'A') {
      res += cnt;
      i--;
      continue;
    }
    cnt = 0;
    i--;
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(void)
{
    int  a,b[200000],i=0,j,m,n,x,y,z=1;
    char c[10100],s[10100];

    scanf("%d%d",&n,&m);

    while (1)
    {
        if(m<=z) break;
        z=z+n-1;
        i++;
    }
    printf("%d",i);  
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265359
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
double a,b,x;

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

  cin >> a >> b >> x;
  if (x > b*pow(a,2)/2) {
    double c = 2*(a*b-x/a) / pow(a,2);
    cout << setprecision(10) <<  atan(c) * 180/PI << "\n";
  } else {
    double c = pow(b,2)*a/(2*x);
    cout << setprecision(10) << atan(c) * 180/PI << "\n";
  }

  return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		for( int i=0; i<N; i++ ){
			char ch = S.charAt(i);
			char ccc = T.charAt(i);
			String ss = String.valueOf(ch);
			String sss = String.valueOf(ccc);          
			System.out.print(ss+sss);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+999;

int a[maxn],n;

inline bool check(int k){
    if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;
    if((a[n-1]>k&&a[n]>k)||(a[n]>k&&a[n+1]>k))return 0;
    for(int i=1;i<n-1;i++){
        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;
        if((a[n+i]>k&&a[n+i+1]>k)||(a[n-i]>k&&a[n-i-1]>k))return 0;
    }
    return a[1]<=k;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;++i)scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while(l<r){
		int mid=l+r>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	cout<<l;
} 

Measured memory_bytes: 1024
pos = list(map(int, input().split()))
d = [pos[0] - pos[2], pos[1] - pos[3]]

current = [pos[2] + d[1], pos[3] - d[0]]
print(*current, end=" ")
current = [current[0] + d[0], current[1] + d[1]]
print(*current)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

int main()
{
	string str;
	cin >> str;
	rep(i, str.size()-8) {
		cout << str[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
local h, w = io.read("*n", "*n", "*l")
local t = {}
for i = 1, (w + 2) * (h + 2) do t[i] = "." end
for i = 2, h + 1 do
  local s = io.read()
  for j = 2, w + 1 do
    t[(i - 1) * (w + 2) + j] = s:sub(j - 1, j - 1)
  end
end
for i = 2, h + 1 do
  for j = 2, w + 1 do
    local idx = (i - 1) * (w + 2) + j
    if t[idx] == "." then
      local cnt = 0
      local lis = {- w - 3, -w - 2, -w  - 1, -1, 1, w + 1, w + 2, w + 3}
      for k = 1, #lis do
        if t[idx + lis[k]] == "#" then
          cnt = cnt + 1
        end
      end
      io.write(cnt)
    else
      io.write("#")
    end
  end
  io.write("\n")
end


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nCrを返す関数.
long long int comb(long long int n, long long int r){
	if(n < r || n < 0)
		return 0;
	long long int x = 1, y = 1;
	if (n-r < r) r = n - r;
	for (long long int i = 0; i < r; i++)
	{
		x = x * (n - i);
		y = y * (i + 1);
	}
	return x / y;
}


int main(){
	int n;
	cin >> n;
	map<ll, ll> l;
	map<ll, ll> r;
	rep(i, n)
	{
		ll a;
		cin >> a;
		l[a + i + 1]++;
		r[(i + 1) - a]++;
	}
	ll ans = 0;
	for(auto x:l){
		ans += x.second * r[x.first];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 37824
module DoublyLinkedList = struct
  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next
    in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri head ~f =
    let rec doit i ite =
      if ite == head then ()
      else (f i ite.data; doit (i + 1) ite.next)
    in
    doit 0 head.next
end

module L = DoublyLinkedList

let () =
  let n = read_int () in
  let head = L.make () in
  let rec read i =
    if i >= n then ()
    else begin
      match Str.split (Str.regexp " ") (read_line ()) with
      | "insert" :: n :: _ -> (L.insert (int_of_string n) head; read (i + 1))
      | "delete" :: n :: _ -> (L.delete_node (int_of_string n) head; read (i + 1))
      | "deleteFirst" :: _ -> (L.delete_first head; read (i + 1))
      | "deleteLast" :: _ -> (L.delete_last head; read (i + 1))
      | _ -> exit 1
    end
  in
  read 0;
  L.iteri head ~f:(fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n);
  print_newline ()

Measured memory_bytes: 40108
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

int readtime(){
	int hh,mm; scanf("%d:%d",&hh,&mm);
	return 60*hh+mm;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int s; scanf("%d",&s); s--;
		int s_time=readtime();
		int g; scanf("%d",&g); g--;
		int g_time=readtime();

		vector< pair<int,int> > seq[100]; // seq[i] := ( 電車 i の運行予定 )
		rep(i,m){
			int sz; scanf("%d",&sz);
			seq[i].resize(sz);
			rep(j,sz){
				int u; scanf("%d",&u); u--;
				seq[i][j]=make_pair(readtime(),u);
			}
			sort(seq[i].begin(),seq[i].end());
		}

		// train[t][u] := ( 時刻 t に駅 u から発車する電車の情報 )
		static vector< pair<int,int> > train[1440][1000];
		rep(t,1440) rep(u,n) train[t][u].clear();
		rep(i,m){
			rep(j,seq[i].size()){
				int t=seq[i][j].first;
				int u=seq[i][j].second;
				train[t][u].push_back(make_pair(i,j));
			}
		}

		static int dp[1440][1000];
		rep(t,1440) rep(u,n) dp[t][u]=-1; // -1 は到達不可能の意味
		dp[s_time][s]=0;
		rep(t,1439) rep(u,n) if(dp[t][u]!=-1) {
			 dp[t+1][u]=max(dp[t+1][u],dp[t][u]); // 電車に乗らずにその駅で待つ
			 rep(i,train[t][u].size()){ // 電車に乗る
				int id=train[t][u][i].first;
				for(int j=train[t][u][i].second+1;j<seq[id].size();j++){
					int t_next=seq[id][j].first;
					int u_next=seq[id][j].second;
					dp[t_next][u_next]=max(dp[t_next][u_next],max(dp[t][u],t_next-t));
				}
			 }
		}

		int ans=-1;
		rep(t,g_time+1) ans=max(ans,dp[t][g]);
		if(ans==-1) puts("impossible");
		else        printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 26000
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<"   "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<"   "<<#y<<" "<<y<<"   "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define sz(x)	(ll)x.size()
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
//#define endl '\n'
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
//shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above-----------------------------------------------

int main()
{
	boost

	 string st;cin>>st;
	 int s=0;
	 for(char c:st){
        s+=c-'0';
	 }
   if(s%9==0){
    cout<<"Yes"<<endl;
   }
   else{
    cout<<"No"<<endl;
   }
	return 0;
}


Measured memory_bytes: 3708
from sys import setrecursionlimit
setrecursionlimit(1 << 30)

nv, ne, nBad = map(int, input().split())
g = [[] for _ in range(nv)]
for _ in range(ne):
    u, v = map(lambda x: int(x) - 1, input().split())
    g[u].append(v)
    g[v].append(u)
a = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(nBad)]

def dfs(v):
    id[v] = cur
    comps[-1].append(v)
    for to in g[v]:
        if id[to] == None:
            dfs(to)

id = [None] * nv
cur = 0
comps = []
for v in range(nv):
    if id[v] == None:
        comps.append([])
        dfs(v)
        cur += 1
bad = [0] * nv
for u, v in a:
    if id[u] == id[v]:
        bad[u] += 1
        bad[v] += 1
ret = [None] * nv
for v in range(nv):
    ret[v] = len(comps[id[v]]) - 1 - len(g[v]) - bad[v]
print(' '.join(map(str, ret)))

Measured memory_bytes: 382700
#!/usr/bin/env python
import sys
from math import sqrt

def _s(): return sys.stdin.readline().strip()

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

def g(a):
    if len(a)==1:
        yield a
    else:
        for i in range(len(a)):
            ai = a[i]
            for aa in g(a[:i]+a[i+1:]):
                yield [ ai ] + aa
        

n = _i()
xy = [ _ia() for _ in range(n) ]

s = 0
c = 0
for a in g(xy):
    dist = 0
    prev = None
    for nxt in a:
        if prev:
            dist += sqrt( (prev[0]-nxt[0])**2 + (prev[1]-nxt[1])**2 )
        prev = nxt
    s += dist
    c +=1
#
print(s/c)


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

 using namespace std ;


const int N = 150000;

int  n,k,m,ans=1e6+2,x,t[N],a[N];
map <int , int > mp ;



int main(){
string ch,s;
    cin>>ch>>s ;
    for (int i = 0 ;i<ch.length();i++){
        if (ch[i]==s[i])n++;
            }
    cout<<n ;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		for(int i = 0; i < n - 1; i++) {
			buka[sc.nextInt() - 1]++;
		}

		for(int var : buka) {
			System.out.println(var);
		}

		sc.close();
	}
}


Measured memory_bytes: 53788
let n = Scanf.scanf " %d" (+) 0
let g = Array.make n []
let cs = Array.make n 0
let ans = Array.make n 0
let ci = ref 0
let rec f v p =
  ans.(v) <- cs.(!ci); incr ci;
  List.iter (fun u -> if u <> p then f u v) g.(v)
let _ =
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d" @@ fun u v ->
      g.(u - 1) <- v - 1 :: g.(u - 1); g.(v - 1) <- u - 1 :: g.(v - 1) done;
  for i = 0 to n - 1 do Scanf.scanf " %d" @@ fun c -> cs.(i) <- c done;
  Array.sort (fun x y -> y - x) cs;
  f 0 @@ -1;
  Array.fold_left (+) 0 cs - Array.fold_left max 0 cs |> Printf.printf "%d\n";
  ans |> Array.iter @@ Printf.printf "%d\n"

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    vector<ll> a(3);
    REP(i,3)cin>>a[i];
    
    REP(i,3){
        if(a[i]%2==0){
            cout<<0<<endl;
            return 0;
        }
    }
    
    set<ll> m;
    REP(i,3)REP(j,3){
        if(i!=j)m.insert(a[i]*a[j]);
    }
    
    cout<<*(m.begin())<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int ans=0;
		for(int i=0; i<10; i++){
			for(int j=0; j<10;j++){
				for(int k=0; k<10; k++){
					int[] se={i,j,k};
					int index=0;
					for(int p=0; p<n; p++){
						if(se[index]==s.charAt(p)-'0'){
							index++;
							if(index==3){
								ans++;
								break;
							}
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n;
  cin >> n;
  int a1[101] = {};
  int a2[101] = {};
  for(int i=0;i<n;i++){
    cin >> a1[i];
  }
  for(int i=0;i<n;i++){
    cin >> a2[i];
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    int temp=0;
    for(int j=0;j<=i;j++){
      temp+=a1[j];
    }
    for(int k=i;k<n;k++){
      temp+=a2[k];
    }
    if(ans < temp)ans=temp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int N,K;
int dp[100000];
int high[100000];



int main(int argc, char *argv[]){
  int h;
  cin>>N>>K;
  for(int i=0; i<N; i++){
    cin>>h;
    high[i]=h;
    dp[i]=-1;
    
  }
  dp[0]=0;
  //vector<int> vec(K,0);
  for(int i=1; i<N; i++){
    vector<int> vec;
    for(int j=1; j<=K; j++){
      if(i-j<0) break;
      int tmp=dp[i-j]+abs(high[i]-high[i-j]);
      vec.push_back(tmp);
      
    }
    dp[i]=*min_element(vec.begin(), vec.end());
    //  cout<<i<<" "<<dp[i]<<endl;
  }
  cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int main(void) {
	int a, b;
	while(1){
		cin >> a >> b;
		if (a == 0 && b == 0){
			break;
		}

		if(a < b) {
			cout << a << " " << b << "\n";
		} else {
			cout << b << " " << a << "\n";
		}
	}
}

Measured memory_bytes: 1160
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn ceildiv(a: i64, b: i64) -> i64 {
    (a + b - 1) / b
}

fn main() {
    let mut sc = Scanner::new();
    let s: i64 = sc.cin();
    let t: i64 = sc.cin();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let a2: i64 = sc.cin();
    let b2: i64 = sc.cin();

    let mut u = (a - a2) * s;
    let mut v = (b - b2) * t;

    if u < 0 {
        u *= -1;
        v *= -1;
    }

    if u + v == 0 {
        put!("infinity");
        return;
    }
    if u > 0 && u + v > 0 {
        put!(0);
        return
    }
    let d = -(u+v);
    if u % d == 0 {
        let times = u / d;
        put!(times * 2);
    } else {
        put!(ceildiv(u, d) * 2 - 1);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        // 入力
        string s = Console.ReadLine().Trim();
        int num = int.Parse(Console.ReadLine());

        //substringで5文字以内の文字をすべて抽出
        string[] t_string = substr(s, num);
        Array.Sort(t_string);

        string[] t_string_sort = t_string.Distinct().ToArray();

        Console.WriteLine(t_string_sort[num - 1]);
    }

    static string[] substr(string str, int n)
    {
        int cnt = 0;
        int len = 0;
        for (int i = 1; i <= n; i++)
        {
            len += str.Length - i + 1;
        }
        string[] t_str = new string[len];
        for (int j = 1; j <= n; j++)
        {
            for (int i = 0; i < str.Length - j + 1; i++)
            {
                t_str[cnt] = str.Substring(i, j);
                cnt++;
            }
        }

        return t_str;
    }

}


Measured memory_bytes: 15072
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]


def loadnum(p):
    ni = 0
    for _ in range(k):
        s = 0
        while (s+w[ni]) <= p:
            s += w[ni]
            ni += 1
            if ni == n:
                return n
    return ni

    # Pの数を2分探索で求める
lp, rp = 0, 10000*100000
while lp < rp:
    mp = (lp+rp)//2
    # 探索するPで荷物をいくつ詰めるか求める
    num = loadnum(mp)
    if num >= n:
        rp = mp
    else:
        lp = mp+1

print(lp)



Measured memory_bytes: 9560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
#include <set>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

class UnionFind
{
private:
    vector<ll> data;
    vector<ll> tree_size;

public:
    UnionFind(ll n)
    {
        data = vector<ll>(n);
        tree_size = vector<ll>(n, 1);
        for (ll i = 0; i < n; ++i)
        {
            data[i] = i;
        }
    }

    ll root(ll a)
    {
        if (data[a] == a) return a;
        else return data[a] = root(data[a]);
    }

    void unite(ll a, ll b)
    {
        ll root_a = root(a);
        ll root_b = root(b);
        if (root_a == root_b)
            return;
        else
        {
            tree_size[root_b] += tree_size[root_a];
            tree_size[root_a] = 0;
            data[root_a] = root_b;
            return;
        }
        return;
    }
    ll get_tree_size(ll a)
    {
        return tree_size[root(a)];
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    vector<set<ll>> friends(N);
    UnionFind uf = UnionFind(N);
    for(size_t i=0;i<M; i++)
    {
        cin >> A[i] >> B[i];
        friends[A[i]-1].insert(B[i]-1);
        friends[B[i]-1].insert(A[i]-1);
        uf.unite(A[i]-1, B[i]-1);
    }
    ll max_size=0;
    for(size_t i=0;i<N; i++)
    {
        //cerr << i << ":" << uf.get_tree_size(i) << endl;
        max_size = max(max_size, ll(uf.get_tree_size(i)));
    }
    /*
    for(size_t ind=0;ind<N;ind++)
    {
        //cerr << ind+1 << ":";
        for(auto i: friends[ind])
        {
            friends[ind].insert(friends[i].begin(), friends[i].end());
            friends[ind].erase(ind);
        }
        for(auto i: friends[ind])
        {
            cerr << i+1 << " ";
        }
        cerr << endl;
        //max_size = max(max_size, ll(friends[ind].size()));
    }
    */
    cout << max_size << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 43748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp111 {
    class Program {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            string date1 = "2019/04/30";

            DateTime dt1 = DateTime.Parse(input);
            DateTime dt2 = DateTime.Parse("2019/04/30");

            if(dt1 > dt2)
            {
                Console.WriteLine("TBD");
            }
            else
            {
                Console.WriteLine("Heisei");
            }

        }        
    }
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 25

enum Type{
	YES,
	NO,
	UNDEFINED,
};

int N,K;
int POW[SIZE];
int table[SIZE];
Type dp[1 << 21];


Type recursive(int state){

	if(dp[state] != UNDEFINED){

		return dp[state];
	}

	//部分集合を先に計算
	for(int loop = 0; loop < N; loop++){

		if(state & (1 << loop)){

			recursive(state-POW[loop]);
		}
	}

	//部分集合に少なくとも1件YESがあれば自分もYES
	int count = 0;

	for(int loop = 0; loop < N; loop++){
		if(state & (1 << loop)){

			if(dp[state-POW[loop]] == YES){

				count++;
				break;
			}
		}
	}

	if(count > 0){

		return dp[state] = YES;

	}

	//自分を調べる
	int sum = 0;
	for(int loop = 0; loop < N; loop++){
		if(state & (1 << loop)){

			sum += table[loop];
		}
	}

	if(sum == K){

		return dp[state] = YES;
	}else{

		return dp[state] = NO;
	}
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d",&N,&K);

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

		scanf("%d",&table[i]);
	}

	dp[0] = NO; //1 <= Kより

	for(int state = 1; state < POW[N]; state++){

		dp[state] = UNDEFINED;
	}

	recursive(POW[N]-1);

	int ans = BIG_NUM;

	for(int state = 0; state < POW[N]; state++){
		if(dp[state] == YES)continue;

		int minus = 0;
		for(int loop = 0; loop < N; loop++){
			if(state & (1 << loop)){

				//Do nothing
			}else{

				minus++;
			}
		}

		ans = min(ans,minus);
	}

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

	return 0;
}



Measured memory_bytes: 7320
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define mem(x,val) memset(x,val,sizeof(x))
#define mk make_pair
#define f(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define upp(v,val) upper_bound(v.begin(),v.end(),val)
#define lower(v,val) lower_bound(v.begin(),v.end(),val)
#define test ll t;cin>>t; while(t--)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define dbg2(x,y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define dbg3(x,y,z) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl
#define dbg4(x,y,z,q) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<", "<<#q<<" = "<<q<<endl
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define S second
#define F first
#define fm(it,m) for(it=m.begin();it!=m.end();it++)
#define ct_set(n) __builtin_popcount(n) // count no of set bits
#define INF 0x3f3f3f3f
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265
#define precision cout<<setprecision(15)
//vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end());
using namespace std;

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
 
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;
 
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}

vector<ll> primes;

bool prime[10005];
void seive()
{
	mem(prime,1);
	prime[0]=0;
	prime[1]=0;
	for(ll i=2;i<=10000;i++)
	{
		if(prime[i]==1)
		{
			for(ll j=i*i;j<=10000;j+=i)
			prime[j]=0;
		}
	}
	
}

ll power(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b%2==1)
		ans=(ans%mod*a%mod)%mod;
		a=(a*a)%mod;
		b=b/2;
	}
	return ans;
}

template <typename T>
std::string NumberToString ( T Number )
{
 std::ostringstream ss;
 ss << Number;
 return ss.str();
}

void solve()
{
	double t,x;
	cin>>t>>x;
	cout<<setprecision(20);
	cout<<t/x;

}

int main()
{
	speed()
	
//	seive();
//	for(int i=2;i<=10000;i++)
//	{
//		if(prime[i])
//		primes.pb(i);
//	}
	
	bool codechef=0;
	ll t=1;
	
	if(codechef)
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256