akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <random>
#include <set>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2")
#endif

using namespace std;

using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;
using vi = vector<int>;
using vi64 = vector<i64>;

#define seq(i, a, b) for (int i = (a); i < (b); ++i)
#define rev(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) \
  { cerr << #x << ": " << x << endl; }

// Set max on range [l,r)
// Get val on pos
template <typename T>
class Segment {
 public:
  Segment(int n, T start_val = 0) {
    len = 1;
    while (len < n) len <<= 1;
    data.resize(n + len, start_val);
  }

  void setmin(int l, int r, T val) {
    for (l += len, r += len; l < r; l >>= 1, r >>= 1) {
      if ((l % 2) == 1) {
        data[l] = min(val, data[l]);
        ++l;
      }
      if ((r % 2) == 1) {
        --r;
        data[r] = min(val, data[r]);
      }
    }
  }

  T get(int pos) {
    pos += len;
    T maxi = data[pos];
    for (pos >>= 1; pos > 0; pos >>= 1) {
      maxi = std::min(maxi, data[pos]);
    }
    return maxi;
  }

 private:
  int len;
  vector<T> data;
};

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

  int n,q; cin >> n >> q;
  Segment<int> s1(n, n-2);
  Segment<int> s2(n, n-2);

  long blacks = long(n-2)*(n-2);
  seq(_,0,q) {
    int typ,x; cin >> typ >> x;

    auto& a = typ == 1 ? s1 : s2;
    auto& b = typ == 1 ? s2 : s1;

    int cnt = a.get(x);
    a.setmin(x, x+1, 0);
    b.setmin(2, cnt+2, x-2);
    blacks -= cnt;
  }
  
  cout << blacks << endl;
}


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

int N, M;

int main() {
    cin >> N >> M;
    string str;
    for (int i = 0; i < N; i++) {
        str += '-';
    }

    if (N != 1) {
        bool ans = true;

        for (int i = 0; i < M; i++) {
            int s;
            char c;
            cin >> s >> c;
            if (N != 1 && s == 1 && c == '0') ans = false;
            if (str[s-1] != '-' && str[s-1] != c) ans = false;
            str[s-1] = c;
        }

        for (int i = 0; i < N; i++) {
            if (str[i] == '-') {
                if (i == 0) str[i] = '1';
                else str[i] = '0';
            }
        }

        cout << (ans ? str : "-1") << endl; 
    }
    else {
        bool ans = true;

        for (int i = 0; i < M; i++) {
            int s;
            char c;
            cin >> s >> c;
            
            if (str[s-1] != '-' && str[s-1] != c) ans = false;
            str[s-1] = c;
        }

        for (int i = 0; i < N; i++) {
            if (str[i] == '-') {
                str[i] = '0';
            }
        }

        cout << (ans ? str : "-1") << endl; 
    }

      
    

    return 0;
}

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

typedef long long ll;

