akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

int main(void){
    int n, m;
    std::cin >> n >> m;
    const int nmax = 50;
    int a[nmax],b[nmax];
    for(int i = 0; i < m; i++){
        std::cin >> a[i] >> b[i];
    }

    std::vector <int> ans(n,0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[j] == i+1){
                ans[i]++;
            }
            if(b[j] == i+1){
                ans[i]++;
            }
        }
    }

    for(int i = 0; i < n; i++){
        std::cout << ans[i] << std::endl;
    }
    return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.awt.Point;

public class Main{
	private static final int MAX = 9999999;

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

		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w == 0 && h == 0) break;

			Point sp = null, gp = null; //X^[g,S[
			ArrayList<ArrayList<Point>> map = new ArrayList<ArrayList<Point>>(); //®«1~5ÌêðL¯µ½}bv
			for(int i=0;i<5;i++) map.add(new ArrayList<Point>());

			for(int i=0;i<h;i++){
				char[] s = sc.next().toCharArray();
				for(int j=0;j<w;j++){
					if(s[j] == 'S'){
						sp = new Point(j,i);
					}
					else if(s[j] == 'G'){
						gp = new Point(j,i);
					}
					else if(s[j] != '.'){
						map.get(s[j] - '1').add(new Point(j,i));
					}
				}
			}

			int first = -1; //Í¶ßÉQbg·×«®«
			int ans = MAX; //Å¬RXg

			//ÅÉQbg·é®«ðè
			for(int start=0;start<5;start++){
				int[][] dp = new int[5][1000];
				for(int i=0;i<5;i++) Arrays.fill(dp[i],MAX);
				int next = (start + 1) % 5;

				for(int i=0;i<map.get(next).size();i++){
					dp[next][i] = dist(sp,map.get(next).get(i));
				}

				int now = next;
				for(;now!=(start+4)%5;now=(now+1)%5){
					for(int i=0;i<map.get(now).size();i++){
						next = (now + 1) % 5;
						for(int j=0;j<map.get(next).size();j++){
							dp[next][j] = Math.min(dp[next][j], dp[now][i]+dist(map.get(now).get(i),map.get(next).get(j)));
						}
					}
				}

				for(int i=0;i<map.get(now).size();i++){
					int d = dp[now][i] + dist(map.get(now).get(i), gp);
					if(ans > d){
						ans = d;
						first = start;
					}
				}
			}

			if(first == -1) System.out.println("NA");
			else System.out.println((first+1) + " " + ans);
		}
	}

	private static int dist(Point a,Point b){
		return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
	string a,b,d;
	cin>>a>>b;
	int c=a.sz;
	d=a;
	int e=0;
	fo(i,c){
      fo(j,c){
        d[j]=a[(j+i)%c];
      }
      if(d==b){
        e=1;
		break;
      }
    }
  if(e)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll MOD=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

const int MAX = (int)1e6;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
     for (int i = 2; i < MAX; i++){
         fac[i] = fac[i - 1] * i % MOD;
         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
         finv[i] = finv[i - 1] * inv[i] % MOD;
     }
 }
 // 二項係数計算
 long long COM(int n, int k){  //nCkの計算をする
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }
 //main関数にCOMinit();を忘れない

