akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import numba as nb


@nb.njit('(i1[:],)', cache=True)
def solve(s):
    n = len(s)
    size = n // 2
    MOD = 998244353
    dp_can = np.zeros((n + 1, size + 1, size + 1), dtype=np.int8)
    dp_cnt = np.zeros((n + 1, size + 1, size + 1), dtype=np.int64)

    dp_cnt[n, 0] = 1
    for j in range(size):
        dp_cnt[n, j + 1] = np.cumsum(dp_cnt[n, j]) % MOD

    for i in range(n - 1, -1, -1):
        if s[i] == 0:
            for j in range(size + 1):
                dp_cnt[i, j] = np.cumsum(dp_cnt[i + 1, j]) % MOD
        else:
            for k in range(size + 1):
                dp_cnt[i, :, k] = np.cumsum(dp_cnt[i + 1, :, k]) % MOD

    dp_can[0, 0, 0] = 1
    for i in range(n):
        dp_can[i + 1] |= dp_can[i]
        if s[i] == 0:
            dp_can[i + 1, 1:, :-1] |= dp_can[i, :-1, 1:]
        else:
            dp_can[i + 1, :-1, 1:] |= dp_can[i, 1:, :-1]
        if i < n - 1:
            if s[i] == 0 or s[i + 1] == 0:
                dp_can[i + 2, 1:, :] |= dp_can[i, :-1, :]
            if s[i] == 1 or s[i + 1] == 1:
                dp_can[i + 2, :, 1:] |= dp_can[i, :, :-1]
    dp_can[1:, 0, 0] = 0

    ans = 0

    for i in range(n, -1, -1):
        for j in range(size + 1):
            for k in range(size + 1):
                if dp_can[i, j, k] == 0:
                    continue

                ans = (ans + dp_cnt[i, j, k]) % MOD

                a, b = j, k
                for h in range(i - 1, -1, -1):
                    if s[h] == 0:
                        a -= 1
                    else:
                        b -= 1
                    if a < 0 or b < 0:
                        break
                    dp_can[h, a, b] = 0

    return ans


s = np.array([int(c) for c in input()], dtype=np.int8)
print(solve(s))


Measured memory_bytes: 168580
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		VI a(n); rep(i, n)cin >> a[i];
		int ma = 0, mi = 0;
		rep(i, n - 1) {
			ma = max(ma, a[i + 1] - a[i]);
			mi = min(mi, a[i + 1] - a[i]);
		}
		Cout2(ma, -mi);
	}
}


Measured memory_bytes: 3092
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int A[100005];

int main() {
  int n;
  S(n);
  rep(i,1,n+1) {
    S(A[i]);
  }
  if(A[n] != 2) {
    P(-1);
    return 0;
  }

  LL a = 2, b = 2;
  for(int i = n; i; i--) {
    LL mn = ((a + A[i] - 1) / A[i]) * 1LL * A[i];
    LL mx = (b / A[i]) * 1LL * A[i];
    if(mn > b) {
      P(-1);
      return 0;
    }
    a = mn;
    b = mx + A[i] - 1;
  }
  printf("%lld %lld\n",a,b);
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace ABC065
{
    class C
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];
            long mod = 1000000007;


            if (M < N - 1 || N < M - 1)
            { Console.WriteLine(0); return; }
            else
            {
                long p = 1;
                long p2 = 1;
                long res = 0;
                for (int i = Math.Max(N, M); i >= 1; i--)
                {
                    p = (p * i) % mod;
                    if (i < Math.Max(N, M)) p2 = (p2 * i) % mod;
                }

                if (M == N)
                {
                    res = 2 * (p * p) % mod;
                }
                else
                {
                    res = (p * p2) % mod;
                }
                Console.WriteLine(res);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int n,val,pos,a[MAXN];
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]>val) {val=a[i],pos=i;}
	}
	for (int i=1;i<=n;i++) {
		if (i!=pos) {printf("%d\n",val);}
		else {
			int nval=0;
			for (int j=1;j<=n;j++) {
				if (j!=i) {nval=max(nval,a[j]);}
			}
			printf("%d\n",nval);
		}
	}
	return 0;
}