int main()
{
    string S, T;
    cin >> S >> T;
    int ans = 10000;

    for (int i = 0; i < S.size() - T.size() + 1; ++i)
    {
        int temp = 0;
        for (int j = 0; j < T.size(); ++j)
        {
            if (S[i + j] != T[j])
            {
                ++temp;
            }
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
}


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

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


def solve(X: int, Y: int):
    if Y % 2 == 0 and Y / 2 - X >= 0 and 2 * X - Y / 2 >= 0:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61756
N, X, Y = gets.chomp.split(" ").map(&:to_i)

ans = Array.new(N, 0)
(1...N).each{|i|
  wk = (0..N).to_a.map{|j| (j-i).abs}
  if wk[Y] - wk[X] > 1 then
    wk[Y] = wk[X] + 1
    (Y+1).upto(N){|j|
      break if wk[j] - wk[Y] <= (j-Y)
      wk[j] = wk[Y] + (j-Y)
    }
    (Y-1).downto(0){|j|
      break if wk[j] <= wk[Y] + (Y-j)
      wk[j] = wk[Y] + (Y-j)
    }
  end
  (i..N).each{|j| ans[wk[j]] += 1}
}

ans.shift
puts ans.join("\n")


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

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	bool ctr=1;
	bool ct=1;
	
	while(1)
	{
		if(ctr)
		{
			c-=b;
			ctr=0;
		}
		else{
			a-=d;
			ctr=1;
		}
		
		if(a<=0||c<=0)
		{
			if(a<=0)
				ct=0;
			break;
		}
	}
	
	if(ct)
		cout<<"Yes \n";
	else cout<<"No \n";
	
	return 0;
}

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

int main(){
  int k;

  cin >> k;

  if(k%2 == 0){
    cout << k/2*k/2 << endl;
  }
  else{
    cout << (k/2)*(k/2+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define INF 1e9
using namespace std;

int main()
{
    int x;
    cin>>x;
    bool a[100002];
    if(x<100){
        cout<<0;
        return 0;
    }
    for (int i = 100; i <= 105; i++)
    {
        a[i]=true;
    }
    
    for (int i = 106; i <= x; i++)
    {
        for (int j = 100; j <= 105; j++)
        {
            if(a[i-j]){
                a[i]=true;
            }
        }
        
    }

    cout<< a[x] ? 1 : 0;
    
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int DigitSum(int N){
    int digit,sum=0;
    do{
        digit = N % 10;
        N -=  digit;
        N /= 10;
        sum += digit;
    }while(N!=0);
    return sum;
}

int main(){
    long int N;
    scanf("%ld", &N);
    if(N % DigitSum(N)==0){
        printf("Yes");
    } else {
        printf("No");
    }   
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		int i = nextInt();
		out.println(n - i + 1);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21076
#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--)


void aryan_p() {
	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
	return;
}


int32_t main() {
	

	int n ;
	cin >> n;

	string s;
	cin >> s;

	int count = 0 ;
	for (int i = 0 ; i < n ; i++) {
		count++;
		while (s[i] == s[i + 1] and i < n - 1) {
			i++;
		}
	}
	cout << count;



	return 0;
}

Measured memory_bytes: 3720
import java.util.Scanner;

import static java.lang.System.in;

public final class Main {
	static Scanner sc = new Scanner(in);

	public static void main(String[] args) {
		char[] S = sc.next().toCharArray();
		int N = S.length + 1;
		int[] l = new int[N];
		int[] r = new int[N];
		for (int i = 1; i < N; i++) {
			if (S[i - 1] == '<') {
				l[i] = l[i - 1] + 1;
			}
		}
		for (int i = N - 2; i >= 0; i--) {
			if (S[i] == '>') {
				r[i] = r[i + 1] + 1;
			}
		}
		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += Math.max(l[i], r[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 32856
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    int n, a, b; cin >> n >> a >> b;
    int m = a + b - n;
    if(m < 0) m = 0;
    cout << min(a, b) << " " << m << endl;
}

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

    solve();
    return 0;
}
 


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

int main(void)
{
    int n,m;
    int total=0;
    int ans=0;
    float base;
    
    scanf("%d %d",&n,&m);
    // printf("%d %d",n,m);

    int  a[n];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        // printf("%d\n",a[i]);
        if (a[i]=='\0'){
            printf("No\n");
            return 0;
        }
        total=total+a[i];
    }
    // printf("total=%d\n",total);
    // printf("基準=%d\n",total*1/(4*m));
    base=total/(4.0*m);

    for (int i=0;i<n;i++){
        if (a[i]>=base)
            ans=ans+1;
            // flag=1;   
    }

    // printf("ans=%d\n",ans);
    if (ans>=m)
        printf("Yes\n");
    else
        printf("No\n");






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

    // for (i=0;i<n-1;i++){
    //     if (a[i+1]-a[i]>max)
    //         max=a[i+1]-a[i];
    // }

    // if (a[0]+x-a[n-1]>max)
    //     max=a[0]+x-a[n-1];

    // ans=x-max;
    // printf("%d\n",ans);
    
    return 0;
}

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

int main() {
  long n, a, b;

  cin >> n >> a >> b;

  if (a == 0) {
    cout << 0;
    return 0;
  }

  cout << n / (a + b) * a + min(a, n % (a + b));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;

struct Node {
    int v, d;
    int l,r;
    Node *left, *right;
    Node(int ll, int rr){
	l = ll; r=rr;
	left = NULL; right=NULL;
	v = 0;d=0;
	if(ll==rr) return;
	int m = l + (r-l)/2;
	left = new Node(l, m);
	right = new Node(m+1, r);
    }

    void pushdown(){
	if(d!=0){
	    if(left!=NULL){
		left->v += d;
		left->d += d;
	    }
	    if(right!=NULL){
		right->v += d;
		right->d += d;
	    }
	    d = 0;
	}
    }

    void add(int ll, int rr, int dd){
	if(ll==l && rr==r){
	    d += dd;
	    v += dd;
	    return;
	}
	
	pushdown();
	int m = l + (r-l)/2;
	if(rr<=m){
	    left->add(ll,rr,dd);
	}else if(ll>m){
	    right->add(ll,rr,dd);
	}else{
	    left->add(ll, m, dd);
	    right->add(m+1, rr, dd);
	}

	v = max(left->v, right->v);
    }

    int query(int ll, int rr){
	if(l==ll && r==rr){
	    return v;
	}

	pushdown();
	int m = l + (r-l)/2;
	if(rr<=m){
	    return left->query(ll, rr);
	}else if(ll>m){
	    return right->query(ll, rr);
	}else{
	    return max(left->query(ll, m), right->query(m+1,rr));
	}
	return 0;
    }
    
};

const int MX = 300005;

int N, K, A[MX];

int solve(){
    Node sg(0, MX);
    int ans = 0;
    for(int i=0; i<N; i++){
        int a = A[i];
        int l = max(a - K, 0), r = min(a + K, MX);
        int cur = sg.query(l, r) + 1;
        int c0 = sg.query(a, a);
        if(cur > c0){
            sg.add(a, a, cur - c0);
        }
        ans = max(ans, cur);
    }
    return ans;
}

int main(){
    //freopen("in.txt", "r", stdin);
    cin>>N>>K;
    for(int i=0; i<N; i++){
        cin>>A[i];
    }
    cout<<solve()<<endl;
    return 0;
}





Measured memory_bytes: 32900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//const int mxN=2e5;
//int a[mxN];

int main()
{int n,m,sum=0;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<n-sum;
    }
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

const int maxn = 2000 + 10;
int fac[maxn], invfac[maxn];

#define MOD 1000000007
long long qpow(long long a, long long b){
    long long s = 1;
    while (b > 0) {
        if (b & 1)s = s * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return s;
}
void init() {
    int n = maxn - 1;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % MOD;
    invfac[n] = qpow(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; --i) {
        invfac[i] = 1ll * invfac[i + 1] * (i + 1) % MOD;
    }
}
long long comb(int n, int m) {
    if (n < m) return 0;
    return 1ll * fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}

int lp(int now, int k){
  if(!(now > 0 && k > 0 && now >= k)) return 0;
  return pow(9, k) * comb(now-1, k-1) + lp(now-1, k);
}

int main(){
  init();
  string n;
  cin >> n;
  int k;
  cin >> k;
  int m = n.length();
  long long ans = 0;
  int z_count = 0;
  for(int i = m; i > 0; i--){
    int now_top = int(n[m-i])-48;
    if(!now_top) z_count++;
    ans += (now_top > 0) * lp(i-1, k-(m-i)+z_count); //下の桁
    ans += (now_top > 0) * (now_top - 1) * lp(i-1, k-(m-i)+z_count-1); //同じ桁
    ans += now_top * (k-(m-i)+z_count == 1 && now_top != 0); //1 0 ... 0 0 の形 * now_top
  }
  cout << ans << endl;
}


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

typedef long long ll;

int main()
{

    ll n,a,b,i;
    string st;
    cin >> a;
    if(a==25)
        st="Christmas";
    else if(a==24)
        st="Christmas Eve";
    else if(a==23)
        st="Christmas Eve Eve";
    else if(a==22)
        st="Christmas Eve Eve Eve";

    cout << st << "\n";



    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)



int n,c,k,t[100010],cnt,ans;
signed main(){
  cin>>n>>c>>k;
  rep(i,n){
    cin>>t[i];
  }


  sort(t,t+n);
  for(int i=0;i<n;i++){
    ans++;
    for(int j=1;j<n-i;j++){
      if(j>c)break;
      if((t[i]+k)>=(t[i+j]) && c-1>cnt){
        cnt++;
      }
    }
    i+=cnt;
    cnt=0;
    //cout<<"i="<<i<<endl;
  }

  cout<<ans<<endl;

  return 0;
}


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


string S[100];
int P[100];
pair<string, pair<int, int>> data[100];
int N;


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> S[i] >> P[i];
        data[i] = make_pair(S[i], make_pair(-P[i], i + 1));
    }
    sort(data, data + N);
    for(int i = 0; i < N; i++){
        cout << data[i].second.second << endl;
    }
}


Measured memory_bytes: 256
var cc : array [1..100001] of longint ;
    max,n,a,b,c,d,e,f,g : longint ;
begin
 readln(n);
 for a:=1 to n do
  begin
   read(cc[a]);
  end;
 for a:=1 to n do
  begin
   if cc[a]=a then
    b:=b+1
   else
    begin
     max:=max+((b+1)div 2);
     b:=0;
    end;
  end;
 if b>0 then
  max:=max+((b+1)div 2);
 writeln(max);
end.


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


int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
  return 0;
  
}

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

int main(){
  int N;
  cin >> N;
  int x[N-1][3];
  for(int i = 0; i < N-1; ++i){
    cin >> x[i][0] >> x[i][1] >> x[i][2];
  }
  for(int j = 0; j < N; ++j){
    int t = 0;
    for(int i = j; i < N-1; ++i){
      if(t < x[i][1]){
	t = x[i][1] + x[i][0];
      }else if(t % x[i][2] == 0){
	t += x[i][0];
      }else{
	int gap = t % x[i][2];
	t += x[i][2] - gap;
	t += x[i][0];
      }
    }
    cout << t << endl;
  }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 100010
int a[mx],p[mx],k,koko[mx];

void sieve()
{
    a[1]=1;
    for(int i=2; i<sqrt(mx); i++)
    {
        if(!a[i])
        {
            p[k++]=i;
            for(int j=i*i; j<mx; j=j+i)
            {
                a[j]=1;
            }
        }
    }
}

int main()
{
    //sieve();
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    if((abs(a-b)-1)%2 ==0) printf("Borys\n");
    else printf("Alice\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define INF (1 << 30)

using namespace std;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> a(m), md = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6}, d(10, INF);
    vector<string> dp(n + 1);
    vector<bool> valid(n + 1);
    valid.at(0) = 1;
    for (int i = 0; i < m; ++i) {
        scanf("%d", &a.at(i));
        d.at(a.at(i)) = md.at(a.at(i));
    }
    for (int i = 1; i <= n; ++i) for (int j = 1; j < 10; ++j) if (i >= d.at(j) && valid.at(i - d.at(j))) dp.at(i) = max(dp.at(i), dp.at(i - d.at(j)) + char('0' + j), [](string s, string t) { return s.size() < t.size() || (s.size() == t.size() && s < t); }), valid.at(i) = 1;
    printf("%s\n", dp.back().c_str());
    return 0;
}


Measured memory_bytes: 41472
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, a, b = rli()
    if (b-a) % 2 == 0:
        print((b-a)//2)
        return
    ans = (b-a)//2
    ans += min(a, n-b+1)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
print(700 + 100 * S.count('o'))


Measured memory_bytes: 26700
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <typeinfo>
#include <stdlib.h>


using namespace std;

int main(int argc, char* argv[]){
  int n,v,j;
  cin >> n;
  std::vector<int> a(n+1);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }

  //表示
  for(int k=0; k<n-1; k++){
    cout << a[k] << " ";
  }
  cout << a[n-1] << endl;

  for (int i=1; i<n; i++){
    //挿入ソートの1ステップ
    v = a[i];
    j = i-1;
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];//右に1つずらす
      j --;
    }
    a[j+1] = v;

    //表示
    for(int k=0; k<n-1; k++){
      cout << a[k] << " ";
    }
    cout << a[n-1] << endl;
  }
// 1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
// 2   for i が 1 から N-1 まで
// 3     v = A[i]
// 4     j = i - 1
// 5     while j >= 0 かつ A[j] > v
// 6       A[j+1] = A[j]
// 7       j--
// 8     A[j+1] = v
  
  return 0;
}



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

int main(){
  bool f=1;
  vector<vector<int>> x(3,vector<int>(3));
  REP(i,3) REP(j,3) cin>>x.at(i).at(j);
  REP(i,2){
    int d[3];
    REP(j,3) d[j]=x.at(i+1).at(j)-x.at(i).at(j);
    if(d[0]!=d[1]||d[1]!=d[2]) f=0;
  }
  REP(i,2){
    int d[3];
    REP(j,3) d[j]=x.at(j).at(i+1)-x.at(j).at(i);
    if(d[0]!=d[1]||d[1]!=d[2]) f=0;
  }

  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a[MAX],b[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    queue<pair<int,int> >q;
    int r=n-1;
    reverse(b,b+n);
    for(int i=0; i<n; i++)
    {
        if(a[i]!=b[i])
            q.push({b[i],i});
    }
    for(int i=0; i<n; i++)
    {
        if(a[i]==b[i])
        {
            int f=0;
            int cnt=0,sz=q.size();
            while(!q.empty())
            {
                pair<int,int>cur=q.front();
                q.pop();
                int val=cur.first;
                int idx=cur.second;
                if(val!=a[i] && b[i]!=a[idx])
                {
                    swap(b[idx],b[i]);
                    f=1;
                    q.push({val,idx});
                    break;
                }
                q.push(cur);
                cnt++;
                if(cnt==sz)
                    break;
            }
            if(!f)
            {
                cout<<"No"<<endl;
                return 0;
            }
            q.push({b[i],i});

        }
    }
    cout<<"Yes"<<endl;
    for(int i=0; i<n; i++)
        cout<<b[i]<<" ";
    cout<<endl;


    return 0;
}


Measured memory_bytes: 6812
#include<bits/stdc++.h>
using namespace std;
int n,y,i,j,k;
int main(){
	scanf("%d%d",&n,&y);
	if(n*1000>y||n*10000<y||y%1000!=0){
		printf("-1 -1 -1\n");
		return 0;
	}
	for(i=0;i<=n&&i*10000<=y;i++)
		for(j=0;i+j<=n&&i*10000+j*5000<=y;j++)
			if(i*9000+j*4000+n*1000==y){//i*10000+j*5000+(n-i-j)*1000
				printf("%d %d %d\n",i,j,n-i-j);
				return 0;
			}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String first = in.nextLine();
        final String second = in.nextLine();
        if (first.equals(second.substring(0, second.length() - 1))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

using namespace std;

int main(void){
    int N,M;
    cin>>N>>M;
    vector<int> K(N);
    vector<vector<int>> A(N,vector<int>(M));
    for(int i=0;i<N;i++){
        cin>>K[i];
        for(int j=0;j<K[i];j++){
            cin>>A[i][j];
            A[i][j]--;
        }
    }
    map<int,int> dict;
    for(int i=0;i<N;i++){
        for(int j=0;j<K[i];j++){
            dict[A[i][j]]++;
        }
    }
    int ans=0;
    for(int i=0;i<M;i++){
        if(dict[i]==N) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
H, W, D = map(int, input().split(' '))
n_position_dict = {}

for h in range(H):
    A = list(map(int, input().split(' ')))
    for w in range(W):
        n_position_dict[A[w]] = (h, w)

diffs = [1 for _ in range(H*W+1)]
for i in range(D+1, H*W+1):
    h, w = n_position_dict[i]
    next_h, next_w = n_position_dict[i-D]
    diffs[i] = diffs[i-D] + abs(h - next_h) + abs(w - next_w)
# print(diffs)

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split(' '))
    ret = diffs[r] - diffs[l]
    print(ret)









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

int main(void) {
	int N, odd, even;
	cin >> N;

	even = odd = N / 2;
	if (N % 2 != 0)
		++odd;

	double ans = (double)odd / (double)N;

	cout << fixed << setprecision(10) << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MN 100005
typedef long long ll;
int T,n,a[2][MN],id1[MN],id2[MN];
bool cmp1(int x,int y){return a[0][x]>a[0][y];}
bool cmp2(int x,int y){return a[1][x]>a[1][y];}
int main(){
//	freopen("test.in","r",stdin);
//	freopen("mysol.out","w",stdout);
	scanf("%d",&n);int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		a[i%2][x]++;
	}for(int i=1;i<=1e5;i++)id1[i]=id2[i]=i;
	sort(id1+1,id1+100001,cmp1);
	sort(id2+1,id2+100001,cmp2);
	if(id1[1]!=id2[1])printf("%d\n",n-a[0][id1[1]]-a[1][id2[1]]);
	else {
		int tmp=min(n-a[0][id1[1]]-a[1][id2[2]],n-a[0][id1[2]]-a[1][id2[1]]);
		printf("%d\n",tmp);
	}
}


Measured memory_bytes: 5376
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for(auto x : s) cout << x << "";
    cout << "" << std::endl;
    return 0;
}

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

int main(){
  int H, W;
  string b[8];
  cin >> H >> W;
  for(int i=0; i<H; i++){
    cin >> b[i];
  }
  int posx=0, posy=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(b[i][j]=='#'){
        if(i<posx || j<posy){
          cout << "Impossible" << endl;
          return 0;
        }else{
          posx = i;
          posy = j;
        }
      }
    }
  }
  cout << "Possible" << endl;
  return 0;
}

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

//#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

//#define int long long
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0;
	for (int i = 0; i <= min(n, k); i++) {
		for (int j = 0; j <= min(n, k) - i; j++){
			vector<int> c;
			for (int q = 0; q < i; q++) c.pb(a[q]);
			for (int q = n - 1; q >= n - j; q--) c.pb(a[q]);
			sort(all(c));
			int sum = 0;
			int now = k - i - j;
			for (int i : c) {
				if (i < 0 && now) {
					now--;
				}
				else {
					sum += i;
				}
			}
			ans = max(sum, ans);
		}
	}
	cout << ans;
}


signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

int main(){
  unordered_map<char,int>mp;
  string s;
  cin>>s;
  for (auto x : s){
    mp[x]++;
  }
  for (auto x : mp){
    if (x.second!=2){
      cout<<"No";
        return 0;
    }
  }
  cout<<"Yes";
}
  


Measured memory_bytes: 3564
#include <stdio.h>
int main(){
  int a,b;
  int x,y;
  int n;
  scanf("%d%d",&x,&y);
  if(x>=y){
    a=x;
    b=y;
  }
  else{
    a=y;
    b=x;
  }
  while(b!=0){
    n=b;
    b=a%b;
    a=n;
  }
  printf("%d\n",a);
  return 0;
}



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll X, N; cin >> X >> N;
	vector<ll> V(N); REP(i, N) cin >> V[i];

	ll res;
	ll dif{INF};
	for (ll i = 0; i <= 200; ++i)
	{
		if (find(ALL(V), i) != V.end()) continue;

		if (dif > abs(X - i))
		{
			dif = abs(X-i);
			res = i;
		}
	}

	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 3652
import numpy as np
N,W = map(int,input().split())
w,v = [],[]
for i in range(N):
    a,b = map(int,input().split())
    w += [a]
    v += [b]
dp = np.zeros(W+1,dtype = int)
for i in range(N):
    dp[w[i]:] = np.maximum(dp[:-w[i]]+v[i],dp[w[i]:])
print(dp[-1])

Measured memory_bytes: 18336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split(" ");
		int a[] = new int[n];
		for (int i = 0; i < str.length; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		int count = 0;

		while (true) {
			for (int i = 0; i < n; i++) {
				if (a[i] % 2 != 0) {
					System.out.println(count);
					System.exit(0);
				} else {
					a[i] /= 2;
				}
			}
			count++;
		}
	}
}

Measured memory_bytes: 21328
//Volume5 -> 0501

#include <iostream>
#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>
#include <iomanip>

int main();

int main(){
	std::vector<int> totalAPoint;		//Aの得点
	std::vector<int> totalBPoint;		//Bの得点
	int dataSetCount = 0;				//ゲーム数

	while (1){
		int n = 0;		//1ゲームの入力数

		std::cin >> n;
		//n=0で終了
		if (n == 0){
			break;
		}

		dataSetCount++;

		int aPoint = 0;		//1ゲームにおけるAの得点
		int bPoint = 0;		//1ゲームにおけるBの得点

		for (int i = 0; i < n; i++){
			int tempA;
			int tempB;

			std::cin >> tempA >> tempB;
			if (tempA > tempB){
				aPoint += (tempA + tempB);
			}
			else if (tempA < tempB){
				bPoint += (tempA + tempB);
			}
			//引き分け
			else{
				aPoint += tempA;
				bPoint += tempB;
			}
		}

		totalAPoint.push_back(aPoint);
		totalBPoint.push_back(bPoint);
	}

	//結果出力
	for (int i = 0; i < dataSetCount; i++){
		std::cout << totalAPoint[i] << " " << totalBPoint[i] << std::endl;
	}

	//while (1);
	return 0;
}


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

int main(){
 int H, R;
 cin>>H>>R;
 if (H + R > 0) cout<<1<<endl;
 if (H + R == 0) cout<<0<<endl;
 if (0 > H + R) cout<<-1<<endl;
return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

bool isprime(int x) {
  for(int i = 2; i * i <= x; ++i) {
    if(x % i == 0) return false;
  }
  return true;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  VI ans(1000010, 0);
  FOR(i, 2, ans.size()-1) {
    if(i % 2 == 0) ans[i+1] = ans[i];
    else if(isprime(i) && isprime((i+1)/2)) ans[i+1] = ans[i] + 1;
    else ans[i+1] = ans[i];
  }
  int q;
  cin >> q;
  VI l(q), r(q);
  rep(i, q) cin >> l[i] >> r[i];
  rep(i, q) {
    out(ans[r[i]+1] - ans[l[i]]);
  }
  return 0;
}


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

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            
               
                List<int> a = new List<int>();
                while (true)
                {
                    string i = Console.ReadLine();
                    if (i == "0") break;
                    a.Add(int.Parse(i));
                }
                for(int i = 0; i < a.Count; i++)
                {
                    Console.WriteLine("Case {0}: {1}", i+1, a[i]);
                }




        }
    }
}

Measured memory_bytes: 9476
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0; i<=n; i++){
        for (int j=0; j<=m; j++){
            int ans=i*m+j*(n-i*2);
            if (k==ans){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
	return 0 ;
}

Measured memory_bytes: 128
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

totalVote = 0
for a in A:
    totalVote += a

boader = totalVote / (4*M)

countPopularItem = 0
for a in A:
    if a >= boader:
        countPopularItem += 1

if countPopularItem >= M:
    print('Yes')
else:
    print('No')


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

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

void alpha(){

	ll h, a;
	cin>>h>>a;

	if(h%a) cout<<h/a+1<<endl;
	else cout<<h/a<<endl;

	
	return;

}

int main(){

	ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

Measured memory_bytes: 256
A, B, C, D = map(int,input().split())
cnt = 0
while True:
    if cnt % 2 == 0:
        C -= B
    else:
        A -= D
    if C <= 0:
        print("Yes")
        break
    elif A <= 0:
        print("No")
        break
    cnt += 1


Measured memory_bytes: 61596
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] diff = new boolean[N]; //N not possible as max gap = N-1; N/2 is bad for even
		boolean[] used = new boolean[N+1];
		int bad = -1;
		if (N%2==0) bad=N/2;
		System.out.println(1+" "+N);
		diff[1]=true;
		diff[N-1]=true;
		used[1]=true;
		used[N]=true;
		M--;
		int START = 2;
		while (M>0) {
			for (int d = N-1; d>=1; d--) {
				int diff1 = d;
				int diff2 = N-d;
				int END = START+diff1;
				if (!diff[diff1]&&!diff[diff2]&&!used[END]&&diff1!=bad) {
					System.out.println(START+" "+END);
					diff[diff1]=true;
					diff[diff2]=true;
					used[END]=true;
					START++;
					M--;
					if (M==0) break;
				}
			}
		}
	}	
}

Measured memory_bytes: 46328
#!/usr/bin/env python
# coding: utf-8

# In[5]:


x,y = map(int, input().split())


# In[6]:


if x <= y:
    if abs(x) <= abs(y):
        ans = min(y-x, y-(-x)+1)
    else:
        ans = min(y-x, abs(-y-x)+1)
else:
    ans = abs(abs(x)-abs(y))+1
    if x*y > 0:
        ans += 1
print(ans)


# In[ ]:






Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n;
  cin>>n;
  unordered_map<ll,ll> mp;
  ll sum=0;
  for(int i=0;i<n;i++)
  {
    ll x;
    cin>>x;
    mp[x]++;
    sum+=x;
  }
  int q;
  cin>>q;
  while(q--)
  {
    ll l,r;
    cin>>l>>r;
    if(mp.find(l)==mp.end())
    {
      cout<<sum<<endl;
      continue;
    }
    ll cnt=mp[l];
    ll curr=(cnt*(r-l));
    sum+=curr;
    mp.erase(l);
    mp[r]+=cnt;
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 6692
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
  let pqr: Vec<f64> = read_vec();
  let xs = [pqr[0] + pqr[1], pqr[1] + pqr[2], pqr[2] + pqr[0]];
  let ans: f64 = xs.iter().fold(0.0/0.0, |a, &c| a.min(c));

  println!("{}", ans as u32);
}


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

int main() {
  int64_t N;
  cin >> N;
  for(int64_t h=1; h<=3500; h++)
  for(int64_t n=h; n<=3500; n++)
    if(4*h*n-N*h-N*n>0 && N*h*n%(4*h*n-N*h-N*n)==0){
      cout << h << " " << n << " "<< N*h*n/(4*h*n-N*h-N*n);
      return 0;
    }
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  string s,t; cin >>s >>t; int cnt=0;
  for(int i=0; i<s.size(); i++) if(s[i]!=t[i]) cnt++;
  cout <<cnt;
return 0;}

Measured memory_bytes: 3832
#include <iostream>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll K, A[50];

int main(void) {
  ll N = 50;
  cin >> K;

  REP(i, 0, N) A[i] = (N - i - 1) + (K / N);
  REP(i, 0, K % N) A[i]++;

  cout << N << endl;
  REP(i, 0, N) {
    cout << A[i];
    if(i + 1 != N) cout << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
public static void main(String[] args){
	int a,b,c,d,i,n,cnt;
	Scanner input=new Scanner(System.in);
	while(input.hasNext()){
	n=input.nextInt();
	cnt=0;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					if(a+b+c+d==n)cnt++;
				}
			}
		}
	}
	System.out.println(cnt);
	}
}
}

