akhauriyash/Code-Regression huggingface dataset:
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{

	int n;cin>>n;
	int v[n];
	FOR(i,n)
	{
		cin>>v[i];
	}
	int dp[n];
	//cout<<v[1]<<" "<<v[0]<<endl;
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	//cout<<dp[1]<<endl;
	//dp[2]=min(abs(v[2]-v[1])+dp[1],abs(v[2]-v[0]));
	for(int i=2;i<n;++i)
	{
		dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],dp[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1000000000+7;
const int maxn = 10000+1;
const int maxd = 100+1;
ll memo[maxn][2][maxd];
string str; 
int D;

ll dp(int pos,int menor,int m){
	if(pos >= str.size()){
		if(m == 0)return 1;
		return 0;
	}
	int limit = (menor) ? 9 : (str[pos]-'0');
	ll &res = memo[pos][menor][m];
	if(res != -1)return res;
	res = 0;
	for(int i = 0; i <= limit; i++){
		int newMenor = (menor) ? menor : (i == (str[pos]-'0')) ? 0 : 1;
		res += dp(pos+1,newMenor,(m+i)%D);
		res %= mod;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,maxn)forn(j,0,2)forn(k,0,maxd)memo[i][j][k] = -1;
	cin >> str >> D;
	ll res = dp(0,0,0); res--;
	if(res < 0)res += mod;
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 16896
a = int(input())

k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(k[a-1])

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
    g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}

pii dp(Graph &g, int p, int bef)
{
    int w = 1, b = 1;
    for (auto i : g[p]) {
        if (i.d != bef) {
            pii tmp = dp(g, i.d, p);
            w = (w * tmp.fir) % MOD;
            b = (b * tmp.sec) % MOD;
        }
    }
    return {(w + b) % MOD, w};
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    Int(n);
    Graph g(n);
    for (int i = 0; i < n-1; i++) {
        int2(tmpx, tmpy);
        tmpx--; tmpy--;
        addEdge(g, tmpx, tmpy );
    }

    pii ans = dp(g, 0, -1);

    std::cout << ans.fir << std::endl;

    return 0;
}


Measured memory_bytes: 18176
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
count=0

for i in range(n):
    if (a[-(i + 1)][0] + count) % a[-(i + 1)][1]==0:
        continue

    else:
        x = (a[-(i + 1)][0] + count) % a[-(i + 1)][1]
        count += a[-(i + 1)][1] - x



print(count)

Measured memory_bytes: 27380
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;



int main() {
  //
  int N;
  cin >> N;
  int nums[N];
  for (int i = 0; i < N; ++i) {
    cin >> nums[i];
  }

  //
  sort(nums, nums+N);

  //
  int current_size = nums[0], ans=1;
  for (int i = 1; i < N; ++i) {
    if(nums[i] > current_size){
      ans++;
      current_size = nums[i];
    }
//    cout << nums[i] << endl;
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
*n,t=open(0).read().split()
n,k,r,s,p=map(int,n)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(t[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)

Measured memory_bytes: 44004
#include <iostream>
#include <string>

using namespace std;

int main(){
    string a;
    cin >> a;
    if(a == "a" || a == "i" || a == "u" || a == "e" || a == "o"){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int factors[2000000];
void factorize(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) factors[i]++;
		while(n % i == 0) n /= i;
	}
	if(n > 1) factors[n]++;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n; cin >> n;
	int g = 0;
	for(int i = 0; i < n; i++) {
		int a; cin >> a;
		g = __gcd(g, a);
		factorize(a);
	}
	bool setwise = g == 1;
	bool pairwise = true;
	for(int i = 0; i < 2000000; i++) if(factors[i] > 1) pairwise = false;
	if(pairwise) cout << "pairwise";
	else if(setwise) cout << "setwise";
	else cout << "not";
	cout << " coprime\n";
}


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

int main() {
    //freopen("in.txt", "r", stdin);

    int a[27][1] = {0};
    char tmp;

    for (int i = 0; i < 26; ++i) {
        a[i][1] = 0;
    }

    while ((tmp = getchar()) != EOF) {
        if (tmp >= 65 && tmp <= 90) {
            a[tmp - 65][1]++;
        } else if (tmp >= 97 && tmp <= 122) {
            a[tmp - 97][1]++;
        } else {
            // do nothing
        }
    }
    for (int i = 0; i < 26; ++i) {
        cout << (char) (i + 97) << " : " << a[i][1] << endl;
    }
}

Measured memory_bytes: 3092
s = gets.to_i
an = s
count = 1
while true
  if an < 10
    case an 
    when 1
      result = count+3
    when 2
      result = count+3
    when 3
      result = count+8
    when 4
      result = count+3
    when 5
      result = count+6
    when 6
      result = count+9
    when 7
      result = count+17
    when 8
      result = count+4
    when 9
      result = count+20
    end
    break
  end
  if an%2 == 0
    an = an/2
  else
    an = 3*an+1
  end
  count +=1
end
puts result

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 10;
int n, ans;
ll d;
int main() {
    scanf("%d%lld", &n, &d); d *= d;
    for(int i = 1; i <= n; ++i) {
        ll x, y, dist;
        scanf("%lld%lld", &x, &y);
        dist = x * x + y * y;
        ans += dist <= d;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3740
#include <stdio.h>
#define N 2000

int A[N],Q[200],n;

int solve(int i,int ans){
  int res;
  if(ans==0)return 1;
  if(i>=n)return 0;
  res = (solve(i+1,ans)+solve(i+1,ans-A[i]));
  return res;

}

int main(){
  int i,j,q;

  scanf("%d",&n);

  for(i=0;i<n;++i) scanf("%d",&A[i]);

  scanf("%d",&q);
 
  for(i=0;i<q;++i) scanf("%d",&Q[i]);
  for(i=0;i<q;++i){
    if(solve(0,Q[i])==0)printf("no\n");
    else printf("yes\n");
  }
 
  
}




Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  for(int i = 0; i <= s.size() - 1; i += 2){
    cout << s[i];
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
A,B,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a) + min(b)
for i in range(m):
	sum = 0
	x,y,c = map(int,input().split())
	sum = a[x-1] + b[y-1] - c
	ans = min(ans,sum)
print(ans)

Measured memory_bytes: 18616
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
counts = Counter(a)
q = int(input())

total = sum(a)

for i in range(q):
    b, c = map(int, input().split())
    if b < c:
        total += (c - b) * counts[b]
        counts[c] += counts[b]
        counts[b] = 0
    else:
        total -= (b - c) * counts[b]
        counts[c] += counts[b]
        counts[b] = 0
    print(total)

Measured memory_bytes: 24180
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 n, m;
set<i32> v[100001];
vec<i32> ans1, ans2;
set<i32> s;

bool valid() {
    return v[*ans1.rbegin()].size() == 0 && v[*ans2.rbegin()].size() == 0;
}

i32 main()
{
    cin >> n >> m;
    times(m, i) {
        i32 a, b; cin >> a >> b;
        v[a].insert(b);
        v[b].insert(a);
    }

    i32 a = 1, b = *v[a].begin();
    ans1.append(a);
    ans2.append(b);
    for (i32 i: v[a]) {
        v[i].erase(a);
    }
    for (i32 i : v[b]) {
        v[i].erase(b);
    }
    s.insert(a); s.insert(b);
    while (!valid()) {
        a = *ans1.rbegin();
        b = *ans2.rbegin();
        while (v[a].size() > 0 && s.find(*v[a].begin()) != s.end()) {
            v[a].erase(v[a].begin());
        }
        while (v[b].size() > 0 && s.find(*v[b].begin()) != s.end()) {
            v[b].erase(v[b].begin());
        }
        bool added = false;
        i32 i;
        if (v[b].size() > 0) {
            i = *v[b].begin();
            ans2.append(i);
            added = true;
        }
        if (!added && v[a].size() > 0) {
            i = *v[a].begin();
            ans1.append(i);
            added = true;
        }
        if (!added) continue;
        for (i32 j : v[i]) {
            v[j].erase(i);
        }
        s.insert(i);
    }
    vec<i32> ans;
    downto(ans1.size() - 1, 0, i) {
        ans.append(ans1[i]);
    }
    upto(0, ans2.size() - 1, i) {
        ans.append(ans2[i]);
    }
    cout << ans.size() << endl;
    times(ans.size() - 1, i) {
        cout << ans[i] << " ";
    }
    cout << ans[ans.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 16124
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

// ll gcd(ll a, ll b) {
//     if (b == 0) return a;
//     return gcd(b,a%b);
// }

int main(void) {
    ll N, X;
    vector<tuple<ll,ll,ll>> b(200010);
    cin >> N >> X;
    for (int i=0;i<N;i++) {
        ll s, l, u;
        cin >> s >> l >> u;
        b[i] = tie(s,l,u);
    }
    sort(b.begin(), b.end(), [&] (tuple<ll,ll,ll> c, tuple<ll,ll,ll> d) {
        ll p = X*get<2>(c) - get<0>(c)*(get<2>(c)-get<1>(c));
        ll q = X*get<2>(d) - get<0>(d)*(get<2>(d)-get<1>(d));
        if (p > q) return true;
        else return false;
    });
    vector<ll> c(200010,0);
    for (int i=1;i<=N;i++) c[i] = c[i-1] + X*get<2>(b[i-1]) - get<0>(b[i-1])*(get<2>(b[i-1])-get<1>(b[i-1]));
// #ifdef DEBUG
//     for (int i=0;i<=N;i++) cout << c[i] << endl;
// #endif

    ll aoki = 0, ans = N*X;
    for (int i=0;i<N;i++) aoki += get<0>(b[i])*get<1>(b[i]);
    for (int i=0;i<N;i++) {
        ll a = get<0>(b[i]), l = get<1>(b[i]), u = get<2>(b[i]);
        ll left = 0, right = X*N, mid, s;
        while (left < right) {
            mid = left+(right-left)/2LL;
            s = -aoki;
            s += c[mid/X];
            if (mid/X > i && mid%X != 0) s += (c[mid/X+1] - c[mid/X]) - (c[i+1] - c[i]);
#ifdef DEBUG
            cout << "check: " << mid/X << ", " << a << ", " << (mid%X-a)*u + a*l << ", " << mid*l << endl;
#endif
            mid %= X;
            if (mid > a) s += (mid-a)*u + a*l;
            else s += mid*l;
#ifdef DEBUG
            cout << "bin: " << i << ", " << left << ", " << right << ", " << left + (right-left)/2LL << ", " << s << endl;
#endif
            if (s < 0) left = left+(right-left)/2LL + 1;
            else right = left+(right-left)/2LL;
        }
#ifdef DEBUG
        cout << i << ", " << left << ", " << right << ", " << left + (right-left)/2LL << endl;
#endif
        ans = min(ans,left + (right-left)/2LL);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        System.out.println(k%2==1?k/2*(k/2+1):k*k/4);
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vvll d(n,vll(2));
  REP(i,n)cin>>d[i][0]>>d[i][1];

  bool flag=false;
  for(ll i=0; i+2<n; i++){
    bool flag2=true;
    REP(j,3){
      if(d[i+j][0]!=d[i+j][1])
        flag2=false;
    }

    if(flag2)
      flag=true;
  }

  if(flag)
    yes;
  else
    no;
}



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


int32_t main(){
	int n,K;
	scanf("%d%d",&n,&K);
	vector<int> A(n);
	for(auto &a:A) scanf("%d",&a);
	vector<bool> dp(K+1);
	for(int s = 0;s<=K;s++)
		for(int x:A)
			if(s>=x and !dp[s-x]){
				dp[s] = true;
			}
	puts(dp[K]? "First": "Second");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    ll a,b;
    cin >> a >> b;
    if(a<b){
        puts("a < b");
    }else if(a>b){
        puts("a > b");
    }else if(a==b){
        puts("a == b");
    }
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
long mod = 1e9+7;
int main(){
    long n,ans=1,x=-1,y=-1,z=-1;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        int cnt = 0;
        int flag = 0;
        if(a==x+1){
            cnt++;
            flag++;
        }
        if(a==y+1){
            cnt++;
            flag += 2;
        } 
        if(a==z+1){
            cnt++;
            flag += 4;
        }
        ans = ans*cnt%mod;
        if(flag==1||flag==3||flag==7) x++;
        if(flag==2||flag==6) y++;
        if(flag==4||flag==5) z++;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
require 'prime'
a = 10**9+7
n = gets.chomp.to_i
h = Hash.new(0)
(1..n).each do |i|
  x = Prime.prime_division(i)
  x.each do |n, e|
    h[n] += e
  end
end
ret = 1
h.values.each do |i|
  ret *= ((i + 1) % a)
end

puts ret % a


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int v;
    cin >> v;
    vector<vector<char>> a(v,vector<char>(v));
    rep(i,0,v) rep(j,0,v) cin >> a[i][j];

    int x=0,y=0,f=0;
    {
        vector<bool> used(v);
        rep(i,0,v){
            if(used[i]) continue;
            used[i]=true;
            vector<int> vi;
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                int p=que.front();
                que.pop();
                vi.push_back(p);
                rep(j,0,v){
                    if(used[j] or a[p][j]=='N') continue;
                    que.push(j);
                    used[j]=true;
                }
            }
            if(vi.size()%2==0) ++x;
            else ++y;
            int cnt=0;
            rep(j,0,vi.size()) rep(k,j+1,vi.size()) if(a[vi[j]][vi[k]]=='Y') ++cnt;
            f=(f+vi.size()*(vi.size()-1)/2-cnt+2)%2;
        }
    }

    static bool dp[1001][1001][2]={},done[1001][1001][2]={};
    function<bool(int,int,int)> rec=[&](int x,int y,int f){
        if(done[x][y][f]) return dp[x][y][f];
        done[x][y][f]=true;
        if((x==1 and y==0) or (x==0 and y==1)) return dp[x][y][f]=true;
        bool res=false;
        if(f==1) res|=!rec(x,y,1-f);
        if(x>=2) res|=!rec(x-1,y,1-f);
        if(y>=2) res|=!rec(x+1,y-2,f);
        if(x>=1 and y>=1) res|=!rec(x-1,y,1-f);
        return dp[x][y][f]=res;
    };

    if(rec(x,y,f)) cout << "Taro" << endl;
    else cout << "Hanako" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 6032
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int monster1 = sc.nextInt();

        for (int i = 1; i < n; i++) {
            monster1 = gcd(monster1, sc.nextInt());
        }
        System.out.println(monster1);
    }

    private static int gcd (int a, int b) {
        return (b == 0) ? a : gcd(b, a%b);
    }
}

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

using namespace std;

int main() {
	int n, r = 0, g = 0, b = 0; cin >> n;
	long long ans;
	string s; cin >> s;
	for ( char a : s) {
		switch(a) {
			case 'R':
				r++;
				break;
			case 'G':
				g++;
				break;
			case 'B':
				b++;
				break;
		}
	}
	
	ans = 1ll * r * g * b;
	
	for(int i = 1; i < n-1; ++i) {
		for ( int j = 1; j <= n/2; j++) {
			if (i-j < 0 || i + j >= n) continue;
			if(s[i-j] != s[i] and s[i-j] != s[i+j] and s[i] != s[i+j]) ans--;
		}
	}
	
	cout << ans;
}





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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    int cnt = 0;
    int q;
    cin >> q;
    rep(i, q)
    {
        int c;
        cin >> c;
        rep(i, n)
        {
            if (s[i] == c)
            {
                cnt++;
                break;
            }
        }
    }

    OP(cnt);

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define N 1000006
#define M 10000007

using namespace std;

struct edge{
	int to, nxt;
}e[M];

int n, cnt, tot, numx, numy;
int fir[N], a[N], b[N], prime[M], link[N], x[N], y[N];
bool vis[M], book[N];

void init();
void add(int ,int);
bool dfs(int);

int main(){
	scanf("%d", &n);init();
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	sort(a + 1,a + 1 + n);a[0] = a[n + 1] = 99999999;
	for(int i = 1; i <= n; ++i){
		if(a[i] != a[i - 1] + 1) b[++cnt] = a[i];
		if(a[i] != a[i + 1] - 1) b[++cnt] = a[i] + 1;
	}
	for(int i = 1; i <= cnt; ++i){
		if(b[i] & 1) x[++numx] = b[i];
		else y[++numy] = b[i];
	}
	cnt = 0;
	for(int i = 1; i <= numx; ++i)
		for(int j = 1; j <= numy; ++j)
			if(!vis[abs(x[i] - y[j])])
				add(i, j);
	for(int i = 1; i <= numx; ++i){
		memset(book, false, sizeof book);
		dfs(i);
	}
	int ans = 0;
	for(int i = 1; i <= numy; ++i)
		if(link[i]) 
			++ans;
	numy -= ans;numx -= ans;
	ans += (numy / 2) * 2 + (numx / 2) * 2;
	ans += (numy % 2) * (numx % 2) * 3;
	cout << ans << endl;
	return 0;
}

void add(int u,int v){
	e[++cnt].to = v;e[cnt].nxt = fir[u];fir[u] = cnt;
	return ;
}

void init(){
	int m = 1e7;
	for(int i = 2; i <= m; ++i){
		if(!vis[i]) prime[++tot] = i;
		for(int j = 1; j <= tot && i * prime[j] <= m; ++j){
			vis[i * prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
	vis[1] = vis[2] = true;
	return ;
}

bool dfs(int u){
	if(book[u]) return false;
	book[u] = true;
	for(int i = fir[u]; i; i = e[i].nxt){
		int v = e[i].to;
		if(!link[v] || dfs(link[v])){
			link[v] = u;
			return true;
		}
	}
	return false;
}

Measured memory_bytes: 30976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1<<30;
vector<int> G[MAX];
int dis[MAX];

void BFS(){
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int a=Q.front();Q.pop();
        
        for(int to:G[a]){
            if(dis[to]==INF){
                dis[to]=dis[a]+1;
                Q.push(to);
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int H,W;cin>>W>>H;
        if(H+W==0) break;
        
        for(int i=0;i<H*W;i++){
            G[i].clear();
            dis[i]=INF;
        }
        dis[0]=0;
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W-1;j++){
                int a;cin>>a;
                if(a==0){
                    G[i*W+j].push_back(i*W+j+1);
                    G[i*W+j+1].push_back(i*W+j);
                }
            }
            
            if(i==H-1) break;
            
            for(int j=0;j<W;j++){
                int a;cin>>a;
                if(a==0){
                    G[i*W+j].push_back((i+1)*W+j);
                    G[(i+1)*W+j].push_back(i*W+j);
                }
            }
        }
        
        BFS();
        
        if(dis[H*W-1]==INF) cout<<0<<endl;
        else cout<<dis[H*W-1]+1<<endl;
        
    }
}



Measured memory_bytes: 3120
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 2e5 + 10;
int a[maxn], pre[maxn], suf[maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    pre[1] = a[1];
    suf[n] = a[n];
    for (int i = 2; i <= n; ++i){
        pre[i] = max(pre[i - 1], a[i]);
    }
    for (int i = n - 1; i >= 1; --i){
        suf[i] = max(suf[i + 1], a[i]);
    }
    for (int i = 1; i <= n; ++i){
        cout << max(pre[i - 1], suf[i + 1]) << '\n';
    }
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,sum3=0;
    cin>>n;
    vector<ll>v;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum3+=x;
        v.push_back(x);
    }
    ll sum1=v[0];
    ll sum2=abs(sum3-sum1);
    ll diff=abs(sum1-sum2);
    ll ans=diff;
    for(int i=1;i<n-1;i++)
    {
        sum1+=v[i];
        sum2-=v[i];
        diff=abs(sum1-sum2);
        if(diff<ans)
        ans=diff;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5328
import java.util.*;

public class Main {
    public static boolean[][] visited;
    public static char[][] map;
    public static int[] moveR = {0,0,1,-1};
    public static int[] moveC = {-1,1,0,0};
    public static int R;
    public static int C;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // int TC = Integer.parseInt(sc.next(), 10);
        
        while (true) {
            C = sc.nextInt();
            R = sc.nextInt();
            if (C == 0 && R == 0) break;
            
            int rPos = -1;
            int cPos = -1;
            visited = new boolean[R][C];
            
            map = new char[R][C];
            for (int r = 0; r < R; r++) {
                String line = sc.next();
                for (int c = 0; c < C; c++) {
                    map[r][c] = line.charAt(c);
                    if (map[r][c] == '@') {
                        rPos = r;
                        cPos = c;
                    }
                }
            }
            
            System.out.println(floodFill(rPos, cPos));
        }
    }
    
    public static int floodFill(int r, int c) {
        if (r < 0 || r >= R || c < 0 || c >= C) return 0;
        if (visited[r][c] || map[r][c] == '#') return 0;
        visited[r][c] = true;
        int ret = 1;
        for (int m = 0; m < 4; m++) {
            ret += floodFill(r + moveR[m], c + moveC[m]);
        }
        return ret;
    }
}




Measured memory_bytes: 38752
#include <iostream>
#include <math.h>
#include <algorithm>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[m], r[m];
    int l_max = 0, r_min = 1000000;
    REP(i, m)
    {
        cin >> l[i] >> r[i];
        l_max = max(l_max, l[i]);
        r_min = min(r_min, r[i]);
    }
    if (r_min - l_max + 1 <= 0)
        cout << 0 << endl;
    else
        cout << r_min - l_max + 1 << endl;
    return 0;
}


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

typedef pair<int, int> pii; typedef vector<int> vi;
typedef long long ll; typedef vector<long long> vll;
const int MOD = 1'000'000'007, MOD2 = 1'000'000'009;
const int INF = 0x3f3f3f3f; const ll BINF = 0x3f3f3f3f3f3f3f3fLL;

struct DSU {
	int n;
	vector<int> p;
	DSU(int sz) : n(sz), p(sz) {
		iota(p.begin(), p.end(), 0);
	}
	int fi(int x) {return p[x] = p[x] - x ? fi(p[x]) : x;}
	inline void un(int u, int v) {p[fi(u)] = p[fi(v)];}
};

int solve() {
	int n, m; cin >> n >> m;
	DSU dsu(n);
	for (int i=0;i<m;i++) {
		int op, x, y; cin >> op >> x >> y;
		int gx = dsu.fi(x), gy = dsu.fi(y);
		if (op == 0) {
			if (gx != gy) dsu.un(gx, gy);
		} else {
			cout << (gx == gy) << endl;
		}
	}
	return 0;
}

int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 3228
#include<cstdio>

int n, st;

int main() {
	scanf("%d%d", &n, &st);
	int s = (st + (st+n-1)) * n / 2;
	if (st>=0) s -= st;
	else
	if (st+n-1<0) s -= (st+n-1);

	printf("%d\n", s);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 5e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, q, c[26][N];
char s[N], cq[2];
void upd(int x, int v, int idx)
{
	for(int i=x; i<=n; i+=(i&-i)) c[idx][i] += v;
}
int ask(int x, int idx)
{
	int ans = 0;
	for(int i=x; i>0; i-=(i&-i)) ans += c[idx][i];
	return ans;
}
bool ask(int l, int r, int idx)
{
	return ask(r, idx) - ask(l-1, idx) > 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> (s+1);
	for(int i=1; i<=n; i++) upd(i, 1, s[i]-'a');
	cin >> q;
	while(q--)
	{
		int type;
		cin >> type;
		if(type==1)
		{
			int x;
			cin >> x >> cq;
			if(s[x]!=cq[0])
			{
				upd(x, -1, s[x]-'a');
				upd(x, 1, cq[0]-'a');
				s[x] = cq[0];
			}
		}
		else
		{
			int l, r;
			cin >> l >> r;
			int res = 0;
			for(int i=0; i<26; i++) res += ask(l, r, i);
			cout << res << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 51584
fun main(args: Array<String>) = yorukatsu15d()

fun yorukatsu15d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    var answer = Mint()

    for (i in 0..62) {
        var zero = Mint()
        var one = Mint()
        for (a in aList) if (a % 2 == 0L) zero++ else one++

        answer += Mint(2L).modPow(i.toLong()) * one * zero

        for (j in aList.indices) aList[j] = aList[j] / 2
    }

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private fun modPow(n: Long, p: Long): Long {
    var x = n
    var y = p
    var result = 1L
    x %= MOD
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % MOD
        y = y shr 1
        x = (x * x) % MOD
    }
    return result
}

private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * other)
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2))
    operator fun div(other: Mint) = this.div(other.value)
    fun mod(mod: Long) = Mint(this.value % mod)
    fun modPow(other: Long) = Mint(modPow(this.value, other))
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }
}


Measured memory_bytes: 160696
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
int N, A[10];
//---------------------------------------------------------------------------------------------------
int ans = 0;
int D[10];
void f(int dpt) {
    if (dpt == N) {
        ll x = 1;
        rep(i, 0, N) x *= (A[i] + 1 - D[i]);
        if (x % 2 == 0) ans++;
        return;
    }

    rep(i, 0, 3) {
        D[dpt] = i;
        f(dpt + 1);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    f(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
Answer = 0
count = 0
initial = 0

while N - initial > Answer:
    for i in range(N):
        if initial + i == N-1:
            break
        if H[initial+i]>=H[initial+i+1]:
            count += 1
        else:
            break
    initial = initial + count +1
    if Answer<count:
        Answer = count
    count = 0

print(Answer)


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

int ceildiv(int x,int y){return (x+y-1)/y;}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int p1;
	for(int i=1;i<=n;++i){
		int x;scanf("%d",&x);
		if(x==1){
			p1=i;
			break;
		}
	}
	int a=ceildiv(p1-1,k-1);
	p1=a*(k-1)+1;
	a+=ceildiv(n-p1,k-1);
	printf("%d",a);
}


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


int main()
{
    int n,i;

    scanf("%d", &n);

    if(n%2==1)
    {
        i=ceil(n*1.0/2.0);
        printf("%d",(i)*(i-1));
    }

    else
        printf("%d", n/2 * n/2);


    return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long int
#define pb push_back
#define all(a) a.begin(),a.end()

bool func(pair<int,int> a, pair<int,int> b){
	return ((a.second<b.second) || (a.second==b.second) && (a.first<b.first));
}

signed main(){
	IOS;
	int n,k;
	cin>>n>>k;
	int x=(n-1)*(n-2)/2-k;
	if(x<0){
		cout<<-1;
		return 0;
	}
	int c=n-1+x;
	cout<<c<<endl;
	for(int i=2;i<=n;i++){
		cout<<1<<" "<<i<<endl;
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(x>0){
				cout<<i<<" "<<j<<endl;
				x--;
			}
			if(x==0){
				break;
			}
		}
		if(x==0) break;	
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

void del(int x){
    for(int i = 0 ; i < n ; i++){
        if(a[i] == x){
            a.erase(a.begin() + i);
            return;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    if(n == 3) finish("2 5 63");
    if(n == 4) finish("2 5 20 63");
    if(n == 5) finish("2 5 20 30 63");
    int sum = 0;
    int cur = 1;
    while((int)a.size() < n){
        if(cur % 2 && cur % 3){
            cur++;
            continue;
        }
        a.push_back(cur);
        sum += cur;
        sum %= 6;
        cur++;
    }
    if(sum == 2){
        del(8);
        while(cur % 6) cur++;
        a.push_back(cur);
    }
    else if(sum == 3){
        del(9);
        while(cur % 6) cur++;
        a.push_back(cur);
    }
    else if(sum == 5){
        del(9);
        while(cur % 6 != 4) cur++;
        a.push_back(cur);
    }
    for(auto &i : a) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main()
{ int A_1,A_2,A_3,sum=0;
scanf("%d%d%d",&A_1,&A_2,&A_3);
sum=(A_1+A_2+A_3);
if(sum>=22)
{printf("bust\n");}
   else
   {
      printf("win\n");
   }
    return 0;
}
//ug02-50-19-015



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
vector<int> v[2]; int mx1[2],mx2[2]; set<pii> s[2];
int main()
{	int n,x; cin>>n;
	for(rint i=1;i<=n;i++)
	{	scanf("%d",&x);
		v[i&1].push_back(x);
	}
	sort(v[0].begin(),v[0].end()); sort(v[1].begin(),v[1].end());
	for(rint id=0;id<=1;id++)
	for(rint i=0,j;i<v[id].size();i=j)
	{	for(j=i+1;j<v[id].size()&&v[id][j]==v[id][j-1];j++);
		s[id].insert(mp(j-i,v[id][i]));
	}
	s[0].insert(mp(0,-233)); s[1].insert(mp(0,-233));
	set<pii>::iterator it0=--s[0].end(),it1=--s[1].end();
	if((*it0).second==(*it1).second)
	{	set<pii>::iterator itt0=it0,itt1=it1; --it0; --it1;
		cout<<min(v[0].size()-(*it0).first+v[1].size()-(*itt1).first,
		v[0].size()-(*itt0).first+v[1].size()-(*it1).first);
	}
	else cout<<v[0].size()-(*it0).first+v[1].size()-(*it1).first;
	return 0;
}


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

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimaxze("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
#define endl '\n'

using namespace std;

const int maxn = 200228;
int a[maxn];
vector < int > g[maxn];
vector < int > nums;
bool used[maxn];
int ans[maxn];
map < int, int > answer;

int ind(int x){
    int l = -1, r = nums.size();
    while (l < r - 1){
        int m  = (l + r) / 2;
        if (nums[m] > x){
            r = m;
        }
        else{
            l = m;
        }
    }
    return l;
}

struct segtree{
    int ld, rd, ma;
    segtree* l = 0; segtree *r = 0;
    segtree(int curl, int curr){
        ld = curl; rd = curr;
        if (ld < rd - 1){
            int m = (ld + rd) / 2;
            l = new segtree(ld, m);
            r = new segtree(m, rd);
            ma = max(l -> ma, r -> ma);
        }
        else{
            ma = ans[ld];
        }
    }
    int get_max(int L, int R){
        if (ld >= L && rd <= R){
            return ma;
        }
        if (max(ld, L) >= min(rd, R)){
            return -1;
        }
        return max(l -> get_max(L, R), r -> get_max(L, R));
    }
    void update(int index, int x){
        if (ld == rd - 1){
            ma = x;
            ans[index] = x;
            return;
        }
        int m = (ld + rd) / 2;
        if (m <= index){
            r -> update(index, x);
        }
        else{
            l -> update(index, x);
        }
        ma = max(l -> ma, r -> ma);
    }
    void print(){
        cout << ld << " " << rd << " " << ma << endl;
        if (l){
            l -> print();
            r -> print();
        }
    }
};



void dfs(int root, segtree& t){
    int index = ind(a[root]);
    int st = ans[index];
    if (index){
        t.update(index, t.get_max(0, index) + 1);
    }
    else{
        t.update(0, 1);
    }
    answer[root] = t.get_max(0, nums.size());
    for (auto to : g[root]){
        if (!used[to]){
            used[to] = true;
            dfs(to, t);
        }
    }
    t.update(index, st);
}

signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int i, n, k;
    cin >> n;
    set < int > s;
    for (i = 0; i < n; i++){
        cin >> a[i];
        s.insert(a[i]);
    }
    for (auto cur : s){
        nums.push_back(cur);
    }
    for (i = 0; i < n - 1; i++){
        int x, y; cin >> x >> y; x--; y--;
        g[x].push_back(y); g[y].push_back(x);
    }
    segtree t = segtree(0, nums.size());
    used[0] = true;
    dfs(0, t);
    for (i = 0; i < n; i++){
        cout << answer[i] << endl;
    }
    return 0;
}

/*
9
2 1 2 3 1 2 2 2 3
1 2
1 3
2 6
2 7
7 8
8 9
3 4
3 5
*/


Measured memory_bytes: 78652
import java.util.*;

public class Main{
  static int H, W;
  static char[][] field;
  static int[][] var, hor;
  static boolean[][] reached_v, reached_h;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    H = Integer.parseInt(S[0]);
    W = Integer.parseInt(S[1]);
    
    field = new char[H][W];
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        field[i][j] = T.charAt(j);
      }
    }
    
    var = new int[H][W];
    hor = new int[H][W];
    reached_v = new boolean[H][W];
    reached_h = new boolean[H][W];
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(!reached_v[i][j]){
          var[i][j] = func(i,j,0,1);
        }
        
        if(!reached_h[i][j]){
          hor[i][j] = func(i,j,0,2);
        }
      }
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        int n = var[i][j] + hor[i][j];
        ans = ans < n ? n : ans; 
      }
    }
    System.out.println(ans-1);
  }
  
  public static int func(int h, int w, int count, int swi){
    if(h >= H || w >= W || h < 0 || w < 0){
      return count;
    }
    if(swi == 1){
      reached_v[h][w] = true;
      if(field[h][w] == '#'){
        return count;
      }
      return var[h][w] = func(h+1, w, count+1, 1);
    }else{
      reached_h[h][w] = true;
      if(field[h][w] == '#'){
        return count;
      }
      return hor[h][w] = func(h, w+1, count+1, 2);
    }
  }
}

Measured memory_bytes: 97892
import sys
input = sys.stdin.readline

h, w = (int(i) for i in input().split())
a = [input() for i in range(h)]

class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.size = [1] * N
        self.N = N

    # xのrootを返す
    def root(self, x):
        if self.par[x] == x:
            return x
        else: 
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    # x, yが同じrootの場合true
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    # x,yのrootが違った場合、併合
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if self.size[rx] < self.size[ry]:
            self.par[rx] = ry
            self.size[ry] += self.size[rx]
        else:
            self.par[ry] = rx
            self.size[rx] += self.size[ry]
            
uf = UnionFind(h*w)

for j in range(h):
    for i in range(w):
        if i != w-1 and a[j][i+1] != a[j][i]:
            uf.unite(w*j+i,w*j+i+1)
        if j != h-1 and a[j+1][i] != a[j][i]:
            uf.unite(w*j+i,w*(j+1)+i)

for v in range(h*w):
    uf.root(v)

wc = [0]*(h*w)
bc = [0]*(h*w)
for j in range(h):
    for i in range(w):
        idx = w*j+i
        if a[j][i] == ".":
            wc[uf.par[idx]] += 1
        else:
            bc[uf.par[idx]] += 1

res = 0
for i in range(h*w):
    res += wc[i] * bc[i]
print(res)

Measured memory_bytes: 13364
from collections import deque
N, K = map(int, input().split())
tree = [[] for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

depth = [-1]*N
mod = 10**9+7

# WFS
next_v = deque([0])
depth[0] = 0
ans = K
while next_v:
    s = next_v.popleft()
    color = max(K-depth[s]-1, K-2)

    for t in tree[s]:
        if depth[t] != -1:
            continue
        next_v.append(t)
        depth[t] = depth[s] + 1

        ans *= color
        ans %= mod
        color -= 1

print(ans)


Measured memory_bytes: 25424
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    A, B, C = MAP()

    tmp = B
    for i in range(C):
        tmp -= A
        if tmp < 0:
            print(i)
            break
    else:
        print(C)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256