Measured memory_bytes: 2432
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from numba import njit


def getInputs():
    D = int(readline())
    CS = np.array(read().split(), np.int32)
    C = CS[:26]
    S = CS[26:].reshape((-1, 26))
    return D, C, S


def _compute_score(output, i, d, last):
    mask = np.ones((26, ), np.int32)
    mask[i] = 0
    score = S[d][i] - np.sum(C * (d + 1 - last) * mask)

    return score


def _evaluate(output, i, d, last, k):
    score = _compute_score(output, i, d, last)
    score -= np.sum(C * (d + k + 1 - last))
    return score


def solve(k):
    output = np.array([], np.int32)
    last = np.zeros((26, ), np.int32)
    SCORE = 0
    for d in range(D):
        max_score = float('-inf')
        best_i = 0
        for i in range(26):
            output = np.append(output, i)
            #score = _compute_score(output, i, d, last)
            score = _evaluate(output, i, d, last, k)
            if max_score < score:
                max_score = score
                best_i = i + 1
            output = output[:-1]
        output = np.append(output, best_i)
        last[best_i - 1] = d + 1
        SCORE += max_score

    return output, SCORE


D, C, S = getInputs()

max_score = float('-inf')
for k in range(7, 14):
    ans, score = solve(k)
    if max_score < score:
        max_score = score
        ANS = ans

print('\n'.join(ANS.astype(str).tolist()))

Measured memory_bytes: 92532
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

int power(int x, int y) 
{ 
    int res = 1;
    x = x % mod; 
  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % mod; 
        y = y>>1; 
        x = (x*x) % mod;   
    } 
    return res; 
}
     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //start from here

    read(n) readarr(a, n)

    int cnt[n] = {};
    fori (i, 1, n) cnt[a[i]]++; 

    bool flag = true;

    if(n % 2)
    {
    	if(cnt[0] != 1) flag = false;
    	fori (i, 1, n-1)
    	{
    		if(i % 2 && cnt[i]) flag = false;
    		else if(i % 2 == 0 && cnt[i] != 2) flag = false; 
    	}
    }

    else
    {
    	fori (i, 1, n-1)
    	{
    		if(i % 2 && cnt[i] != 2) flag = false;
    		else if(i % 2 == 0 && cnt[i]) flag = false; 
    	}
    }

    if(flag) print(power(2, n/2))
    else print(0)

    return 0;
}


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

struct Edge{
    int from,to,cost;  
};
using Graph=vector<vector<Edge>>;
const int INF=1e9;
int solve(){
    int n,m,c;
    cin>>n>>m>>c;
    if(n==0) return false;
    Graph g(n);
    for(int i=0;i<m;i++){
        int f,t,cc;
        cin>>f>>t>>cc;
        f--,t--;
        g[f].push_back(Edge{f,t,cc});
    }
    
    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<>> que;
    que.push({0,{0,0}});
    vector<vector<int>> d(n,vector<int>(n,INF));
    d[0][0]=0;
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        int v=tmp.second.first;
        int c=tmp.second.second;
        if(d[v][c]<tmp.first) continue;
        for(auto &e:g[v]){
            if(d[v][c]+e.cost<d[e.to][c]){
                d[e.to][c]=d[v][c]+e.cost;
                que.push({d[e.to][c],{e.to,c}});
            }
            if(c+1<n && d[v][c]<d[e.to][c+1]){
                d[e.to][c+1]=d[v][c];
                que.push({d[e.to][c+1],{e.to,c+1}});
            }
        }
    }
    for(int i=0;i<n;i++){
        if(d[n-1][i]<c){
            cout<<i<<endl;
            return true;
        }
    }
    return false;
}
int main(){
    while(solve()) ;
    return 0;
}