Measured memory_bytes: 26264
#include <set>
#include <cstdio>
#include <map>
#include <iostream>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define f first
#define s second
#define mp make_pair

using namespace std;

template<class T>
class ID{
  map<T,int> _id;
public:
  ID(){}
  int operator()(const T &val){
    if(_id.find(val) == _id.end()){
      int next = _id.size();
      return _id[val] = next;
    }
    return _id[val];
  }
};

int main(){
  string s;
  while(cin >> s){
    vector<int> v(8);
    ID<string> id;
    v[0] = id(s);
    REP(i,7){
      cin >> s;
      v[i+1] = id(s);
    }

    set<string> ans;
    sort(v.begin(), v.end());

    do{
      vector<string> tmp(24, "        ");

      REP(i,4){
	REP(j,4){
	  tmp[i][(i+j)%4]   = v[j] + '0';
	  tmp[i][(i+j)%4+4] = v[j+4] + '0';

	  tmp[i+4][(i+j)%4]   = v[4+(3-j)] + '0';
	  tmp[i+4][(i+j)%4+4] = v[3-j] + '0';
	}
      }

      REP(i,8){
	tmp[i+8][0] = tmp[i][0];
	tmp[i+8][1] = tmp[i][3];
	tmp[i+8][2] = tmp[i][7];
	tmp[i+8][3] = tmp[i][4];
	tmp[i+8][4] = tmp[i][1];
	tmp[i+8][5] = tmp[i][2];
	tmp[i+8][6] = tmp[i][6];
	tmp[i+8][7] = tmp[i][5];
      }

      REP(i,8){
	tmp[i+16][0] = tmp[i][0];
	tmp[i+16][1] = tmp[i][4];
	tmp[i+16][2] = tmp[i][5];
	tmp[i+16][3] = tmp[i][1];
	tmp[i+16][4] = tmp[i][3];
	tmp[i+16][5] = tmp[i][7];
	tmp[i+16][6] = tmp[i][6];
	tmp[i+16][7] = tmp[i][2];
      }

      sort(tmp.begin(), tmp.end());
      ans.insert(tmp[0]);

    }while(next_permutation(v.begin(), v.end()));

    /*
    for(set<string>::iterator it = ans.begin();
	it != ans.end(); ++it){
      cout << *it << endl;
    }
    */


    printf("%d\n", ans.size());
  }
}

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

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int m = a>c?a-c:c-a;
	int n = b>d?b-d:d-b;
	if(a<c&&b<d)
	{
		for(int i = 0 ;i < n ;i++)
			cout << "U";
		for(int j = 0;j < m ;j++)
			cout <<"R";
		for(int j = 0;j < n ;j++)
			cout <<"D";
		for(int j = 0;j < m ;j++)
			cout <<"L";
		cout << "L";
		for(int j = 0;j < n+1 ;j++)
			cout <<"U";
		for(int j = 0;j < m+1 ;j++)
			cout <<"R";
		cout << "D" <<"R";
		for(int j = 0;j < n+1 ;j++)
			cout <<"D";
		for(int j = 0;j < m+1 ;j++)
			cout <<"L";
		cout << "U";
	}
	else if(a>c&&b>d)
	{
		for(int i = 0 ;i < n ;i++)
			cout << "D";
		for(int j = 0;j < m ;j++)
			cout <<"L";
		for(int j = 0;j < n ;j++)
			cout <<"U";
		for(int j = 0;j < m ;j++)
			cout <<"R";
		cout << "R";
		for(int j = 0;j < n+1 ;j++)
			cout <<"D";
		for(int j = 0;j < m+1 ;j++)
			cout <<"L";
		cout << "U" <<"L";
		for(int j = 0;j < n+1 ;j++)
			cout <<"U";
		for(int j = 0;j < m+1 ;j++)
			cout <<"R";
		cout << "D";
	}
	else if(a==c&&b<d)
	{
		for(int j = 0;j < n ;j++)
			cout <<"U";
		cout << "R";
		for(int j = 0;j < n ;j++)
			cout <<"D";
		cout <<"LL";
		for(int j = 0;j < n ;j++)
			cout <<"U";
		cout << "RULL";
		for(int j = 0;j < n+2 ;j++)
			cout <<"D";
		cout<< "LLU";
	}
	else if(a==c&&b>d)
	{
		for(int j = 0;j < n ;j++)
			cout <<"D";
		cout << "L";
		for(int j = 0;j < n ;j++)
			cout <<"U";
		cout <<"RR";
		for(int j = 0;j < n ;j++)
			cout <<"D";
		cout << "LDRR";
		for(int j = 0;j < n+2 ;j++)
			cout <<"U";
		cout<< "RRD";
	}
	else if(a<c&&b==d)
	{
		for(int j = 0;j < m ;j++)
			cout <<"R";
		cout << "D";
		for(int j = 0;j < m ;j++)
			cout <<"L";
		cout << "UU";
		for(int j = 0;j < m+1 ;j++)
			cout <<"R";
		cout <<"DDD";
		for(int j = 0;j < m+2 ;j++)
			cout <<"L";
		cout <<"UUR";	
	}
	else if(a>c&&b==d)
	{
		for(int j = 0;j < m ;j++)
			cout <<"L";
		cout << "U";
		for(int j = 0;j < m ;j++)
			cout <<"R";
		cout << "DD";
		for(int j = 0;j < m+1 ;j++)
			cout <<"L";
		cout <<"UUU";
		for(int j = 0;j < m+2 ;j++)
			cout <<"R";
		cout <<"DDL";	
	}
	else if(a<c&&b>d)
	{
		for(int j = 0;j < m ;j++)
			cout <<"R";
		for(int j = 0;j < n ;j++)
			cout <<"D";
		for(int j = 0;j < m ;j++)
			cout <<"L";
		for(int j = 0;j < n ;j++)
			cout <<"U";
		cout << "U";
		for(int j = 0;j < m+1 ;j++)
			cout <<"R";
		for(int j = 0;j < n+2 ;j++)
			cout <<"D";
		for(int j = 0;j < m+2 ;j++)
			cout <<"L";
		for(int j = 0;j < n+1 ;j++)
			cout <<"U";
		cout << "R";
	}
	else if(a>c&&b<d)
	{
		for(int j = 0;j < m ;j++)
			cout <<"L";
		for(int j = 0;j < n ;j++)
			cout <<"U";
		for(int j = 0;j < m ;j++)
			cout <<"R";
		for(int j = 0;j < n ;j++)
			cout <<"D";
		cout << "D";
		for(int j = 0;j < m+1 ;j++)
			cout <<"L";
		for(int j = 0;j < n+2 ;j++)
			cout <<"U";
		for(int j = 0;j < m+2 ;j++)
			cout <<"R";
		for(int j = 0;j < n+1 ;j++)
			cout <<"D";
		cout << "L";
	}
	return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