int main(){
  COMinit();
  ll N,K;
  cin>>N>>K;
  ll ans(0);
  if (K&1){
    cout << (N / K)*(N/K)*(N/K) << endl;
  }else{
    ans += (N/K)*(N/K)*(N/K);
    ll cnt(0);
    for (int i(1);i<=N;i++){
      if (i%K == K/2){
        cnt++;
      }
    }
    //cout << cnt << endl;
    ans += cnt*cnt*cnt;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 23680
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct DynArrayStack{
    int top;
    int capacity;
    int *array;
};

struct DynArrayStack *CreateStack(){
    struct DynArrayStack *S=malloc(sizeof(struct DynArrayStack));
    if(!S) return NULL;
    S->capacity=100;
    S->top=-1;
    S->array=malloc(S->capacity*sizeof(int));
    if(!S->array) return NULL;
    return S;
}

int IsFullStack(struct DynArrayStack *S){
    return (S->top==S->capacity-1);
}

void DoubleStack(struct DynArrayStack *S){
    S->capacity*=2;
    S->array=realloc(S->array,S->capacity);
}

void Push(struct DynArrayStack *S,int x){
    if(IsFullStack(S)) DoubleStack(S);
    S->array[++S->top]=x;
}

int IsEmptyStack(struct DynArrayStack *S){
    return S->top==-1;
}

int Top(struct DynArrayStack *S){
    if(IsEmptyStack(S)) return INT_MIN;
    return S->array[S->top];
}

int Pop(struct DynArrayStack *S){
    if(IsEmptyStack(S)) return INT_MIN;
    return S->array[S->top--];
}

void DeleteStack(struct DynArrayStack *S){
    if(S){
        if(S->array) free(S->array);
        free(S);
    }
}

int main(void){
    struct DynArrayStack *S=CreateStack();
    char s[100];
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            int a=Pop(S),b=Pop(S);
            int c=a+b;
            Push(S,c);
        }
        else if(s[0]=='-'){
            int a=Pop(S),b=Pop(S);
            int c=b-a;
            Push(S,c);
        }
        else if(s[0]=='*'){
            int a=Pop(S),b=Pop(S);
            int c=a*b;
            Push(S,c);
        }
        else{
            int x=atoi(s);
            Push(S,x);
        }
    }
    printf("%d\n",Top(S));
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,i,j,k,l,m,z;
	cin>>n;
	vector<string> vec;
	for(i=0;i<n;i++)
	{
		string str;
		cin>>str;
		sort(str.begin(),str.end());
		vec.push_back(str);
	}
	sort(vec.begin(),vec.end());
	z=0;
	k=0;
	l=0;
	for(i=0;i<vec.size()-1;i++)
	{
		if(vec[i]==vec[i+1])
		{
			z++;
			l++;
		}
		else
		{
			k+=z*(z+1)/2;
			z=0;
			l=0;
		}
		if(i==vec.size()-2 && l!=0)
		{
			k+=z*(z+1)/2;
		}
	}
	cout<<k<<"\n";
	return 0;
}


