akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,m = LI()
    a = LIR(n)
    ans = 0
    for i in range(2):
        for j in range(2):
            for k in range(2):
                a.sort(key = lambda x:(-1)**i*x[0]+(-1)**j*x[1]+(-1)**k*x[2])
                p = [0,0,0]
                for l in range(m):
                    p[0] += a[l][0]
                    p[1] += a[l][1]
                    p[2] += a[l][2]
                p = abs(p[0])+abs(p[1])+abs(p[2])
                if p > ans:
                    ans = p
    print(ans)
    return

#B
def B():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y,su):
        x = root(x)
        y = root(y)
        su += comb_2(s[x])+comb_2(s[y])
        if rank[x] < rank[y]:
            s[y] += s[x]
            su -= comb_2(s[y])
            par[x] = y
        else:
            s[x] += s[y]
            su -= comb_2(s[x])
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
        return su

    def comb_2(a):
        return a*(a-1)//2

    n,m = LI()
    v = LIR(m)
    par = [i for i in range(n)]
    rank = [0]*n
    s = [1]*n
    su = comb_2(n)
    ans = [su]
    for a,b in v[:0:-1]:
        a -= 1
        b -= 1
        if root(a) != root(b):
            su = unite(a,b,su)
        ans.append(su)
    for i in ans[::-1]:
        print(i)
    return

#C
def C():
    def root(x):
        if par[x] == x:
            return par[x]
        r = root(par[x])
        d[x] += d[par[x]]
        par[x] = r
        return par[x]

    def weight(x):
        root(x)
        return d[x]

    def unite(x,y,w):
        w += weight(x)
        w -= weight(y)
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
            d[x] = -w
        else:
            par[y] = x
            d[y] = w
            if rank[x] == rank[y]:
                rank[x] += 1
    n,m = LI()
    par = [i for i in range(n)]
    rank = [0]*n
    d = [0]*n
    for i in range(m):
        l,r,w = LI()
        l -= 1
        r -= 1
        if root(l) != root(r):
            unite(l,r,w)
        else:
            if weight(r)-weight(l) != w:
                print("No")
                return
    print("Yes")
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#G
def G():

    return

#H
def H():

    return

#I
def I_():

    return

#Solve
if __name__ == "__main__":
    C()


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

N=int(input())

ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

ANS=N

def acorns(N,ga,sa,ba,gb,sb,bb):
    X=[]
    if ga<gb:
        X.append((ga,gb))
    if sa<sb:
        X.append((sa,sb))
    if ba<bb:
        X.append((ba,bb))

    if len(X)==0:
        return N
    
    if len(X)==1:
        ga,gb=X[0][0],X[0][1]
        t=N//ga
        return N-t*ga+t*gb
    
    if len(X)==2:
        ga,gb=X[0][0],X[0][1]
        sa,sb=X[1][0],X[1][1]
        ANS=N
        
        t=N//ga
        for i in range(t+1):
            M=i*gb
            R=N-i*ga
            u=R//sa

            ANS=max(ANS,M+R+u*(sb-sa))
        return ANS
    
    if len(X)==3:
        ga,gb=X[0][0],X[0][1]
        sa,sb=X[1][0],X[1][1]
        ba,bb=X[2][0],X[2][1]
        ANS=N

        t=N//ga
        for i in range(t+1):

            R=N-i*ga
            u=R//sa
            
            for j in range(u+1):
                R2=R-j*sa

                ANS=max(ANS,i*gb+j*sb+R2+R2//ba*(bb-ba))

        return ANS

N2=acorns(N,ga,sa,ba,gb,sb,bb)
print(acorns(N2,gb,sb,bb,ga,sa,ba))
                
                
        
            
        


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

int main() {
	string s;
	cin >> s;
	vector<ll> m(26);
	for (auto c : s) {
		m[c - 'a']++;
	}
	ll n = (s.size() - 1) * s.size() / 2 + 1;
	for (auto e : m) {
		n -= (e - 1) * e / 2;
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int a=0, b=0;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == 'W') {
			a++;
			b += i;
		}
	}
	cout << b - a * (a - 1) / 2 << endl;
}


Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a,b,c;
        a = sc.nextInt();
        b = sc.nextInt();
        if(a<b){
            c = a; a = b; b = c;
        }
        while(true){
            c = a%b;
            if(c==0){break;}
            a=b;b=c;
        }
        System.out.println(b);
    }
}