lst=ruiseki(a)
ans=float('inf')

kirekomi=[1,3]

for i in range(2,n-1):
    while 1:
        if abs(lst[kirekomi[0]]-(lst[i]-lst[kirekomi[0]]))>abs(lst[kirekomi[0]+1]-(lst[i]-lst[kirekomi[0]+1])):
            kirekomi[0]+=1
        else:
            break
    
    while 1:
        if abs((lst[n]-lst[kirekomi[1]])-(lst[kirekomi[1]]-lst[i]))>abs((lst[n]-lst[kirekomi[1]+1])-(lst[kirekomi[1]+1]-lst[i])):
            kirekomi[1]+=1
        else:
            break
    
    # print(kirekomi)
    p=lst[kirekomi[0]]
    q=lst[i]-lst[kirekomi[0]]
    r=lst[kirekomi[1]]-lst[i]
    s=lst[n]-lst[kirekomi[1]]
    anslst=[p,q,r,s]
    ans=min(ans,max(anslst)-min(anslst))
    # print(anslst)
print(ans)

Measured memory_bytes: 102072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    string S, T; cin >> S >> T;
    int N = S.length();
    int M = T.length();
    int ans = M;
    rep(i, N-M+1) {
        int cnt = M;
        rep(j, M) {
            if (S[i+j] == T[j]) cnt--;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, M ;
    LL K;
    cin >> N >> M >> K;
    vector<LL> SA(N);
    vector<LL> SB(M);
    rep(i, N) {
        int A;
        cin >> A;
        if (0 < i) {
            SA[i] = A + SA[i-1];
        } else {
            SA[0] = A;
        }
    }
    rep(i, M) {
        int B;
        cin >> B;
        if (0 < i) {
            SB[i] = B + SB[i-1];
        } else {
            SB[0] = B;
        }
    }

    int ans = 0;
    for (int a = 0; a <= N; ++a) {
        LL sa = (a == 0) ? 0 : SA[a-1];
        if (K < sa) {
            break;
        }
        LL res = K - sa;
        auto it = upper_bound(SB.begin(), SB.end(), res);
        int b = (it-SB.begin());
        ans = max(ans, a+b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6364