akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
int n;
int chk[1<<17];
struct dj{
    vector<int> root, siz;

    void init(int n)
    {
        root.resize(n);
        siz.resize(n);
        for(int i=0;i<n;i++)
            root[i] = i, siz[i] = 1;
    }

    int find(int x)
    {
        return root[x] = (root[x] == x ? x : find(root[x]));
    }

    int merge(int x, int y)
    {
        x = find(x);
        y = find(y);
        if(x == y) return 0;
        siz[x] += siz[y];
        root[y] = x;
        return 1;
    }

    ll get_size(int x)
    {
        return siz[find(x)];
    }
};
dj djx, djy;
vector<int> vx, vy, cx, cy;
vector<int> mx[1<<17], my[1<<17];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i=0;i<n;i++)
    {
        int x, y;
        cin >> x >> y;
        vx.push_back(x), vy.push_back(y);
    }
    cx = vx, cy = vy;
    sort(cx.begin(), cx.end());
    cx.resize(unique(cx.begin(), cx.end()) - cx.begin());
    sort(cy.begin(), cy.end());
    cy.resize(unique(cy.begin(), cy.end()) - cy.begin());
    for(int i=0;i<n;i++)
    {
        vx[i] = lower_bound(cx.begin(), cx.end(), vx[i]) - cx.begin();
        vy[i] = lower_bound(cy.begin(), cy.end(), vy[i]) - cy.begin();
        mx[vx[i]].push_back(i);
        my[vy[i]].push_back(i);
    }

    djx.init(n);
    djy.init(n);
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        ll cnt = 0;
        if(mx[vx[i]].size() > 1 && my[vy[i]].size() > 1 && !chk[i])
        {
            queue<int> q;
            for(int j : mx[vx[i]])
            {
                if(!chk[j])
                {
                    q.push(j);
                    chk[j] = 1;
                    cnt++;
                }
            }
            for(int j : my[vy[i]])
            {
                if(!chk[j])
                {
                    q.push(j);
                    chk[j] = 1;
                    cnt++;
                }
            }
            while(!q.empty())
            {
                int j = q.front();
                q.pop();
                if(djx.root[vx[i]] != djx.root[vx[j]])
                {
                    djx.merge(vx[i], vx[j]);
                    for(int k : mx[vx[j]])
                    {
                        if(!chk[k])
                        {
                            q.push(k);
                            chk[k] = 1;
                            cnt++;
                        }
                    }
                }
                if(djy.root[vy[i]] != djy.root[vy[j]])
                {
                    djy.merge(vy[i], vy[j]);
                    for(int k : my[vy[j]])
                    {
                        if(!chk[k])
                        {
                            q.push(k);
                            chk[k] = 1;
                            cnt++;
                        }
                    }
                }
            }
            ans += djx.get_size(vx[i]) * djy.get_size(vy[i]) - cnt;
        }
    }
    cout << ans;
}

Measured memory_bytes: 13044
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<s1.length();i++){sb.append(s1.charAt(i));}
    return Integer.parseInt(sb.toString());
}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
                assign();
                int t=1;//read().charAt(0)-'0',cn=1;
                while(t--!=0){
                	long[] z=long_arr();
                	long x=z[0],k=z[1],d=z[2];
                    x=Math.abs(x);
                    long s=x/d; long res=0;
                    if(k<=s){
                    	res=x-k*d;
                    }
                    else{
                    	x-=s*d;
                    	if(x==0l){
                    		if((k-s)%2==0) res=0;
                    		else res=d;
                    	}
                    	else if(x>0){
                    		if((k-s)%2==0) res=x;
                    		else res=Math.abs(x-d);
                    	}
                    	else{
                    		if((k-s)%2==0) res=Math.abs(x);
                    		else res=Math.abs(x+d);
                    	}
                    }
                    out.write(res+"\n");            
                }                
                out.flush();

    }
}

Measured memory_bytes: 36912
#C
from itertools import combinations