Measured memory_bytes: 7436
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, M, sum = 0; cin >> N >> M;
  vector<int> vo(N);
  for(int i = 0; i < N; i++) {
    cin >> vo.at(i);
    sum += vo.at(i);
  }
  sort(vo.begin(), vo.end(), greater<int> ());
  cout << ((vo.at(M - 1) >= (sum + 4 * M - 1)/ (4 * M)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
if (n - 1) * (n - 2) // 2 < k:
    print(-1)
else:
    print(n * (n - 1) // 2 - k)
    for i in range(n, 0, -1):
        for j in range(i + 1, n + 1):
            if k > 0:
                k -= 1
            else:
                print(i, j)


Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>

int main()
{
	int ioi,joi;
	int i,len;
	int ret;
	char IOI[4] = "IOI", JOI[4] = "JOI";
	char str[10001];
	while(1){
		ret=scanf("%s", str);
		if(ret==EOF){
			break;
		}
		ioi=0;
		joi=0;
		len = strlen(str);
		for(i=0; i<len-2; i++){
			if(str[i] == 'J'){
				if(str[i+1]=='O'&&str[i+2]=='I'){
					joi++;
				}
			}
			if(str[i]== 'I'){
				if(str[i+1]=='O'&&str[i+2]=='I'){
					ioi++;
				}
			}
		}
		printf("%d\n", joi);
		printf("%d\n", ioi);
	}
	return 0;
}

Measured memory_bytes: 552
s = input()
t = input()
ans = 10 ** 10
ls = len(s)
lt = len(t)
for i in range(ls - lt + 1):
    cnt = 0
    for j in range(lt):
        if s[i + j] != t[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 9060
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn main() {
    input!(N: usize);
    input!(mut cs: Chars);
    let R: usize = cs
        .iter()
        .fold(0, |acc, &x| if x == 'R' { 1 } else { 0 } + acc);
    let W: usize = cs
        .iter()
        .fold(0, |acc, &x| if x == 'W' { 1 } else { 0 } + acc);

    // 左から見ていく
    let mut left_r = 0;
    for i in 0..R {
        if cs[i] == 'R' {
            left_r += 1;
        }
    }

    cs.reverse();
    // 右から見ていく
    let mut right_w = 0;
    for i in 0..W {
        if cs[i] == 'W' {
            right_w += 1;
        }
    }

    let mut ans = max(R - left_r, W - right_w);

    println!("{}", ans)
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
int a[100010];
const ll mod=1e9+7;
ll qpow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
int vis[100010];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        vis[a[i]]++;
        if(vis[a[i]]>=3)
        {
            printf("0\n");
            return 0;
        }
    }
    if(n%2==0)
    {
        printf("%lld\n",qpow(2ll,n/2));
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[a[i]]==1)
        {
            if(a[i]!=0)
            {
                printf("0\n");
                return 0;
            }
            else
            {
                printf("%lld\n",qpow(2ll,n/2));
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head];
  head =(head +1)%LEN;
  return x;
}
int min(int a,int b){return a<b ? a:b;}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head =1;
  tail=n+1;

  while(head != tail){
    u=dequeue();
    c= min(q,u.t);
    u.t-=c;
    elaps+=c;
    if(u.t>0)enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll p = 0;
  queue<int> q;
  rep(i,k) {
    p += a[i];
    q.push(a[i]);
  }

  for (int i = k; i < n; i++) {
    ll pre = p;
    p -= q.front();
    p += a[i];
    q.pop();
    q.push(a[i]);
    if (p > pre) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 4752
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;

void main() {
  int n, a, b;
  auto l = readln.chomp.split.map!(to!int);
  n = l[0], a = l[1], b = l[2];

  long ans; // longである必要はない

  foreach(i; 1..(n + 1)) {
    int sum, num = i;
    while (num > 0) {
      sum += (num % 10);
      num /= 10;
    }

    if (a <= sum && sum <= b) {
      ans += i;
    }
  }

  ans.writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
#include <list>
using namespace std;
#define FORN(i,m,n) for(ll i=m; i<ll(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;
typedef long double ld;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  cout<<n*n<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	int n,k;
	cin>>n>>k;
	cout<<(n-1)*(k-1);
	return 0;
 }

Measured memory_bytes: 256
L = [0] * 7

num = int(input())

for _ in range(num):
    h = float(input())
    if h < 165:
        L[1] += 1
    elif h < 170:
        L[2] += 1
    elif h < 175:
        L[3] += 1
    elif h < 180:
        L[4] += 1
    elif h < 185:
        L[5] += 1
    else:
        L[6] += 1

for i in range(1,7):
    print("{}:{}".format(i, "*" * L[i]))



Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  if (x == 3 || x == 5 || x == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    for (auto& c : s) {
        c = 'A' + (c - 'A' + n) % 26;
    }
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 505
#define ll long long
int n;
ll ans;
int a[M][M];
ll f[M][M],g[M][M],s[M][M],h[M][M];
ll get_s(int a,int b,int c,int d) {
    return s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1];
}
void work() {
    for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++) s[i][j]=s[i-1][j]+a[i][j];
    for(int j=1;j<=n;j++)
	for(int i=1;i<=n;i++) s[i][j]+=s[i][j-1];
    for(int i=1;i<n;i++)
	for(int j=1;j+i<=n;j++) h[j][j+i]=h[j][j+i-1]+h[j+1][j+i]-h[j+1][j+i-1]+a[j][j+i];
    for(int i=0;i<=n;i++)
	for(int j=0;j<=n;j++) f[i][j]=1e18;
    for(int i=1;i<n;i++)
	{
	    for(int j=0;j<=i;j++) g[j][i]=1e18;
	    for(int j=0;j<i;j++)
		for(int k=j+1;k<i;k++) g[k][i]=min(g[k][i],f[j][k]+get_s(i+1,j+1,n,k)+h[k+1][i]);
	    for(int j=0;j<i;j++) f[j][i]=g[j][i];
	    f[0][i]=h[1][i];
	}
    ans=1e18;
    for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	    ans=min(ans,f[i][j]+h[j+1][n]);
    cout<<ans<<'\n';
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++) if(i!=j) cin>>a[i][j];
    work();
    return 0;
}

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

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

    if(n%10 == 3){
        cout << "bon" << endl;
    }

    else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        cout << "pon" << endl;
    }

    else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3644
#include<stdio.h>
#define N 100

int main(){
  int Array[N];
  int temp;
  int n;
  int i,j;
  int count=0;

  /* Input */
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&Array[i]);
  }

  for(j=0;j<n;j++){
    for(i=n-1;i>=1;i--){
      if(Array[i]<Array[i-1]){
	temp=Array[i-1];
	Array[i-1]=Array[i];
	Array[i]=temp;
	count++;
      }
    }
  }

  /* Output */
  for(i=0;i<n-1;i++){
    printf("%d ",Array[i]);
  }
  printf("%d\n",Array[n-1]);
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2104
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	string S;
	cin >> S;

	int N = S.length();
	int num = 1, win = 0, lose = 0;
	FOR(i, 1, N){
		if(S[i] == 'g'){
			if(num > 0){
				win++;
				num--;
			}
			else{
				num++;
			}
		}
		else{
			if(num > 0){
				num--;
			}
			else{
				lose++;
				num++;
			}
		}
	}

	cout << win - lose << endl;

	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<60)

#define MAX_V (100+2)

struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];  //グラフのパス
int level[MAX_V];       //始点からの距離
int iter[MAX_V];        //どこまで調べたか

