akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from heapq import heappush, heappop

N, M = list(map(int, input().split()))
jobs = defaultdict(list)
heap = []
ans = 0
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a <= M:
        jobs[a].append(b)

for m in range(1, M+1):
    for b in jobs[m]:
        heappush(heap, -b)
    if heap:
        maxb = -heappop(heap)
        ans += maxb
print(ans)



Measured memory_bytes: 32176
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
    int w, a, b;
    cin>>w>>a>>b;
    if(a > b+w || a+w < b){
        cout<<min(abs(b+w-a), abs(a+w-b))<<endl;
    }
    else cout<<0<<endl;

}

int32_t main(){
   Fast;

   solve();
    return Okay;
}



Measured memory_bytes: 3648
#include <stdio.h>

int func(int * a, int * b1, int * b2, int c, int c1, int c2) {
	int ret = 0;
	if (c<10) {
		if ( (ret==0)&&( *(a+c) > *(b1+c1) ) ) {
			*(b1+c1+1) = *(a+c);
			ret = func( a, b1, b2, c+1, c1+1, c2);
		}
		if ( (ret==0)&&( *(a+c) > *(b2+c2) ) ) {
			*(b2+c2+1) = *(a + c);
			ret = func(a, b1, b2, c+1, c1, c2+1);
		}
	}else {
		ret = 1;
	}
	return ret;
}