Measured memory_bytes: 26348
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
koho = []
for l in range(n):
    for r in range(l,n):
        koho.append(cum[r+1] - cum[l])
ret = 0
for keta in reversed(range(60)):
    currkoho = []
    for s in koho:
        if s & (1 << keta) != 0:
            currkoho.append(s)
    if len(currkoho) >= k:
        koho = currkoho
        ret += (1 << keta)
print(ret)


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

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] < 0) {
            A[i] = -A[i];
            cnt++;
        }
    }
    sort(A.begin(), A.end());

    long long ans = 0;
    for(int i = 0; i < N; i++) {
        ans += A[i];
    }
    if(cnt % 2 != 0) ans = ans -(2 * A[0]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#define N 100000
typedef struct{
  char mark;
  int num;
}card;
int partition(card *,int,int,int);
void quickSort(card *,int,int,int);
void mergeSort(card *,int,int,int);
void merge(card *,int,int,int,int);
card L[N/2+2],R[N/2+2];
int main()
{
  int i,v,n;
  card A1[N],A2[N];
  char S[10];
  int stable=1;
  /*入力*/
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%s %d",S,&v);
    A1[i].mark=A2[i].mark=S[0];
    A1[i].num=A2[i].num=v;
  }

  mergeSort(A1,n,0,n);
  quickSort(A2,n,0,n-1);


  for(i=0;i<n;i++)
  {
    if(A1[i].mark != A2[i].mark)
      stable = 0;
  }

  /*出力*/
  if(stable == 1)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for(i=0;i<n;i++)
  {
    printf("%c %d\n",A2[i].mark,A2[i].num);
  }
return 0;
}

void quickSort(card A[],int n,int p,int r)
{
  int q;
  if(p < r)
    {
      q = partition(A,n,p,r);
      quickSort(A,n,p,q-1);
      quickSort(A,n,q+1,r);
    }
}

int partition(card A[],int n,int p,int r)
{
  int i,j;
  card x,y;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
  {
    if(A[j].num <= x.num)
    {
      i++;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
    }
  }
  y=A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}
void merge(card A[],int n,int left,int mid,int right)
{
  int i,j,k,n1,n2,l;
  n1 = mid - left ;
  n2 = right - mid;
  for(i=0;i<n1;i++)
    L[i] = A[left + i];
  for(i=0;i<n2;i++)
    R[i] = A[mid + i];
  L[n1].num=R[n2].num=2000000000;
  i = 0;
  j = 0;
  for(k=left;k<right;k++)
    {
      if(L[i].num <= R[j].num)
        {
          A[k] = L[i++];
        }
      else
        {
          A[k] = R[j++];
        }
    }
}
void mergeSort(card B[],int n,int left,int right)
{
  int mid;
  if(left+1 < right)
  {
    mid = (left + right)/2;
     mergeSort(B,n,left,mid);
     mergeSort(B,n,mid,right);
    merge(B,n,left,mid,right);
  }
}



Measured memory_bytes: 4140
#include <bits/stdc++.h>  
using namespace std;
using Int = int;