// fromからtoへ向かう、容量capの辺をグラフに追加する
void add_edge(int from,int to,int cap){
    G[from].push_back(  (edge){ to  ,cap,(int)G[to  ].size()   }  );
    G[to  ].push_back(  (edge){ from,0  ,(int)G[from].size()-1 }  );
}

// sからの最短距離をBFSで計算する
void bfs(int s){
    rep(i,MAX_V)level[i]=-1;
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        
        rep(i,G[v].size()){
            edge &e=G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

//増加パスをDFSで探す
int dfs(int v,int t,int f){
    if(v==t)return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s,int t){
    if(s==t)return INF;
    int flow=0;
    for(;;){
        bfs(s);
        if(level[t]<0)return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dfs(s,t,INF))>0){
            flow+=f;
        }
    }
}



vector<ll> divisor(ll n){
    vector<ll> ret;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            ret.pb(i);
            if(i!=n/i)ret.pb(n/i);
        }
    }
    //  sort(all(ret));
    return ret;
}

signed main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int S = n;
    int T = S+1;
    
    int posit = 0;
    rep(i,n){
        if(v[i]>0){
            posit+=v[i];
            add_edge(S,i,v[i]);
        }else{
            add_edge(i,T,-v[i]);
        }
    }
    
    for(int i=n-1;i>=0;i--){
        vector<ll> div = divisor(i+1);
        rep(j,div.size()){
            add_edge(i,div[j]-1,INF);
        }
    }
    
    cout<<posit-max_flow(S,T)<<endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
n,m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
  a,b = map(int, input().split())
  uf.union(a-1, b-1)

ans = 0
for i in uf.roots():
  ans = max(ans, uf.size(i))
print(ans)