N,M,X=map(int,input().split())
Z=[[int(x) for x in input().split()] for i in range(N)]
num=[i for i in range(N)]

com=[]
for i in range(1,N+1):
    com=com+list(combinations(num, i))
    
Min=10**8
for A in com:
    cost=0
    B=[0 for j in range(M)]
    for i in A:
        cost+=Z[i][0]
        for j in range(M):
            B[j]+=Z[i][j+1]
        
    if min(B)<X:
        continue
    else:
        Min=min(Min,cost)
        
if Min==10**8:
    print(-1)
else:
    print(Min)

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

void factorize( int n ) {
	cout << n << ':';

	while( n % 2 == 0 ) {
		cout << ' ' << 2;
		n /= 2;
	}

	int d = 3;
	int e = sqrt( n );

	while( n >= d ) {
		if( d > e ) {
			cout << ' ' << n;
			break;
		}

		if( n % d == 0 ) {
			cout << ' ' << d;
			n /= d;
		}
		else {
			d += 2;
		}
	}

	cout << endl;
}

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;
	factorize( n );
}



Measured memory_bytes: 3200
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim ans = "NO"

        Dim A = NextInt()
        Dim B = NextInt()
        Dim C = NextInt()

        Dim X = A
        For i As Integer = 0 To B
            If X Mod B = C Then
                ans = "YES"
                Exit For
            End If
            X += A
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1010
#define ll long long
#define mod 1000000007
using namespace std;

int n, m, map[N][N], sum, f1, f2, s, s1, ans;
ll k;
char S[N];

struct mat{
	int a[3][3];
	void clear(){memset(a, 0, sizeof(a));}
}A, B, C;

inline int pow(int y, ll x){
	int s=1, t=y;
	while(x){if(x&1)s=(ll)s*t%mod; t=(ll)t*t%mod; x>>=1;}
	return s;
}
inline mat operator*(mat A, mat B){
	mat C; C.clear();
	for(int i=1; i<=2; i++)
		for(int j=1; j<=2; j++)
			for(int k=1; k<=2; k++)C.a[i][j]=(C.a[i][j]+(ll)A.a[i][k]*B.a[k][j]%mod)%mod;
	return C;
}
inline mat pow1(mat A, ll x){
	mat s, t=A; s.clear(); for(int i=1; i<=2; i++)s.a[i][i]=1;
	while(x){if(x&1)s=s*t; t=t*t; x>>=1;}
	return s;
}

