akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
	int n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		if(a[i]==0){
			cout<<0;
			return;
		}
	}
	const ll m=1000000000000000000;
	ll mul=1;
	rep(i,n){
		if(mul>m/a[i]){
			cout<<-1;
			return;
		}
		mul*=a[i];
		if(mul>m){
			cout<<-1;
			return;
		}
	}
	cout<<mul;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c,d;cin >>a>>b>>c>>d;
  cout << (a-1)*(b-1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;
 
const ll INF = 1LL << 60;
 
signed main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	int odd=0;
	REP(i,n){
		cin >> a[i];
		if(a[i]%2==1){
			odd++;
		}
	}
	if(odd==0){
		cout << "second" << endl;
	}
	else{
		cout << "first" << endl;
	}
}

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

int main(){
  int K,N;
  string S;
  cin >> N >> S >> K;
  char c=S[K-1];
  for(int i=0; i<N; i++){
    if(S[i]!=c) cout << '*';
    else cout << c;
  }
  cout << endl;
}

Measured memory_bytes: 256
#D問題
import heapq
N,M = map(int,input().split())
AB = []
for i in range(N):
    ab = list(map(int,input().split()))
    heapq.heappush(AB,ab)
    
ans = 0
cand = []
for i in range(M):
    while AB:
        ab = heapq.heappop(AB)
        if ab[0] <= (i+1):
            heapq.heappush(cand,10**5-ab[1])
        else:
            heapq.heappush(AB,ab)
            break
    
    if len(cand) >= 1:
        cd = heapq.heappop(cand)
        ans+=(10**5-cd)
    
print(ans)

Measured memory_bytes: 27872
n = 0
while n == 0:
    m = map(int,raw_input().split())
    if m[0] + m[1] + m[2] == -3:
        break
    if m[0] == -1 or m[1] == -1:
        print "F"
    else:
        for i in xrange(2):
            if m[i] == -1:
                m[i] = 0
        k = m[0] + m[1]
        if k >= 80:
            print "A"
        elif k >= 65:
            print "B"
        elif k >= 50:
            print "C"
        elif k >= 30:
            if m[2] >= 50:
                print "C"
            else:
                print "D"
        elif k < 30:
            print "F"

Measured memory_bytes: 6436
#include <iostream>

using namespace std;