int main() {
	int n, i, a[10], b1[10]={0}, b2[10]={0};
	int ret=0;
	scanf("%d",&n);
	while(n>0) {
		for(i=0;i<10;i++) scanf("%d",&a[i]);
		ret = func(&a[0], &b1[0], &b2[0], 0, 0, 0);
		
		if (ret==1) printf("YES\n");
		else printf("NO\n");
		n--;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N;
    cin>>N;
    int a[3*N];
    REP(i,3*N)cin>>a[i];

    priority_queue<int, vector<int>, greater<int> > go;
    priority_queue<int> back;

    LL Max[N+1];
    LL Min[N+1];
    Max[0]=0;Min[0]=0;
    REP(i,N){
        Max[0]+=0L+a[i];
        go.push(a[i]);
        Min[0]+=0L+a[3*N-1-i];
        back.push(a[3*N-1-i]);
    }

    REP(i,N){
        Max[i+1]=Max[i]+a[N+i];
        go.push(a[N+i]);
        Max[i+1]-=0L+go.top();
        go.pop();

        Min[i+1]=Min[i]+a[2*N-1-i];
        back.push(a[2*N-1-i]);
        Min[i+1]-=0L+back.top();
        back.pop();

    }

    LL ans=Max[0]-Min[N];
    REP(i,N+1){
        ans=max(ans,Max[i]-Min[N-i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int x3,y3,x4,y4;
    int a=x2-x1;
    int b=y2-y1;
    x3=x2-b;
    y3=y2+a;
    x4=x3-a;
    y4=y3-b;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}


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

int main(){
  int x,n; cin >>x >>n;
  int num[101];
  rep(i,n){
    int p; cin >>p;
    num[p] = 1;
  }
  pair<int, int> ans(99999, -1);
    rep(i,102){
      if(num[i]==1) continue;
      int dif = abs(x-i);
      ans = min(ans, pair<int, int>(dif, i));
    }
  cout << ans.second << endl;
  return 0; 
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){
	
	char s;
	
	while(1){
		scanf("%c", &s);
		if(islower(s) != 0){
			s = toupper(s);
		}else if(isupper(s) != 0){
			s = tolower(s);
		}
		printf("%c", s);
		if(s == '\n')break;
	}
	
	return 0;
}

Measured memory_bytes: 3172
import java.util.*;
import java.text.*;

public class Main {
    static long MOD = (long)1e9+7;
    static String s;
    static int n, D;
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        s = in.next();
        D = in.nextInt(); n = s.length();
        long[][] ways = new long[D][1+n];
        ways[0][0] = 1;
        for(int c = 0; c < n; c++)
            for(int di = 0; di < D; di++)
                for(int nxt = 0; nxt < 10; nxt++)
                    ways[(di+nxt)%D][c+1] = (ways[(di+nxt)%D][c+1]+ ways[di][c])%MOD;
                    
        long ans = MOD-1;
        int rem = 0;
        for(int idx = 0, digits = n-1; idx < n; idx++, digits--){
            int dig = s.charAt(idx)-'0';
            for(int di = 0; di < dig; di++){
                int remainder = (D-(rem+di)%D)%D;
                ans += ways[remainder][digits];
                if(ans >= MOD)ans -= MOD;
            }
            rem = (rem+dig)%D;
        }
        if(rem == 0)ans = (ans+1)%MOD;
        System.out.println(ans);
    }
}

Measured memory_bytes: 30292
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = 0;
	
		for (int i = 1;i <= a;i++) {
			b += i;
		}
		
		System.out.println(b);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <vector>
#include <functional>
using namespace std;

using ll = long long;
using P = pair<int, int>;

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

    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;

    int kokunai = 0, kaigai = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'a' && kokunai + kaigai < a + b) {
            cout << "Yes" << endl;
            kokunai++;
        } else if (s[i] == 'b' && kokunai + kaigai < a + b && kaigai < b) {
            cout << "Yes" << endl;
            kaigai++;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


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

int main(){
	int A,B,K;
  	cin >> A >> B >> K;
  	if(B-A+1>2*K){
	    
      	for(int i = A ; i < A+K ; i++ )cout << i<< endl;
      
    	for(int i = B-K+1 ; i <= B ; i++ )cout << i << endl;
    
    }else{
    
    	for(int i = A ; i <= B ; i++ )cout << i << endl;
    
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
double S(ll n){
	double cnt = 0;
	while(n){
		cnt += n%10;
		n /= 10;
	}
	return cnt;
}
int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	int k; cin >> k;
	ll a = 0, b = 1;
	while(k--){
		a += b;
		cout << a << endl;
		if (b < (a+b)/S(a+b))b *= 10;
	}
}

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

int main() {
  int N;
  cin >> N;
  
  if ( N < 10 ) {
    cout << N << endl;
  }
  if ( 100 > N) {
    if ( N >= 10 ) 
    cout << 9 << endl;
  }
  
  if ( 1000 > N ) {
    if ( N >= 100 ) 
    cout << N - 99 + 9 << endl;
  }
  
  if ( N < 10000 ) {
    if ( N >= 1000 )
    cout << 900 + 9 << endl;
  }
  if ( N >= 10000 ) {
    if ( N < 100000 )
      cout << N - 9999 + 909 << endl;
  }
  
  if ( N >= 100000) {
    if ( N < 1000000 ) 
      cout << 90909 << endl;
  }
}

Measured memory_bytes: 256
import sys
n=int(input())
ai=[]
for i in range(n):
    ai.append(int(input()))
    
already=[0 for j in range(n)]
i=0
dist=0
while(1):
    if(dist>n):
        print(-1)
        sys.exit()
    i=ai[i]-1
    if(i==1):
        break
    dist+=1
print(dist+1)

Measured memory_bytes: 7864
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

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

const int INF = 1<<30;

int main(){
  ll h;cin>>h;
  int bit=0;
  while(h>0){bit++;h/=2;}
  cout<<ll(pow(2, bit))-1<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <complex>
#include <tuple>

using namespace std;


const int P = 2e5 + 3;
int ep[P];
int inv[P];
using ll = long long;
using ld = double;
using base = complex <ld>;

const ld pi = acos(-1);

string A, B, C;
vector <ll> X, Y, Z;
ll n, m, ans;

void fft(vector <base> &A, bool f)
{
	int k = A.size(), i, j, l, t;
	base w, x, y; ld th;

	for(i = 1, j = 0; i < k; i ++){
		for(l = k >> 1; j >= l; l >>= 1) j -= l;
		j += l; if(i < j) swap(A[i], A[j]);
	}

	for(i = 1; i < k; i <<= 1, t --){
		th = (f? -pi : pi) / i;
		w = base(cos(th), sin(th));
		for(j = 0; j < k; j += i + i){
			for(l = 0; l < i; l ++){
				if(l & 2047) x *= w;
				else x = l? base(cos(th * l), sin(th * l)) : 1;
				y = x * A[l | i | j];
				A[l | i | j] = A[l | j] - y;
				A[l | j] += y;
			}
		}
	}

	if(f) for(i = 0; i < k; i ++){
		A[i] /= k;
	}
}

vector <ll> mult(vector <ll> &X, vector <ll> &Y)
{
	ll s, i, j;

	for(s = 1; s < X.size() + Y.size(); s <<= 1);

	vector <base> P(s), Q(s);
	vector <ll> Z(X.size() + Y.size() - 1);

	for(i = 0; i < X.size(); i ++){
		P[i] = base(X[i] >> 12, X[i] & 4095);
	}
	for(i = 0; i < Y.size(); i ++){
		Q[i] = base(Y[i] >> 12, Y[i] & 4095);
	}
	fft(P, 0); fft(Q, 0);

	for(i = 0; i + i <= s; i ++){
		j = i? s - i : 0;
		base v1 = P[i] + conj(P[j]), v2 = conj(P[i]) - P[j];
		tie(P[i], Q[i], P[j], Q[j]) = make_tuple(
			v1 * Q[i], conj(v2) * conj(Q[j]),
			conj(v1) * Q[j], -v2 * conj(Q[i]));
	}
	fft(P, 1); fft(Q, 1);

	for(i = 0; i < Z.size(); i ++){
		Z[i] = (((ll)round(P[i].real()) << 23) + ((ll)round(Q[i].real()) >> 1)
			+ ((ll)round(P[i].imag() + Q[i].imag()) << 11));
	}

	return Z;
}

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

    int n; cin >> n;
    int arr[n];
    int t = 1; for(int i = 0; i < P - 1; ++i)
    {
        ep[i] = t;
        inv[t] = i;
        t *= 2; t %= P;
    }

    vector<long long> A(P - 1), B, ret;
    for(int i = 0; i < n; ++i)
    {
        int x; cin >> x;
        arr[i] = x;
        if(x) ++A[inv[x]];
    }
//    for(int i = 0; i < A.size(); ++i) if(A[i]) cout << i << ' ' << A[i] << endl;
    B = A;
    ret = mult(A, B);
    ret.push_back(0);

//    for(int i = 0; i < ret.size(); ++i) if(ret[i]) cout << i << ' ' << ret[i] << endl;

    long long ans = 0;
    for(int i = 0; i < P - 1; ++i)
    {
        ans += 1ll * ep[i] * (ret[i] + ret[i + P - 1]);
    }
    for(int i = 0; i < n; ++i)
    {
        ans -= 1ll * arr[i] * arr[i] % P;
    }
    cout << ans / 2;
    return 0;
}


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

int main() {
	string N;
	cin >> N;
	int a=0;
	string s;
	rep(i, N.size()) {
		s = N.at(i);
		a += stoi(s);
	}
	if(a%9 == 0) std::cout << "Yes" << '\n';
	else std::cout << "No" << '\n';
}


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

int i,j,cnt,degit,N;

int main(){
    cin >> N;

    for(i=0,cnt=0;i<=N;++i){
        for(j=i,degit=0;j;){
            j/=10;
            ++degit;
        }
        if(degit%2){
            ++cnt;
        }
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
    int h, a;
    cin >> h >> a;

    dunk((h+a-1)/a);
}
    

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;

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

ll lcm(ll a, ll b)
{
  ll g = gcd(a, b);
  return a / g * b;
}

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

  cout << sum - n << endl;

  // ll lcmVal = v[0];

  // for (int i = 1; i < n; i++)
  // {
  //   lcmVal = lcm(lcmVal, v[i]);
  // }
  // lcmVal--;
  // cout << lcmVal << endl;
  //
  // ll res = 0;
  // for (int i = 0; i < n; i++)
  // {
  //   res += lcmVal % v[i];
  // }

}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<long long> red(a), green(b), col(c);
  for(int i = 0; i < a; i++)
  {
    cin >> red[i];
  }
  for(int i = 0; i < b; i++)
  {
    cin >> green[i];
  }
  for(int i = 0; i < c; i++)
  {
    cin >> col[i];
  }
  sort(red.begin(), red.end(), greater<long long>());
  sort(green.begin(), green.end(), greater<long long>());
  sort(col.begin(), col.end(), greater<long long>());
  vector<long long> final;
  for(int i = 0; i < min(x, a); i++)
  {
    final.push_back(red[i]);
  }
  for(int i = 0; i < min(y, b); i++)
  {
    final.push_back(green[i]);
  }
  for(int i = 0; i < c; i++)
  {
    final.push_back(col[i]);
  }
  sort(final.begin(), final.end(), greater<int>());
  long long ans = 0;
  for(int i = 0; i < x + y; i++)
  {
    ans += final[i];
  }
  cout << ans << endl;
  return 0;
}


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

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var l = 1;
            var r = N;
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var L = input[0];
                var R = input[1];

                l = Math.Max(l, L);
                r = Math.Min(r, R);
            }
            Console.WriteLine(Math.Max(0, r - l + 1));
        }
    }
}