Measured memory_bytes: 18436
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):
    ret = NO
    n = len(S)
    for i in range(n):
        for j in range(n):
            if (S[i:n] + S[:i]) == T:
                ret = YES
                break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if((a + b) > (c + d))
		printf("Left\n");
	else if((a + b) < (c + d))
		printf("Right\n");
	else
		printf("Balanced\n");
	return 0;
}

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

using namespace std;

#define int long long

void solve() {
    string s;
    int k;
    cin >> s >> k;
    while (s[0] == '0') s.erase(s.begin());
    int dp[s.size()][k + 1][10][2];
    for (int i = 0; i < s.size(); ++i) for (int j = 0; j <= k; ++j) for (int id = 0; id < 10; ++id) for (int id2 = 0; id2 < 2; ++id2) dp[i][j][id][id2] = 0;
    dp[0][0][0][0] = 1;
    for (int i = 1; i < (s[0] - '0'); ++i) dp[0][1][i][0] = 1;
    dp[0][1][s[0] - '0'][1] = 1;
    for (int i = 1; i < s.size(); ++i) {
        for (int j = 0; j <= k; ++j) {
            for (int id = 0; id < 10; ++id) {
                for (int ind = 0; ind < 2; ++ind) {
                    for (int id2 = 0; id2 < 10; ++id2) {
                        if (id2 != 0 && j < k) {
                            //cout << i << ' ' << j << ' ' << id << ' ' << id2 << '\n';
                            if (ind == 0 || (s[i] - '0') >= id2) {
                                if (ind && (s[i] - '0') == id2) dp[i][j + 1][id2][ind] += dp[i - 1][j][id][ind];
                                else dp[i][j + 1][id2][0] += dp[i - 1][j][id][ind];
                            }
                            continue;
                        }
                        if (id2 != 0) continue;
                        if (ind && s[i] == '0') dp[i][j][id2][1] += dp[i - 1][j][id][ind];
                        else dp[i][j][id2][0] += dp[i - 1][j][id][ind];
                    }
                }
            }
        }
    }
    /*for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j <= k; ++j) {
            for (int id = 0; id < 10; ++id) cout << i << ' ' << j << ' ' << id << ' ' << dp[i][j][id].first << ' ' << dp[i][j][id].second << '\n';
        }
    }*/
    int ans = 0;
    for (int i = 0; i < 10; ++i) ans += dp[s.size() - 1][k][i][0] + dp[s.size() - 1][k][i][1];
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int T = scanner.nextInt();
        int A = scanner.nextInt();
        List<Integer> list = IntStream.range(0, N)
                .map(i -> scanner.nextInt())
                .boxed()
                .collect(Collectors.toList());
        System.out.println(list.indexOf(list.stream()
                .min(Comparator.comparingDouble(d -> Math.abs(T - d * 0.006 - A)))
                .orElse(0)) + 1);
    }
}

Measured memory_bytes: 28892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        
        static void SolveA(string[] args)
        {
            int[] nmq = ReadAndParseIntArr();
            int n = nmq[0];
            int m = nmq[1];
            int Q = nmq[2];
            int[] L = new int[m];
            int[] R = new int[m];
            for(int i=0;i<m;++i)
            {
                int[] lr = ReadAndParseIntArr();
                L[i] = lr[0];
                R[i] = lr[1];
            }
            int[] p = new int[Q];
            int[] q = new int[Q];
            for(int i=0;i<Q;++i)
            {
                int[] pq = ReadAndParseIntArr();
                p[i] = pq[0];
                q[i] = pq[1];
            }

            int[,] sum = new int[n+1, n+1];
            for(int i=0;i<m;++i)
            {
                sum[L[i], R[i]] += 1;
            }

            for(int i=1;i<=n;++i)
            {
                for(int j=1;j<=n;++j)
                {
                    sum[i, j] += sum[i - 1,j];
                    sum[i, j] += sum[i, j - 1];
                    sum[i, j] -= sum[i - 1, j - 1];
                }
            }
            
            for(int i=0;i<Q;++i)
            {
                int l = p[i];
                int r = q[i];
                int total = sum[r, r] - sum[l - 1, r] - sum[r, l - 1] + sum[l - 1, l - 1];
                Console.WriteLine(total);
            }
        }
    }
}


