akhauriyash/Code-Regression huggingface dataset:
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){

  int N;
  cin >> N;
  string S;
  cin >> S;
  int Rs = 0, Ws = 0;

  for(int i = 0; i < N; i++){
    if('R' == S[i]){
      Rs++;
    }else{
      Ws++;
    }
  }
  int have_to_change = 0;
  for(int i = 0; i < Rs; i++){
    if('W' == S[i]){
      have_to_change++;
    }
  }

  cout << have_to_change << endl;
  return 0;
}


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

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  int res=0;
  rep(i,n){int a;cin>>a;res+=k<=a;};
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FORR(i, a, b)  for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b)  for (int i = (b); i >= (a); --i)
#define REPP(i, a, b)  for (int i = (a); i < (b); ++i)
#define REPD(i, a, b)  for (int i = (b); i > (a); --i)
#define fi             first
#define se             second
#define mp             make_pair
#define pb             push_back
#define pf             push_front
#define cmin(a, b)     if ((a) > (b)) (a) = (b)
#define cmax(a, b)     if ((a) < (b)) (a) = (b)
#define BIT(x, i)      (((x) >> (i)) & 1)
#define MASK(i)        (1LL << (i))
#define debug(x)       cout << (x) << "\n"
#define endl           "\n"
#define ii             pair <int, int>
#define ll             long long
#define reset(x)       memset(x, 0, sizeof(x))
#define mem(a, x)      memset(x, (a), sizeof(x))
#define task           ""
#define IO             freopen (task".inp","r",stdin),freopen (task".out","w",stdout);

using namespace std;

const int mod = 1007050321;
const int base = 521;
const int MOD = 1e9 + 7;
const int inf = 2e9;
const int N = 1e6 + 5;

int n, a[200005], cnt[N];
bool d[2*N];

int main() {
    ios_base :: sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
        if (cnt[a[i]] >= 2)
            d[a[i]] = true;
    }
    sort(a+1, a+1+n);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (d[a[i]] == false)
            ans ++;
        for (int j = a[i] + a[i]; j <= a[n]; j += a[i])
                d[j] = true;
    }
    cout << ans;
    return 0;
}


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

int main(void)
{
    long long n, k;
    cin >> n >> k;
    
    long long tmp = n % k;
    long long tmp2 = k - tmp;
    
    if (tmp <= tmp2) cout << tmp << endl;
    else cout << tmp2 << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    N, K = input().split()
    A = list(map(int, input().split()))

    id2count = {}
    for x in A:
        if x not in id2count:
            id2count[x] = 1
        else:
            id2count[x] += 1

    sorted_items = sorted(id2count.items(), key=lambda x: x[1])
    total = 0
    for (key, count) in sorted_items[:len(sorted_items)-int(K)]:
        total += count
    print(total)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38964
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NMX = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var c = new int[NMX[0]];
            var A = new int[NMX[0],NMX[1]];
            for(int i = 0; i < NMX[0]; i++){
                var read = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
                c[i] = read[0];
                for(int j = 0; j<read.Length-1;j++){
                    A[i,j] = read[j+1];
                }
            }
            int INF = int.MaxValue;
            int ans = INF;
            
            for(var i = 1; i<(1<<NMX[0]);i++){
                var understand = new int[NMX[1]];
                var cost = 0;
                for(var j = 0; j<NMX[0];j++){
                    if(((i>>j)&1)==1){
                        for(int k = 0; k<NMX[1];k++){
                            understand[k] += A[j,k];
                        }
                        cost += c[j];
                    }
                }
                if(understand.All(x=>x>=NMX[2])){
                    ans = Math.Min(ans,cost);
                }
            }
            Console.WriteLine(ans!=INF?ans:-1);
        }
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}

Measured memory_bytes: 19608
N,M=map(int,input().split())
l=[N,M]
l.sort()
buf=0
f=0
c=0
if l[0]==1:
    if l[1]==1:
        print("1")
    else:
        print(l[1]-2)
else:   #l[0]>1
    print((l[0]-2)*(l[1]-2))




Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <ctime>
#include <queue>
#include <set>
using namespace std;

#define N 100010
#define M 500010
	