Measured memory_bytes: 3280
c = []
for h in range(3):
    c.append([int(x) for x in input().split()])
b = c[0]
a = [0, c[1][0]-b[0], c[2][0]-b[0]]
for n in range(1,3):
    for h in range(1,3):
        if c[h][n] != a[h]+b[n]:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3060
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
GCD = gcd(N, M)
s = S[::N//GCD]
t = T[::M//GCD]
if s != t:
  print(-1)
else:
  print(N * M // gcd(N, M))


Measured memory_bytes: 5688
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





int main(){
  int a;
  int ans = 1;
  while(1) {
    cin >> a;
    if(a == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  return 0;
}


Measured memory_bytes: 3148
N = int(input())
A = [input() for _ in range(N)]

def isOk():
    if len(set(A)) < N:
        return False

    for a, b in zip(A, A[1:]):
        if a[-1] != b[0]:
            return False
    return True

print('Yes' if isOk() else 'No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
  ll n;
  cin >> n;
  ll x[n],y[n],z[n],w[n];
  rep(i,n){
    cin >> x[i] >> y[i];
    z[i]=x[i]+y[i];
    w[i]=x[i]-y[i];
  }
  sort(z,z+n);
  sort(w,w+n);
  cout << max(abs(w[n-1]-w[0]),abs(z[n-1]-z[0]));
}

Measured memory_bytes: 9852
import java.util.Scanner;

public class Main{
	
	int x,y;
	
	public void in(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
	}
	
	public void cube(){
		y = x*x*x;
		System.out.println(y);
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.in();
		obj.cube();
	}
}

Measured memory_bytes: 17160
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[][] a;
	int n;

	void run(){
		n=3;
		for(;;){
			a=new int[n][n];
			for(int j=0; j<n; j++){
				String s=sc.next();
				if(s.equals("0")){
					return;
				}
				for(int i=0; i<n; i++){
					switch(s.charAt(i)){
					case 'b':
						a[j][i]=0;
						break;
					case 'w':
						a[j][i]=1;
						break;
					case '+':
						a[j][i]=-1;
						break;
					}
				}
			}
			solve();
		}
	}

	void solve(){
		if(check(0)){
			println("b");
		}else if(check(1)){
			println("w");
		}else{
			println("NA");
		}
	}

	boolean check(int e){
		boolean f=false;
		for(int j=0; j<n; j++){
			boolean f1=true, f2=true;
			for(int i=0; i<n; i++){
				f1&=a[j][i]==e;
				f2&=a[i][j]==e;
			}
			f|=f1|f2;
		}
		boolean f1=true, f2=true;
		for(int i=0; i<n; i++){
			f1&=a[i][i]==e;
			f2&=a[i][n-1-i]==e;
		}
		return f|f1|f2;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
const int INF = 1e9;
int fast_pow(int x, int y, int p);

void solve() {
	int n;
	cin>>n;
	VI a(n);
	int dp[n][n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		dp[i][i]=0;
	}
	for(int len = 1;len<n;len++){
		for(int i = 0 ;i+len<n;i++){
			int x = i,y=i+len;
			int sm = 0;
			dp[x][y]=LLONG_MAX;
			for(int j=x;j<=y;j++)sm+=a[j];
			for(int j=x;j<y;j++){
				dp[x][y]=min(dp[x][y],sm+dp[x][j]+dp[j+1][y]);
			}
		}
	}
	cout<<dp[0][n-1];
	

	
	
	

}

int32_t main() {

	IOS;
	int test = 1;
	// cin>>test;
	for (int i = 1; i <= test; i++) {
//        cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}
int fast_pow(int x, int y, int p) {
	int res = 1;
	x = x % p;
	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

Measured memory_bytes: 4876
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc170/tasks/abc170_a>
 問題文============================================================
 A - Five Variables
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    vector<int> x(5);
    for(auto& in:x) cin >> in;
    res = find(x.begin(),x.end(),0) - x.begin() + 1;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

vector<vector<int64_t>> edges;
vector<int64_t> scores;
vector<bool> visited;

void mark(int64_t i, int64_t score) {
  // cout << " I " << i << endl;
  scores[i] = score;
  for (int64_t next : edges[i]) {
    if (scores[next] == -1) {
      mark(next, score + 1);
    }
  }
}

int64_t max_score(int64_t i, int64_t cost) {
  // cout << " i " << i << " score " << scores[i] << endl;
  visited[i] = true;
  if (scores[i] <= cost) {
    return scores[i];
  }
  int64_t score = scores[i] - 1;
  for (int64_t next : edges[i]) {
    if (!visited[next]) {
      score = max(score, max_score(next, cost + 1));
    }
  }
  return score;
}

void solve() {
  int64_t N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  edges.resize(N);
  scores.resize(N, -1);
  visited.resize(N);
  for (int64_t i = 0; i < N - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    --a;
    --b;
    // cout << " a " << a << " b " << b << endl;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  mark(v, 0);
  cout << max_score(u, 0) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 9856
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
void tc(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    sort(ALL(a));
    sort(ALL(b));
    if(n & 1){
        cout << b[n / 2] - a[n / 2] + 1;
    }else{
        int x = a[n / 2 - 1] + a[n / 2];
        int y = b[n / 2 - 1] + b[n / 2];
        cout << y - x + 1;
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) tc();
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

N=int(input())
D=list(map(int,input().split()))

mod=998244353

from collections import Counter
C=Counter(D)

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0


if C[0]!=1 or D[0]!=0:
    print(0)
    sys.exit()

MAX=max(D)

for i in range(MAX):
    if C[i]==0:
        print(0)
        sys.exit()

ANS=1

for i in range(1,MAX+1):
    ANS=ANS*pow(C[i-1],C[i],mod)%mod

print(ANS)


Measured memory_bytes: 76300
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
count :: (a -> Bool) -> [a] -> Int
count = (length .) . filter
-- end of templete

f x
  | x>=1.1 = 'A'
  | x>=0.6 = 'B'
  | x>=0.2 = 'C'
  | otherwise = 'D'

main = do
    s <- transpose . map (map (f . readDouble) . words) . lines <$> getContents
    forM_ "ABCD" $ \c -> do
        putStrLn $ sjoin $ map (count (==c)) s


Measured memory_bytes: 4268
#include<iostream>
#include<map>

int main(){
 std::map<int,int> m;
 int a[3][3];
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        std::cin >> a[i][j];
             if(m[a[i][j]]==0)
                 m[a[i][j]]=1;
    }
}

 int n;
 std::cin >> n;
 int b[n];
 for(int i=0;i<n;i++){
    std::cin >> b[i];
}
 for(int k=0;k<n;k++){
    if(m[b[k]]==1){
  for(int i=0;i<3;i++){
     for(int j=0;j<3;j++){
          if(b[k]==a[i][j])
              a[i][j]=-1;
         }
      }
   }
}

bool t=0;
if(a[0][0]==-1 && a[0][1]==-1 && a[0][2]==-1) t=1;
else if(a[1][0]==-1 && a[1][1]==-1 && a[1][2]==-1) t=1;
else if(a[2][0]==-1 && a[2][1]==-1 && a[2][2]==-1) t=1;

else if(a[0][0]==-1 && a[1][0]==-1 && a[2][0]==-1) t=1;
else if(a[0][1]==-1 && a[1][1]==-1 && a[2][1]==-1) t=1;
else if(a[0][2]==-1 && a[1][2]==-1 && a[2][2]==-1) t=1;

else if(a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1) t=1;
else if(a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1) t=1;

t==1?std::cout << "Yes" : std::cout << "No";

 return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
   
   if (n <= 1)  return false; 
   if (n <= 3)  return true; 
 
   if (n%2 == 0 || n%3 == 0) return false; 
 
   for (ll i=5; i*i<=n; i=i+6) 
       if (n%i == 0 || n%(i+2) == 0) 
          return false; 
 
   return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
   if( a<0 ) a = -a;
   if( b<0 ) b = -b;
   while( b!=0 ){
       a %= b;
       if( a==0 ) return b;
       b %= a;
   }
   return a;
}
 
int findLargestDivisor(int n) 
{ 
int max = 1;
   for (int i = 2; i < n; i++) {        
       if(n %(i) == 0) { 
           max = i;
       } 
    }
   return max;     
} 
 
 
ll power(ll x, ll y)  
{  
   ll temp;  
   if(y == 0)  
       return 1;  
   temp = power(x, y / 2);  
   if (y % 2 == 0)  
       return temp * temp;  
   else
   {  
       if(y > 0)  
           return x * temp * temp;  
       else
           return (temp * temp) / x;  
   }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
   return (a.second < b.second); 
} 
void solve(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0 ; i < (int)s.length() ; i++){
        if(s[i] == 'R'){
            int count = 1;
            while(s[i] == s[i+1] && i < (int)s.length()){
                i++;count++;
            }
            ans = maxthis(ans, count);
        }
    }
    cout << ans << "\n";
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
    solve();
    }
  return 0; 
}



  



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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		s = br.readLine().split(" ");
		check(0, 0);
		int q = Integer.parseInt(br.readLine());
		String[] m = br.readLine().split(" ");
		for (int i = 0; i < q; i++) {
			System.out.println(makable[Integer.parseInt(m[i])] ? "yes" : "no");
		}
	}
	public static void check(int i, int sum) {
		if (sum >= max) return;
		makable[sum] = true;
		if (i == n) return;
		check(i + 1, sum);
		check(i + 1, sum + Integer.parseInt(s[i]));
	}
	public static int n;
	public static String[] s;
	public static int max = 2001;
	public static boolean[] makable = new boolean[max];
}

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

using namespace std;

int main() {
    int N;
    int highest = 0;
    int result = 1;

    cin >> N;

    vector<int> h(N);
    
    int tmp = 0;
    int i = 0;
    while(cin >> tmp) {
        h[i] = tmp;
        i ++;
        if(i >= N) {
            break;
        }
    }

    highest = h[0];

    for(int i = 1; i < h.size(); i++) {
        if(highest <= h[i]) {
            result ++;
            highest = h[i];
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long MOD = 1000000007;
const long long max_cache=1000000;
long long cache_fact[max_cache],cache_inv_fact[max_cache];
long long combination_cached(long long n,long long r,long long m){
  if(r<0||r>n)return 0;
  if(r==0||r==n)return 1;
  static bool cached=false;
  if(cached==false){
    cached=true;
    cache_inv_fact[1]=1;
    for (long long i = 2; i < max_cache; i++) {
      cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m;
    }
    for (long long i = 2; i < max_cache; i++){
      cache_inv_fact[i]=cache_inv_fact[i]*cache_inv_fact[i-1]%m;
    }
    cache_fact[0]=1;
    for (long long i = 1; i < max_cache; i++) {
      cache_fact[i]=cache_fact[i-1]*i%m;
    }
  }
  r=min(r,n-r);
  return cache_fact[n]*cache_inv_fact[r]%m*cache_inv_fact[n-r]%m;
}
void solve(long long N, long long K){
  REP(K){
    cout<<combination_cached(N-K+1,i+1,MOD)*combination_cached(K-1,i,MOD)%MOD<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
    long long N, P;
    cin >> N >> P;
    long long answer = 1;
    // P = ans^N * buf
    long long ans = pow(P, (double)1/N) + 1;
    while(true){
        long long a = pow(ans, N);
        if(P % a == 0){
            answer = ans;
            break;
        }
        ans--;
    }

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
H = int(input())
A = [0]
for i in input().split(): A.append(int(i))

def maxHeapify(i):
    l = 2*i
    r = 2*i+1
    if l <= H and A[l] > A[i]: L = l
    else: L = i
    if r <= H and A[r] > A[L]: L = r
    if L != i:
        A[i],A[L] = A[L],A[i]
        maxHeapify(L)

for i in range(1,H//2+1)[::-1]: maxHeapify(i)
for i in range(1,H+1): print(" {}".format(A[i]),end="")
print("")


Measured memory_bytes: 63964
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    x: usize,
    y: usize
  };
  if x * 4 >= y && x * 2 <= y && y % 2 == 0 {
    echo!("Yes");
  } else {
    echo!("No");
  }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll A, B, N;
    cin >> A >> B >> N;

    ll tmp = min(B - 1, N);
    ll l = A * tmp;
    l /= B;

    cout << l << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
long long int llabs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	for (i = 0; i < n; i++)
		a[i] -= i + 1;
	qsort(a, n, sizeof(long long int), asc);
	long long int b = a[(n - 1) / 2];
	long long int ans = 0;
	for (i = 0; i < n; i++)
		ans += llabs(a[i] - b);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin>>N;
  int ans = 0, t, tmin = 2e5;
  for(int i=0;i<N;i++){
    cin>>t;
    if(tmin >= t){
      ans++;
      tmin = t;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
module Main where

import Data.Functor

main :: IO ()
main =  do
 { [h,w] <- getInts
 ; if h == 0 && w == 0 then done
   else putStrLn (unlines (chessboard h w)) >> main
 }

chessboard :: Int -> Int -> [String]
chessboard h w = map (take w) $ take h $ cycle [cycle "#.", cycle ".#"]

done :: IO ()
done = return ()

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 4024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  int a[5];
  rep(i, 0, 5) {
    cin >> a[i];
    if(a[i] == 0) {
      cout << i+1 << "\n";
    }
    
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  int a,b,k;
  cin >>a >> b >> k;
  int minn;
  if(a>=b) minn=b;
  else if(a<b) minn=a;
  int count=0;
  int ans;
 rep(i,a){
   if(a%(minn-i)==0 &&b%(minn-i)==0){
     count++;
   }
   if(count==k){
     ans=minn-i;
     break;
   }
 }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0;
    cin >> n ;
    ll temp=n;
    ans+=(n/500)*1000;
    n%=500;
    ans+=(n/5)*5;
    cout << ans ;
    
    return 0;
}

Measured memory_bytes: 256
//道具を使う順番もあまり関係なかったりする。でも素直に耐久力と経験値に注目しちゃえば良い。
//stack使う＆遷移後枝刈り→TLE(1ケース1秒)、遷移前枝刈りにする→TLE(1ケース0.2秒くらい？)、
//stackっぽいものを配列で自作→？？
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

int d, n;
int a[100], e[100], r[100];

signed main() {
	while( cin >> d >> n ) {
		if(!d) break;
		int i, j;
		for( i = 0; i < n; i++ )
			cin >> a[i] >> e[i] >> r[i];
		
		int dp[101][101];		//dp[残り耐久力][min(EXP,100)]
		for( i = 0; i < 101; i++ ) {
			for( j = 0; j < 101; j++ ) {
				dp[i][j] = 1000000;
			}
		}
		int data[10000], dnum = 0;
		data[dnum++] = ((0)<<(20)) + ((d)<<(10)) + ((0)<<(0));
		
		while( dnum > 0 ) {
			int Cost = (data[dnum-1]>>(20));
			int Dif = (data[dnum-1]>>(10)) % (1<<(10));
			int Exp = (data[dnum-1]) % (1<<(10));
			
			dnum--;
			dp[Dif][Exp] = Cost;
			
			for( i = 0; i < n; i++ ) {
				if( Exp >= r[i] ) {
					//殴る
					int nCost = Cost+1;
					int nDif = max(0, Dif - a[i]);
					int nExp = min(100, Exp + e[i]);
					//枝刈り
					if( dp[nDif][nExp] <= nCost )
						continue;
					//遷移する
					data[dnum++] = (nCost<<(20)) + (nDif<<(10)) + (nExp<<(0));
				}
			}
		}
		
		int ans = 100000;
		for( i = 0; i < 101; i++ ) {
			if( dp[0][i] < 10000 ) {
				ans = min(dp[0][i], ans);
			}
		}
		if( ans < 10000 )
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=201234;

int n,h[nmax],mid,lmax,rmax;
ll a[nmax],res;

struct linetree
{
    int l,r;
    ll v;
} dp[4*nmax];

void build(int f)
{
    if(dp[f].l!=dp[f].r)
    {
        int mid=(dp[f].l+dp[f].r)/2;
        dp[2*f].l=dp[f].l;
        dp[2*f].r=mid;
        dp[2*f+1].l=mid+1;
        dp[2*f+1].r=dp[f].r;
        build(2*f);
        build(2*f+1);
    }
    else{
        if(f<lmax)
            lmax=f;
        if(rmax<f)
            rmax=f;
    }
}

ll solve(int pos)
{
    int i=1;
    res=0;
    while(dp[i].l!=dp[i].r)
    {
        mid=(dp[i].l+dp[i].r)/2;
        if(dp[i].v+a[pos]>res)
            res=dp[i].v+a[pos];
        if(h[pos]<=mid)
            i=2*i;
        else
            i=2*i+1;
    }
    if(dp[i].v+a[pos]>res)
        res=dp[i].v+a[pos];
    i=1;
    while(dp[i].l!=dp[i].r)
    {
        if(dp[i].l==h[pos])
            dp[i].v=res;
        mid=(dp[i].l+dp[i].r)/2;
        if(h[pos]<=mid)
        {
            if(dp[2*i+1].v<res)
                dp[2*i+1].v=res;
            i=2*i;
        }
        else
            i=2*i+1;
    }
    dp[i].v=res;
}

int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        scanf("%d",&h[i]);
    }
    for(int i=1; i<=n; ++i)
    {
        scanf("%lld",&a[i]);
    }
    dp[1].l=1;
    dp[1].r=n;
    lmax=5*nmax;
    build(1);
    for(int i=1; i<=n; ++i)
    {
        solve(i);
    }
    res=0;
    for(int i=lmax; i<=rmax; ++i)
    {
        if(res<dp[i].v)
            res=dp[i].v;
    }
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <atcoder/modint>
#include <atcoder/convolution>
#include <vector>
#include <set>
#include <utility>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
mint f[100010],fi[100010],p[100010];
mint pw(mint a,int x){
    mint ret = 1;
    while(x){
        if(x&1) ret *= a;
        a *= a; x /= 2;
    }
    return ret;
}
vector<mint> v[100010];
set<pair<int,int>> s;
int cnt[100010];
int main(){
    int i,j,n; cin >> n;
    for(i=0;i<2*n;i++){
        int h; cin >> h; h--;
        cnt[h]++;
    }
    f[0] = 1,fi[0] = 1;
    for(i=1;i<=100000;i++) f[i] = f[i - 1]*i;
    fi[100000] = pw(f[100000],998244353 - 2);
    for(i=99999;i>=1;i--){
        fi[i] = fi[i + 1]*(i + 1);
    }
    int inv = (998244353 + 1)/2;
    p[0] = 1;
    for(i=1;i<=100000;i++) p[i] = p[i - 1]*inv;
    for(i=0;i<100000;i++){
        for(j=0;2*j<=cnt[i];j++){
            mint z = f[cnt[i]]*fi[j]*fi[cnt[i] - 2*j]*p[j];
            v[i].push_back(z);
        }
        s.insert({v[i].size(),i});
    }
    while(s.size()>1){
        pair<int,int> p = *s.begin();
        s.erase(p);
        pair<int,int> q = *s.begin();
        s.erase(q);
        int l = p.second,r = q.second;
        vector<mint> c = convolution(v[l],v[r]);
        swap(v[l],c);
        pair<int,int> z = {v[l].size(),l};
        s.insert(z);
    }
    pair<int,int> pp = *s.begin();
    int k = pp.second;
    mint ans = 0,s = 1;
    for(i=0;i<v[k].size();i++){
        ans += s*v[k][i]*p[n - i]*f[2*n - 2*i]*fi[n - i];
        s *= -1;
    }
    cout << ans.val() << endl;
}

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

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

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

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

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

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    if (a<=8 && b<=8){
        cout<<"Yay!\n";
    }else{
        cout<<":(\n";
    }
    return 0;
}


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

int main()
{
ll a , b , c ;
cin >> a >> b >> c ;
ll k ;
cin >> k ;
if(k%2)ans=b-a;
else ans=a-b;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define all(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
        enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


signed main(){
        IOS;
        int n , W ;
        cin >> n >> W ;

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

        int m = accumulate(all(v),0ll);

        vector<int>dp(m+1,INT32_MAX);
        dp[0] = 0;
        for(int i=0;i<n;i++){
                for(int j = m-v[i] ; j >= 0 ; j-- ){
                        dp[j+v[i]] = min(dp[j]+w[i],dp[j+v[i]]);
                }
        }
        int ans = 0 ;
        for(int i=0;i<=m;i++){
                if(dp[i] <= W) ans = i;
        }
        cout << ans << endl ;
        return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>


int main(void){
	int n;
	int count;

	scanf("%d",&n);
	count = 0;
	while( n != 0){
		if(n%10==2){
			count++;
		}
	n /= 10;
	}
	printf("%d\n",count);

	return 0;
}

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

int main(){
  string s;
  cin >> s >> s;
  ll ans = 0;
  for(ll i = 0; i < 1000; i++){
    string t = to_string(1000 + i);
    t.erase(t.begin());
    ll at = 0;
    for(auto& c : s) if(c == t[at]){
      at++;
      if(at == 3){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}
      

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

void solve() {
    int N; string s;
    cin >> N >> s;
    int i = 0, j = s.size() - 1, ans = 0;
    while (i < j) {
        if (s[i] == 'R') { ++i; continue; }
        if (s[j] == 'W') { --j; continue; }
        ++ans;
        ++i;
        --j;
    }
    cout << ans << "\n";
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3732
n,x,m=map(int,input().split())
mod=m

lst=[]
ans=0
gg=0
while True:
    gg+=1
    if x==0:
        print(sum(lst))
        exit()

    elif x in lst:
        break

    else:
        lst.append(x)
        x=(x**2)%mod
    
    if gg==n:
        print(sum(lst))
        exit()


log=[]
for i,v in enumerate(lst):
    if v==x:
        log.append(i)


ans+=sum(lst)
n-=len(lst)

newlst=lst[log[0]:]
ans+=sum(newlst)*(n//len(newlst))
if n%len(newlst)!=0:
  ans+=sum(newlst[:n%len(newlst)])

print(ans)

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2]){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }

}

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

int main(){
    int n,m,c;
    cin>>n>>m>>c;
    
    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin>>b.at(i);
    }
    
    vector<vector<int>> a(n,vector<int> (m));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a.at(i).at(j);
        }
    }

    int count=0;

    for(int i=0; i<n; i++){
        int req=0;
        for(int j=0; j<m; j++){
            req+=a.at(i).at(j)*b.at(j);
        }
        req+=c;
        if(req>0){
            count++;
        }
    }

    cout<<count<<endl;
}

Measured memory_bytes: 256