akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

        if (N == 100) {
            System.out.println((int) Math.pow(100, D) * 101);
        } else {
            System.out.println((int) Math.pow(100, D) * N);
        }

    }

}

Measured memory_bytes: 25300
# if true

# include <iostream>
# include <algorithm>
# include <numeric>

using Int = long long;


int main()
{

    Int N, L;
    std::cin >> N >> L;

    Int defaultSum{};
    for (Int i{}; i < N; ++i) 
        defaultSum += L + i;

    Int result{std::numeric_limits<int>::min()};
    for (Int e{}; e < N; ++e)
    {
        auto currentSum = defaultSum - (L + e);
        if (std::abs(currentSum - defaultSum) < std::abs(result - defaultSum))
            result = currentSum;
    }

    std::cout << result;


    return 0;
}


# endif

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Maxn = 1000005;
ll a[Maxn];
ll p = 2;
ll qpow(ll y,int z,int p){
    y%=p;ll ans=1;
    for(int i=z;i;i>>=1,y=y*y%p)if(i&1)ans=ans*y%p;
    return ans;
}
ll C(ll n,ll m){
    if(m>n)return 0;
    return ((a[n]*qpow(a[m],p-2,p))%p*qpow(a[n-m],p-2,p)%p);
}
ll Lucas(ll n,ll m){
    if(!m)return 1;
    return C(n%p,m%p)*Lucas(n/p,m/p)%p;
}