Measured memory_bytes: 17460
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
ab = [[None] * 2] * N
work = np.array(ab)
# print(work)
for i in range(N):
    input = stdin.readline().split()
    work[i][0], work[i][1] = int(input[0]), int(input[1])
# print(work)
# print(np.argsort(work[:,1]))
work_sort_b = work[np.argsort(work[:,1])]
# print(work_sort_b)

time = 0
for i in range(N):
    time += work_sort_b[i][0]
    if time > work_sort_b[i][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 32852
-- ABC124 D problem
import Control.Monad
import Data.List
import Data.Ord
import qualified Data.Text as T
import qualified Data.Vector as V

-- conversion from String to Int
toInt :: String -> Int
toInt x = read x :: Int
 
-- obtain [Int] from I/O
getInts :: IO [Int]
getInts = do
  x <- getLine
  let y = (map $ toInt) $ words x
  return y

-- cumulative sum with list
cumsum :: [Int] -> Int -> [Int]
cumsum [] n = []
cumsum (x:xs) n = [x+n] ++ (cumsum xs (x+n))

-- cumulative sum with V.vector
cumsumV :: V.Vector Int -> V.Vector Int
cumsumV vec =
  V.generate (1 + (V.length vec)) p_sum where p_sum = \n -> V.sum $ V.slice 0 n vec

abc124d :: V.Vector Char -> V.Vector Int -> Int -> Int -> V.Vector Int -> V.Vector Int
abc124d s1 leng n k btoe=
  let shift = \i -> if (s1 V.! (leng V.! i)) == '0' then 2*k else 2*k+1 :: Int
      gain = \i ->
        if i+(shift i) >= (V.length leng) then n - (leng V.! i) else (leng V.! (i+(shift i))) - (leng V.! i)
  in V.map gain btoe

-- main function
main :: IO ()
main = do
  [n, k] <- getInts
  s <- getLine
  let s1 = V.fromList s
  let v = map length (group s)
  let leng = V.fromList (0 : (cumsum v 0))
  let btoe = V.fromList [0..(V.length leng - 2)]
  print $ V.maximum $ abc124d s1 leng n k btoe

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

typedef long long ll;
typedef pair<ll,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for(int i=0; i<x; i++) cin >> a[i];
  for(int i=0; i<y; i++) cin >> b[i];
  for(int i=0; i<z; i++) cin >> c[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  vector<ll> ans;
  for(int i=0; i<x; i++){
    for(int j=0; j<y; j++){
      for(int m=0; m<z; m++){
        if((i+1)*(j+1)*(m+1)<=k) ans.push_back(a[i]+b[j]+c[m]);
        else break;
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<ll>());
  for(int l=0; l<k; l++){
    cout << ans[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 4312
import java.util.Scanner;

public class Main {
    public static void main (String[] args){

        Scanner scan = new Scanner(System.in);
        String mark = "SHCD";
        boolean[][] cards = new boolean[4][13];

        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            char c = scan.next().charAt(0);
            int num = scan.nextInt();

            cards[mark.indexOf(c)][num-1] = true;
 
        }

        for(int t = 0; t < 4; t++){
            for(int f = 0; f < 13; f++){
                if(cards[t][f] == false){
                    System.out.println(mark.charAt(t) + " " + (f+1));

                }
            }
        }

    }
}



Measured memory_bytes: 26196
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**18
def solve(N,A):
    P = set()

    for i in range(N):
        n = A[i]
        if n % 2 == 0 and 2 in P: break
        while n % 2 == 0:
            P.add(2)
            n //= 2
            
        f = 3
        while f * f <= n:
            if n % f == 0:
                if f in P: break
                P.add(f)
                while n%f == 0:
                    n //= f
            else:
                f += 2
        else:
            if n != 1:
                if n in P: break
                P.add(n)
            
            continue
        break
    else:
        return 0
        
    return 1 



def main():
    N=ii()
    A=np.array(list(mi()))

    flag = solve(N,A)
    if flag == 0:
        print("pairwise coprime")
    else:
        gcd = np.gcd.reduce(A)
        if gcd == 1:
            print("setwise coprime")
        else:
            print("not coprime")
       

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')

    # basic types: https://numba.pydata.org/numba-doc/0.13/types.html
    cc.export('solve', '(i8,i8[:])')(solve)
    cc.compile()

if __name__ == '__main__':
    # cc_export()
    try:
        from my_module import solve
    except:
        cc_export()
        exit()

    main()


Measured memory_bytes: 145436
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=3e3+5;
string s,f[N];
int n,a[N],b[N],id[N<<1],ne[N<<1];
signed main(){
	n=read();cin>>s;s=' '+s;
	for(int i=1,ta=0,tb=0;i<=n<<1;i++){
		if(s[i]=='a')ta++,id[i]=ta,a[ta]=i;
		else tb++,id[i]=tb,b[tb]=i;
	}a[n+1]=b[n+1]=(n<<1|1),id[n<<1|1]=n+1;
	for(int i=0,j=0;i<=n+1;i++)while(j<min(a[i],b[i]))ne[++j]=i;
	for(int i=n;i>=1;i--){
		if(a[i]>b[i]){
			int j=b[i];
			for(;b[id[j]]<a[id[j]]&&(id[j]<=i||b[id[j]]<a[id[j]-1]);j++)if(id[j]>=i)f[i]+=s[j];
			f[i]+=f[id[j]];
		}else f[i]="ab"+f[ne[b[i]+1]];
		f[i]=max(f[i],f[i+1]);
	}return cout<<f[1],signed();
}

Measured memory_bytes: 16360
#include<iostream>

using namespace std;

int main(){
    char c[3][3];

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

    for(int i=0;i<3;++i){
        cout << c[i][i];
    }

}


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

#define reset(X) memset(X, 0, sizeof(X))
#define int long long
typedef long long ll;
#define pb push_back
#define se second
#define fi first
//#define endl '\n'
#define all(X) X.begin(),X.end()

const int INF=1e9;
const int mod=1e9+7;
const int mod2=998244353;



#define readn(a) int a;cin>>a;
#define readv(a,n) vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];
#define reada(a,n,m) int a[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++) cin>>a[i][j];



typedef vector<int> vi;
typedef pair<int, int> pii;
int pow(int a, int b, int mod)
{
    int prod=1;
    int mult=a;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2, mod);
}
vector<pair<int, int> > factorisize(int a)
{
    vector<pair<int , int> > e;
    for(int i=2;i*i<=a;i++)
    {
        int cnt=0;
        if(a%i==0)
        {
            while(a%i==0)
            {
                cnt++;
                a/=i;
            }
            e.pb({i, cnt});
        }
    }
    if(a!=1)
    {
        e.pb({a, 1});
    }
    return e;
}
int calc_lcm(vector<int> a)
{
    int n=a.size();
    map<int, int> prime_powers;
    for(auto i:a)
    {
        auto ee=factorisize(i);
        for(auto i:ee)
        {
            prime_powers[i.fi]=max(prime_powers[i.fi], i.se);
        }

    }
    int ans=1;
    for(auto i:prime_powers)
    {
        ans=(ans*pow(i.fi, i.se,mod))%mod;
    }
    return ans;
}
signed main()
{

  
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE 
    if (fopen("INPUT.txt", "r")) {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
//---------------------------------------------------------------------------------------------------
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i:a)
        cin>>i;
    vector<pair<int, int > > e;
    vector<int> lc;
    for(int i=0;i<n;i++)
    {
        int p=a[i]/__gcd(a[0], a[i]);
        int q=a[0]/__gcd(a[i], a[0]);
        e.pb({q,p});
        lc.pb(p);
    }
    int lcm=calc_lcm(lc);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int p=e[i].fi;
        int q=e[i].se;
        ans+=(((lcm*(p))%mod)*mod_inv(q, mod))%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1276
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    sys.exit(0)

l = 9 * k
if k % 7 == 0:
    l //= 7

ans = 1
num = 10
while True:
    if num % l == 1:
        break
    num = (num % l) * 10
    ans += 1
print(ans)


Measured memory_bytes: 62856
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		char c[];

		c = sc.nextLine().toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 'a') {
				if (i + 1 < c.length && c[i + 1] == 'p') {
					if (i + 2 < c.length && c[i + 2] == 'p') {
						if (i + 3 < c.length && c[i + 3] == 'l') {
							if (i + 4 < c.length && c[i + 4] == 'e') {
								c[i] = 'p';
								c[i + 1] = 'e';
								c[i + 2] = 'a';
								c[i + 3] = 'c';
								c[i + 4] = 'h';
							}
						}
					}
				}
			} else if (c[i] == 'p') {
				if (i + 1 < c.length && c[i + 1] == 'e') {
					if (i + 2 < c.length && c[i + 2] == 'a') {
						if (i + 3 < c.length && c[i + 3] == 'c') {
							if (i + 4 < c.length && c[i + 4] == 'h') {
								c[i] = 'a';
								c[i + 1] = 'p';
								c[i + 2] = 'p';
								c[i + 3] = 'l';
								c[i + 4] = 'e';
							}
						}
					}
				}
			}
		}
		System.out.println((char[])c);
	}
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int c = 0;
  int d = min(A, B);
  while (c < K) {
    if (A % d == 0 && B % d == 0) {
      c++;
    }
    d--;
  }
  cout << d + 1 << endl;
  return 0;
}



Measured memory_bytes: 256
# AOJ 0083 Era Name Transformation
# Python3 2018.6.11 bal4u

start_date = [18680908, 19120730, 19261225, 19890108, 99999999]
era = ["pre-meiji", "meiji", "taisho", "showa", "heisei"]

import sys
for line in sys.stdin:
    y, m, d = list(map(int, line.split()))
    date = y*10000 + m*100 + d
    for i in range(5):
        if date < start_date[i]:
            if i is 0:
                print(era[0])
            else:
                print(era[i], date//10000 - start_date[i-1]//10000 + 1, m, d)
            break



Measured memory_bytes: 5600
k, n = map(int,input().split())
a = list(map(int,input().split()))
new_a = sorted(a)
num = len(new_a) - 1
s_a = []
b = (k - new_a[num]) + new_a[0]
s_a.append(b)
cun = 0
for i in new_a[1::]:
    s = i - new_a[cun]
    s_a.append(s)
    cun += 1
max_num = max(s_a)
print(sum(s_a) - max_num)



Measured memory_bytes: 32256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int n, mi = 10000000, ma = -10000000;
    long sum = 0;
    cin >> n;
    int i, b;
    for (i = 0; i < n; i++)
    {
        cin >> b;
        mi = min(mi, b);
        ma = max(ma, b);
        sum += b;
    }
    cout << mi << " " << ma << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3120
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    long N=gl();
	    long M=gl();
        List<Long> l=new ArrayList<Long>();

	    for(long i=1; i<=Math.sqrt(M);i++) {
	    	if(M%i==0) {
	    		l.add(i);
	    		l.add(M/i);
	    	}
	    }
	    Collections.sort(l);
	    long ans=1;
	    for(int i=0; i<l.size();i++) {
	    	long v=l.get(i);
	    	if(v>=N) {
	    		ans=M/v;
	    		break;
	    	}
	    }

	    System.out.print(ans);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35780
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[1<<18];
int r[1<<18];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<(1<<a);i++)scanf("%d",p+i);
	multiset<int>S;
	for(int i=0;i<(1<<a);i++)S.insert(p[i]);
	auto tmp=S.rbegin();
	r[0]=(*tmp);
	auto tmp3=S.lower_bound(r[0]);
	S.erase(tmp3);
	int sz=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<sz;j++){
			auto tmp2=S.lower_bound(r[j]);
			if(tmp2==S.begin()){
				printf("No\n");return 0;
			}
			tmp2--;
			r[sz+j]=(*tmp2);
			S.erase(tmp2);
		}
		sz*=2;
	}
	printf("Yes\n");
}