int main(){
  Int N,M;
  cin >> N >> M;
  auto S = vector<int>(M);
  auto C = vector<char>(M);
  for(int i=0; i<M; i++) {
    cin >> S[i] >> C[i];
  }
  
  for(int n=0; n<1000; ++n) {
    auto nstr = to_string(n);
    if (nstr.size() != N) continue;
    bool f = true;
    for(int i=0; i<M; i++) {
      if (nstr[S[i]-1] != C[i]) {
        f = false;
        break;
      }
    }
    if (f) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#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>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    string S;
    cin>>S;
    ll N=S.length();
    ll ans=0;
    FORI(i,0,N)
    {
        ans+=(ll)S[i]-(ll)'0';
        ans=ans%9;
    }
    if(ans==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3968
from collections import Counter

N, K, *DC = map(int, open(0).read().split())

D = tuple(zip(*[iter(DC[:K * K])] * K))
C = tuple(zip(*[iter(DC[K * K:])] * N))

A = [Counter() for _ in range(3)]
for k in range(K):
    for i in range(N):
        for j in range(N):
            A[(i + j) % 3][k] += D[C[i][j] - 1][k]

ans = float("inf")
for i in range(K):
    for j in range(K):
        for k in range(K):
            if i == j or j == k or k == i:
                continue
            ans = min(ans, A[0][i] + A[1][j] + A[2][k])

print(ans)

Measured memory_bytes: 79504
import sys
for line in sys.stdin:
    if line == None or line == '\n':
        break
    line = line.rstrip()
    line = line.split(" ")
    if len(line) == 1:
        N = int(line[0])
        continue
    else:
        coordinates = line

        coordinates.insert(0, 0)
        coordinates.append(0)

        prev_coord = int(coordinates[0])
        total_cost = 0
        for i in range(1, len(coordinates)):
            total_cost += abs(int(coordinates[i]) - int(coordinates[i-1]))

        for i in range(1, len(coordinates) - 1):
            print(total_cost - abs(int(coordinates[i]) - int(coordinates[i - 1])) - abs(int(coordinates[i]) - int(coordinates[i + 1])) + abs(int(coordinates[i + 1]) - int(coordinates[i - 1])))


Measured memory_bytes: 11112
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  vector<pair<int,int>> a;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    a.push_back(make_pair(x+y, x-y));
  }
  sort(a.begin(),a.end());
  int r = -mod - mod;
  int ret = 0;
  for(int i=0;i<n;i++){
    if(r<=a[i].second){
      ret++;
      r = a[i].first;
    }
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

ll a[200000],n,done[200000],memo[200000],sum[200000];

bool judge(ll now){
    ll k;

    k  = now;
    while(k < n - 1 && sum[k] * 2 >= a[k + 1])
        k++;
    if(k == n - 1 && sum[n - 2] * 2 >= a[n - 1])
        return 1;
    else
        return 0;
}

int main(void){

    ll now,ub,lb,mid;
    scanf("%lld",&n);

    REP(i,n){
        scanf("%lld",&a[i]);
    }

    sort(a,a + n);

    REP(i,n)
        if(i == 0)
            sum[i] = a[i];
        else
            sum[i] += sum[i - 1] + a[i];

    lb = -1;ub = n;
    while(ub - lb > 1){
        mid = (lb + ub) / 2;
        if(judge(mid))
            ub = mid;
        else
            lb = mid;
    }

    printf("%lld\n",n - ub);
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int r;
    cin >> r;
    cout << 2*M_PI*r;

    return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>

int main(){
	double x,y;
	double a,b,c,d,e,f;

	while(scanf("%lf %lf %lf %lf %lf %lf", &a,&b,&c,&d,&e,&f) != EOF){
		if(e == 0 && d*b != 0){
			x = (f/d);
			y = (c/b)-(a*f)/(b*d);
		}else if(b == 0 && a*e != 0){
			x = (c/a);
			y = (f/e)-(c*d)/(a*e);
		}else if(a == 0 && b*d != 0){
			y = (c/b);
			x = (f/d)-(c*e)/(b*d);
		}else if(d == 0 && a*e != 0){
			y = (f/e);
			x = (c/a)-(b*f)/(a*e);
		}else{
			x = (e*c - b*f)/(a*e - b*d);
			y = (f/e) - (d/e)*x;
		}

		if(x<0.0005 && x>-0.0005) x = 0;
		if(y<0.0005 && y>-0.0005) y = 0;

		printf("%.3lf %.3lf\n", x,y);
	}

	return 0;
}

Measured memory_bytes: 652
A, B, M = list(map(int, input().split()))

a_items = list(map(int, input().split()))
b_items = list(map(int, input().split()))


m = min(a_items) + min(b_items)
value = m

for _ in range(M):
    x, y, c = list(map(int, input().split()))
    z = a_items[x-1] + b_items[y-1] - c

    if value > z:
        value = z

print(value)

Measured memory_bytes: 18608
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};
    static int[] x8 = {-1, -1, 0, 1, 1, 1, 0, -1};
    static int[] y8 = {0, -1, -1, -1, 0, 1, 1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h = in.nextInt(), w = in.nextInt();
        char[][] s = new char[h][w];
        int[][] d = new int[h][w];
        for(int i = 0; i < h; i++) {
            s[i] = in.next().toCharArray();
            Arrays.fill(d[i], Integer.MAX_VALUE);
        }

        Queue<P> queue = new ArrayDeque<>();
        queue.add(new P(0, 0));
        d[0][0] = 0;
        while(!queue.isEmpty()) {
            P c = queue.remove();
            for(int i = 0; i < 4; i++) {
                int x = c.x + x4[i];
                int y = c.y + y4[i];
                if(x < 0 || w <= x || y < 0 || h <= y) continue;
                if(s[y][x] != '.' || d[y][x] != Integer.MAX_VALUE) continue;

                d[y][x] = d[c.y][c.x] + 1;
                queue.add(new P(x, y));
            }
        }

        if(d[h-1][w-1] == Integer.MAX_VALUE) {
            System.out.println(-1);
            return;
        }

        int ans = h*w - (d[h-1][w-1]+1);
        for(int i = 0; i < h; i++)
            for(int j = 0; j < w; j++) if(s[i][j] == '#') ans--;

        System.out.println(ans);
    }

    static public void printArray2D(char[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%c\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }

    static public void printArray2D(int[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%d\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }
}

class P {
    int x, y;
    P(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1;
    cin >> M2 >> D2;
    if (M1 != M2) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3644
def abc138_c():
    N = int(input())
    values = sorted(list(map(int, input().split())))

    while len(values) > 1:
        values[0] = (values[0] + values[1]) / 2
        values.pop(1)
        values.sort()

    print(values[0])

if __name__ == '__main__':
    abc138_c()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> c(N), t(N);
    REP(i, N) {
        cin >> c[i] >> t[i];
    }
    int result = 1001;
    REP(i, N) {
        if (t[i] <= T) {
            if (c[i] < result) {
                result = c[i];
            }
        }
    }
    if (result == 1001) cout << "TLE" << endl;
    else cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

N, Q = map(int, input().split())
S = input()

cnt = [0]*N

for i in range(N):
    if i >= N-1:
        continue
    if S[i] == "A":
        if S[i+1] == "C":
            cnt[i+1] = 1

acum = list(itertools.accumulate(cnt))

for j in range(Q):
    l, r = map(int, input().split())
    print(acum[r-1]-acum[l-1])

Measured memory_bytes: 14016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> vecB(M);
    for(int i=0;i<M;i++){
        cin >> vecB.at(i);
    }
   vector<vector<int>> vecA(N,vector<int>(M));
   for(int i=0;i<N;i++){
       for(int j=0;j<M;j++){
           cin >>vecA.at(i).at(j);
       }
   }
   int count = 0;
   for(int i=0;i<N;i++){
       int XX =0;
       for(int j=0;j<M;j++){
           XX += vecB.at(j)*vecA.at(i).at(j);
       }
       XX += C;
       if(XX>0){
           ++ count;
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
count = 0
ans = 0
for i in range(len(h)-1):
    if h[i]>=h[i+1]:
        count += 1
    else:
        ans = max(ans,count)
        count = 0
ans = max(ans,count) 
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int a,b;
    cin >>a >>b;
    cout << a*b <<endl;

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,s=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<n;i++)
    {
        a[i]=a[i]+max(b[i-1],c[i-1]);
        b[i]=b[i]+max(a[i-1],c[i-1]);
        c[i]=c[i]+max(a[i-1],b[i-1]);
    }
    s=max(a[n-1],max(b[n-1],c[n-1]));
    
    cout<<s<<"\n";
}


Measured memory_bytes: 1408
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

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

fn main() {
    let mut n = read::<i64>();
    let k = read::<i64>();
    let x = read::<i64>();
    let y = read::<i64>();

    let mut ans = min(n, k) * x;
    n -= min(n, k);
    ans += y * n;
    println!("{}", ans);
}

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

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


Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
typedef int  ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define INF 1e9


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int v,e,x,y,w,r;
    pll h;
    cin>>v>>e>>r;
    vector<ll> dist(v,INF);
    dist[r]=0;//nodo de inicio
    vector<vector<pll> > grafo(v,vector<pll> (0));

	for(int i=0;i<e;i++)
    {
        cin>>x>>y>>w;
        h.first=y;
        h.second=w;
        grafo[x].push_back(h);
        /*h.first=x;
        grafo[y].push_back(h);*/
    }

	for(int i=0;i<v-1;i++)
    {
        bool con=0;
        for(int j=0;j<v;j++)
        {
            for(int k=0;k<grafo[j].size();k++)
            {
                if(dist[j]<INF)
                {
                    dist[grafo[j][k].first]=min(dist[grafo[j][k].first],dist[j]+grafo[j][k].second);
                    con=1;
                }
            }
        }
        if(con==0)
            break;
    }

    bool con=0;//detecta ciclo negativo
    for(int j=0;j<v;j++)
    {
        for(int k=0;k<grafo[j].size();k++)
        {
            if(dist[j]<INF&&dist[grafo[j][k].first]>dist[j]+grafo[j][k].second)
            {
                con=1;
            }
        }
    }


    if(con)
    {
        cout<<"NEGATIVE CYCLE\n";
    }
    else
    {
        for(int i=0;i<v;i++)
        {
            if(dist[i]!=INF)
            cout<<dist[i]<<endl;
            else cout<<"INF\n";
        }
    }


	return 0;
}



Measured memory_bytes: 3236
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/
 
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll                          long long
#define ld                          long double
 
#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second
 
#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define  MN                           INT_MIN
#define  MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
 
bool check(string s, int len,int n){
	unordered_map<string,int> m;
	for(int i = 0;i < n - len + 1;i++)
	{
		if(m[s.substr(i,len)] > 0 &&  i > m[s.substr(i,len)])return true;
		if(!m[s.substr(i, len)])m[s.substr(i,len)] = i + len - 1;
	}
	return false;
}
int32_t main()
{
	fastio;
	int n;
	string s;
	cin >> n >> s;
	int l = 0, r = n / 2;
	int ans = 0;
	while(l<=r)
	{
		int mid = l + (r-l) / 2;
		if(check(s,mid,n)){
			ans = mid;
			l = mid + 1;
		}else{
			r = mid - 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9972
// user:halahen
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int i,j,k;
int n,a[maxn];
long long tot,num;
char c=' ';
int read(){
	int tot=0,fh=1;
	char c=getchar();
	while ((c<'0')||(c>'9')){ if(c=='-') fh=-1; c=getchar(); }
	while ((c>='0')&&(c<='9')){ tot=tot*10+c-'0'; c=getchar(); }
	return tot*fh;
}
int main(){
	while ((c<'A')||(c>'Z')){ c=getchar(); }
	while ((c>='A')&&(c<='Z')){ n++; a[n]=c; c=getchar(); }
	for (i=1;i<=n;i++){
		tot=tot+i*(a[i]=='W');
		num=num+(a[i]=='W');
	}
	printf("%lld\n",tot-(((num+1)*num)/2));
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int s,array[1000005]={};
    scanf("%d",&s);
    array[1]=s;
    int flag=0;
    for(int i=2;!flag;i++){
        if(array[i-1]%2==0) array[i]=array[i-1]/2;
        else array[i]=3*array[i-1]+1;
        for(int j=1;j<i;j++){
            if(array[j]==array[i]){
                printf("%d\n",i);
                flag=1;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4096
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	x := sc.nextInt()
	y := sc.nextInt()

	g := map[int]int{1: 1, 3: 1, 5: 1, 7: 1, 8: 1, 10: 1, 12: 1, 4: 2, 6: 2, 9: 2, 11: 2, 2: 3}

	if g[x] == g[y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int n,a,b,c,x;
  cin >> n >> a >> b >> c >> x;
  while(1){
    if(n==0)break;
    int y[n];
    for(int i=0;i<n;i++)cin >> y[i];
    int i,j=0,ret=0,ch;
    for(i=0;i<=10000;i++){
      if(x==y[j]){
        ret = i;
        j++;
        if(j==n)break;
      }
      x = (a*x+b)%c;
    }
    if(j==n)cout << ret << endl;
    else cout << -1 << endl;
    cin >> n >> a >> b >> c >> x;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

int n;
bool flag;
vector<int> ans;

void solve() {
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    while(!a.empty()) {
        flag = false;
        for(int i = a.size() - 1; i >= 0; i--) {
            if(a[i] == i) {
                a.erase(a.begin() + i);
                ans.pb(i + 1);
                flag = true;
                break;
            }
        }
        if(!flag) {
            ans.clear();
            ans.pb(-1);
            break;
        }
    }
    reverse(ans.begin(), ans.end());
    for(int i : ans) cout << i << "\n";
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    solve();

}

Measured memory_bytes: 3660
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7
a,b,k=MI()
count=0
for i in range(1,101):
    l=100-i+1
    if a%l==0 and b%l==0:
        count+=1
        if count==k:
            print(l)

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
main() {
    int A[3];  
    for(int i=0;i<3;i++) cin >> A[i];
    sort(A,A+3);
    int B=2*A[2]-A[1]-A[0];
    cout << (B%2==0 ? B/2 : B/2+2);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
E = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    E.append([a, b])

E.sort(key=lambda x: x[1])

r = 0
ans = 0
for a, b in E:
    if a >= r:
        ans += 1
        r = b

print(ans)


Measured memory_bytes: 21336
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ll> sum(n + 1);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i] + a[i];
  }
  vector<ll> t(n + 1);
  for (int i = 0; i <= n; ++i) {
    t[i] = (sum[i] - i) % k;
  }
  ll ans = 0;
  map<ll, ll> mp;
  for (int i = 0; i <= n; ++i) {
    if (0 <= i - k) {
      mp[t[i - k]]--;
    }
    ans += mp[t[i]];
    mp[t[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19564
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	cin >> n;
	while(n --){
		string s,t;
		cin >> s >> t;
		RREP(i, s.size()){
			if(s[i] == 'P') FOR(c, t) if(isdigit(*c) && !isdigit(--*c)) *c = '9';
			if(s[i] == 'M') FOR(c, t) if(isdigit(*c) && !isdigit(++*c)) *c = '0';
			if(s[i] == 'A') reverse(ALL(t));
			if(s[i] == 'J') t = t[t.size()-1] + t.substr(0, t.size()-1);
			if(s[i] == 'C') t = t.substr(1, t.size()-1) + t[0];
			if(s[i] == 'E') REP(i, t.size()/2) swap(t[i], t[t.size()-t.size()/2+i]);
			
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

typedef pair<int,int> P;

int main(){
	int N;
	while(cin >> N, N){
		vector<P> v;
		int ans=0, sum=0, mx=0;
		bool dp[1005][1005] = {0};
		dp[0][0] = true;
		rep(i,N){
			int r, w;
			cin >> r >> w;
			v.emplace_back(r, w);
			sum += r;
			mx = max(mx, r);
			ans += r + w;
		}
		sort( v.begin(), v.end() );
		v.pop_back();
		if( 2*mx > sum ){
			rep(t, v.size()) rep(k,2){
				int w = v[t].first + ( k ? 0 : v[t].second );
				for(int j=1000; j>=0; j--){
					if( dp[t][j] && j+w <= 1000 ){
						dp[t+1][j+w] = true;
					}
					dp[t+1][j] |= dp[t][j];
				}
			}
			//rep(i,10){
			//	cout << i << " " << dp[v.size()][i] << endl;
			//}
			//int df = 2*mx - sum;
			int df = mx;
			//cout << "hit" << df << endl;
			rep(i,df+1){
				//cout << df-i << endl;
				if( dp[ v.size() ][ df-i ] ){
					ans += i;
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define INF 1e9
using namespace std;

int main() {

    string S; cin >> S;

    for (int i = 0; i < S.size()-1; ++i) {
        if (S[i] == S[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n, int mod) {
    if (n == 0) { return 1 % mod; }
    int x = rui(a, n / 2, mod);
    x *= x; x %= mod;
    if (n % 2 == 1) { x *= a; x %= mod; }
    return x;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vel uni(vel x) {
    if (x.size() == 0) { return x; }
    sor(x);
    int n = x.size();
    vel ans(1, x[0]);
    for (int j = 1; j < n; j++) {
        if (x[j - 1] != x[j]) { ans.push_back(x[j]); }
    }
    x = ans;
    return x;
}
void pr(vel& v) {
    int n = v.size();
    if (n != 0) {
        cout << v[0];
        rep(i, n - 1) {
            cout << " " << v[i + 1];
        }
        cout << endl;
    }
}
signed main(){
    int n, a, b; cin >> n >> a >> b;
    n %= 12;
    rep(i, n) {
        if (i % 2 == 0) {
            a = a - b;
        }
        else {
            b = a + b;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}



Measured memory_bytes: 3732
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let h: Vec<usize> = s.by_ref().take(n).map(|a| a.parse().unwrap()).collect();
	let a: Vec<i64> = s.take(n).map(|a| a.parse().unwrap()).collect();
	let mut bit = BIT::new(n, 0, |a, b| std::cmp::max(a, b));
	for (h, a) in h.into_iter().zip(a.into_iter()) {
		let m = bit.fold(h - 1);
		bit.apply(h - 1, m + a);
	}
	println!("{}", bit.fold(n));
}

pub struct BIT<T, F> {
	data: Vec<T>,
	e: T,
	op: F,
}

impl<T, F> BIT<T, F>
where
	T: Clone,
	F: Fn(T, T) -> T,
{
	pub fn new(n: usize, e: T, op: F) -> Self {
		Self {
			data: vec![e.clone(); n],
			e,
			op,
		}
	}

	pub fn fold(&self, i: usize) -> T {
		let mut r = self.e.clone();
		let mut i = i;
		while i > 0 {
			r = (self.op)(self.data[i - 1].clone(), r);
			i &= i - 1;
		}
		r
	}

	pub fn apply(&mut self, i: usize, value: T) {
		let mut i = i;
		while i < self.data.len() {
			self.data[i] = (self.op)(self.data[i].clone(), value.clone());
			i |= i + 1;
		}
	}
}


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

vector<int> to[100005];
const int INF = 1001001001;

int main()
{
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep (i, n) {
    if (i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s;
	cin >> s;
	ll ans = 0;
	REP(i, (int)s.size()) ans += s[i] - '0';
	REP(i, (int)s.size()){
		ll tmp = 0;
		REP(j, (int)s.size()){
			if (j < i){
				tmp += s[j] - '0';
			}
			else if (j == i){
				tmp += s[j] - '0';
				tmp--;
			}
			else tmp += 9;
		}
		ans = max(ans, tmp);
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int cnt[4];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  repeat(i,3){
    int a,b;cin>>a>>b;a--;b--;
    cnt[a]++;cnt[b]++;
  }
  int c=0;
  repeat(i,4){
    if(cnt[i]&1)c++;
  }
  cout << (c==2? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    string s;
    int W[114514];
    int N,K;
    cin >> s >> K;
    N=s.size();
    REP(i,N){
        W[i]=(int)(s[i]-'a');
    }
    REP(i,N){
        if(W[i]==0)continue;
        if(K>=26-W[i]){
            K-=26-W[i];W[i]=0;
        }
    }
    W[N-1]=(W[N-1]+K)%26;
    REP(i,N){
        cout << (char)('a'+W[i]);
    }
    cout << endl;
    return 0;
}   

Measured memory_bytes: 1408
N, Q = map(int,input().split())
S = input()
cnt = [0]*N
for i in range(1,N):
    cnt[i] = cnt[i-1] + (1 if S[i-1:i+1] == 'AC' else 0)
for i in range(Q):
    l, r = map(int,input().split())
    print(cnt[r-1] - cnt[l-1])

Measured memory_bytes: 7748
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    for(int i = a;i<=a*b;i+=a){
        if(i%b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[101];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=n-1;i>=0;i--){
    if(i==0){
      cout<<a[i];
    }
    else 
      cout<<a[i]<<" ";
  }
  cout<<endl;

  return 0;
}



Measured memory_bytes: 3080