ll N;
ll b[Maxn];
ll ans;
int main()
{
	a[1] =a[0] =  1;
	for(int i=2;i<Maxn;i++)	a[i] = (a[i-1] * i)%p;
	cin>>N;
	for(int i=1;i<=N;i++) scanf("%1lld",&b[i]);
	for(int i=1;i<N;i++) b[i] = abs(b[i] - b[i+1]);
	N--;
	bool HaveOne = false;
	for(int i=1;i<=N&&!HaveOne;i++) if(b[i] == 1) HaveOne = true;
	if(!HaveOne)	for(int i=1;i<=N;i++) b[i]/=2;
	for(int i=1;i<=N;i++)
	{
		ans += Lucas(N-1,i-1) * b[i];
		ans %= 2;
	}
	if(!HaveOne) ans *=2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
int n,num[110],ans=0;
signed main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>num[i];
	for(int i=0;i<n;i++){
		if((i+1)%2==1&&num[i]%2==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
	int i,m,k,t=0,cnt=0;
	scanf("%d %d",&m,&k);
	int a[m];
	for(i=0;i<m;i++){
		scanf("%d",&a[i]);
	}
		for(i=0;i<m-1;i++){
		if(a[i]>a[i+1]){
			t=a[i+1];
			a[i+1]=a[i];
			a[i]=t;
		}
	}
	if(a[m-1]<k){
		printf("0");
	}else{
	
	for(i=0;i<m;i++){
		if(a[i]>=k)
		cnt++;
	}
	printf("%d",cnt);
}
	return 0;
}

Measured memory_bytes: 512
import itertools
N, M = map(int, input().split())
k = []
s = []
for i in range(M):
    t = list(map(int, input().split()))
    k += [t[0]]
    ts = [False] * N
    # print(t[1:])
    for ti in t[1:]:
        ts[ti-1] = True
    s += [ts]
p = list(map(int, input().split()))

# print(s)
nf = (1, 0)

ans = 0
for joutai in itertools.product(*[nf] * N):
    mitasu = True
    for i in range(M):
        # print([joutai[ji] for ji in range(N) if s[i][ji]])
        if sum([joutai[ji] for ji in range(N) if s[i][ji]]) % 2 != p[i]:
            mitasu = False
    if mitasu:
        ans += 1

print(ans)


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

int s,x,y;

int tax(int price,int rate){
  return price*(100+rate)/100;
}

int max_rate(int x,int y,int s){
  int maximum=0;
  for(int i=1; i<s;i++){
    for(int j=i; j<s;j++){
      if (tax(i,x)+tax(j,x)==s){
	maximum=max(maximum,tax(i,y)+tax(j,y));
      }
    }
  }
  return maximum;
}


int main(){
  while( cin >> x >> y >> s && x>0){
    cout << max_rate(x,y,s)<<endl;
  }
}

Measured memory_bytes: 3024
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#include <bitset>
#include <algorithm>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, int>;

const ll INF = 1e18;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main() {
    int h, w, k;
    cin >> h >> w >> k;
    int si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    --si; --sj; --ti; --tj;

    vector<string> g(h);
    rep(i, h) cin >> g[i];

    auto toId = [&](int i, int j, int v) {
        return (i*w + j)*4 + v;
    };
    auto modCeil = [&](ll x) {
        return (x + k - 1)/k*k;
    };

    vector<ll> dist(h*w*4, INF);
    priority_queue<LP, vector<LP>, greater<LP>> q;
    auto push = [&](int i, int j, int v, ll x) {
        int id = toId(i, j, v);
        if (dist[id] <= x) return;
        dist[id] = x;
        q.emplace(x, id);
    };
    rep(v, 4) push(si, sj, v, 0);
    while (!q.empty()) {
        ll d = q.top().first;
        int id = q.top().second;
        q.pop();
        if (dist[id] != d) continue;
        int i = id/w/4;
        int j = id/4%w;
        int v = id%4;
        rep(nv, 4) push(i, j, nv, modCeil(d));

        int ni = i + di[v], nj = j + dj[v];
        if (0 <= ni && ni < h && 0 <= nj && nj < w) {
            if (g[ni][nj] == '.') {
                push(ni, nj, v, d+1);
            }
        }
    }

    ll ans = INF;
    rep(v, 4) ans = min(ans, dist[toId(ti, tj, v)]);
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        ans = modCeil(ans)/k;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 44092
N = int(input())
L = list(map(int,input().split()))
L = sorted(L, reverse = False)

count =0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] != L[j] != L[k] and L[k] < (L[j] + L[i]):
                count += 1
print(count) 

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i > 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<P> xy(n);
    REP(i,n){
        double x,y; cin >> x >> y;
        xy[i] = P(x,y);
    }
    vector<int> perm(n);
    REP(i,n){
        perm[i] = i;
    } 
    double ans=0; 
    do{
        REP(i,n-1){
            ans += sqrt((xy[perm[i+1]].first -xy[perm[i]].first)*(xy[perm[i+1]].first -xy[perm[i]].first) + (xy[perm[i+1]].second -xy[perm[i]].second)*(xy[perm[i+1]].second -xy[perm[i]].second));
        }
    }while(next_permutation(ALL(perm)));
    int comb = 1;
    REPR(i,n){
        comb *= i;
    }
    ans /= comb;

    cout <<ans<< endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;
  string ans = s;
  for(int j = 0; j < min(N,K); ++j){
    string t = s;
    reverse(t.begin(), t.end());
    s += t;
    for(int i = 0; i < N; ++i){
      string x = s.substr(i,N);
      //cerr << i << " " << x << endl;
      ans = min(ans,x);
    }
    //cerr << ans << endl;
    reverse(ans.begin(), ans.end());
    s = ans;
    string tmp = s;
    sort(tmp.begin(), tmp.end());
    if(tmp[0] == tmp.back())
      break;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
set <int> a;
int main() {
	int n,m;
	cin>>n;
	while(n--) {
		cin>>m;
		if(a.find(m)!=a.end())a.erase(m);
		else a.insert(m);
	}
	cout<<a.size();
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
char s[220010],S[200010];

int main(){
	cin>>(s+1);
	cin>>(S+1);
	for(int i=1;i<=strlen(s+1);++i){
		if(s[i]!=S[i]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int c[h][w];
  rep(i, h) rep(j, w) {
    char x;
    cin >> x;
    c[i][j] = ((x == '.') ? 0 : 1);
  }

  int ans = 0;

  rep(is, 1 << h) {
    rep(js, 1 << w) {
      int cnt = 0;
      rep(i, h) {
        if (is >> i & 1) continue;
        rep(j, w) {
          if (js >> j & 1) continue;
          cnt += c[i][j];
        }
      }
      if (cnt == k) ++ans;
    }
  }

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


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

class people{
public:
  int t,w;
  people(void){}
  people(int a,int b){t = a; w = b;}
  const bool operator<(const people a)const{return t>a.t;}
};

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

  for(;;){
    cin >> n;
    if(!n)break;

    priority_queue<people> in,out;
    for(int i=0;i<n;i++){
      cin >> m >> a >> b;
      in.push(people(a,m));
      out.push(people(b,m));
    }

    int now=0;
    while(in.size() || out.size()){
      people p1,p2;
      if(in.empty()){
	p1 = out.top();out.pop();
	now -= p1.w;
      }else if(out.empty()){
	p1 = in.top();in.pop();
	now += p1.w;
      }else{
	p1 = out.top();
	p2 = in.top();
	if(p1.t>p2.t){
	  in.pop();
	  now += p2.w;
	}else{
	  out.pop();
	  now -= p1.w;
	}
      }
      if(now>150)break;
    }

    if(now>150)cout << "NG\n";
    else cout << "OK\n";
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  vector<string> s;
  for(int i=0;i<n;i++){
    string str;
    cin>>str;
    s.push_back(str);
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    cout<<s[i];
  }
}
  

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int k=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		for(int i=a;i<=b;i++)
		{
			if(i%k==0)
			{
				System.out.println("OK");
				System.exit(0);
			}
		}
		System.out.println("NG");

	}

}


Measured memory_bytes: 36068
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
/*
typedef int weight;
struct edge
{
	int from, to; weight cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};

typedef vector<edge> Edges;
typedef vector<Edges> Graph;
*/
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


typedef int Weight;
typedef int Flow;

struct Edge {
	int src, dest, rev;
	Flow cap;
	Weight cost;
	bool operator < (const Edge &rhs) const
	{
		return cost > rhs.cost;
	}
	Edge(int s, int d) : src(s), dest(d) { ; }
	Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
	Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int src, int dest, Flow cap)
{
	g[src].push_back(Edge{ src, dest, (int)g[dest].size(), cap, 0 });
	g[dest].push_back(Edge{ dest, src, (int)g[src].size() - 1, 0, 0 });
}

Flow dfs(Graph &g, vector<bool> &used, int v, int t, Flow f)
{
	if (v == t) return f;
	used[v] = true;
	for (Edge& e : g[v])
	{
		if (!used[e.dest] && e.cap > 0)
		{
			Flow d = dfs(g, used, e.dest, t, min(f, e.cap));
			if (d > 0)
			{
				e.cap -= d;
				g[e.dest][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

Flow ford_fulkerson(Graph &g, int s, int t)
{
	Flow flow = 0;
	for (;;)
	{
		vector<bool> used(g.size(), false);
		Flow f = dfs(g, used, s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

int main()
{
	int n, m, l;
	while (cin >> n >> m >> l, n)
	{
		vector<vi> dist(n, vi(n));
		REP(i, n)REP(j, n) dist[i][j] = (i == j ? 0 : INF);
		REP(i, m)
		{
			int u, v, d;
			cin >> u >> v >> d;
			dist[u][v] = dist[v][u] = d;
		}
		REP(k, n)REP(i, n)REP(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
		Graph g(2*l + 2);
		REP(i, l)
		{
			add_edge(g, 2 * l, i, 1);
			add_edge(g, l + i, 2 * l + 1, 1);
		}
		vi p(l), t(l);
		REP(i, l) cin >> p[i] >> t[i];
		REP(i, l)REP(j, l)
		{
			if (i == j) continue;
			if (dist[p[i]][p[j]] <= t[j] - t[i]) add_edge(g, i, j+l, 1);
		}
		cout << l - ford_fulkerson(g, 2 * l, 2 * l + 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 26460
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    for i in 1..10 {
        for j in 1..10 {
            if i * j == n {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
// five elements

#define ll long long
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rev(i, s, n) for (int i = s; i > n; i = i - 1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<ll>
#define vii vector<pair<ll, ll>>
// akane_psycho
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define c1(a) cout << a << endl;
#define c2(a, b) cout << a << " " << b << endl;
#define inf 1e18
#define mod 1000000007
#define ii pair<ll,ll>
#define sw(v)      cout << endl;                                                                \
  for(auto u:v) {cout << u << " ";}                                     \
  cout << endl;
  
  /*
  ll ml(ll a, ll b){
  	return ( (a%mod)*(b%mod) )%mod;
  }
ll fp(ll num,ll g)
{
    if(g==0)return 1;
    if(g%2==1)return ml(num,fp(ml(num,num) ,g/2) );
    return fp( ml(num,num),g/2);
}
ll d(ll a, ll b) {//a/b
	return a*fp(b, mod - 2) % mod;
}
ll pm(ll f[] , ll n, ll r){
	return d(  f[n] , f[n-r] );
}
ll cm(ll f[] , ll n , ll r ){
		return d( f[n] , ml( f[r],f[n-r] ) );
	}
*/
ll val( ll a, ll b , ll x){
	
	return (a*x)/b - a*(x/b);
}

int main(){
	string s;cin>>s;
	if(s[1]=='B')s[1]='R';
	else s[1]='B';
	c1(s)
}


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

int main() {
  int A;
  int B;
    cin>>A>>B;
  if(A>=13) 
    cout<< B <<endl;
  
  else if(A>=6 && A<=12)
    cout<< B/2 <<endl;
  
  else if(A<=5)
    cout <<0<<endl;
}
   

Measured memory_bytes: 256
# include <cstdio>
const long long mod = 1e9+7;
long long inv[100003]={1,1}, fi[100003]={1,1};
int main(){
    int n;
    long long ans = 0, b=1, x;
    scanf("%d",&n);
    for(int i=2; i<=n; ++i){
        inv[i] = inv[mod%i]*(mod-mod/i)%mod;
        fi[i] = (fi[i-1]+inv[i])%mod;
    }
    for(int i=1; i<=n; ++i){
        scanf("%lld",&x);
        ans = (ans + (fi[i]+fi[n-i+1]-1+mod)%mod*x%mod)%mod;
        b = b*i%mod;
    }
    printf("%lld\n",ans*b%mod);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
	int sump=0,sumn=0,i=0;
	int p,n;
	double aven;

	while(scanf("%d,%d",&p,&n)!=EOF){
		sump+=p*n;
		sumn+=n;
		i++;
	}
	aven=(double)sumn/i;
	//cout<<sumn<<endl;
	aven*=10;
	aven+=5;
	aven/=10;

	printf("%d\n%d\n",sump,(int)aven);

}

Measured memory_bytes: 1184
#include <stdio.h>

int main(void)
{
	int max, min, count, n, i;
	long add;

	scanf("%d", &count);

	for (i = 0; i < count; i++)
	{
		if (i == 0)
		{
			scanf("%d", &n);
			max = n;
			min = n;
			add = n;
		}
		else
		{
			scanf("%d", &n);
			add = add + n;
			if (n > max) max = n;
			if (n < min) min = n;
		}
	}
	printf("%d %d %ld\n", min, max, add);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
 
int main(){
	
    char a[11];
	char b[11];
	char c[11];
	
    scanf("%s %s %s", &a, &b, &c);
 
    int x = strlen(a);
	int y = strlen(b);
    
    if(a[x-1] == b[0] && b[y-1] == c[0]){
    	
        puts("YES");
        
    }else{
    	
        puts("NO");
        
    }
}

Measured memory_bytes: 2084
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    
    long a1 = solve(true, a);
    long a2 = solve(false, a);
    
    System.out.println(Math.min(a1, a2));
  }
  
  private static long solve(boolean evenPlus, int[] a) {
    
    long ans = 0;
    long sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += a[i];
      if (((evenPlus && i%2 == 0)
          || (!evenPlus && i%2 == 1))
          && sum <= 0) {
        long diff = 1 - sum;
        sum += diff;
        ans += diff;
      } else if (((evenPlus && i%2 == 1)
                  || (!evenPlus && i%2 == 0))
                  && sum >= 0) {
        long diff = sum + 1;
        sum -= diff;
        ans += diff;
      }
    }
    return ans;
  }
}

Measured memory_bytes: 50536
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(begin(a), end(a));
    if ( a[2] %2 == 0 ) {
        cout << 0 << endl;
    } else {
        cout << a[0] * a[1] << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> a(13);
  rep(i, n) {
    int d; cin >> d;
    a[d]++;
  }

  if (a[0] > 0 || a[12] >= 2) {
    cout << 0 << endl;
    return 0;
  }

  for(int i=1; i<=11; i++) {
    if (a[i] >= 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  //debugln("hoge");
  vector<bool> time(25);
  time[0] = time[24] = true;
  for(int i=1; i<=11; i++) {
    if (a[i] == 2) {
      time[i] = true;
      time[24-i] = true;
    }
  }
  if (a[12] == 1) {
    time[12] = true;
  }
  //debugln("fuga");
  int ans = 0;
  int s = 1<<11;
  for(int i=0; i<s; i++) {
    for(int j=0; j<=10; j++) {
      if (a[j+1] == 1) {
        int k = 1<<j;
        if (i&k) {
          time[j+1] = true;
          time[24-j-1] = false;
        } else {
          time[j+1] = false;
          time[24-j-1] = true;
        }
      }
    }
    int now = 24;
    int before = 0;
    for(int j=1; j<=24; j++) {
      if (time[j]) {
        //debug(j);debug(j-before);
        chmin(now, j-before);
        before = j;
      }
    }
    //debug(i);
    //debugln(now);
    chmax(ans, now);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
protocol InitFromString {
    init?(_ str: String)
}

extension Int: InitFromString {}
extension Int8: InitFromString {}
extension Int16: InitFromString {}
extension Int32: InitFromString {}
extension Int64: InitFromString {}
extension String: InitFromString {}

func input<T: InitFromString>() -> [T] {
    readLine()!.split(separator: " ").map(String.init).compactMap(T.init)
}

let nk: [Int] = input()
let n = nk[0]
let k = nk[1]

let mod = 1000_000_000 + 7

let result = (k...(n+1)).reduce(0, { res, i in
    let max = sum((n-i+1)...n)
    let min = sum(0...(i - 1))
    return (res + max - min + 1) % mod
})

print(result == 0 ? 1 : result % mod)

func sum(_ arr: ClosedRange<Int>) -> Int {
    return (arr.first! + arr.last!) * arr.count / 2
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int a, b;
	cin >> a >> b;
	if (b >= a){
		cout << "unsafe";
	}else{
		cout << "safe";
	}
}


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

int main(){
  int n;
  while(cin >> n, n) {
    int cnt = 0, a, num[101];
    for(int i = 0 ; i < n ; i++) cin >> num[i];
    
    for(int i = 0 ; i < n-1 ; i++) {
      for(int j = n-1 ; j > i ; j--) {
	if(num[j-1] > num[j]) {
	  a = num[j-1];
	  num[j-1] = num[j];
	  num[j] = a;
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int unsigned long long int
signed main(){
    //int t;cin>>t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,t;cin>>n>>x>>t;
    int ans=(n/x+(n%x!=0))*t;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
n = int(input())
red = []
for i in range(n):
    red.append(list(map(int, input().split())))
blue = []
for i in range(n):
    blue.append(list(map(int, input().split())))
red_sort = sorted(red, key=lambda x: x[1], reverse=True)
blue_sort = sorted(blue)
count = 0
flag = [0] * n
for b in blue_sort:
    for i, r in enumerate(red_sort):
        if r[0] < b[0] and r[1] < b[1] and flag[i] == 0:
            count += 1
            flag[i] = 1
            break
print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  int x;
  cin>>x;
  int h,m,s;
  h=x / 3600;
  m=x % 3600 / 60;
  s=x % 3600 % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;
  return 0;
}

Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
#include<unordered_set>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MOD = 1000 * 1000 * 1000 + 7;

const int MAX = 2 * 1000 * 100 + 47;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m, d;
	cin >> n >> m >> d;
	FOR(i, 0, n)
	{
		FOR(j, 0, m)
		{
			int x = i - j + 1000;
			int y = i + j + 1000;

			x /= d;
			y /= d;
			x %= 2;
			y %= 2;

			cout << "RYGB"[x * 2 + y];
		}

		cout << endl;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

const int MAX_V=210;
ll d[MAX_V][MAX_V];
int V,E,R;

void wardshall_froyd(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main(){
  cin >> V >> E >> R;
  rep(i,V) rep(j,V) d[i][j]=INF;
  rep(i,V) d[i][i]=0;
  vector<int> vr(R);
  rep(i,R){
    int r; cin >> r; r--;
    vr[i]=r;
  }
  sort(all(vr));
  rep(i,E){
    ll a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    chmin(d[a][b],c);
    chmin(d[b][a],c);
  }
  wardshall_froyd();
  int ans=INF;
  do{
    int sum=0;
    vector<int> vrr(0);
    for(int x:vr) vrr.push_back(x);
    rep(i,R-1) sum+=d[vrr[i]][vrr[i+1]];
    if(sum<ans) ans=sum;
  }while(next_permutation(all(vr)));
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    SORT(p);
    ll ans = 0;
    REP(i, K){
        ans += p[i];
    }
    pr(ans);
}

Measured memory_bytes: 3628
#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;


template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }


int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    //timesave;

    //while(1){

    string s;

    cin >> s;

    int x, y;

    x = s[0]-'0'; x *= 10; x += s[1]-'0';
    y = s[2]-'0'; y *= 10; y += s[3]-'0';

    if((x >= 1 && x <= 12) && (y >= 1 && y <= 12)) cout << "AMBIGUOUS" << endl;
    else if(x >= 1 && x <= 12) cout << "MMYY" << endl;
    else if(y >= 1 && y <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    //}

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(long long A, long long B, long long C, long long X){
  ll ans=0;
  rep(i,A+1){
    rep(j,B+1){
      rep(k,C+1){
        if(500*i+100*j+50*k==X)ans++;
      }
    }
  }
  op(ans)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long X;
    scanf("%lld",&X);
    solve(A, B, C, X);
    return 0;
}


Measured memory_bytes: 256
// C - Anti-Division
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, d, h, n, w, ans = 1, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> a >> b >> c >> d;

  lli sum = b - a + 1;
  lli x, y, z;
  lli e = lcm(c, d);

  if (a % c == 0)
    x = b / c - a / c + 1;
  else
    x = b / c - a / c;

  if (a % d == 0)
    y = b / d - a / d + 1;
  else
    y = b / d - a / d;

  if (a % e == 0)
  {
    z = b / e - a / e + 1;
  }
  else
  {
    z = b / e - a / e;
  }

  ans = sum - (x + y - z);
  cout << ans << endl;
}

Measured memory_bytes: 3660
using System;

class Program {
  static void Main(string[] args) {
    int N, M, P, X, rep;
    int[] T;
    string[] bufa;

    N = int.Parse(Console.ReadLine());
    T = new int[N];
    bufa = Console.ReadLine().Split(' ');

    for(int i = 0; i < N; ++i) {
      T[i] = int.Parse(bufa[i]);
    }

    M = int.Parse(Console.ReadLine());

    for(int j = 0; j < M; ++j) {
      rep = 0;
      bufa = Console.ReadLine().Split(' ');
      P = int.Parse(bufa[0]) - 1;
      X = int.Parse(bufa[1]);
      for(int i = 0; i < N; ++i) {
        rep += i == P ? X : T[i];
      }
      Console.WriteLine(rep);
    }

  }
}


Measured memory_bytes: 13140
import sys, heapq, copy
from collections import deque
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, K = map(int, input().split())
V_init = deque(map(int, input().split()))
max_score = 0
hands = [0] * K
heapq.heapify(hands)

for i_rget in range(K + 1):
	for i_lget in range(max(K - i_rget, 0) + 1):
		tmp = 0
		score = 0
		hands = [0] * K
		V = copy.copy(V_init)
		for i in range(i_rget + 1):
			if i > 0 and V:
				tmp = V.pop()					
				heapq.heappush(hands, tmp)
				score += tmp
			
		for i in range(i_lget + 1):
			if i > 0 and V:
				tmp = V.popleft()
				heapq.heappush(hands, tmp)
				score += tmp
		
		for i in range(max(K - i_rget - i_lget, 0) + 1):
			if i > 0:
				tmp = heapq.heappop(hands)
				if tmp < 0:
					score -= tmp
				else:
					break
		
		if score > max_score:
			max_score = score

print(max_score)


Measured memory_bytes: 57052
#include <stdio.h>

int main()
{
    int N,A,B,sum_n,sum_d,i;

    scanf("%d %d %d",&N,&A,&B);

    sum_n = 0;

    for(i=1;i<N+1;i++){
        sum_d = 0;
        sum_d =  i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
        if((A<=sum_d)&&(sum_d<=B)){
            sum_n = sum_n + i;
        }
    }

    printf("%d",sum_n);

    return 0;
}

Measured memory_bytes: 128
import math
import itertools
import collections
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

n,k = MAP()
p = LMAP()

p.sort()

print(sum(p[:k]))

Measured memory_bytes: 9580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		while (true) {
			int max = (int) Math.sqrt(x) + 1;
			boolean flag = true;
			for (int i = 2; i < max; i++) {
				if (x % i == 0) {
					flag = false;
					break;
				}
			}
			if (flag) {
				System.out.println(x);
				break;
			} else {
				++x;
				continue;
			}
		}
	}
}


Measured memory_bytes: 23380
N = int(input())
A = sorted([(a, i) for i, a in enumerate(map(int, input().split()))], reverse=True)
dp = [[0]*(N+1) for _ in [0]*(N+1)]

for j, (a, i) in enumerate(A):
    for l in range(j+1):
        r = N-1-(j-l)
        dp[j+1][l] = max(dp[j+1][l], dp[j][l]+a*(r-i))
        dp[j+1][l+1] = max(dp[j+1][l+1], dp[j][l]+a*(i-l))

print(max(dp[N]))


Measured memory_bytes: 100284
#include <iostream>
#include <fstream>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef __int128 lll;
constexpr ll mod = 1000000007;

int main() {
    ll s;
    scanf("%lld", &s);
    ll l = 1000000000;
    ll x2 = l - (s % l), y2 = s / l + 1;
    if (x2 == l) {
        x2 = 0;
        y2--;
    }
    printf("0 0 1000000000 1 %lld %lld\n", x2, y2);
}

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

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// using int128 = __int128;
// using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &(a))
#define output(a) printf("%lld\n", (a))
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

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

ll N, A[100000], B[100000];

signed main() {
    ll a, b, k;
    cin >> a >> b >> k;
    rep(i, k) {
        if (i & 1) {
            a += b / 2, b /= 2;
        } else {
            b += a / 2, a /= 2;
        }
    }
    cout << a << ' ' << b << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        s:[Bytes;h],
    }

    // d[i][j][k] = Σs[i..j][0..k]
    let mut d = vec![vec![vec![0; w + 2]; h + 1]; h];
    for i in 0..h {
        let mut sum = 0;
        for l in 0..w {
            sum += (s[i][l] - b'0') as usize;
            d[i][i + 1][l + 1] = sum;
        }
    }
    for i in 0..h {
        for j in i + 2..=h {
            for l in 0..=w {
                d[i][j][l] = d[i][j - 1][l] + d[j - 1][j][l];
            }
        }
    }

    // step[i][j][l] :  Σs[i..j][l..l+c] <= K となる最大のc
    let mut step = vec![vec![vec![0; w + 1]; h + 1]; h];
    for i in 0..h {
        for j in i + 1..=h {
            let mut r = 0;
            // Σ s[i..j][l..l+c] = d[i][j][l+c]-d[i][j][l]
            d[i][j][w + 1] = 1000000;
            for l in 0..w {
                while d[i][j][r] - d[i][j][l] <= k {
                    r += 1;
                }
                step[i][j][l] = r - l - 1;
            }
        }
    }
/*
    for i in 0..h {
        for j in i + 1..=h {
            print!("{} {} : ", i, j);
            for l in 0..=w {
                print!("{} ", step[i][j][l]);
            }
            println!("");
        }
    }
*/

    const MAX_CT: usize = 100000;
    let mut v = Vec::with_capacity(11);
    fn dfs(
        i: usize,
        h: usize,
        w: usize,
        v: &mut Vec<(usize, usize)>,
        step: &Vec<Vec<Vec<usize>>>,
    ) -> usize {
        if i == h {
            let mut ct = v.len() - 1;
            let mut x = 0;
            while x < w {
                let mut min_step = w + 1;
                for &(i, j) in &*v {
                    min_step = min(min_step, step[i][j][x]);
                }
                if min_step == 0 {
                    return MAX_CT;
                }
                x += min_step;
                ct += 1;
            }
            ct - 1
        } else {
            let mut min_ct = MAX_CT;
            for j in i + 1..=h {
                v.push((i, j));
                min_ct = min(min_ct, dfs(j, h, w, v, step));
                v.pop();
            }
            min_ct
        }
    }

    let ans = dfs(0, h, w, &mut v, &step);
    println!("{}", ans);
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s,t;
  cin >> s >> t;
  ll ans = 0;
  for(int i = 0; i < 3; ++i){
    if(s[i] == t[i]) ++ans;
  }
  cout << ans;
  return 0;
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

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

int main() {
	int n; cin >> n;
	vll a(n); Loop(i, n) cin >> a[i];
	ll ans = 0;
	Loop(i, n) {
		Loop(j, n) {
			if (i < j) {
				ans += a[i] * a[j];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

void solve(){
	int n;
	bool flag = false;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int x = a[n - 1];
	int i = -1;
	for (int j = 0; j < n - 1; j++){
		if (a[j] <= x) swap(a[++i], a[j]);
	}
	swap(a[++i], a[n - 1]);
	for (int k = 0; k < n; k++){
		if (flag) cout << " ";
		else flag = true;
		if (k == i) cout << "[" << a[k] << "]";
		else  cout << a[k];
	}
	cout << endl;
}

signed main(){
	solve();
}

Measured memory_bytes: 3052
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"7 5 1"# => r#"YES"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize, b: usize, c: usize,
    }
    let mut ans = "NO";
    let mut cnt = 0;

    loop {
        cnt += a;
        if b*a < cnt {
            break;
        }

        // println!("{}: {} / {} = {}, {}", cnt, cnt, b, cnt / b, cnt % b);
        if cnt % b == c {
            ans = "YES"
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
const int max_n=100000;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n;cin>>n;
  vi v(n);
  rep(i,n){
    int a;cin>>a;
    v[a-1]=i;
  }
  int k=0,ans=0;
  rep(i,n-1){
    if(v[i]<v[i+1]){
      k++;
      chmax(ans,k);
    }
    else k=0;
  }
  cout<<n-ans-1<<endl;
}


Measured memory_bytes: 1792