int main() {
	int Q; cin >> Q;
	for (int t = 0; t < Q; ++t) {
		int c, a, n; cin >> c >> a >> n;

		int cca = 0, ccc = 0, can = 0;
		can += min( min(c, a), n); c -= can, a -= can, n -= can;
		cca = min(c/2, a); c -= cca * 2, a -= cca;
		ccc = c/3;

		int ans = cca + ccc + can;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const newNode = (id, left, right) => {

    const degree = left === -1 && right === -1 ? 0
                 : left === -1 || right === -1 ? 1
                 : 2;

    return {
        id : id,
        parent : -1,
        left : left,
        right : right,
        degree : degree,
        depth : null,
        height : 0,
        sibling : -1,
        type : ''
    };
};

const setDepth = tree => {
    const root = tree.filter(x => x.parent === -1)[0];
    const helper = (node, n) => {
        node.depth = n;
        if (node.left !== -1) helper(tree[node.left], n+1);
        if (node.right !== -1) helper(tree[node.right], n+1);
    };
    helper(root, 0);
};

const setType = node => {
    node.type = node.parent === -1 ? 'root'
              : node.left === -1 && node.right === -1 ? 'leaf'
              : 'internal node';
};

const setHeight = (tree, id, n) => {
    if (id === -1) return n-1;
    return Math.max(setHeight(tree, tree[id].left, n+1), setHeight(tree, tree[id].right, n+1));
};

const setSibling = (tree) => {
    tree.forEach(x => {
        if (x.left !== -1) tree[x.left].sibling = x.right;
        if (x.right !== -1) tree[x.right].sibling = x.left;
    });
};

const nodeToString = node => {
    return `node ${node.id}: parent = ${node.parent}, sibling = ${node.sibling}, degree = ${node.degree}, depth = ${node.depth}, height = ${node.height}, ${node.type}`;
};

const n = parseInt(line[0]);
const data = line.slice(1, n+1)
                 .map(x => x.split(' ').map(Number));
const tree = data.map(xs => newNode(xs[0], xs[1], xs[2]));
tree.sort((a, b) => a.id - b.id);
tree.forEach(x => {
    if (x.left !== -1) tree[x.left].parent = x.id;
    if (x.right !== -1) tree[x.right].parent = x.id;
});
tree.forEach(x => setType(x));
setDepth(tree);
tree.forEach(x => {
    x.height = setHeight(tree, x.id, 0);
});
setSibling(tree, 0);
tree.map(x => nodeToString(x))
    .forEach(x => console.log(x));



Measured memory_bytes: 15376
//パラメータ値格納用配列
var N = 0;
var M = 0;
var A = [];
var B = [];
var C = [];

function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  N = Number.parseInt(inputStr[0]);
  M = Number.parseInt(inputStr[1]);
  //頂点と辺の情報を格納
  for(var i=1 ; i<=M ; i++){
    inputStr = input[i].split(" ");
    A.push(Number.parseInt(inputStr[0]-1));
    B.push(Number.parseInt(inputStr[1]-1));
    C.push(Number.parseInt(inputStr[2]));
  }
  //メモ用配列の定義と初期化()
  var dp = [];
  for (var i=0; i<N ; i++){
	dp[i] = [];	//2次元配列の次元追加
	for (var j=0 ; j<N ; j++){
      if (i!=j)
        dp[i].push(Number.MAX_VALUE);
      else
        dp[i].push(0);
    }
  }
  //メモ(dp)に対して現在分かっている最短経路を記録する。
  //メモは各ポイント間の2次元マップ。パラメタはA→Bだが、メモはB→Aも記録。
  for (var i=0; i < M; i++){
    if (dp[A[i]][B[i]] > C[i]){
        dp[A[i]][B[i]] = C[i];
    }
    if (dp[B[i]][A[i]] > C[i]){
        dp[B[i]][A[i]] = C[i];
    }
  }
  
  //比較対象を取っておく(値渡しが上手く行かないのでループで回して格納)
  var cp = [];
  for(var i=0 ; i<N ; i++ ){
    cp[i] = [];
    cp[i] = dp[i].slice();
  }
  
  //ダイクストラ法本体処理
  //始点・終点が明示されていない。Kは全ノードを回る為のループ
  for ( var k=0; k<N; k++){
    //以下の2つがダイクストラ法。双方ノード数N回ループ
    for ( var i=0; i<N; i++){
      for ( var j=0; j<N; j++){
        //ある経路(dp[i][j])より、別経路を通る方が早く着く場合は、その値で上書きする。
        if (dp[i][j] > dp[i][k] + dp[k][j]){
          dp[i][j] = dp[i][k] + dp[k][j];
        }
      }
    }
  }

  //console.log(cp);
  //console.log(dp);
  
  //集計処理(ここがダイクストラ法本体だった)
  var ans=M;
  for ( var i=0; i<M ; i++){
    var shortest = false;
    for (var j=0; j < N; j++){
      if (dp[j][A[i]] + C[i] == dp[j][B[i]]){
        shortest = true;
      }
    }
    if (shortest == true){ ans-- };
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 12176
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>

using namespace std;

int main()
{
	set<string> str;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		str.insert(s);
	}
	cout << str.size() << endl;
}

Measured memory_bytes: 19200
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
	double c=0;
	int a,b,d=0,e=0;
	cin>>a>>b;
	d=a/b;
	e=a%b;
	c=(double)a/(double)b;
	cout<<d<<" "<<e<<" "<<fixed<<setprecision(5)<<c<<endl;
}
	

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

int main(){
	int N, W, M = 1e5; cin>>N>>W;
	int w[N+1], v[N+1];
	for(int i = 1; i <= N; i++) cin>>w[i]>>v[i];
	long long dp[N+1][M+1];
	for(int i = 0; i <= N; i++){
		for(int j = 1; j <= M; j++) dp[i][j] = -1;
	}
	for(int i = 0; i <= N; i++) dp[i][0] = 0;
	for(int i = 1; i <= N; i++){
		dp[i][v[i]] = w[i];
		for(int j = 1; j <= M; j++){
			if(dp[i-1][j] != -1){
				if(dp[i][j] != -1) dp[i][j] = min(dp[i][j], dp[i-1][j]);
				else dp[i][j] = dp[i-1][j];
				dp[i][j + v[i]] = dp[i-1][j] + w[i];
			}
		}
	}
	
	for(int j = M; j >= 1; j--){
		if(dp[N][j] != -1 && dp[N][j] <= W){
			cout<<j<<endl; break;
		}
	}
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
const long long MOD = 1000000007;
typedef long long ll;

int n,k;
string s,t;

int main() {
  cin >> n;
  cout << (n+1)/2 << endl;
}

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

using namespace std;

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

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int r, t;
		scanf("%d %d", &r, &t); //r: kyori, t: kakudo
		
		bool flag[4] = {};
		if (r % 100 == 0) flag[1] = flag[3] = true;
		if (t % 30 == 0) flag[2] = flag[3] = true;
		r /= 100; t /= 30;
		int a[4] = {t * 5 + r, t * 5 + r + 1, (t + 1) * 5 + r, (t + 1) * 5 + r + 1};
		vector<int> ans;
		REP(i, 4) if (!flag[i]) ans.push_back(a[i]);
		
		REP(i, ans.size()) printf("%s%d", i ? " " : "", ans[i]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>p(N);
  for(int i=0;i<N;i++){
cin>>p[i];
  }
  int ans=0;
  
  for(int i=1;i<=N-2;i++){
    if((p[i-1]<p[i]&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

    

Measured memory_bytes: 256
s = input()
a = s[:2]
b = s[2:]
l = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
if a not in l and b not in l:
    print("NA")
elif a in l and b in l:
    print("AMBIGUOUS")
elif a in l and b not in l:
    print("MMYY")
else:
    print("YYMM")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define inv(x) (ksm(x, P - 2))

using namespace std;

const int maxn = 1e6 + 5;
const int P = 998244353;

int n, m, fac[maxn], ifac[maxn], ans;

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

inline int pls(int x, int y) { x += y; return x >= P ? x - P : x; }
inline int dec(int x, int y) { x -= y; return x < 0 ? x + P : x; }
inline int ksm(int x, int k, int rnt = 1) {
	for(int i = k; i; i >>= 1, x = 1ll * x * x % P) if(i & 1) rnt = 1ll * rnt * x % P;
	return rnt;
}

const int inv2 = inv(2);

inline int C(int n, int m) { return 1ll * fac[n] * ifac[n - m] % P * ifac[m] % P; }

int main() {
	n = read(); m = read(); fac[0] = 1; int N = n + m;
	if(n < m) swap(n, m);
	rep(i, 1, N) fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[N - 1] = inv(fac[N - 1]);
	dep(i, N - 2, 0) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
	rep(i, 1, m) ans = pls(ans, 1ll * C(i + i, i) * C(N - 2 * i, n - i) % P);
	ans = 1ll * ans * inv(2ll * C(N, n) % P) % P;
	cout << pls(ans, n) << endl;
	return 0;
}
/*
*/

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        String S;

        try (Scanner sc = new Scanner(System.in)) {
            S = sc.next();
        }
        char[] cArr = S.toCharArray();
        long[] down = new long[S.length() + 1];
        long[] up = new long[S.length() + 1];
        long[] ans = new long[S.length() + 1];

        long temp = 0;
        for (int i = S.length()-1; i >= 0; i--) {
            if(cArr[i] == '>'){
                temp ++;
            }else{
                temp = 0;
            }
            down[i] = temp;
        }
        temp = 0;
        for (int i = 1; i <= S.length(); i++) {
            if(cArr[i-1] == '<'){
                temp ++;
            }else{
                temp = 0;
            }
            up[i] = temp;
        }

        for (int i = 0; i < S.length()+1; i++) {
            ans[i] = Math.max(up[i], down[i]);
        }

        long result = 0;
        for(long l : ans){
            result += l;
        }

        //System.out.println(Arrays.toString(up));
        //System.out.println(Arrays.toString(down));
        //System.out.println(Arrays.toString(ans));
        System.out.println(result);

    }

}


Measured memory_bytes: 51204
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
vector<int> emp,nemp;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    int x[n],y[n],h[n],s[n];
    for (int i=0;i<n;i++) {
        cin>>x[i]>>y[i]>>h[i];
        if (h[i]==0) emp.push_back(i);
        else nemp.push_back(i);
    }
    for (int cx=0;cx<101;cx++) {
        for (int cy=0;cy<101;cy++) {
            for (int i=0;i<n;i++) {
                s[i] = (int)(abs(cx-x[i])+abs(cy-y[i]));
            }
            if (!nemp.empty()) {
                int ch = h[nemp[0]]+s[nemp[0]];
                bool val = true;
                for (int i=1;i<nemp.size();i++) {
                    if ((h[nemp[i]]+s[nemp[i]])!=ch) {
                        val = false;
                        break;
                    }
                }
                for (auto i:emp) {
                    if (ch>s[i]) {
                        val = false;
                        break;
                    }
                }
                if (val) {
                    cout<<cx<<" "<<cy<<" "<<ch;
                    return 0;
                }
            }
            else {
                int ch = mod;
                for (int i=0;i<n;i++) {
                    ch = min(s[i],ch);
                }
                if (ch==1) {
                    cout<<cx<<" "<<cy<<" "<<ch;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair


int main()
{
  ll a,b;
  cin>>a>>b;
  ll c[a+1];
  for(ll i=1;i<=a;i++)
  cin>>c[i];
  ll visit[a+1]={0};
  ll st=1;
  vector<ll> v;
  while(!visit[st])
  {
    visit[st]=1;
    v.pb(st);
    st=c[st];
  }
  ll khase;
  for(ll i=0;i<(ll)v.size();i++)
  {
    if(v[i]==st)
    {
      khase=i;
      break;
    }
  }
//  for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
  ll m=(ll)v.size()-khase,n;
  if(b<=khase)
  cout<<v[b]<<endl;
  else
  {
    b-=(khase+1);
    cout<<v[khase+((b%m)+1)%m];
  }

}


Measured memory_bytes: 8464
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val Array(a, b) = in.readLine().split("\\s+").map(_.toLong)

    System.out.println((prime(a).toSet & prime(b).toSet | Set(1)).size)
  }


  def prime(n: Long): List[Long] = {
    def _prime(n: Long, ps: List[Long]): List[Long] = {
      (2 to Math.sqrt(n).toInt).find(n % _ == 0) match {
        case Some(p) => _prime(n / p, p :: ps)
        case None => n :: ps
      }
    }

    _prime(n, Nil)
  }
}


Measured memory_bytes: 34788
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    string s;
    cin >> s;
    int a=0, b=0, c=0;
    for (int i = 0; i < 3; ++i) {
        switch (s[i]) {
            case 'a':
                a=1;
                break;
            case 'b':
                b = 1;
                break;
            case 'c':
                c = 1;
                break;
        }
    }

    if(a+b+c == 3) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long int
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,x;
            cin>>n;
            
            int sz=(1<<n);int ar[sz+1];
            for(i=1;i<=sz;++i)
                cin>>ar[i];
            sort(ar+1,ar+sz+1);
            multiset<int> st,st2;
            for(i=1;i<=sz-1;++i)
                st.insert(ar[i]);
            int maxi=ar[sz];
            st2.insert(maxi);
            vector<int> v;
            for(i=1;i<=n;++i)
            {
                v.clear();
                for(auto it:st2)
                {
                    multiset<int>::iterator it2=st.lower_bound(it);
                    if(it2!=st.begin())
                    {
                        --it2;
                        x=(*it2);
                        v.pb(x);
                        st.erase(st.find(*it2));
                    }
                }
                for(auto it:v)
                    st2.insert(it);
            }
            if(st.size()!=0)
                cout<<"No"<<endl;
            else
                cout<<"Yes"<<endl;
        }
        return 0;
    }


Measured memory_bytes: 14080
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
d = a[0]
t = mx/2
if n==2:
    print(max(a),min(a))
    exit()
for i in a:
    if abs(i-t)<abs(d-t):
        d = i
print(mx,d)

Measured memory_bytes: 14428
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 1001
using namespace std;
LL n,m;
char s[MAXN];
int main()
{
    scanf("%s",s);
    scanf("%lld",&n);
    m=strlen(s);
    
    if(s[0]!=s[m-1])
    {
        LL ans=0;
        for(int i=1,j=1;i<=m;i++)
        {
            if(s[i]!=s[i-1])
            {
                ans+=j/2;
                j=0;
            }
            j++;
        }
        cout<<ans*n<<endl;
    }
    else
    {
        LL ans=0;
        int L=0,R=m-1;
        while(s[L]==s[0]&&L<m)L++;
        while(s[R]==s[m-1]&&R)R--;
        if(L==m)
        {
            cout<<n*(LL)m/2<<endl;
            return 0;
        }
        ans+=(L+m-1-R)/2;
        for(int i=L,j=0;i<=R+1;i++)
        {
            if(s[i]!=s[i-1])
            {
                ans+=j/2;
                j=0;
            }
            j++;
        }
        //cout<<L<<" "<<R<<" "<<ans<<endl;
        ans=ans*n;
        ans-=(L+m-1-R)/2;
        ans+=L/2+(m-1-R)/2;
        cout<<ans<<endl;
    }
    
    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))
using ll = long long;
using P = pair<int, int>;
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
//using namespace std;

template <typename T>
using gtree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;


int main() {
    string s;
    cin >> s;
    vector<string> v;
    int k;
    cin >> k;
    gtree<string> t;
    rep(i, s.size()) {
        string a = "";
        for (int j=i; j<s.size(); ++j) {
            a += s[j];
            if (a.size() > k) break;
            t.insert(a);
        }
    }

    cout << *t.find_by_order(k-1) << endl;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}

int main(void){

  int n,count=1;
  scanf("%d\n", &n);
  char s[n][11];
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }

  qsort(s, n, sizeof(s[0]), cmp_s);

  int count_list[n];
	count_list[0] = 1;
	int max = 1;
	for (int i = 1; i < n; i++) {
		if (strcmp(s[i],s[i-1]) != 0) {
          count++;
		} 
	}
  printf("%d\n",count);

  return 0;
}


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

int main(){
    int N;  cin >> N;
    int cake = ceil(1.0*N/4), donut = ceil(1.0*N/7);
    bool ans = false;
    for(int i=0; i<=cake; i++){
        for(int j=0; j<=donut; j++){
            if(4*i + 7*j == N) ans = true;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <set>
using namespace std;

vector<int> V[100010];

int main() {
  int N; // 頂点の数
  int M; // 辺の数
  cin >> N >> M;
  for (auto i=0; i<M; i++) {
    int s, t;
    cin >> s >> t;
    V[s].push_back(t);
    V[t].push_back(s);
  }
  // 深さ優先探索
  stack<int> S;
  int visited[100010];
  int depth[100010];
  int parent[100010];
  int lowest[100010];
  S.push(0);
  parent[0] = -1;
  fill(visited, visited+N, 0);
  fill(lowest, lowest+N, -1);
  while (!S.empty()) {
    int node = S.top();
    S.pop();
    if (visited[node] == 0) {
      visited[node]++;
      depth[node] = ((parent[node] >= 0) ? depth[parent[node]]+1 : 0);
      S.push(node); // 訪問を終えたらlowestを求めるためにまた入れる。
      for (unsigned int i=0; i<V[node].size(); i++) {
        int child = V[node][i];
        if (!visited[child]) {
          S.push(child);
          parent[child] = node; // 何回も書き換わるかもしれないが、最後に更新したものが正しい親である。
        }
      }
    } else if (visited[node] == 1) {
      visited[node]++;
      lowest[node] = depth[node];
      for (unsigned int i=0; i<V[node].size(); i++) {
        int child = V[node][i];
        if (child != parent[node]) {
          if (lowest[child] == -1) { // この場合backedge
            lowest[node] = min(lowest[node], depth[child]);
          } else {
            lowest[node] = min(lowest[node], lowest[child]);
          }
        }
      }
    }
  }
  // 関節点を求める。
  set<int> A;
  // rootが関節点か。
  int root_children = 0;
  for (auto i=0; i<N; i++) {
    if (parent[i] == 0) root_children++;
  }
  if (root_children >= 2) { 
    A.insert(0);
  }
  // その他の辺は関節点か。
  for (auto i=1; i<N; i++) {
    if (parent[i] != 0 && depth[parent[i]] <= lowest[i]) {
      A.insert(parent[i]);
    }
  }
  for (auto it=A.begin(); it!=A.end(); it++) {
    cout << *it << endl;
  }
}

Measured memory_bytes: 4664
N, M = map(int, raw_input().split(" "))
A = {int(raw_input()) for _ in range(M)}

memo = [0] * (N + 1)
memo[0] = 1
memo[1] = 0 if 1 in A else 1

if N == 1:
    print(memo[1])
else:
    for i in range(2, N + 1):
        if i in A:
            continue
        memo[i] = (memo[i - 2] + memo[i - 1]) % 1000000007
    print(memo[N])


Measured memory_bytes: 13948
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2781

signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int H, W;
	int pd = INF;
	vector<string> mp;
	queue<pair<int,pair<int,int>>> Q;
	vector<vector<int>> dis;
	
	cin>>H>>W;
	
	mp.resize(H);
	dis.resize(H,vector<int>(W, INF));
	
	for(int i = 0; i < H; i++){
		cin>>mp[i];
		for(int j = 0; j < W; j++){
			if(mp[i][j] == '%'){
				dis[i][j] = 0;
				Q.push(make_pair(0,make_pair(i, j)));
			}
		}
	}
	
	while(!Q.empty()){
		pair<int,pair<int,int>> p = Q.front(); Q.pop();
		int d = p.first, x = p.second.second, y = p.second.first;
		
		if(dis[y][x] < d) continue;
		
		if(mp[y][x] == '@') pd = d;
		
		for(int i = 0; i < 4; i++){
			int ny = y + (2 - i)%2, nx = x + (i - 1)%2;
			
			if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			
			if(mp[ny][nx] == '#') continue;
			
			if(dis[ny][nx] > d + 1){
				dis[ny][nx] = d + 1;
				Q.push(make_pair(d+1,make_pair(ny,nx)));
			}
		}
	}
	
	if(pd == INF){
		cout<<-1<<endl;
		return 0;
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(mp[i][j] == '$'){
				if(pd >= dis[i][j]){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	
	cout<<"Yes"<<endl;
	
	return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    cin>>c;
    if(c>=92)cout<<"a\n";
    else cout<<"A\n";
    return 0;  
}   

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>

using namespace std;

char town[21][21];
pair<int, int> p;

// ú»
void initTown(int h, int w){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			town[i][j] = '#';
		}
	}
}

// eÌÊ
void shoot(int y, int x, int direction){
	if(town[y][x] == '#'){
		return;
	}
	if(town[y][x] == '*'){
		town[y][x] = '.';
		return;
	}
	
	if(y > 0 && direction == 0){
		shoot(y - 1, x, 0);
	}
	else if(direction == 1){
		shoot(y, x + 1, 1);
	}
	else if(direction == 2){
		shoot(y + 1, x, 2);
	}
	else if(x > 0 && direction == 3){
		shoot(y, x - 1, 3);
	}
	
	return;
}

// íÔÌì
void control(int n){
	char cont;
	for(; n > 0; --n){
		scanf(" %c", &cont);
		if(cont == 'U'){
			if(p.first > 0 && town[p.first - 1][p.second] == '.'){
				town[p.first][p.second] = '.';
				town[p.first - 1][p.second] = '^';
				p.first--;
			}else{
				town[p.first][p.second] = '^';
			}
		}
		else if(cont == 'D'){
			if(town[p.first + 1][p.second] == '.'){
				town[p.first][p.second] = '.';	
				town[p.first + 1][p.second] = 'v';
				p.first++;
			}else{
				town[p.first][p.second] = 'v';
			}
		}
		else if(cont == 'L'){
			if(p.second > 0 && town[p.first][p.second - 1] == '.'){
				town[p.first][p.second] = '.';
				town[p.first][p.second - 1] = '<';
				p.second--;
			}else{
				town[p.first][p.second] = '<';
			}
		}
		else if(cont == 'R'){
			if(town[p.first][p.second + 1] == '.'){
				town[p.first][p.second] = '.';
				town[p.first][p.second + 1] = '>';
				p.second++;
			}else{
				town[p.first][p.second] = '>';
			}
		}
		else if(cont == 'S'){
			if(town[p.first][p.second] == '^'){
				shoot(p.first, p.second, 0);
			}
			else if(town[p.first][p.second] == '>'){
				shoot(p.first, p.second, 1);
			}	
			else if(town[p.first][p.second] == 'v'){
				shoot(p.first, p.second, 2);
			}
			else if(town[p.first][p.second] == '<'){
				shoot(p.first, p.second, 3);
			}
		}
		
	}
}
int main(){
	int t;
	scanf("%d", &t);
	for(;t > 0; --t){
		int h,w;
		scanf("%d %d", &h, &w);
		initTown(21, 21);
		for(int i = 0; i < h; i++){
			scanf("%s", town[i]);
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(town[i][j] == '^' || town[i][j] == '<' || town[i][j] == '>' || town[i][j] == 'v'){
					p.first = i;
					p.second = j;
				}
			}
		}
		
		int n;
		scanf("%d", &n);
		control(n);
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				printf("%c", town[i][j]);
			}
			printf("\n");
		}
		if(t != 1){
			printf("\n");
		}
	}
	return 0;
	
}

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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

string s;
vector<string> f;
int k, n;

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    cin >> s;
    cin >> k;
    int n = sz(s);
    REP(i, n) {
        string tmp;
        REP(j, k) if (i+j<sz(s)) {
            tmp.pb(s[i+j]);
            f.pb(tmp);
        }
    }
    sort(all(f));
    f.erase(unique(all(f)), f.end());
    cout << f[k-1] << "\n";
}




Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>x(n),y(n);
  rep(i,n){
    ll a,b;cin>>a>>b;
    x[i]=a+b;
    y[i]=a-b;
  }
  ll f=1;
  rep(i,n-1){
    if(abs(x[i])%2!=abs(x[i+1])%2||abs(y[i])%2!=abs(y[i+1])%2){
      f=0;
    }
  }
  if(f==0){
    cout<<-1<<endl;
    return 0;
  }
  vector<ll>arms;
  //arms.push_back(1LL<<35);
  if(x[0]%2==0)arms.push_back(1);
  rep(i,35)arms.push_back(1LL<<i);
  ll l=35+1-abs(x[0])%2;
  cout<<l<<endl;
  rep(i,l){
    cout<<arms[i]<<" ";
  }
  cout<<endl;
  string s="LDUR";//xy
  if(x[0]%2){
    rep(i,n){
      string res="";
      x[i]+=1LL<<35;
      y[i]+=1LL<<35;
      ll xx=0,yy=xx;
      bitset<36>tx=x[i],ty=y[i];
      //cout<<tx<<endl;
      rep(j,35){
        res+=s[tx[j+1]*2+ty[j+1]];
        xx+=(2*tx[j+1]-1)*(arms[j+1]);
        yy+=(2*ty[j+1]-1)*(arms[j+1]);
        //cout<<arms[j+2]*(2*tx[j+1]-1)<<endl;
      }
      //cout<<xx<<" "<<yy<<endl;
      cout<<res<<endl;
    }

  }
  else {

      rep(i,n){
        string res="L";
        x[i]+=(1LL<<35);
        y[i]+=(1LL<<35);
        ll xx=-1,yy=xx;
        bitset<36>tx=x[i],ty=y[i];
        //cout<<tx<<endl;
        rep(j,35){
          res+=s[tx[j+1]*2+ty[j+1]];
          xx+=(2*tx[j+1]-1)*(arms[j+2]);
          yy+=(2*ty[j+1]-1)*(arms[j+2]);
          //cout<<arms[j+2]*(2*tx[j+1]-1)<<endl;
        }
        //cout<<xx<<" "<<yy<<endl;
        cout<<res<<endl;
      }

  }




  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		if(N < 357) {
			System.out.println("0");
			return;
		}
		int[] n = new int[10];
		n[0] = 3;
		n[1] = 2;
		n[2] = 1;
		
		int ans = 0;
		while(true) {
			long num = 0;
			boolean flag7 = false, flag5 = false, flag3 = false;
			for(int i = 0;i < n.length;++i) {
				if(n[i] == 3) {
					num += 7 * (long)Math.pow(10, i);
					flag7 = true;
				}else if(n[i] == 2) {
					num += 5 * (long)Math.pow(10, i);
					flag5 = true;
				}else if(n[i] == 1) {
					num += 3 * (long)Math.pow(10, i);
					flag3 = true;
				}
			}
			if(num <= N) {
				if(flag7 && flag5 && flag3)
					ans++;
			} else {
				break;
			}
			n[0]++;
			for(int i = 0;i < n.length-1;++i) {
				if(n[i] >= 4) {
					n[i] = 1;
					n[i+1]++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

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

int main() {

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

	int N; cin >> N;
	map<ll,ll>A;
	rep(i, N) {
		ll a;cin >> a;
		A[a]++;
	}
	ll ans = 0;
	for (auto p : A) {
		if (p.second >= 4) {
			chmax(ans, p.first* p.first);
		}
	}
	ll x = 0;int cnt = 0;
	for (auto p : A) {
		if (cnt == 0&&p.second>=2) {
			x = p.first;
			++cnt;
			continue;
		}
		if (p.second >= 2) {
			chmax(ans, p.first* x);
			x = p.first;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 6528
n = int(input())
a = list(map(int,input().split()))
counter = 1

if n == 1:
    print("1")
else:
    if a[0] > a[1]:
        now = -1
    elif a[0] < a[1]:
        now = 1
    else:
        now = 0
        
    for i in range(1,n-1):
        if now == -1:
            if a[i] < a[i+1]:
                counter += 1
                now = 0
        elif now == 1:
            if a[i] > a[i+1]:
                counter += 1
                now = 0
        else:
            if a[i] > a[i+1]:
                now = -1
            elif a[i] < a[i+1]:
                now = 1
    print(counter)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
void *wmem;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf=(char *)wmem;
  rd(buf);
  x = buf;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char memarr[96000000];
string S;
int main(){
  wmem = memarr;
  rd(S);
  if(S<="2019/04/30"){
    wt_L("Heisei");
    wt_L('\n');
  }
  else{
    wt_L("TBD");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// string S;
// {
//   rd(S);
//   wt(if[S<="2019/04/30", "Heisei", "TBD"]);
// }


Measured memory_bytes: 256
<?php
list($N, $u, $v) = ints();
$G = loadTree();
dfs($u);$d1 = $distance;
dfs($v);$d2 = $distance;
$max = 0;
for($i = 1; $i <= $N; $i++){
  if($d1[$i] < $d2[$i]){
    chmax($max, $d2[$i] - 1);
  }
}
echo $max;

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}
function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  $G = array_fill(1, $N - 1, []);
  for($i = 0; $i < $N - 1; $i++){
    list($a, $b) = ints();
    $G[$a][] = $b;
    $G[$b][] = $a;
  }
  return $G;
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}


Measured memory_bytes: 78328
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    X = LI()
    for i in range(len(X)):
        if X[i] == 0:
            print(i+1)
            return

main()



Measured memory_bytes: 78276
using System;

namespace A_AC
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();

            if(s == "ABC")
            {
                s = "ARC";
            }
            else
            {
                s = "ABC";
            }

            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 25784
s=input()

if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)
else:
    pass


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <array>

using namespace std;


bool dp[110][10010];

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

	std::vector<int> s;

	for(int i=0; i<N; i++){
		int s_;
		cin >> s_;
		s.push_back(s_);
	}

	dp[0][0] = true;
	dp[0][s[0]] = true;

	for(int i=1; i<N; i++){
		for(int j=0; j<10010; j++){
			if(dp[i-1][j]){
				dp[i][j] = true;
				dp[i][j+s[i]] = true;
			}
		}
	}

	
	for(int j=10009; j>=0; j--){
		if(dp[N-1][j] && j%10){
			cout << j << endl;
			return 0;
		}
	}

	cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  map<ll, ll> odd, even;
  for (ll i = 0; i < N; i++) {
    ll v;
    cin >> v;
    if (i % 2 == 0) {
      odd[v]++;
    } else {
      even[v]++;
    }
  }

  struct ValueFreq {
    ll value;
    ll freq;
  };
  vector<ValueFreq> oddVec, evenVec;
  transform(begin(odd), end(odd), back_inserter(oddVec), [](auto x) {
    return ValueFreq{x.first, x.second};
  });
  transform(begin(even), end(even), back_inserter(evenVec), [](auto x) {
    return ValueFreq{x.first, x.second};
  });

  // 要素数が足りないとまずいのでダミーデータを決め打ちで追加する
  oddVec.push_back({-1LL, 0LL});
  evenVec.push_back({-1LL, 0LL});

  sort(begin(oddVec), end(oddVec), [](auto x, auto y) { return x.freq > y.freq; });
  sort(begin(evenVec), end(evenVec), [](auto x, auto y) { return x.freq > y.freq; });

  ll ans = 0;
  if (oddVec[0].value != evenVec[0].value) {
    ans = (N / 2) - oddVec[0].freq + (N / 2) - evenVec[0].freq;
  } else {
    const ll ans1 = (N / 2) - oddVec[0].freq + (N / 2) - evenVec[1].freq;
    const ll ans2 = (N / 2) - oddVec[1].freq + (N / 2) - evenVec[0].freq;
    ans = min(ans1, ans2);
  }

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


Measured memory_bytes: 8824
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

ll dp[3010][3010];
// dp[i][j] : s(1~i文字目), t(1~j文字目) のlcsの長さ

void solve() {
    string s, t; cin >> s >> t;
    ll sl = s.size(), tl = t.size();
    dp[0][0] = 0; 
    Rep(i, 1, sl){
        Rep(j, 1, tl){
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    //復元 後ろから復元
    string ans = "";
    ll i = s.size(), j = t.size();
    while(i > 0 && j > 0){
        if(dp[i-1][j] == dp[i][j]) i--;
        else if(dp[i][j-1] == dp[i][j]) j--;
        else if(dp[i-1][j-1] != dp[i][j]){
            ans = s[i-1] + ans;
            i--; j--;
        }
    }
    
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 70784
//tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int gcd(int a,int b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
    int a[200005],b[200005],n,m,k;
    ll sum=0,ans=0,i,j;
    cin>>n>>m>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    j=n-1;
    for(i=0;i<m;i++)
    cin>>b[i];
    for(i=0;i<=m;i++)
    {
        while(j>=0&&sum>k)
        {
            sum-=a[j];
            --j;
        }
        if(sum>k)
        break;
        ans=max(ans,i+j+1);
        sum+=b[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5128
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  int flag = 0;

  if (NN != 3) {
    if (NN != 5) {
      if (NN != 7) {
        flag = 1;
      }
    }
  }


  if (flag == 0) {
    std::cout << "YES" << '\n';
  }else{
    std::cout << "NO" << '\n';
  }


  return 0;
}


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

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

const int inf = -1000;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
int main() {



   ll a, b, c, d; cin >> a >> b >> c >> d;
	ll T = b - a + 1;
	ll L = lcm(c, d);

	ll X = (b / c) - (a / c) + (!(a % c) ? 1 : 0);
	ll Y = (b / d) - (a / d) + (!(a % d) ? 1 : 0);;
	ll Z = (b / L) - (a / L) + (!(a % L) ? 1 : 0);;

	cout << T - (X + Y - Z) << endl;

    return 0;

      }


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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> arr(N, 0);
  rep(i, N) { cin >> arr[i]; }
  int idx = 0;
  rep(i, N) {
    if (arr[idx] == 2) {
      cout << i + 1 << endl;
      return 0;
    } else {
      idx = arr[idx] - 1;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

typedef long long ll;
using namespace std;

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

    vector<int> mati(n);
    for (int i = 0; i < n; i++) {
        cin >> mati[i];
    }

    sort(mati.begin(), mati.end());
    double res = mati[0];
    for (int i = 1; i < n; i++) {
        res = (res + mati[i]) / 2;
    }

    printf("%.10f", res);
}


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

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}
  
	public static void main(String[] args) 
	{ 
		FastReader sc = new FastReader(); 
		int n = sc.nextInt();
      	int count = 0;
      	for(int i=0;i<n;i++){
          	int arr = sc.nextInt();
          	if(arr!=(i+1)) count++;
        }
		
      	System.out.print( (count<=2)?"YES":"NO" ); 
	} 
} 


Measured memory_bytes: 21972
#include<iostream>
#include<vector>

using namespace std;

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> v(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> v[i];
    }

    vector<int> sum;
    sum.emplace_back(0);

    int cnt = 1;
    for(int i = 0 ; i < n - 1 ; ++i){
        if(v[i] != v[i + 1]){
            ++cnt;
        }else{
            sum.emplace_back(sum.back() + cnt);
            cnt = 1;
        }
    }
    sum.emplace_back(sum.back() + cnt);

    const int m = (int)sum.size();

    int ans = 0;
    for(int i = 0 ; i < m ; ++i){
        chmax(ans, sum[min(i + 3, m - 1)] - sum[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3444
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const long long Mod=1e9+7;
long long n,a=1,b=1,c=1;
int main() 
{
	cin>>n;
	while(n--)
	a=a*10%Mod,b=b*9%Mod,c=c*8%Mod;
	cout<<(((a+c)%Mod+Mod-b)%Mod+Mod-b)%Mod<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long st[maxn << 2], lz[maxn << 2];
vector<int> Start[maxn];
vector<pair<int, int> > End[maxn];
void down(int id) {
    long long &tmp = lz[id];
    if (tmp == 0) return;
    st[id << 1] += tmp;
    lz[id << 1] += tmp;
    st[id << 1 | 1] += tmp;
    lz[id << 1 | 1] += tmp;
    tmp = 0;
}
void update(int id, int l, int r, int u, int v, long long val) {
    if (l > v || r < u) return;
    if (u <= l && r <= v) {
        st[id] += val;
        lz[id] += val;
        return;
    }
    down(id);
    int mid = (l + r) >> 1;
    update(id << 1, l, mid, u, v, val); update(id << 1 | 1, mid + 1, r, u, v, val);
    st[id] = max(st[id << 1], st[id << 1 | 1]);
}
long long Get(int id, int l, int r, int u, int v) {
    if (l > v || r < u) return -1e18;
    if (u <= l && r <= v) return st[id];
    down(id);
    int mid = (l + r) >> 1;
    return max(Get(id << 1, l, mid, u, v), Get(id << 1 | 1, mid + 1, r, u, v));
}
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int l, r, v;
        cin >> l >> r >> v;
        Start[l].push_back(v);
        End[r].push_back({l, v});
    }
#define update(l, r, x) update(1, 1, n + 1, (l) + 1, (r) + 1, x)
#define Get(x) Get(1, 1, n + 1, 1, (x) + 1)
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
        for (int x : Start[i]) 
            update(0, i - 1, x);
        long long cur = Get(i - 1);
        if (cur == 14) cerr << i << endl;
        res = max(res, cur);
        update(i, i, cur);
        for (auto x : End[i]) 
            update(0, x.first - 1, -x.second);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 33280