int main(){
	scanf("%d%d%lld", &n, &m, &k);
	for(int i=1; i<=n; i++){
		scanf("%s", S+1);
		for(int j=1; j<=m; j++)map[i][j]=S[j]=='#'?1:0;
	}
	sum=0;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)sum+=map[i][j];
	f1=f2=0;
	for(int i=1; i<=n; i++)if(map[i][1]&&map[i][m])f1=1;
	for(int i=1; i<=m; i++)if(map[1][i]&&map[n][i])f2=1;
	if(!k){printf("1"); return 0;}
	if(f1&&f2){printf("1"); return 0;}
	if(!f1&&!f2){printf("%d", pow(sum, k-1)); return 0;}
	if(f1){
		s=s1=0;
		for(int i=1; i<=n; i++)if(map[i][1]&&map[i][m])s++;
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m-1; j++)if(map[i][j]&&map[i][j+1])s1++;
	}else{
		s=s1=0;
		for(int i=1; i<=m; i++)if(map[1][i]&&map[n][i])s++;
		for(int i=1; i<=n-1; i++)
			for(int j=1; j<=m; j++)if(map[i][j]&&map[i+1][j])s1++;
	}
	B.a[1][1]=sum; B.a[1][2]=0; B.a[2][1]=s1; B.a[2][2]=s;
	A=pow1(B, k-1);
	ans=(pow(sum, k-1)-A.a[2][1]+mod)%mod; printf("%d", ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n,m;
void solve()
{
    cin>>n>>m;
    if(n>1&&m>1)cout<<(n*m)/2+(n*m)%2;
    else cout<<1;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("STRWC.inp","r",stdin);
    //freopen("STRWC.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<pair<int, int> > e[maxn];
long long x[2][maxn]; // x[0][i] * t + x[1][i]
int seen[maxn];
void dfs(int cur){
	seen[cur] = 1;
	for(auto ed : e[cur]){
		int nxt, cost; tie(nxt, cost) = ed;
		if(seen[nxt]) continue;
		x[0][nxt] = -x[0][cur];
		x[1][nxt] = cost - x[1][cur];
		dfs(nxt);
	}
}
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u, v, w; cin >> u >> v >> w;
		e[u].push_back({v, w});
		e[v].push_back({u, w});
	}
	x[0][1] = 1;
	dfs(1);
	long long lo = 1, hi = 1ll<<60, ans = -1;
	for(int i = 1; i <= n; i++){
		if(x[0][i] == 1){
			lo = max(lo, - x[1][i] + 1);
		} else {
			hi = min(hi, x[1][i] - 1);
		}
		auto fail = [&](){
			cout << 0 << endl;
			exit(0);
		};
		for(auto ed : e[i]){
			int nxt, cost; tie(nxt, cost) = ed;
			long long x0 = x[0][i] + x[0][nxt];
			long long x1 = x[1][i] + x[1][nxt];
			if(x0 == 0){
				if(x1 != cost) fail();	
			} else {
				long long diff = cost - x1;
				if(diff%2) fail();
				diff /= x0;
				if(diff <= 0) fail();
				if(ans == -1) ans = diff;
				if(ans != diff) fail();
			}
		}
	}
	if(ans == -1) cout << max(0ll, hi - lo + 1) << endl;
	else {
		if(lo <= ans && ans <= hi) cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;






int main(){
    string s;cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if(i%2){
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
            }
            else{
                puts("No");
                return 0;
            }
        }
        else{
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
            }
            else{
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long

//
// int main(){
//   int n,t;cin>>n>>t;
//   int a[n];rep(i,n)cin>>a[i];
//   int ans=0;
//   rep(i,n-1){
//     ans+=min(t,a[i]-a[i-1]);
//     }
//   cout<<ans<<endl;
// }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,t;
  cin >> n >> t;
  vector<int> a(n);
  ll ans=t;
  for(int i=0;i<n;++i){
    cin >> a[i];
	}
  for(int i=0;i<n-1;++i){
    ans+=min(t,a[i+1]-a[i]);
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int N,K; cin >> N>>K;
	if (K == 1)cout << 0 << endl;
	else cout << N - K << endl;
	

}




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    vector<vi> A(h,vi(w)),B(h,vi(w)),C(h,vi(w));
    rep(i,h)rep(j,w) cin>>A[i][j];
    rep(i,h)rep(j,w) cin>>B[i][j];
    rep(i,h)rep(j,w) C[i][j] = abs(A[i][j]-B[i][j]);
    using BS = bitset<12800>;
    vector<vector<BS> > dp(h,vector<BS>(w));
    dp[0][0][C[0][0]] = true;
    //貰うDP
    rep(i,h)rep(j,w){
        if (i>0){
            rep(k,12800){
                if (dp[i-1][j][k]==false) continue;
                dp[i][j][k+C[i][j]] = true;
                dp[i][j][abs(k-C[i][j])] = true;
            }
        }
        if (j>0){
            rep(k,12800){
                if (dp[i][j-1][k]==false) continue;
                dp[i][j][k+C[i][j]] = true;
                dp[i][j][abs(k-C[i][j])] = true;
            }
        }
    }
    int ans=20020;
    rep(k,12800){
        if (dp[h-1][w-1][k]==true){
            ans = k;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10496
use std::io::*;
use std::str::FromStr;

fn main() {
	let (n, m): (isize, isize) = (read(), read());
	let mut temp: isize;
	let mut sum: isize = 0;
	for _ in 0..m {
		temp = read();
		sum += temp;
	}
	let ans = if sum <= n { n-sum } else { -1 };
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


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

int main() {
  int N, x;
  cin >> N >> x;
  int a[N];
  for (int i=0 ; i<N ; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i=0 ; i<N-1 ; i++) {
    int sum1 = a[i] + a[i+1];
    if (sum1 > x) {
      if (sum1 - x <= a[i+1]) {
        a[i+1] -= sum1 - x;
        ans += sum1 - x;
      } else {
        a[i+1] = 0;
        a[i] -= sum1 - x - a[i+1];
        ans += sum1 - x;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;

  int ans = INT32_MAX;
  for (int i = 0; i < S.size() - 2; i++) {
    int X = stoi(S.substr(i, 3));
    ans = min(ans, abs(X - 753));
  }

  printf("%d", ans);
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll count = 0;
    map<ll, ll> m;
    cin >> N;
    rep(i, N) {
        ll temp;
        cin >> temp;
        m[temp]++;
    }
    iter(i, m) {
        if(i.second >= i.first) count += i.second - i.first;
        else count += i.second;
    }
    cout << count << endl;
    return 0;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  
  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) ans++;
    }
  }
  cout << ans << endl;     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, m, q; cin >> n >> m >> q;
    vvi lr(n+2, vi(n+2, 0));
    rep(i, m){
        ll l, r; cin >> l >> r;
        lr[l][r]++;
    }
    repf(i, n) repf(j, n) lr[i][j+1] += lr[i][j];
    repf(i, n) repf(j, n) lr[j+1][i] += lr[j][i];

    rep(i, q){
        ll l, r; cin >> l >> r;
        cout << lr[r][r] - lr[l-1][r] << endl;
    }
}

Measured memory_bytes: 5284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  char c[26] = {'a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  string ans = "";
  vl dpa(13, 0);
  ll num = 1;
  dpa[0] = 0;
  for (ll i = 1; i < 15; i++){
    dpa[i] = dpa[i-1]*26+26;
  }
  vl dpb(12);
  for(ll i=1;i<12;i++){
    dpb[i] = dpa[i] - dpa[i-1];
  }
  ll m;
  for (ll i = 11; i >= 0;i--){
    if(n>dpa[i]){
      m = i;
      break;
    }
  }
  for (ll i = m; i >= 0; i--){
    if(i==0){
      ans.pb(c[n - 1]);
      break;
    }
    if(n>dpa[i]){
      ll l = n;
      l -= dpa[i];
      ll r = (l-1) / dpb[i];
      ans.pb(c[r]);
      n -= dpb[i] * (r+1);
    }
    else{
      ans.pb('a');
    }
  }
  print(ans);
}


Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	int n, k, c;
	scanf("%d %d %d", &n, &k, &c);
	char s[200005];
	scanf("%s", s);
	int i, j;
	int l[200005], r[200005];
	j = 0;
	for (i = 0;j < k; j++)
	{
		while (s[i] == 'x')
			i++;
		l[j] = i;
		i += c + 1;
	}
	j = k - 1;
	for (i = n - 1; j >= 0; j--)
	{
		while (s[i] == 'x')
			i--;
		r[j] = i;
		i -= c + 1;
	}
	for (i = 0; i < k; i++)
		if (l[i] == r[i])
			printf("%d\n", l[i] + 1);
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;


int main() {
  double L;
  cin >> L;
  double r = L/3 * L/3 * L/3;
  printf("%lf\n", r);

  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val P = Array(N) {
        val (x, y) = readLine()!!.split(" ").map(String::toDouble)
        V(x, y)
    }
    val distances = P.toPairs().map { it.first.distanceTo(it.second) }
    val ans = distances.sum() * fact(N - 1) * 2 / fact(N)
    println(ans)
}

data class V(val x: Double, val y: Double) {
    fun distanceTo(o: V) = Math.sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y))
}

fun fact(n: Int) = (1..n).fold(1) { i, j -> i * j }

fun <T> Array<T>.toPairs(): Array<Pair<T, T>> {
    val ret = mutableListOf<Pair<T, T>>()
    for (i in 0 until this.size - 1) {
        for (j in i + 1 until this.size) {
            ret += Pair(this[i], this[j])
        }
    }
    return ret.toTypedArray()
}

Measured memory_bytes: 37904
#include <iostream>

using namespace std;

void solve()
{
	int t;
	while(cin >> t, t)
	{
		int n;
		cin >> n;
		int sum = 0;
		while(n--)
		{
			int s, f;
			cin >> s >> f;
			sum += f - s;
		}
		if(sum >= t)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << t - sum << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  int P = 0;
  int ans = N;
  for (int i = 0; i < N - 1; i++)
  {
    P += A.at(i);
    if (2 * P < A.at(i + 1)) ans = N - i - 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		while(true) {
			String x = sc.next();
			if(x.equals("0")) {
				break;
			}
			String[] line = x.split("");
			int[] tmp = new int[line.length];
			long count = 0;
			for(int i=0;i<line.length;i++) {
				tmp[i] = Integer.parseInt(line[i]);
				count+=tmp[i];
			}
			System.out.println(count);
		}
		sc.close();
	}
}


Measured memory_bytes: 27308
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	int cnt = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (i + 1 == p[i]) {
			swap(p[i], p[i + 1]);
			++cnt;
		}
	}
	if (p[n - 1] == n) ++cnt;
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    int n;
    cin >> n;
    
    vector<ll> a(n * 3, 0);
    REP(i, n * 3){
        cin >> a[i];
    }
    
    priority_queue<ll, vector<ll>, greater<ll>> p1;
    ll sum = 0;
    REP(i, n){
        sum += a[i];
        p1.push(a[i]);
    }
    
    vector<ll> t1(3 * n, 0);
    t1[n - 1] = sum;
    for(int i = n; i < 2 * n; i++){
        // cout << sum << ' ';
        sum += a[i];
        p1.push(a[i]);
        sum -= p1.top();
        p1.pop();
        t1[i] = sum;
    }
    // cout << sum << endl;
    
    
    priority_queue<ll> p2;
    sum = 0;
    REP(i, n){
        // cout << a[3 * n - i - 1] << endl;
        sum += a[3 * n - i - 1];
        p2.push(a[3 * n - i - 1]);
    }
    
    vector<ll> t2(3 * n, 0);
    t2[2 * n] = sum;
    for(int i = 2 * n - 1; i >= n; i--){
        // cout << sum << ' ';
        sum += a[i];
        p2.push(a[i]);
        sum -= p2.top();
        p2.pop();
        t2[i] = sum;
    }
    // cout << sum << endl;
    
    ll ans = -INF;
    for(int i = n - 1; i < 2 * n; i++){
        // cout << t1[i] - t2[i + 1] << endl;
        ans = max(ans, t1[i] - t2[i + 1]);
    }
    
    cout << ans << endl;
}

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

long long int count(char start_with, long long int len);

char S[1000001];
int main(void) {
  scanf("%s", S);
  long long int len = strlen(S);
  char state;

  long long int zero = count('0', len);
  long long int one = count('1', len);

  printf("%lld\n", (zero > one ? one : zero));

  return 0;
}

long long int count(char start_with, long long int len) {
  long long result = 0;
  char state = start_with;
  for(long long i=0;i<len;i++) {
    if(S[i] != state) {
      result ++;
    }
    state = (state=='0' ? '1' : '0');
  }
  return result;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, j, temp, n;

  scanf("%d", &n);

  i = temp = 1;
  while (temp < n) temp += ++i;
  for (j = 1; j <= i; j++) {
    if (j == temp - n) continue;
    printf("%d\n", j);
  }

  return 0;
}


Measured memory_bytes: 128
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, ans = 0;
    cin >> n;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    int prime[1000005];
    prime[0] = 0;
    prime[1] = 0;
    for (ll i = 2; i < 1000005; i++) prime[i] = 1;
    for (ll i = 2; i < 1000005; i++) {
        ll count = 2;
        while (i*count <= 1000005) {
            prime[i*count] = 0;
            count++;
        }
    }
    for (ll i = 2; i*i <= n; i++) {
        if (prime[i]) {
        ll c = 0;
        while (n%i == 0) {
            c++;
            n /= i;
        }
        //cout << p1 << ' ' << c << endl;
        ll t = 1;
        while ((t*(t+1))/2 <= c) t++;
        ans += t-1;
        }
    }
    if (n > 2) ans += 1;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 7552
#include<stdio.h>

int main(void){
int a, b;

scanf("%d %d", &a, &b);

if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
printf("Possible");
}else{
printf("Impossible");
}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main(){
  int n, w, d;
  while(cin >> n >> w >> d, n||w||d){
    int p, s;
    vector< pair<int, int> > C;
    C.push_back(make_pair(w,d));
    for(int i = 0; i < n; ++i){
      cin >> p >> s;
      w = C[p-1].first;
      d = C[p-1].second;
      C.erase(C.begin() + p-1);
      s %= w + d;
      if(s < w){
	C.push_back(make_pair(min(s, w-s), d));
	C.push_back(make_pair(max(s, w-s), d));
      }else{
	s -= w;
	C.push_back(make_pair(w, min(s, d-s)));
	C.push_back(make_pair(w, max(s, d-s)));
      }
    }
    vector<int> S;
    for(int i = 0; i <= n; ++i)
      S.push_back(C[i].first*C[i].second);
    sort(S.begin(),S.end());
    for(int i = 0; i < n; ++i){
      cout << S[i] << " ";
    }
    cout << S[n] << endl;
  }
  return 0;
}

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

int main() {
   
  int n, k;
  cin >> n >> k;
  int x;
  int a = 0;
  
  for (int i = 0; i < n; i++){
    cin >> x;
    if (k-x >= x-0){
       a += x * 2;
       continue;
       }
    if (k-x < x-0){
       a += (k - x) * 2;
       continue;
       }
    
  }
  
  cout << a << endl;
}



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

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

    string s;
    cin >> s;
    if(s[2] == s[3])
        if(s[4] == s[5])
            cout << "Yes";
        else cout << "No";
    else cout << "No";


    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<string> W(N);
  rep(i, N)
  {
    string w;
    cin >> w;
    W[i] = w;
  }

  string ans = "Yes";
  rep(i, N - 1)
  {
    if (W[i].back() != W[i + 1][0])
      ans = "No";
  }
  sort(W.begin(), W.end());
  rep(i, N - 1)
  {
    if (W[i] == W[i + 1])
      ans = "No";
  }

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

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    cout << 0 << endl;
  } else {
    cout << min({a * b, b * c, a * c}) << endl;
  }
  return 0;
}



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

int main()
{
	int n; cin>>n;
	if(n==22) cout<<"Christmas Eve Eve Eve\n";
	else if(n==23) cout<<"Christmas Eve Eve\n";
	else if(n==24) cout<<"Christmas Eve\n";
	else cout<<"Christmas\n";
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using Pdi = pair<double, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    Sort(A); Sort(B);

    int ans;
    if(N % 2){
        ans = B[N / 2] - A[N / 2] + 1;
    }else{
        ans = B[N / 2 - 1] + B[N / 2] - A[N / 2 - 1] - A[N / 2] + 1;
    }

    Out(ans);

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<char> vec_n(n);
    
  for(int i= 0; i < n; i++){
    cin >> vec_n.at(i);
  }
  for(int i= 0; i < n; i++){
    if (vec_n.at(i) == 'Y'){
      cout << "Four" << endl;
      break;
    }
    if (i == n-1){
      cout << "Three" << endl;
    }
  }
}
  
  

Measured memory_bytes: 3632
A, B = map(int, input().split(" "))


if A % B == 0:
    print(A)
elif B % A == 0:
    print(B)
else:
    A_, B_ = A, B
    common = 1
    n_max = int(min(A,B)**0.5+1)
    for n in range(2, n_max+1):
        while True:
            if (A_ % n == 0) and (B_ % n == 0):
                common *= n
                A_ = A_ // n
                B_ = B_ // n
            else:
                break

    print(common * A_ * B_)



Measured memory_bytes: 9368
def leap_year?(year)
  year % 400 == 0 || (year % 100 != 0) && (year % 4 == 0)
end

def main
  a,b = gets.chomp.split(' ').map(&:to_i)
  return if a|b == 0

  loop do
    leap_year_found = false
    (a..b).each do |year|
      if leap_year?(year)
        puts year
        leap_year_found = true
      end
    end

    unless leap_year_found
      puts "NA"
    end

    a,b = gets.chomp.split(' ').map(&:to_i)
    break if a|b == 0

    puts ""
  end
end

main

Measured memory_bytes: 8776
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:i32 = read(); // 500
    let b:i32 = read(); // 100
    let c:i32 = read(); // 50
    let x:i32 = read();

    let mut cnt = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if x - ((500 * i) + (100 * j) + (50 * k)) == 0 {
                    cnt += 1;
                }
            }
        }
    }

    println!("{}", cnt);
}