Measured memory_bytes: 14592
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, A[100000], Cur = 2, ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	ANS = A[0] - 1;
	for (int i = 1; i < N; i++) {
		if (Cur == A[i]) Cur++;
		else {
			ANS += (A[i] - 1) / Cur;
		}
	}
	cout << ANS << endl;
}

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

int main()
{
  int n,m,C[20],T[50001];
  cin>>n>>m;
  for(int i=0;i<m;i++)cin>>C[i];

  for(int i=0;i<=n;i++)T[i]=100000;
  T[0]=0;

  for(int i=0;i<m;i++){
    for(int j=C[i];j<=n;j++){
      if(T[j]>T[j-C[i]]+1)T[j]=(T[j-C[i]]+1);
    }
  }
  cout<<T[n]<<endl;
  return 0;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
#define loop(_i,_v,_n)  for(int _i=_v;_i<_n;++_i)
using namespace std;
typedef vector<vector<int>> vv;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> vm(M);
  for (int i = 0; i < M; ++i) {
    int m; cin >> m;
    vm.push_back(m);
  }
  
  int l_cost = 0, r_cost = 0;
  for (int i = X; i > 0; --i) {
    auto it = std::find(vm.begin(), vm.end(), i);
    if (it != vm.end()) l_cost++;
  }
  for (int i = X; i < N; ++i) {
    auto it = std::find(vm.begin(), vm.end(), i);
    if (it != vm.end()) r_cost++;
  }
  
  // cout << "lc = " << to_string(l_cost) << " rc = " << r_cost << endl;
  cout << min(l_cost, r_cost) << endl;
  
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,i;
  int h[100000];
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &h[i]);
  }
  int possible=1;
  int fixroom=1;
  for(i=0;i<n-1;i++){
    if(h[i]<h[i+1]){
      fixroom=1;
    }
    if(h[i]>h[i+1]+1){
      possible=0;
    }
    if(h[i]==h[i+1]+1){
      if(fixroom==0){
        possible=0;
      }else{
        fixroom=0;
      }
    }
  }
  if(possible){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr
	

N = INT()

n = [0]*(101)  #100以内の数でN!の素因数としての数

for i in range(1, N+1):
	arr = factorization(i)
	for s, t in arr:
		n[s] += t

n[1] = 0  # 1の約数は無視

num =[0]*(101)
for i in range(101):
	if 0 < n[i]:
		num[n[i]] += 1

num = list(accumulate(num[::-1]))[::-1]

print(num[74] + num[24]*(num[2]-1) + num[14]*(num[4]-1) + num[4]*(num[4]-1)//2*(num[2]-2))



Measured memory_bytes: 10668
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);
    if (a%2==0 && b%2==0) {
        printf("%d\n", (a+b)/2);
    } else {
        printf("%d\n", (a+b+1)/2);
    }
    return 0;
}


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

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