typedef long long ll;
const int INF = 1 << 30;
const int mod = 1000000007;

int a[N], x, y;

bool Check(int n, int k)
{
	ll t = 0;
	for (int i = 1; i <= n; ++i) if (a[i] > y * k) t += (1ll * a[i] - y * k + x - 1) / x;
	return t <= k;
}

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
 	
 	int n, l = 0, r = 0, mid;
 	cin >> n >> x >> y;  x = x - y;
 	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), r = max(r, (a[i] + y - 1)/ y);
	
 	while (l < r)
 	{
 		mid = (l + r) >> 1;
 		if (Check(n, mid)) r = mid;
 		else l = mid + 1;
	}
	cout << l << endl;
	return 0; 
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int W,H,N;
  cin >> W >> H >> N;
  int x,y,genx,geny,count=0;
  for(int i=0;i<N;i++){
    cin >> x >> y;
    if(i!=0){
      while(genx!=x||geny!=y){
	count++;
	if(genx<x&&geny<y){
	  genx++;
	  geny++;
	}
	else if(genx==x&&geny<y) geny++;
	else if(genx<x&&geny==y) genx++;
	else if(genx>x&&geny>y){
	  genx--;
	  geny--;
	}
	else if(genx==x&&geny>y) geny--;
	else if(genx>x&&geny==y) genx--;
	else if(genx>x&&geny<y) genx--;
	else if(genx<x&&geny>y) genx++;
      }
    }
    else{
      genx = x;
      geny = y;
    }
  }
  cout << count << endl;
  return 0;
} 

Measured memory_bytes: 1160
N,C=map(int,input().split())
 
D=[list(map(int,input().split())) for i in range(C)]
grid=[list(map(int,input().split())) for i in range(N)]
 
a=[[0]*C for i in range(3)]
 
 
for i in range(N):
    for j in range(N):
        a[(i+j)%3][grid[i][j]-1]+=1
 
b=[[0]*C for i in range(3)]
for i in range(3):
    for j in range(C):
        b[i][j]=[ sum([ D[k][j] * a[i][k] for k in range(C)]), j]
 
b=[ sorted(b[i]) for i in range(3)]
 
ans=1000000000
for i in range(3):
    for j in range(3):
        for k in range(3):
            if b[0][i][1]!=b[1][j][1] and b[1][j][1]!=b[2][k][1] and b[2][k][1]!=b[0][i][1]:
                ans=min(ans,b[0][i][0]+b[1][j][0]+b[2][k][0])
 
print(ans)

Measured memory_bytes: 5620
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);

@s = qw(1 3 5 7 11 13 17 19);

%a = ();

for(my $i=0;$i<=$#s;$i++){
  for(my $j=0;$j<=$#s;$j++){
    for(my $k=0;$k<=$#s;$k++){
      for(my $l=0;$l<=$#s;$l++){
        my $m = $s[$i] * $s[$j] * $s[$k] * $s[$l];
        next if $m > 199 or $m < 105;
        my %yk = ();
        for(my $x=0;$x<16;$x++){
          my $y = 1;
          $y *= $s[$i] if ($x & 1)!=0;
          $y *= $s[$j] if ($x & 2)!=0;
          $y *= $s[$k] if ($x & 4)!=0;
          $y *= $s[$l] if ($x & 8)!=0;
          $yk{$y} = 1;
        }
        my @nyk = keys %yk;
        next if $#nyk != 7;
        $a{$m} = 1;
      }
    }
  }
}

my $c = 0;
foreach my $k (sort keys %a){
  my $aa = $k - 0;
  $c++ if( $aa <= $n );
}

print "$c\n";

exit(0);





Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int check_palindrome(string S){
      string s_row = S;
      reverse(S.begin(), S.end());
      if (S == s_row){
          return 1;
      }else{
          return 0;
      }
}