Measured memory_bytes: 4352
#pragma GCC optimize("O3", "unroll-loops")

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <limits>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

const int inf = (1 << 30) + 9e8;
const int MAXN = 1e5;
const int MAXN2 = 1e4;
const int P = 131;
const long long MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<bool> vb;

#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define all(a) a.begin(), a.end()
#define pb push_back
#define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define ppb pop_back
#define ppf pop_front
#define fs first
#define sd second
#define eb emplace_back

template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, W;
    cin >> n >> W;
    vi m(n + 1), v(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> m[i] >> v[i];
    }
    vvll dp(n + 1, vll(W + 300, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= W; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j >= m[i]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - m[i]] + v[i]);
            }
        }
    }
    ll mx = -inf;
    for (int i = W; i >= 0; --i) {
        mx = max(mx, dp[n][i]);
    }
    cout << mx;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    FAST;
    int q = 1;
    // cin >> q;
    // int st = clock();
    while (q--) {
        solve();
    }
    // int en = clock();
    // cout << en - st << "ms.";
    return 0;
}


Measured memory_bytes: 83128
#include <iostream>
#include <algorithm>

#define INF 1e9

using namespace std;

int main() {
    int n, m, c[21];
    int dp[50001];

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }

    fill(dp, dp + 50001, INF);

    dp[0] = 0;

    for (int i = 0; i < m; i++) {
        for (int j = 0; j + c[i] <= n; j++) {
            dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3308
n = int(input())
nums = list(map(int, input().split()))

for i in range(n):
    nums[i] -= (i + 1)

nums.sort()
        
if (n-1) % 2 != 0:
    m = n//2 - 1
else:
    m = (n-1)//2
    
a = sum(nums[m+1:]) - (n-m-1)*nums[m]
b = - sum(nums[0:m+1]) + (m+1)*nums[m]

print(a+b)

Measured memory_bytes: 26180
from collections import deque

N = int(input())
line = [[] for _ in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    line[u-1].append(v-1)
    line[v-1].append(u-1)

not_visited = [-1]*N
not_visited[0] = 0
stack = deque()
stack.append(0)

while stack != deque([]):
    now = stack.popleft()
    for i in line[now]:
        if not_visited[i] == -1:
            not_visited[i] = now
            stack.append(i)

route = []
now = N-1
while not_visited[now] != 0:
    route.append(now)
    now = not_visited[now]
route.append(now)
route.reverse()

l = len(route)

not_visited = [-1]*N
for i in route[l//2:]:
    not_visited[i] = -2
not_visited[0] = 0
stack = deque()
stack.append(0)

F = 0
while stack != deque([]):
    now = stack.popleft()
    for i in line[now]:
        if not_visited[i] == -1:
            not_visited[i] = not_visited[now] + 1
            stack.append(i)
            F += 1

S = N-F-2

if F > S:
    print("Fennec")
else:
    print("Snuke")

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

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

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

    ll N; cin >> N;
    ll A[200005];
    ll B[200005];
    ll m = -1;
    bool f = false;
    for (int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] > m){
            m = A[i];
            f = false;
        }else if(A[i] == m){
            f = true;
        }
        B[i] = A[i];
    }

    sort(B,B+N);

    for (int i = 0;i < N;i++){
        if(f) cout << m << endl;
        else{
            if(A[i] == m) cout << B[N-2] << endl;
            else cout << m << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=5005;
const int mod=1e9+7;
int n,p[max_n];
int par[max_n],sz[max_n];
int findpar(int x){
    return x==par[x]?x:par[x]=findpar(par[x]);
}
int Pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return res;
}
int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
int f[max_n];
int dp[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",p+i);
    for(int i=1;i<=n;i++)par[i]=i,sz[i]=1;
    int cnt=0,k=0;
    for(int i=1;i<=n;i++){
        if(p[i]!=-1){
            int x=i,y=p[i];
            x=findpar(x),y=findpar(y);
            if(x!=y)par[x]=y,sz[y]+=sz[x];
            else cnt++;
        }
        else k++;
    }
    int ans=1ll*(n-cnt)*Pow(n-1,k)%mod;
    dp[0]=1;
    for(int i=1;i<=n;i++){
        if(p[i]!=-1)continue;
        int x=sz[findpar(i)];
        ans=Sub(ans,1ll*(x-1)*Pow(n-1,k-1)%mod);
        for(int j=k;j>=1;j--)dp[j]=Add(dp[j],1ll*x*dp[j-1]%mod);
    }
    f[0]=1;
    for(int i=1;i<=n;i++)f[i]=1ll*f[i-1]*i%mod;
    for(int i=2;i<=k;i++)ans=Sub(ans,1ll*dp[i]*f[i-1]%mod*Pow(n-1,k-i)%mod);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3876
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

string solve(string &s){
    char *p = (char *)s.c_str();
    while(1){
        p = strstr(p, "Hoshino");
        if(p == NULL) break;
        memcpy(p, "Hoshina", 7);
    }
    return s;
}

int main(){
    int n;
    string s;
    getline(cin, s);
    stringstream ss(s);
    ss >> n;
    REP(i,n){
        getline(cin, s);
        cout << solve(s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int maxc = 26;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll qw(ll x,ll y){ll ans = 1;while(y){if(y&1) ans *= x;x *= x;y >>= 1;}return ans;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool is_prime(ll x){if(x <= 1) return 0;for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;	}
ll n,a[maxn];
map<ll,ll> m;
ll ans;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i,1,n){
		cin >> a[i];
		ll t = a[i] - i;
		ans += m[t];
		m[-a[i] - i]++;
	}
	cout << ans << endl;		
	return 0;	
}

Measured memory_bytes: 27888
#include <stdio.h>
int main(void){
  int h,w,k[52][52]={},i,j,x,y;
  char f[50][51];
  scanf("%d%d\n",&h,&w);
  for (i=1;i<=h;i++){
    scanf("%s",f[i-1]);
    for (j=1;j<=w;j++){
      if (f[i-1][j-1]=='#'){
        for (x=-1;x<2;x++){
          for (y=-1;y<2;y++){
            k[i+x][j+y]++;
          }
        }
      }
    }
  }
  for (i=1;i<=h;i++){
    for (j=1;j<=w;j++){
      if (f[i-1][j-1]=='#') printf("#");
      else printf("%d",k[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 128