using ll = long long;
#define INF 1e9

int main(){
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (a, b) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a: usize = ws.next().unwrap().parse().unwrap();
        let b: usize = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    if a > b * 2 {
        println!("{}", a - b * 2)
    } else {
        println!("0")
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n,m;
	cin>>n>>m;
	vs a(n),b(m);
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	rep(i,n-m+1)rep(j,n-m+1){
	    bool ok=true;
	    rep(k,m)rep(l,m){
	        ok&=b[k][l]==a[i+k][j+l];
	    }
	    if(ok){
	        cout<<"Yes"<<endl;
	        return 0;
	    }
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> bits(61, 0);

    for (int i = 0; i < 60; i++)
    {
        ll s0 = 0LL, s1 = 0LL;
        for (int j = 0; j < n; j++)
        {
            (a[j] & (1LL << i)) ? s1++ : s0++;
        }
        bits[i] = s1 * s0 % MOD;
    }

    ll sum = 0LL;
    for (int i = 0; i < 60; i++)
    {   
        ll bi = 1LL << i;
        bi %= MOD;
        sum += bits[i] * bi;
        sum %= MOD;
    }
    cout << sum << endl;
}

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

int main() {
  int N; cin >> N;
  vector<vector<pair<int, int>>> W(N);
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    for (int j = 0; j < A; j++) {
      int x, y; cin >> x >> y; x--;
      W.at(i).push_back(make_pair(x, y));
    }
  }
  int ans = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<15> s(tmp);
    int honest = 0;
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
      if (s.test(i)) { P.at(i) = 1; honest++; }
      else P.at(i) = 0;
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
      for (auto p : W.at(i)) {
        if (P.at(i) == 1 && P.at(p.first) != p.second) ok = false;
      }
    }
    if (ok) ans = max(ans, honest);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
N = len(S)

s = [0] * N
r = 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'L':
        s[i] += r // 2
        s[i-1] += r // 2
        if r % 2:
            s[i-1] += 1
        r = 0
l = 0
for i in range(N-1, -1, -1):
    if S[i] == 'L':
        l += 1
    elif S[i] == 'R':
        s[i] += l // 2
        s[i+1] += l // 2
        if l % 2:
            s[i+1] += 1
        l = 0

print(*s)


Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

const int MOD=2019;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int L,R; cin >> L >> R;
    if(R-L>2019) {
        cout << 0 << endl;
        return 0;
    }
    int  ans=INF;
    rng(i,L,R+1){
        rng(j,i+1,R+1){
            chmin(ans,(i*j)%MOD);
        }
    }
    cout << ans << endl;
}

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