Measured memory_bytes: 18828
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1):
        k = y - i*10000 - j*5000
        k = k // 1000
        if i+j+k == n and k >= 0 and k <= n:
            print("{} {} {}".format(i, j ,k))
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

typedef pair<int, int> P;
set<P > s;
// ?????????[begin, end]?????\???

bool ins(int d){
  if(s.size()==0){
    s.insert(mp(d,d));
    return true;
  }
  if(s.begin()->fi==0){
    return false;
  }

  auto p = s.upper_bound(mp(d,INF));
  if(p == s.begin()){
    if(p->fi == d+1){
      s.insert(mp(d, p->se));
      s.erase(p);
      return true;
    } else {
      s.insert(mp(d,d));
      return true;
    }
  }

  p--;
  if(p->fi <= d && p->se >= d ){
    P tmp = *p;
    if(tmp.fi==1 && !(s.size()==1 && tmp.se==d) ) return false;
    if(tmp.se > d) s.insert(mp(d+1, tmp.se));
    s.erase(p);
    return ins(tmp.fi-1);
  }

  int newl=d, newr=d;
  P pl = *p;
  auto pp = p;
  pp++;
  P pr = *pp;

  if(pl.se+1==d){
    newl = pl.fi;
    s.erase(p);
  }
  if(pp!=s.end() && pr.fi-1==d){
    newr = pr.se;
    s.erase(pp);
  }

  s.insert(mp(newl, newr));
  return true;
}

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

  rep(i,n){
    int d;
    scanf("%d", &d);
    if(ins(d)) printf("Yes\n");
    else printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 9884
package main

import (
	"fmt"
)

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	var ans int
	if A <= 5 {
		ans = 0
	} else if A <= 12 {
		ans = B / 2
	} else {
		ans = B
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n,h[100005],ans;
int cnt;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int a=h[0];
    for(int i=1;i<n;i++){
        if(a>=h[i])cnt++,a=h[i];
        else{
            if(cnt>ans)ans=cnt;
            cnt=0,a=h[i];
        }
    }
    if(cnt>ans)ans=cnt;
    cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		System.out.println(Math.max(Math.min(b, d) - Math.max(a, c), 0));
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	string s;
	cin >> s;
	
	int idx = s.size() - 1;
	bool f = true;
	while( idx >= 0 ){
		if( s[idx] == 'm' ){
			string ss = "";
			rep(i,0,5){
				ss += s[idx--];
			}
			if(ss != "maerd" )
				f = false;
		}
		else if( s[idx] == 'e' ){
			string ss ="";
			rep(i,0,5)
				ss += s[idx--];
			if(ss != "esare")
				f = false;
		}
		else if( s[idx] == 'r' ){
			if( idx > 1 && s[idx-2] == 'm' ){
				string ss ="";
				rep(i,0,7)
					ss += s[idx--];
				if(ss != "remaerd")
					f = false;
			}
			else if(idx > 1 && s[idx-2] == 's' ){
					string ss ="";
					rep(i,0,6)
					ss += s[idx--];
					if(ss != "resare")
						f = false;
			}
			else{
				f = false;
				break;
			}
		}

		if(!f)
			break;
	}

	if(f)
		YES;
	else
		NO;

	ret 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n , k ;
    cin >> n >> k ;
    ll res = k ;
    forn(i , 2 , n ) {
       res = res * (k -1) ;
    }
    cout << res << el ;
}































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();
		double ans=0;

		for(int i=0;i<n;i++) {
			double num = sc.nextDouble();
			String str = sc.next();
			if(str.equals("JPY")) {
				ans+=num;
			}else if(str.equals("BTC")) {
				ans+=num*380000.0;
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long a[n];
  for(long long i; i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  bool s = false;
  for(long long i; i<n;i++){
    if(a[i]==a[i+1]){
      s = true;
      break;
    }
  }
  if(s){
    cout << "NO\n";
  }else{
    cout << "YES\n";
  }
}
      

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

int main() {
  int X;
  cin >> X;
  vector<int> d(X);
  for(int i = 0; i < X; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  int sum = 1;
  for(int i = 0; i < (X - 1); i++){
    if(d.at(i) != d.at(i + 1))
      sum ++;
  }
  cout << sum << endl;
}

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

int n,cnt[50][30];
string s[50];
char res[51];
 
int main() {
    cin>>n;
    int index=0;
    rep(i,n) cin>>s[i];
    rep(i,n) rep(j,s[i].size()) cnt[i][s[i][j]-'a']++;
    rep(i,26){
        int c=cnt[0][i];
        for (int k=1;k<n;k++){
            c=min(c,cnt[k][i]);
        }
        for (int k=index;k<index+c;k++) {
            res[k]='a'+i;
        }
        index+=c;
    }
    cout<<res<<endl;  
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

int main()
{
  int w, h, n;
  cin >> w >> h >> n;
  int cx, cy;
  cin >> cx >> cy;
  int tot = 0;
  for (int i = 1; i < n; i++){
    int nx, ny;
    cin >> nx >> ny;
    if ((cx - nx < 0) == (cy - ny < 0)){
      tot += max(abs(cx - nx), abs(cy - ny));
    }
    else {
      tot += abs(cx - nx) + abs(cy - ny);
    }
    cx = nx;
    cy = ny;
  }
  cout << tot << endl;
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
string s;

int main() {
  cin >> s;
  int k;cin >> k;
  set<string> st;
  for (int i=1; i<=k;++i){
    for (int j=0; j<s.size()-i+1;++j){
      string sub = s.substr(j,i);
      st.insert(sub);
    }
  }
  vector<string> vt;
  for(auto itr = st.begin(); itr != st.end();++itr){
    vt.push_back(*itr);
  }
  sort(vt.begin(), vt.end());
  cout << vt[k-1] << endl;
  return 0;
}


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

int main() {

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

    int sum = 0;
    int max = -1;
    for (int i = 0; i < 5; ++i) {
        int time;
        std::cin >> time;
        int ceiled = std::ceil(time / 10.f) * 10;
        max = std::max(max, ceiled - time);
        sum += ceiled;
    }
    std::cout << sum - max << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define name(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int N=(int)1e6+7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r, d, x;
    cin >> r >> d >>  x;
    int  tym = 10;
    while(tym--) {
        x = r * x - d;
        cout << x << '\n';
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  n++;
  vector<Int> h(n),a(n),d(n),s(n);
  for(Int i=0;i<n;i++) cin>>h[i]>>a[i]>>d[i]>>s[i];
  bool f=1;
  for(Int i=1;i<n;i++)
    if(d[0]-a[i]<=0) f=0;
  if(f){
    cout<<0<<endl;
    return 0;
  }
  for(Int i=1;i<n;i++)
    if(a[0]-d[i]<=0&&a[i]-d[0]>0) f=1;
  if(f){
    cout<<-1<<endl;
    return 0;
  }
  //cout<<"OOO"<<endl;
  auto get=[&](Int i,bool f=1){
     Int k=a[0]-d[i];
     if(k<=0) return 0LL;
     Int res=(h[i]+k-1)/k;
     if(f&&s[i]<s[0]) res--;
     return res;
  };
  auto dm=[&](Int i){return max(a[i]-d[0],0LL);};
  
  vector<Int> x(n-1);
  for(Int i=1;i<n;i++) x[i-1]=i;
  auto tmp=[&](Int p,Int q){return get(p)*dm(p)+(get(p,0)+get(q))*dm(q);};

  
  //cout<<x.size()<<endl;
  
  sort(x.begin(),x.end(),
       [&](Int p,Int q){
	 //cout<<p<<" "<<q<<endl;
	 //cout<<tmp(p,q)<<endl;
	 //cout<<tmp(q,p)<<endl;
	 if(dm(q)==0) return dm(p)!=0;
	 return tmp(p,q)<tmp(q,p);
       });
  
  
  Int t=0;
  Int ans=accumulate(x.begin(),x.end(),0LL,
		     [&](Int res,Int y){
		       //cout<<res<<" "<<t<<":"<<y<<" "<<dm(y)<<endl;
		       if(res>=h[0]) return res;
		       res+=(t+get(y))*dm(y);
		       t+=get(y,0);
		     
		       return res;
		     });
  if(ans>=h[0]) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll dy[4] = {1,0,-1,0};
ll dx[4] = {0,1,0,-1};

ll h,w;
bool in(ll y, ll x){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
    cin >> h >> w;
    char s[h][w];
    ll kuro = 0;
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='#') kuro++;
        }
    }
    queue<P> q;
    q.emplace(0,0);
    vvl d(h, vl(w,INF));
    d[0][0] = 1;
    while(!q.empty()){
        P p = q.front(); q.pop();
        ll y = p.first;
        ll x = p.second;
        rep(i,4){
            ll ny = y + dy[i];
            ll nx = x + dx[i];
            if(in(ny,nx)){
                if(s[ny][nx]=='.' && d[ny][nx] == INF){
                    q.push(P(ny,nx));
                    d[ny][nx] = d[y][x] + 1;
                }
            }
        }
    }
    if(d[h-1][w-1] == INF) puts("-1");
    else{
        cout << h*w - kuro - d[h-1][w-1] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL calc(LL A, LL B, LL x) { return (A * x / B) - A * (x / B); }

int main() {
  LL A, B, N;
  cin >> A >> B >> N;
  LL ma = 0;
  LL th = 10000;
  REP(i, 0, min(N,th)) { ma = max(ma, calc(A, B, i)); }
  ma = max(ma, calc(A,B,N));
  if(B-1<=N)ma = max(ma, calc(A,B,B-1));
  for(LL i = B-1;i<=min(N, th);i+=B){
    ma=max(ma, calc(A,B, i));

  }
  // REP(i, 1, 100) { cout << i << " " << calc(A, B, i) << endl; }
  cout<<ma<<endl;

  return 0;
}


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

int main () {
  int index = 0;
  vector<int> vec(5);
  for (int i=0; i < 5; i++) {
  	cin >> vec.at(i);
  }
  for (int j = 0; j < 5; j++){
   if(vec.at(j) == 0){
   	index = j + 1;
   } 
  }
  
  cout << index;
  
}

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> v(M, 0);

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

        for (int j = 0; j < K; ++j) {
            int a;
            cin >> a;
            ++v[a-1];
        }
    }

    int ans = 0;
    for (int i = 0; i < M; ++i) {
        if (v[i] == N) {
            ++ans;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
import math
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))

count = 0
for a in range(N):
  for b in range(a+1, N):
    sumX = 0
    for c in range(D):
      sumX += (X[a][c]-X[b][c])**2
    if math.sqrt(sumX)%1 == 0:
      count += 1
print(count)

Measured memory_bytes: 3064
import math

# Input the amount of money Takahashi paid
N = int(input())

# Find nearest integer price more than or equal to X/1.08
X = math.ceil(N / 1.08)

# Check if the "taxed price" is equal to N yen
if math.floor(X * 1.08) == N:
	print(X)
else:
	print(":(")


Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
s = max(a)
if s % 2 == 0:
    mid = s // 2
else:
    mid = s // 2 + 1
diff = float("inf")
rec1, rec2 = 0, 0
for i in range(n):
    p = abs(a[i] - mid)
    if p < diff:
        diff = p
        rec2 = a[i]

print(s, rec2)

Measured memory_bytes: 14052