int main(){
    string S;
  	cin >> S;
    int N = S.length();
    string S1 = S.substr(0, (N-1)/2);
    string S2 = S.substr((N+3)/2-1);
    if (check_palindrome(S) & check_palindrome(S1) & check_palindrome(S2)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll A,B,C,D,E,F,G,H,I;
ll ans=0;
ll cnt=0;
string S,T;
map<char,ll> m;
vector<ll> v[100000];
int main()
{
	cin>>S;
	for(ll i=0;i<4;i++) m[S[i]]++;
	for(ll i='A';i<='Z';i++){
		if(m[i]==2) cnt++;
	}
	if(cnt==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
	int x, y; cin >> x >> y;
	cout << (a[x] == a[y] ? "Yes" : "No") << endl;

}

Measured memory_bytes: 256
import Data.Bits
import Control.Monad

solve :: Int -> [[Int]] -> [Int] -> Int
solve n xss ps = length $ filter id $ map (\b -> step xss ps b) [0..2^n-1]
    where
        step :: [[Int]] -> [Int] -> Int -> Bool
        step [] [] b = True
        step (xs:xss) (p:ps) b = res && (step xss ps b)
            where
                res = (foldl step' 0 $ tail xs) `rem` 2 == p
                step' :: Int -> Int -> Int
                step' acc x
                    | (shiftR b (x-1)) .&. 1 == 1 = acc + 1
                    | otherwise = acc

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    xss <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    ps <- map read . words <$> getLine :: IO [Int]
    print $ solve n xss ps

Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

int main(){
    int a;
    while(cin >> a && a){
        if(a%1111==0){
            printf("NA\n");
            continue;
        }
        int ans=0;
        while(a!=6174){
            int d[4];
            rep(i,4){
                d[i]=a%10;
                a/=10;
            }
            sort(d,d+4);
            int b=0;
            rep(i,4){
                b*=10;
                b+=d[i];
            }
            int c=0;
            for(int i=3;i>=0;i--){
                c*=10;
                c+=d[i];
            }
            a=c-b;
            ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1176
#include <stdio.h>
#define P(i) printf(" %d",i);

int main(void){
    int i, n, x;
    scanf("%d", &n);

    for (i = 1; i <= n; i++){
        if (i % 3 == 0){
            P(i);
        }
        else{
            for (x = i; x; x /= 10){
                if (x % 10 == 3){
                    P(i);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int getAbs(int x);

int getMin(vector<int> v);

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    vector<int> costSum = {getAbs(a[1] - a[0]) + getAbs(a[2] - a[1]),
                           getAbs(a[2] - a[0]) + getAbs(a[1] - a[2]),
                           getAbs(a[0] - a[1]) + getAbs(a[2] - a[0]),
                           getAbs(a[2] - a[1]) + getAbs(a[0] - a[2]),
                           getAbs(a[0] - a[2]) + getAbs(a[1] - a[0]),
                           getAbs(a[1] - a[2]) + getAbs(a[0] - a[1])};
    
    cout << getMin(costSum) << endl;
    return 0;
}

int getAbs(int x){
    return (x > 0)? x : -x;
}

int getMin(vector<int> v){
    int res = 40000;
    for(int i = 0; i < v.size(); i++){
        res = min(res, v[i]);
    }
    return res;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	int a, b, c;
	cin >> a >> b >> c;

	cout << a * b / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
import numpy as np
W, H, N = map(int, input().split())

g = np.array([[1] * W for _ in range(H)])

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        g[:,:x] = 0
    elif a == 2:
        g[:,x:] = 0
    elif a == 3:
        g[H - y:,:] = 0
    elif a == 4:
        g[:H - y,:] = 0

print (g.sum())

# print (g)

Measured memory_bytes: 12508
using System;

namespace AOJ.ALDS
{
    public class ExhaustiveSearch
    {
        private static int length;
        private static int[] items;

        private static bool Solve(int i, int m)
        {
            if (m == 0) { return true; }
            if (i == length) { return false; }

            // 再帰呼び出し
            bool res1 = Solve(i + 1, m);            // i番目の要素を使用しない
            bool res2 = Solve(i + 1, m - items[i]); // i番目の要素を使用する

            return res1 || res2;
        }

        public static void Main()
        {
            length = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            items = new int[length];
            for (int i = 0; i < length; i++) { items[i] = int.Parse(input[i]); }

            int q_cnt = int.Parse(Console.ReadLine());
            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < q_cnt; i++)
            {
                bool ans = Solve(0, int.Parse(input[i]));
                Console.WriteLine(ans ? "yes" : "no");
            }
        }
    }
}

Measured memory_bytes: 5324
from bisect import bisect_right

N = int(input())
A = [int(input()) for _ in range(N)]
INF = float('inf')

dp = [-A[0]]
cnt = 1
for i in range(1, N):
    a = -A[i]
    idx = bisect_right(dp, a)
    if idx == cnt:
        dp.append(a)
        cnt += 1
    else:
        dp[idx] = a

print(cnt)


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


def read():
    N, K = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, K, A


class ModInt(int):
    
    MOD = 10**9+7

    def __new__(cls, x, *args, **kwargs):
        return super().__new__(cls, x % ModInt.MOD)

    def __add__(self, other):
        return ModInt(super().__add__(other) % ModInt.MOD)

    def __radd__(self, other):
        return ModInt(super().__radd__(other) % ModInt.MOD)

    def __mul__(self, other):
        return ModInt(super().__mul__(other) % ModInt.MOD)

    def __rmul__(self, other):
        return ModInt(super().__rmul__(other) % ModInt.MOD)

    def __pow__(self, other, *args):
        return ModInt(super().__pow__(other, ModInt.MOD))

    def __rpow__(self, other, *args):
        raise NotImplementedError()

    def __truediv__(self, other):
        return ModInt(super().__mul__(pow(other, ModInt.MOD-2, ModInt.MOD)))

    def __floordiv__(self, other):
        return self.__truediv__(other)

    def __rtruediv__(self, other):
        return ModInt(self.__pow__(ModInt.MOD-2).__mul__(other))

    def __rfloordiv__(self, other):
        return self.__rtruediv__(other)


def solve(N, K, A):
    ModInt.MOD = 10**9+7
    N = len(A)
    k = ModInt(K)
    t0 = k * (k+1) // 2  # 三角数
    t1 = (k-1) * k // 2

    c0 = 0
    c1 = 0
    for i in range(N):
        for j in range(i+1, N):
            if A[i] > A[j]:
                c0 += 1
            elif A[i] < A[j]:
                c1 += 1
    return c0 * t0 + c1 * t1


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	int ans = 0;
	cin >> n;
	map<char, int> dis, tmp;
	string s;
	for (char a = 'a'; a <= 'z'; a++) {
		dis[a] = INF;
	}
	rep(i, n) {
		cin >> s;
		tmp.clear();
		rep(j, s.size()) { tmp[s[j]]++; }
		for (char a = 'a'; a <= 'z'; a++) {
			chmin(dis[a], tmp[a]);
		}
	}
	for (char a = 'a'; a <= 'z'; a++) {
		rep(i, dis[a]) { cout << a; }
	}
	cout << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        int q = Integer.parseInt(scanner.nextLine());
        
        String tmp = str;
        for(int i=1; i<=q; i++){
            String input = scanner.nextLine();
            String inputArr[] = input.split(" ");
            
            int a = 0;
            int b = 0;
            String tmp1 = "";
            String tmp2 = "";
            String tmp3 = "";
            switch(inputArr[0]){
                case "print":
                    a = Integer.parseInt(inputArr[1]);
                    b = Integer.parseInt(inputArr[2]);
                    System.out.println(tmp.substring(a,b+1));
                    break;
                case "reverse":
                    a = Integer.parseInt(inputArr[1]);
                    b = Integer.parseInt(inputArr[2]);
                    tmp1 = tmp.substring(0,a);
                    tmp2 = tmp.substring(a,b+1);
                    tmp3 = tmp.substring(b+1,tmp.length());
                    StringBuffer sb = new StringBuffer(tmp2);
                    tmp = tmp1 + sb.reverse() + tmp3;
                    break;
                case "replace":
                    a = Integer.parseInt(inputArr[1]);
                    b = Integer.parseInt(inputArr[2]);
                    String p = inputArr[3];
                    
                    tmp1 = tmp.substring(0,a);
                    tmp3 = tmp.substring(b+1,tmp.length()); 
                    tmp = tmp1 + p + tmp3;
                    break;
            }
        }

    }
}


Measured memory_bytes: 28948
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(s.substr(0, n / 2) == s.substr(n / 2))
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
S = input()
MMYY = True
YYMM = True
if int(S[0: 2]) < 1 or int(S[0: 2]) > 12:
  MMYY = False
if int(S[2: 4]) < 1 or int(S[2: 4]) > 12:
  YYMM = False
if MMYY:
  if YYMM:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if YYMM:
    print('YYMM')
  else:
    print('NA')
  

Measured memory_bytes: 3060
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(a<=5){
      System.out.println(0);
    }
    else if(a<=12){
      System.out.println((int)(b/2));
    }
    else{
      System.out.println(b);
    }
  }
}

Measured memory_bytes: 21844
def answer(n, A):
  block=0
  count=1
  for a in A:
    if a != count:
      block += 1
    else:
      count += 1
  if block == len(A):
    return -1
  return block

n=int(input())
A=list(map(int,input().split()))
print(answer(n,A))

Measured memory_bytes: 24744
import java.util.*;

public class Main{

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

        // input
        int num = scan.nextInt();
        int direction = 0;
        boolean wait = true;
        int count = 1;
        int memory = Integer.parseInt(scan.next());
        for(int i = 1; i < num; i++){
            int temp = Integer.parseInt(scan.next());
            if(wait){
                if(temp > memory){
                    direction = 1;
                    wait = false;
                } else if (temp < memory){
                    direction = -1;
                    wait = false;
                } else {
                    direction = 0;
                }
            } else {
                if(direction == 1 && temp < memory){
                    count++;
                    direction = 0;
                    wait = true;
                } else if(direction == -1 && temp > memory){
                    count++;
                    direction = 0;
                    wait = true;
                }
            }
            memory = temp;
        }

        // answer
        System.out.println(count);
    }
}

Measured memory_bytes: 45800
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect


def solve():
    n, k = map(int, input().split())
    al = [int(i) for i in input().split()]

    ans = sum(abs(i) for i in al)
    flag0 = 0 in al
    if flag0:
        k -= 1
        n -= 1
        if k == 0:
            print(0)
            return
        al.remove(0)
    nc = bisect.bisect_left(al, 0)
    for i in range(n):
        if i < 0 or i + k - 1 >= n:
            break
        if al[i] < 0 and al[i + k - 1] < 0:
            t1 = abs(al[i])
        else:
            t1 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        if al[i] > 0 and al[i + k - 1] > 0:
            t2 = abs(al[i + k - 1])
        else:
            t2 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    for i in range(n - 1, -1, -1):
        if i - k + 1 < 0 or i >= n:
            break
        if al[i] < 0 and al[i - k + 1] < 0:
            t1 = abs(al[i - k + 1])
        else:
            t1 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        if al[i] > 0 and al[i - k + 1] > 0:
            t1 = abs(al[i])
        else:
            t2 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 62576
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

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

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int Maxn = 100;
const int Maxd = 10;

int f[Maxn][Maxd];
int p[Maxn][Maxd+1];
int res = -INTINF;

int main(){
	int n; cin >> n;
	REP(i, n){
		REP(j, Maxd){
			cin >> f[i][j];
		}
	}
	REP(i, n){
		REP(j, Maxd+1){
			cin >> p[i][j];
		}
	}
	FOR(i, 1, 1 << Maxd){
		int cand = 0;
		REP(j, n){
			int sum = 0;
			REP(k, Maxd){
				sum += bool(i & 1 << k) && f[j][k];
			}
			cand += p[j][sum];
		}
		res = max(res, cand);
	}
	cout << res << endl;
	
	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,k; cin >> n >> k;
  int ans = pow(k-1,n-1);
  ans *= k;

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


Measured memory_bytes: 3876
#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;}

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

    long double a,b,c; cin >> a >> b >> c;
    if(c==0) cout << (b-1.0)/a << endl;
    else cout << (b-1.0)*2*(a-c)/a/a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    ll N,K;cin>>N>>K;
    ll a=N/K;
    ll ans=N-a*K;
    ans=min(ans,abs(ans-K));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
cond = m.times.map {
  k, *ss = gets.split.map(&:to_i)
  ss.inject(0) {|acc, s| acc | (1 << (s - 1))}
}
ps = gets.split.map(&:to_i)

count = 0
(2 ** n).times do |switches|
  f = cond.map.with_index {|c, i| (switches & c).to_s(2).count("1") % 2 == ps[i]}.all?
  count += 1 if f
end

puts count

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

int main() {
    ll a, b, k;
    cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << " " << b << endl;;
    } else {
        ll c = k - a;
        if (b - c > 0) {
            cout << 0 << " " << b - c << endl;;
        } else {
            cout << 0 << " " << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	a := scanInt()
	s := scanText()

	if a < 3200 {
		fmt.Println("red")
	} else {
		fmt.Println(s)
	}
}


Measured memory_bytes: 640
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	map<string,int> mp;
	int n;
	cin>>n;
	int mx = 0;
	string s[n];
	for(int i = 0;i < n; i++){
		cin>>s[i];
		mp[s[i]]++;
		mx = max(mx,mp[s[i]]);
	}
	vector<string> ss;
	for(auto x: mp) if( x.S == mx) ss.push_back(x.F);
	sort(ss.begin(),ss.end());
	for(auto x:ss)cout<<x<<nl;
	return 0;
}



Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

string s;
void solve(ll n, ll x, ll y, ll cnt) {
	while (y >= 26) {
		s.push_back((char)('a' + (n - x) / (y / 26)));
		n -= (n - x) / (y / 26) * (y / 26);
		y /= 26;
	}
	cout << s << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;

	ll x = 1, y = 1, cnt = 1;
	while (x <= n) {
		y *= 26;
		x += y;
		cnt++;
	}
	x -= y;
	cnt--;
	solve(n, x, y, cnt);
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define PRINT(x) std::cout << x << std::endl;
#define FOR(i, n) for(int i = 0; i < (n); ++i);

int k;
string s;

int main() {
 
  cin >> k >> s;
  if (s.size() <= k) {
    PRINT(s)
  } else {
    string newStr = s.substr(0, k);
    PRINT(newStr + "...");
  }
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int,int> >a;
vector<int>v[4];
long n,W,cost;
main()
{
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		int a,b;cin>>a>>b;
		if(i==0)cost=a;
		v[a-cost].push_back(b);
	}
	for(int i=0;i<4;i++)sort(v[i].begin(),v[i].end(),greater<int>());
	a.push_back(make_pair(0,0));
	for(int i=0;i<4;i++)
	{
		int s=a.size();
		for(int j=0;j<s;j++)
		{
			pair<int,int>p=a[j];
			for(int k=0;k<v[i].size();k++)
			{
				p.second+=cost+i;
				p.first+=v[i][k];
				if(p.second>W)break;
				a.push_back(p);
			}
		}
	}
	sort(a.begin(),a.end());
	cout<<a[a.size()-1].first<<endl;
}

Measured memory_bytes: 2420
n=int(input())
plist=[int(s) for s in input().split()]

cnt=0
for i in range(n-2):
    left,mid,right = plist[i],plist[i+1],plist[i+2]
    maxv=max(left,mid,right)
    minv=min(left,mid,right)
    if mid!=maxv and mid!=minv:
        cnt+=1
print(cnt)

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

using namespace std;

void dfs(int u, const vector<vector<int>> &g, vector<int> &dist) {
    for (int v : g[u]) {
        if (!dist[v]) {
            dist[v] = dist[u] + 1;
            dfs(v, g, dist);
        }
    }
}
int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<string> adj(N);
    for (int i = 0; i < N; ++i) {
        cin >> adj[i];
    }
    vector<vector<int>> g(N);
    int m = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            if (adj[i][j] == '1') {
                g[i].push_back(j);
                g[j].push_back(i);
                ++m;
            }
        }
    }
    int mx_res = -1;
    for (int u = 0; u < N; ++u) {
        vector<vector<int>> res;
        res.push_back({u});
        vector<int> vis(N, 0);
        vis[u] = 1;
        int i = 0;
        bool ok = true;
        while (i < (int)res.size()) {
            vector<int> tmp;
            for (int v : res[i]) {
                for (int w : g[v]) {
                    if (!vis[w]) {
                        tmp.push_back(w);
                        vis[w] = i + 2;
                    } else if (vis[w] != i && vis[w] != i + 2) {
                        ok = false;
                    }
                }
            }
            if (!tmp.empty()) {
                res.push_back(tmp);
            }
            ++i;
        }
        if (ok) {
            mx_res = max(mx_res, (int)res.size());
        }
    }
    cout << mx_res << "\n";

    /*if (m > N - 1) {
        cout << -1 << "\n";
        return 0;
    }
    vector<int> dist(N, 0);
    dfs(0, g, dist);
    int u = max_element(begin(dist), end(dist)) - begin(dist);
    dist.assign(N, 0);
    dfs(u, g, dist);
    int d = *max_element(begin(dist), end(dist));
    cout << d << "\n";*/

    return 0;
}

Measured memory_bytes: 512
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

int main()
{
    const ll MOD = 1000000007;

    // Input
    ll n;
    cin >> n;

    if (n == 1) {
        cout << 0;
        return 0;
    }

    ll ans = 0;

    ll all = 1;
    ll noBoth = 1;
    ll one = 1;

    rep(i, n) {
        all *= 10;
        all %= MOD;

        noBoth *= 8;
        noBoth %= MOD;

        one *= 9;
        one %= MOD;
    }

    ans = all - (one * 2 - noBoth);
    ans %= MOD;
    ans = (ans + MOD) % MOD;

    cout << ans;
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

ll n,m,k,a,b;
string s,t;

int main() {
  cin >> a >> b >> n;
  if(b==1)
  cout << 0 << endl;
  else if(b<=n)
  cout << floor(a*(b-1)/b) << endl;
  else 
  cout << floor(a*n/b) << endl;
}

Measured memory_bytes: 3728
import sys
from collections import Counter

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = [0, 0] + list(map(int, input().split()))
    # print(A)
    count = Counter(A)
    for i in range(1, N + 1):
        print(count[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 35016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,ans;
char s[1200005];
bool check(int t){
	int l=0,r=t,p=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='0')l++,r++;
		if(s[i]=='1')l--,r--;
		if(s[i]=='?')l--,r++;
		if(!p){
			l=max(l,0);
			r=min(r,t);
		}
		else{
			if(l<0)l=1;
			if(r>t)r=t-1;
		}
		if(l>r)return 0;
		if(l==r)p=1;
	}
	return 1;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int l=1,r=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))
			ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vector<vector<int> > m;
int w, h;

void cal(ll x, ll y) {
	REP(i, 8) {
		ll nx = x + qx[i];
		ll ny = y + qy[i];
		if(nx >= 0 && nx < h && ny >= 0 && ny < w && m[nx][ny] == 1) {
			m[nx][ny] = 0;
			cal(nx, ny);
		}
	}
}

int main(void) {
	while(true) {
		cin>>w>>h;
		if(w == 0 && h == 0) break;
		m.resize(h);
		REP(i, h) {
			m[i].resize(w);
		}
		REP(i, h) {
			REP(j, w) {
				cin>>m[i][j];
			}
		}
		ll ans = 0;
		REP(i, h) {
			REP(j, w) {
				if(m[i][j] == 1) {
					++ans;
					cal(i, j);
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

const int LEN = 1000;

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

    int c[LEN + 1][LEN + 1];

    string S, T;
    for (int i = 0; i < n; i++)
    {
        cin >> S;
        cin >> T;

        length = S.length() > T.length() ? S.length() : T.length();

        for (int j = 1; j < length+1; j++)
        {
            c[0][j] = c[j][0] = 0;
        }

        for (int j = 0; j < S.length(); j++)
        {
            for (int k = 0; k < T.length(); k++)
            {
                if (S[j] == T[k])
                {
                    c[j+1][k+1] = c[j][k] + 1;
                }
                else
                {
                    c[j+1][k+1] = c[j][k+1] > c[j+1][k] ? c[j][k+1] : c[j+1][k];
                }
            }
        }
        cout << c[S.length()][T.length()] << endl;
    }
}


Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> sc;
  string c;
  int n1,n2,num=0,ten;
  while(cin>>c){
    num=0;
    if(c=="+"){
      n1=sc.top();
      sc.pop();
      n2=sc.top();
      sc.pop();
      sc.push(n1+n2);
    }else if(c=="-"){
      n2=sc.top();
      sc.pop();
      n1=sc.top();
      sc.pop();
      sc.push(n1-n2);
    }else if(c=="*"){
      n1=sc.top();
      sc.pop();
      n2=sc.top();
      sc.pop();
      sc.push(n1*n2);
    }else{
      for(int i=(c.size()-1);i>=0;i--){
	ten=1;
	for(int j=i;j<c.size()-1;j++){
	  ten=ten*10;
	}
	num+=(c[i]-'0')*ten;
      }
      sc.push(num);
    }
  }
  cout<<sc.top()<<endl;
  return 0;
}

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

using namespace std;

vector<vector<int>> G;
vector<int> ed;
map<pair<int,int>,int> edm;

void dfs(int v,int p,int c){
    //cout<<v<<endl;
    int tc=1;
    for(auto x:G[v]){
        if(x==p)continue;
        if(tc==c)++tc;
        dfs(x,v,tc);
        ed[edm[make_pair(x,v)]]=tc;
        ++tc;
    }
}

int main(){
    int n;
    cin>>n;
    G.resize(n);
    ed.resize(n-1);
    for (int i = 0; i < n-1; ++i) {
        int a,b;
        cin>>a>>b;
        --a;--b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        edm[make_pair(a,b)]=i;
        edm[make_pair(b,a)]=i;
    }
    dfs(0,-1,-1);
    int mc=0;
    for (int i = 0; i < n-1; ++i) {
        mc=max(mc,ed[i]);
    }

    cout<<mc<<endl;
    for (int i = 0; i < n-1; ++i) {
        cout<<ed[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 18944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException{
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() throws IOException{
		FastScanner fs = new FastScanner();
		
		int x = fs.nextInt();
		int y = fs.nextInt();
		int a = fs.nextInt();
		int b = fs.nextInt();
		int c = fs.nextInt();
		
		Comparator<Apple> appleComparator = Comparator.comparing(Apple::getUmasa).reversed();
		ArrayList<Apple> appleTreeSet = new ArrayList<>();
		
		for(int i = 0; i < a; i++){
			appleTreeSet.add(new Apple(0, fs.nextLong()));
		}
		for(int i = 0; i < b; i++){
			appleTreeSet.add(new Apple(1, fs.nextLong()));
		}
		for(int i = 0; i < c; i++){
			appleTreeSet.add(new Apple(2, fs.nextLong()));
		}
		
		appleTreeSet.sort(appleComparator);
		
		int red = 0;
		int green = 0;
		int noColor = 0;
		long sumOfUmasa = 0;
		
		for(Apple apple : appleTreeSet){
			if(apple.color == 0){
				if(red < x){
					red++;
					sumOfUmasa += apple.umasa;
				}
			}else if(apple.color == 1){
				if(green < y){
					green++;
					sumOfUmasa += apple.umasa;
				}
			}else{
				noColor++;
				sumOfUmasa += apple.umasa;
			}
			
			if(red+green+noColor == x+y){
				break;
			}
		}
		
		System.out.println(sumOfUmasa);
	}

	
	public class Apple{
		int color;//0: red, 1: green, 2: no color
		long umasa;
		
		public Apple(int color, long umasa){
			this.color = color;
			this.umasa = umasa;
		}
		
		public long getUmasa(){
			return umasa;
		}
	}
	
	public class FastScanner {
		
		BufferedReader reader;
		private StringTokenizer st;
		
		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		
		public String next() throws IOException {
			if(st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}
		
		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		
		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}
		
		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}
		
		public void close() throws IOException {
			reader.close();
		}
	}
}




Measured memory_bytes: 111200
package main

import (
	"fmt"
)

//const pi = math.Pi

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	ans := 0
	if a > b {
		ans += a
		a--
	} else {
		ans += b
		b--
	}
	if a > b {
		ans += a
	} else {
		ans += b
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello
{
    static void Main()
    {
        string alfa = "abcdefghijklmnopqrstuvwxyz";
        var groupe1 = new List<char>(alfa.ToCharArray());

        string data = Console.ReadLine();
        var groupe2 = new List<char>(data.ToCharArray());

        var result = groupe1.Except(groupe2).FirstOrDefault().ToString();
        if (result == "\0") result = "None";
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13652