typedef  long long  ll;
const int maxn = 2e5+5;
int N, h[maxn], a[maxn], NN = 1;
long long dp[maxn] ,ans = 0;

long long st[maxn<<2];


void update(int x, ll k){
    for(st[x += NN] = k; x>1; x >>= 1) st[x>>1] = max(st[x], st[x^1]);
}

ll query(int l, int r){
    ll ans = 0;
    for(int s = NN+l-1, t = NN+r+1;s^t^1; s>>=1, t>>=1){
        if(~(s&1)) ans = max(ans, st[s^1]);
        if(t&1) ans = max(ans, st[t^1]);
    }
    return ans;
}


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N;
    for(int i = 0; i< N; i++)cin>>h[i];
    for(int i = 0; i< N; i++)cin>>a[i];
    
    while(NN<=N+1) NN<<=1;
    
    for(int i = 0; i < N; i++){
        dp[i] = query(1,h[i]) + a[i];
        ans = max(ans, dp[i]);
        update(h[i], dp[i]);
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    vector<string> adj(n);
    for (auto &s : adj) {
        cin >> s;
    }
    int ans = -1;
    for (int start = 0; start < n; start++) {
        queue<int> q;
        vector<int> depth(n, -1);
        q.push(start);
        depth[start] = 1;
        bool check = true;
        while (q.size()) {
            int now = q.front(); q.pop();
            for (int next = 0; next < n; next++) {
                if (adj[now][next] == '1') {
                    if (depth[next] == -1) {
                        depth[next] = depth[now] + 1;
                        q.push(next);
                    } 
                    if (depth[next] != depth[now] - 1 && depth[next] != depth[now] + 1) {
                        check = false;
                    } 
                }
            }
        }
        if (check) {
            for (int i : depth) {
                ans = max(i, ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n;
int bckt[2][100005];
void init(){
    scanf("%d",&n);
    int x;
    for(int i=1;i<=n;++i){
        scanf("%d",&x);
        ++bckt[i&1][x];
    }
    int ans,mx1=0,mx2=0,mx11=0,mx22=0,mi1,mi2;
    for(int i=1;i<=100000;++i){
        if(bckt[0][i]>mx1){
            mx11=mx1;
            mx1=bckt[0][i];
            mi1=i;
        }else{
            mx11=std::max(mx11,bckt[0][i]);
        }
        if(bckt[1][i]>mx2){
            mx22=mx2;
            mx2=bckt[1][i];
            mi2=i;
        }else{
            mx22=std::max(mx22,bckt[1][i]);
        }
    }
    if(mi1==mi2){
        ans=n-std::max(mx1+mx22,mx2+mx11);
    }else{
        ans=n-mx1-mx2;
    }
    printf("%d",ans);
} 
int main(){
    init();
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MOD = 1000*1000*1000+7;
const int MAXN = 100*1000+1;
int n;
vi V[MAXN];
LL dp[MAXN][2];
bool visited[MAXN];

void dfs(int x,int p) {
    visited[x]=1;
    for(auto nbh:V[x]) {
        if(!visited[nbh]) {
            dfs(nbh,x);
        }
    }
    if(p!=-1&&V[x].size()==1) {
        dp[x][0] = dp[x][1] = 1;
    } else {
        dp[x][0] = dp[x][1] = 1;
        for(auto nbh:V[x]) {
            if(nbh!=p) {
                dp[x][1]=(dp[x][1]*dp[nbh][0])%MOD;
                dp[x][0]=(dp[x][0]*(dp[nbh][1]+dp[nbh][0]))%MOD;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int a,b,i=1; i<n;i++) {
        cin>>a>>b;
        V[a].PB(b);
        V[b].PB(a);
    }
    if(n==1) {
        cout<<"2";
        return 0;
    }
    dfs(1,-1);
    cout<<(dp[1][0]+dp[1][1])%MOD;
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, q;
vector<int> a, b, c, d;
ll inf = 1000000007;
ll ans = -inf;
ll now = 0;
void dfs(vector<int> A) {
	if (A.size() == n+1) {
		for (int i = 0; i < q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				now += d[i];
			}
		}
		ans = max(ans, now);
		now = 0;
		return;
	}

	A.push_back(A.back());
	while (A.back() <= m) {
		dfs(A);
		A.back()++;
	}
}
int main() {
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int suma[n+1], sumb[n+1];
	suma[0]=0; sumb[0]=0;
	for (int i=0; i<n; i++) suma[i+1]=suma[i]+a[i];
	for (int i=0; i<n; i++) sumb[i+1]=sumb[i]+b[n-i-1];
	int mx=0;
	for (int i=1; i<=n; i++) {
		int t=suma[i-1]+a[i-1]+b[i-1]+sumb[n-i];
		//printf("%d\n", t);
		mx=max(mx,t);
	}
	printf("%d\n", mx);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	if (*(int*)a < *(int*)b)return -1;
	if (*(int*)a > * (int*)b)return 1;
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int l[2003];
	for (i = 0; i < n; i++)
		scanf("%d", &l[i]);
	qsort(l, n, sizeof(int), asc);
	long long int asn = 0;
	int ss, ll;
	long long int min, mid, max;
	long long int p, q;
	long long int ans = 0;
	for (ss = 0; ss < n - 2; ss++)
	{
		for (ll = ss + 2; ll < n; ll++)
		{
			min = ss + 1;
			max = ll;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (l[ss] + l[mid] <= l[ll])
					min = mid;
				else
					max = mid;
			}
			if (l[ss] + l[min] <= l[ll])min++;
			p = min;
			min = ss + 1;
			max = ll;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (l[ss] + l[ll] <= l[mid])
					max = mid;
				else
					min = mid;
			}
			q = min;
			if (q - p >= 0)
				ans += q - p + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
using namespace std;
 int main(){
   int n,m,k;
   cin >> n >> m >> k;
   int a[n],b[m];
   for(int i=0;i<n;i++){
     cin >> a[i];
   }
   for(int i=0;i<m;i++){
     cin >> b[i];
   }
   
   int t=0,la=n,lb=m;
   for(int i=0;i<n;i++){
     if (t+a[i]<=k) {
       t+=a[i];
     }else{
       la=i;
       break;
     }
   }
   for(int i=0;i<m;i++){
     if (t+b[i]<=k) {
       t+=b[i];
     }else{
       lb=i;
       break;
     }
   }
   int ans = la+lb;
   const int la1=la,lb1=lb;
   
   
   for(int j=0;j<la1;j++){
     la--;
     t-=a[la];
     for(int i=lb;i<m;i++){
       if (t+b[i]<=k) {
         t+=b[i];
       }else{
         lb=i;
         break;
       }
       if(i==m-1) lb=m;
     }
     if(la+lb>ans) ans=la+lb;
   }
     
   cout << ans;
   
   return 0;
 }

Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;
set<int> s;
	int n;
	int flag=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(s.find(x)==s.end())
		s.insert(x);
		else
		{
			flag=1;
		}
	}
	if(flag)
	cout<<"NO";
	else
	cout<<"YES";
}




Measured memory_bytes: 12996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e5+5;
ll rep[A], sz[A];
ll find(ll u)
{
	return rep[u] == u ? u : rep[u] = find(rep[u]);
}
void join(ll a, ll b, ll &ret)
{
	a = find(rep[a]), b = find(rep[b]);
	if (a == b)
		return;
	if (sz[a] < sz[b])
		swap(a, b);
	ret = sz[a] * sz[b];
	rep[b] = a, sz[a] += sz[b], sz[b] = 0;
}

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		rep[i] = i, sz[i] = 1;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		v.pb({x, y});
	}
	reverse(v.begin(), v.end());
	ll ans[m];
	ans[0] = n * (n - 1) / 2;
	for (int i = 0; i < m - 1; i++)
	{
		ll x = find(rep[v[i].F]), y = find(rep[v[i].S]);
		ll ret = -1;
		join(x, y, ret);
		ans[i + 1] = ans[i] - (~ret ? ret : 0);
	}
	for (int i = m - 1; i >= 0; i--)
		cout << ans[i] << '\n';
	return 0;
}


Measured memory_bytes: 5360
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
MOD = 10 ** 9 + 7

factorial = [0] * (n+1)
factorial[0] = 1
for i in range(1, n+1):
    factorial[i] = factorial[i-1] * i

prime_factors = []
target = factorial[n]
i = 2
while i ** 2 <= target:
    if target % i != 0:
        i += 1
        continue

    ext = 0
    while target % i == 0:
        ext += 1
        target //= i

    prime_factors.append((i, ext))
    i += 1

if target != 1:
    prime_factors.append((target, 1))

ans = 1
for pf in prime_factors:
    ans = (ans * (pf[1] + 1)) % MOD

print(ans)


Measured memory_bytes: 39280
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define mpr make_pair
#define fr first
#define se second
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{
     Senky_Bansal
     IIIT_ALLAHABAD
  
     ll n,q;
     cin>>n>>q;
     string s;
     cin>>s;
     vector<ll>v;
     map<ll,ll>mp;
     ll j=0;
     for(int i=0;i<s.size()-1;i++)
     {
         if(s[i]=='A' && s[i+1]=='C'){
         v.pb(i+1);
         j++;}
        
     }
     while(q--)
     {
         ll a,b;
         cin>>a>>b;
         int y=lower_bound(v.begin(),v.end(),a)-v.begin();
         int y1=lower_bound(v.begin(),v.end(),b)-v.begin();
         ll r=y1-y;
         cout<<r<<endl;
     }
}




Measured memory_bytes: 1480
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;

#define MAX_N 10000
int a[MAX_N];

int main() {

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

  // input
  char C;
  cin >> C;

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

  cout << ++C << endl;

  return 0;
  
}


Measured memory_bytes: 256