akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    readLine()
    val s = readLine().split(' ').map(_.toInt).toSet
    readLine()
    val t = readLine().split(' ').map(_.toInt).toSet
    println((s & t).size)
  }
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

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

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; }

int main(void){
    int n,m; cin >> n >> m;
    VI c(m); REP(i,m) cin >> c[i];
    SORT(c);
    int dp[n+1]; REP(i,n+1) dp[i] = INT_INF;
    dp[0] = 0;
    REP(i,m){
        REP(j,n) if(j+1-c[i] >= 0) chmin(dp[j+1], dp[j+1-c[i]]+1);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3368
import Control.Applicative

import Data.List
    (elemIndex, intercalate, nub, sort)
    
import Data.Maybe
    (fromJust)
    
type Data = (Int, Int)

type Problem = ([Data], [Int])

type Result = [Int]

pull :: Int -> [Data] -> [Int] -> Maybe Int

pull q ds ss
    = do
        s <- lookup q ds
        i <- elemIndex s ss
        Just $ i + 1
        
solve :: Problem -> Result

solve (ds, qs)
    = [fromJust $ pull q ds ss | q <- qs] where
        ss = reverse $ sort $ nub $ snd $ unzip ds
        
split :: [String] -> String -> String -> [String]

split list token ""
    = list ++ [token]
    
split list token (x:xs)
    = if x == ','
        then split (list ++ [token]) "" xs
        else split list (token ++ [x]) xs
        
dinput :: [Data] -> IO [Data]

dinput list
    = do
        [p, s] <- map read <$> split [] "" <$> getLine
        if p /= 0 || s /= 0
            then dinput $ list ++ [(p, s)]
            else return list
            
qinput :: IO [Int]

qinput
    = map read <$> lines <$> getContents
    
main :: IO ()

main
    = do
        ds <- dinput []
        qs <- qinput
        putStrLn $ intercalate "\n" $ map show $ solve (ds, qs)

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

int main() {
 int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool battle = true;
  for(int i=0; i<100; ++i){
  c-=b;
    if(c<=0) break;
    a-=d;
    if(a<=0){
      battle = false;
        break;
    }
  }
    if(battle) cout <<"Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], book[maxn];
vector <int> g[maxn];
int n, m;
void dfs(int u)
{
	book[u] = 1;
	for(int i = 0; i < g[u].size(); i++){
		int v = g[u][i];
		if(book[v] == 0){
			a[v] = a[v] + a[u];
			dfs(v);
		}
	}
}
int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n - 1; i++){
		int c, d;
		scanf("%d %d", &c, &d);
		g[c].push_back(d);
	}
	for(int i = 1; i <= m; i++){
		int c, d;
		scanf("%d %d", &c, &d);
		a[c] += d;
	}
	dfs(1);
	for(int i = 1; i <= n; i++){
		printf("%d ", a[i]);
	}
	return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
const double eps=1e-6;
const int MOD=1e5+3;
const int INF=0x3f3f3f3f;
ll a[N],b[N];
int main()
{
    ll n,h;
    while(cin>>n>>h)
    {
        ll sum=0,mxa=0,minb=INF;
        rep(i,0,n)
        {
            cin>>a[i]>>b[i];
            mxa=max(mxa,a[i]);
            minb=min(minb,b[i]);
            sum+=b[i];
        }
       // printf("mxa=%lld  minb=%lld\n",mxa,minb);
        // sort(a,a+n);
        int cnt=n;
        if(mxa<=minb)
        {
            if(sum>=h)
            {
                sort(b,b+n);
                for(int i=0; i<n; i++)
                {
                    sum-=b[i];
                    cnt--;
                    if(sum<h)
                    {
                        printf("%d\n",cnt+1);
                        break;
                    }
                }
            }
            else
            {
                int tmp=h-sum;
                int num=ceil(tmp*1.0/mxa);
              //  printf("1num=%d\n",num);
                printf("%d\n",cnt+num);
            }
        }
        else
        {
            sort(b,b+n);
            int pos=lower_bound(b,b+n,mxa)-b;
            //if(b[pos]==mxa) cnt-=(pos+1);
            //else cnt-=pos;
            //pos=(b[pos]==mxa)?pos+1:pos;
            for(int i=0; i<pos; i++)
                sum-=b[i];
            cnt-=pos;
            if(sum>=h)
            {
                for(int i=pos; i<n; i++)
                {
                    cnt--;
                    sum-=b[i];
                    if(sum<h)
                    {
                        printf("%d\n",cnt+1);
                        break;
                    }
                }
            }
            else
            {
          //      printf("sum=%d\n",sum);
                int tmp=h-sum;
                int num=ceil(tmp*1.0/mxa);
          //      printf("2num=%d\n",num);
                printf("%d\n",cnt+num);
            }
        }
    }
    return 0;
}


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

typedef long long int lli;
#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define REP(i,n) for(lli(i)=0;(i)<(lli)(n);(i)++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;


typedef pair<lli, lli> ii;
typedef pair<ii, lli> iii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef long double C;
typedef complex<C> P;
#define X real()
#define Y imag()
C EPS=1e-9;
C pi=acos(-1.0);
const int N=(1e5+20);
lli INF=1e9+7;

int dp[105][N],w[105],v[105];

int main(){
	fastio;
	int n,k,sum=0; cin>>n>>k;
	rep(i,1,n+1){ cin>>w[i]>>v[i]; sum+=v[i];}

	rep(i,0,n+1) rep(j,0,sum+1) dp[i][j]=INF;
	dp[0][0]=0;

	rep(i,1,n+1){
		rep(j,0,sum+1){
			if(j-v[i]>=0) dp[i][j]=min(dp[i-1][j-v[i]] + w[i],dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}

	for(int i=sum;i>=0;i--){
		if(dp[n][i]<=k){
			cout<<i<<'\n';
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 41216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n,x;
int main(){
     scanf("%d%d",&n,&x);
     for(int i=0;i<=n;i++){
     	for(int j=0;j<=n;j++){
     		if(i+j<=n){
     			if(i*10000+j*5000+(n-i-j)*1000==x){
     				printf("%d %d %d",i,j,n-i-j);
     				return 0;
				 }
			 }
		 }
	 }
	 printf("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 256
N, ds, x = gets.split.map(&:to_i)

dt = ds + (2*N-1)*x
ans = 0
(2*N).step(2, -2) do |i|
    ans += (ds+dt)/2.0
    break if i == 2
    ds = (ds*(i+2) + 5*x)/i.to_f
    dt = (dt*(i+2) - 5*x)/i.to_f
    x = (dt-ds)/(i-3)
end
p ans

Measured memory_bytes: 3836
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
char s[4001];
ll f(int n) {
    int r = 0, g = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r++;
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
    }
    ll res = 1L * r * g * b;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (s[i] == s[j]) continue;
            int k = j + (j - i);
            if (k < n && s[k] != s[i] && s[k] != s[j]) res--;
        }
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin>> s[i];
    }
    cout << f(n) <<endl;
    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int get_bit(int x,int i){return (x>>i)&1;}
int a[1000],b[1000];
int main()
{
    for(int i=1;i<=3;i++)cin>>a[i];
    sort(a+1,a+4);
    cout<<a[1]+a[2]<<endl;
    return 0;
}


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

int main(){
    int a;
    cin >> a;
    int b[a];
    for(int i=0;i<a;i++){
        cin >> b[i];
    }
    int num1=0,num2=1000000000;
    for(int j=1;j<a;j++){
        if(num1<=max(b[j-1],b[j])){
            num1=max(b[j-1],b[j]);
        }
        if(num2>=min(b[j-1],b[j])){
            num2=min(b[j-1],b[j]);
        }
    }
    cout << num1-num2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string evenodd(int x){
  int y=x/2;
  if(y*2==x){
  return "even";
  }
  return "odd";
}
int main(){
  int A,B,C;
  int x=0;
  cin>>A>>B>>C;
  string a,b,c;
  int count=0;
  a=evenodd(A);
  b=evenodd(B);
  c=evenodd(C);
  while(a=="even" && b=="even" && c=="even"){
count++;
    int Ae,Be,Ce;
    Ae=B/2+C/2;
    Be=A/2+C/2;
    Ce=A/2+B/2;
    A=Ae;
    B=Be;
    C=Ce;
      a=evenodd(A);
  b=evenodd(B);
  c=evenodd(C);

    if(A==B/2+C/2 && B==A/2+C/2 && C==A/2+B/2){
    cout<<-1<<endl;
     x=1;
    break;  
    
    }
  }
  if(x==0)
    cout<<count<<endl;
  
}

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

using namespace std;

const long long INF = 1LL << 60;

static int len[2000][2000];
static long long pattern[2000][2000];

int main(){
	string S;
	while(cin >> S){
		long long K; cin >> K;
		int n = S.size();
		for(int i=0;i<n;i++){
			len[i][i] = 1;
			pattern[i][i] = 1;
		}
		for(int i=0;i+1<n;i++){
			len[i][i+1] = (S[i] == S[i+1] ? 2 : 3);
			pattern[i][i+1] = (S[i] == S[i+1] ? 1 : 2);
		}
		for(int d=2;d<n;d++){
			for(int i=0;i+d<n;i++){
				if(S[i] == S[i+d]){
					len[i][i+d] = len[i+1][i+d-1] + 2;
					pattern[i][i+d] = pattern[i+1][i+d-1];
				} else {
					len[i][i+d] = min(len[i+1][i+d], len[i][i+d-1]) + 2;
					pattern[i][i+d] = 0;
					if(len[i+1][i+d] <= len[i][i+d-1]){
						pattern[i][i+d] = min(INF, pattern[i][i+d] + pattern[i+1][i+d]);
					}
					if(len[i+1][i+d] >= len[i][i+d-1]){
						pattern[i][i+d] = min(INF, pattern[i][i+d] + pattern[i][i+d-1]);
					}
				}
			}
		}
		--K;
		if(pattern[0][n-1] <= K){
			cout << "NONE" << endl;
			continue;
		}
		string res = string(len[0][n-1], '.');
		int rs = 0, re = res.size() - 1;
		int idxA = 0, idxB = n-1;
		while(idxA < idxB){
			if(S[idxA] == S[idxB]){
				res[rs] = res[re] = S[idxA];
				++rs;
				--re;
				++idxA;
				--idxB;
			} else {
				bool useFront = true;
				if(len[idxA+1][idxB] < len[idxA][idxB-1]){
				} else if(len[idxA][idxB-1] < len[idxA+1][idxB]){
					useFront = false;
				} else {
					if(S[idxA] < S[idxB]){
						if(pattern[idxA+1][idxB] <= K){
							K -= pattern[idxA+1][idxB];
							useFront = false;
						}
					} else {
						if(pattern[idxA][idxB-1] <= K){
							K -= pattern[idxA][idxB-1];
						} else {
							useFront = false;
						}
					}
				}
				if(useFront){
					res[rs] = res[re] = S[idxA];
					++rs;
					--re;
					++idxA;
				} else {
					res[rs] = res[re] = S[idxB];
					++rs;
					--re;
					--idxB;
				}
			}
		}
		if(idxA == idxB) res[rs] = S[idxA];
		cout << res << endl;
	}
}

Measured memory_bytes: 46780
N,K=map(int,input().split())
*A,=map(int,input().split())

def C(x):
  return sum([(A[i]-.5)//x for i in range(N)]) <= K
  
def binary_search2(func, n_min, n_max):
    left,right=n_min,n_max
    while right-left>1:
        middle = (left+right)//2
        y_middle = func(middle)
        if y_middle: right=middle
        else: left=middle

    return right
  
print(binary_search2(C, 0, max(A)+1))

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

int main() {
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC"  << endl;
    } else if (R < 2800) {
        cout << "ARC"  << endl;
    } else {
        cout << "AGC"  << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x[] = new int[120];
		for(int i=0; i<120; i++){
			x[i]=0;
		}
		for(int i=0; i<n; i++){
			int b = sc.nextInt();  //?£?
			int f = sc.nextInt();  //???
			int r = sc.nextInt();  //??????
			int v = sc.nextInt();  //?????°
			int num=(b-1)*30+(f-1)*10+r;
			x[num-1]=x[num-1] + v;
		}
		for(int i=1; i<121; i++){
			System.out.print(" " + x[i-1]);
			if(i%10==0){
				System.out.println();
			}
			if(i%30==0 && i!=120){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 29264
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#include <iostream> 
#define ll long long
#define N 550
#define inf 1000000000000000
using namespace std;

ll n,dp[N][N],w[N][N],p[N][N],tot[N][N];

inline ll getans(int a,int b,int c,int d){
	return p[b][d]-(c==0?0:p[b][c-1])-(a==0?0:p[a-1][d])+(a==0||c==0?0:p[a-1][c-1]);
}

void fl()
{
	freopen("park.in","r",stdin);
	freopen("park.out","w",stdout);
}

int main()
{
	//fl();
	cin>>n;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) 
			if (i!=j) cin>>w[i][j];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+w[i][j];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			tot[i][j]=tot[i-1][j]+tot[i][j-1]-tot[i-1][j-1]+(i<j?w[i][j]:0);
	for (int i=1;i<=n;i++)
	{
		dp[i][1]=tot[i][i]-tot[0][i]-tot[i][0]+tot[0][0];
		for (int j=2;j<=i;j++)
		{
			dp[i][j]=inf;
			for (int k=1;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[j-1][k]+(tot[i][i]-tot[i][j-1]-tot[j-1][i]+tot[j-1][j-1])+getans(j,i,0,k-1));
		}
	}
	ll ans=inf;
	for (int i=1;i<=n;i++) ans=min(ans,dp[n][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9472
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int A[] = new int[N];
        for (int i = 0; i < N; i++) {
            A[Integer.parseInt(scanner.next()) - 1]++;
        }
        Arrays.sort(A);

        int S[] = new int[N + 1];
        for (int i = 0; i < N; i++) {
            S[i + 1] = S[i] + A[i];
        }

        for (int k = 1; k <= N; k++) {
            int l = 0; // ok
            int r = N / k + 1; // ng
            while (r - l > 1) {
                int mid = (l + r) >>> 1;
                int index = lowerBound(A, 0, A.length, mid);
                int sum = mid * (N - index) + S[index];
                if (sum >= mid * k) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            System.out.println(l);
        }

    }

    // return first index whose value is more than or equal to val;
    static int lowerBound(int[] A, int fromInc, int toExc, int val) {
        int left = fromInc, right = toExc;
        while (right - left > 1) {
            int mid = (left + right) >>> 1;
            if (A[mid] < val) {
                left = mid;
            } else {
                right = mid;
            }
        }
        if (A[left] < val) {
            return left + 1;
        }
        return left;
    }

}


Measured memory_bytes: 78148
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import math

gcd_queue = [
    (0, nums[0]),
]
for n in nums[1:]:
    tmp_queue = []
    for q in gcd_queue:
        tmp_queue.append((q[0] + q[1], n))
        tmp_queue.append((q[0] + q[1]*-1, n*-1))
    gcd_queue = set(tmp_queue[:])
    #print(gcd_queue)
    tmp = {}
    for q in gcd_queue:
        if str(q[1]) in tmp:
            tmp[str(q[1])] = max(q[0], tmp[str(q[1])])
        else:
            tmp[str(q[1])] = q[0]
    #print(tmp)
    gcd_queue = []
    for k, v in tmp.items():
        #print(k, v)
        gcd_queue.append((v, int(k)))
    

gcd_queue = list(gcd_queue)
ans = gcd_queue[0][0] + gcd_queue[0][1]
for q in gcd_queue:
    ans = max(ans, q[0]+q[1])
print(ans)

Measured memory_bytes: 14412
n, m = gets.split.map(&:to_i)

l = Array.new(n)
k = Array.new(m+1) {[]}
n.times do |i|
    _, *l[i] = gets.split.map(&:to_i)
    l[i].each {|e| k[e] << i}
end

visit_l = Array.new(n)
visit_k = Array.new(m+1)

que = [0]
while now = que.shift
    visit_l[now] = true
    l[now].each do |e|
        next if visit_k[e]
        visit_k[e] = true
        k[e].each {|ee| que << ee if !visit_l[ee]}
    end
end

puts visit_l.all?(true) ? "YES" : "NO"

Measured memory_bytes: 30340
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {


		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();


		long [] A = new long[N+1];

		for(int i= 1;i < N+1;i++){
			A[i] = A[i-1]+scan.nextInt();
		}
		
		
		Map<Long, Long> map = new HashMap<>();
		for(int i= 0;i<A.length;i++){
			map.put(A[i]%M, map.getOrDefault(A[i]%M, 0l)+1);
		}
		
		long  result = 0;
		for(long key:map.keySet()){					//mapのkeyを全て呼び出す
			long num = map.get(key);
			result+=(num*(num-1))/2;
		}	
		
		System.out.println(result);
	}
}

Measured memory_bytes: 56792
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pairs;

ll a[200009] , freq[200009] , ways[200009] ;
ll ans[200009] ;
set<ll> s ;
 
 
int main()
{
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //int t ; cin >> t ; while(t--){}
    ll n ; cin >> n ;
    for ( int i = 0 ; i < n ; i++ )
    {
      cin >> a[i] ;
      s.insert(a[i]) ;
      freq[a[i]]++ ;
      ll z = freq[a[i]] - 1;
      ways[a[i]] = z*(1+z)/2 ;
    }
    //for ( int i = 1 ; i <= 2 ; i++ ) cout << i << " " << freq[i] << " " << ways[i] << "\n" ;
    ll sum = 0 ;
    for ( auto x:s )  sum+= ways[x] ; 
    for ( int i = 0 ; i < n ; i++ )
    {
      cout << sum - (freq[a[i]]-1) << "\n" ;
    }
 
    
    
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,x;

ll layer[51];
ll patty[51];

ll burger(ll nn,ll xx){
	if(nn==0){
		return 1;
	}
	else if(xx==1){
		return 0;
	}
	else if(xx<=1+layer[nn-1]){
		return burger(nn-1,xx-1);
	}
	else if(xx==layer[nn-1]+2){
		return patty[nn-1]+1;
	}
	else if(xx<layer[nn]){
		return patty[nn-1]+1+burger(nn-1,xx-layer[nn-1]-2);
	}
	else{
		return patty[nn];
	}
}
	

int main(){
	cin>>n>>x;
	layer[0]=1,patty[0]=1;
	for(int i=1;i<=50;i++){
		layer[i]=layer[i-1]*2+3;
		patty[i]=patty[i-1]*2+1;
	}
	cout<<burger(n,x)<<endl;
	return 0;
}

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

struct Point
{
    double x,y;
};

void koch(int n,Point p1,Point p2)
{
    if(n==0)
    {
        return;
    }
    Point s,t,u;
    double th=M_PI*60.0/180.0;

    s.x=(2*p1.x+1*p2.x)/3.0;
    s.y=(2*p1.y+1*p2.y)/3.0;
    t.x=(1*p1.x+2*p2.x)/3.0;
    t.y=(1*p1.y+2*p2.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    //cout<<u.x<<endl;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
    //cout<<u.y<<endl;

    koch(n-1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,p2);
}

int main()
{
    Point x,y;
    x.x=0;
    x.y=0;
    y.x=100;
    y.y=0;
    int n;
    cin>>n;
    printf("%.8f %.8f\n",x.x,x.y);
    koch(n,x,y);
    printf("%.8f %.8f\n",y.x,y.y);

	return 0;
}




Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

ll n,m;
string s;
ll f[200010],rui[200010];

int main(){
    cin>>n>>m>>s;
    if(s[0]=='R'){
	for(int i=0;i<m;i++){
	    if(s[i]=='R')s[i]='B';
	    else s[i]='R';
	}
    }
    bool th=0;
    ll cnt=0,mi=1e17;
    bool fi=1; ll lead;
    for(int i=0;i<m;i++){
	if(s[i]=='R'){
	    if(fi)lead=cnt; fi=0;
	    th=1;
	    if(cnt%2==1)chmin(mi,cnt);
	    cnt=0;
	}
	else cnt++;
    }
    
    if(th==0){
	f[0]=f[1]=1;
	for(int i=2;i<n;i++){
	    f[i]=(f[i-1]+f[i-2])%mod;
	}
	ll ans=(f[n-2]*2+f[n-1])%mod;
	cout<<ans<<endl;
	return 0;
    }
    if(n%2==1){
	cout<<0<<endl;
	return 0;
    }
    
    if(lead%2==0)lead++;
    chmin(mi,lead);
    mi=(mi+1)/2;
    chmin(mi,n/2);
    f[0]=rui[0]=0;
    for(ll i=1;i<=mi;i++){
	f[i]=i;
    }
    for(int i=1;i<n/2;i++){
	mad(f[i],rui[i-1]);
	if(i-mi-1>=0)mad(f[i],-rui[i-mi-1]);
	rui[i]=(rui[i-1]+f[i])%mod;
    }
    ll ans=0;
    for(int i=1;i<=mi;i++)mad(ans,f[n/2-i]);
    //cout<<mi<<endl;
    //for(int i=0;i<n/2;i++)cout<<i<<":"<<f[i]<<endl;
    ans=ans*2%mod;
    if(mi==n/2)mad(ans,n);
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}



Measured memory_bytes: 2180
#include <iostream>

int main(){

  int L,R;

  std::cin >> L >> R;

  //std::cout << (L*R)%2019 <<std::endl;
  int min=2020;
  
  /*for(int i=L;i<R;i++){
    if(i%2019 == 0){
      min = 0;
      goto END;
      }
    for(int j=i+1;j<=R;j++){
      if(j%2019 == 0){
	min = 0;
	goto END;
      }
      //min = min > (i*j)%2019 ? (i*j)%2019 : min;
      if(min > (i*j)%2019)
	min = (i*j)%2019;
    }
    }*/

  int LD,RD;
  for(int i=L;i<R;i++){
    if(i%2019 == 0){
      min = 0;
      goto END;
      }
    LD=i%2019;
    
    for(int j=i+1;j<=R;j++){
      if(j%2019 == 0){
	min = 0;
	goto END;
      }
      RD=j%2019;
      
      //min = min > (i*j)%2019 ? (i*j)%2019 : min;
      if(min > (LD*RD)%2019)
	min = (LD*RD)%2019;
    }
  }

 END:std::cout << min << std::endl;
  return 0;
}
  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	ll ai, ao, at, aj, al;
	cin >> ai >> ao >> at >> aj >> al;
	ll res = ao;
	if (ai & aj & al & 1)
		res += ai + aj + al;
	else if (ai == 0 || al == 0 || aj == 0) {
		res += (ai / 2 * 2) + (al / 2 * 2) + (aj / 2 * 2);
	}
	else {
		ll tmp1 = (ai / 2 * 2) + (al / 2 * 2) + (aj / 2 * 2);
		ll tmp2 = 3 + ((ai - 1) / 2 * 2) + ((al - 1) / 2 * 2) + ((aj - 1) / 2 * 2);
		res += max(tmp1, tmp2);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int> > ab;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		ab.push_back(make_pair(a, b));
	}
	sort(ab.begin(), ab.end());
	long long int ans = 0;
	int cnt = 0;
	priority_queue<int> qu;
	for (int i = 0; i <= m; i++) {
		if (!qu.empty()) {
			ans += qu.top();
			qu.pop();
		}
		while (cnt < n && ab[cnt].first <= i + 1) {
			qu.push(ab[cnt].second);
			cnt++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1908
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long x = scan.nextLong();
        long k = scan.nextLong();
        long d = scan.nextLong();
        long num = Math.abs(x) / d;
        if (k <= num) {
            if (x > 0) x -= k * d;
            else x += k * d;
            System.out.println(Math.abs(x));
            return;
        }
        x = x % d;
        k -= num;
        if (x > 0 && k > 0) {
            x -= d;
            k--;
        }
        long tmp = k % 2 == 1 ? x + d : x;
        long ans = Math.abs(tmp);
        System.out.println(ans);
    }
}


Measured memory_bytes: 35612
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<P, long long int> P2;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE] = {};
long long int c_diff[TREE_SIZE] = {}; // 子との差

long long int find(int a, int b, int index, long long int diff, int l, int r){
	
	// [a, b) の最大値を求める
	
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		return -INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	long long int ret = -INF;
	ret = max(ret, find(a, b, index * 2, c_diff[index], l, (l + r) / 2));
	ret = max(ret, find(a, b, index * 2 + 1, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	return ret;
}

long long int add(int a, int b, int index, long long int num, long long int diff, int l, int r){
	
	// [a, b) に num を足す
	
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] += num;
		c_diff[index] += num;
		return seg_tree[index];
	}
	
	long long int ret = -INF;
	ret = max(ret, add(a, b, index * 2, num, c_diff[index], l, (l + r) / 2));
	ret = max(ret, add(a, b, index * 2 + 1, num, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	return seg_tree[index] = ret;
}

int main(){
	
	int N, M;
	cin >> N >> M;
	
	long long int S = 0;
	
	vector<P2> v;
	P2 p = P2(P(INF, INF),0);
	v.push_back(p);
	
	for(int i = 0; i < M; i++){
		cin >> p.first.second >> p.first.first >> p.second;
		p.first.first += 1;
		p.first.second += 1;
		v.push_back(p);
		S += p.second;
	}
	
	sort(v.begin(), v.end());
	
	add(1, 2, 1, S, 0, 0, TREE_SIZE / 2);
	
	int pos = 0;
	
	for(int i = 2; i <= N + 2; i++){
		while(v[pos].first.first < i){
			add(1, v[pos].first.second, 1, -v[pos].second, 0, 0, TREE_SIZE / 2);
			pos += 1;
		}
		S = find(1, i, 1, 0, 0, TREE_SIZE / 2);
		add(i, i + 1, 1, S, 0, 0, TREE_SIZE / 2);
	}
	
	cout << S << endl;
	
	return 0;
}


Measured memory_bytes: 17516
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const long long INF =  999999999;

ll nx[29][100100];
char ch[26];
ll pos[30];
//次にch[i]が出る文字の位置
//jを今見ている位置とすると
//j>=pos[i]となるまではnext[i][j]=pos[i]

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

  int n=s.size(),m=t.size();
  vector<vector<int>> is(26);
  REP(i,n)
  is[s[i]-'a'].push_back(i);
  REP(i,n)
  is[s[i]-'a'].push_back(i+n);

  ll ans=0;
  int p=0;
  bool flag=false;

  REP(i,m){
    int c=t[i]-'a';
    if(is[c].size()==0){
      flag=true;
      break;
    }

    p=*lower_bound(is[c].begin(),is[c].end(),p)+1;
    if(p>=n){
      p-=n;
      ans+=n;
    }
  }
  ans+=p;
  cout<<(flag?-1:ans)<<endl;

}


Measured memory_bytes: 1724
#include<cstdio>
#define MAX 100000
#define SENTINEL 2000000000
struct Card{
    char suit;
    int value;
};
int n;
Card X[MAX], Y[MAX];
Card L[MAX/2+2], R[MAX/2+2];

void merge(Card A[], int left, int mid, int right){
    int n1 = mid -left;
    int n2 = right -mid;
    for(int i = 0; i<n1; i++) L[i] = A[left+i];
    for(int i=0; i< n2; i++) R[i] = A[mid+i];
    L[n1].value = R[n2].value = SENTINEL;
    
    int i=0, j=0;
    for(int k=left; k<right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card A[], int left, int right){
    if(right-left>1){
        int mid = (left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
int partition(Card A[], int p, int r){
    Card x = A[r];
    int i = p-1;
    for(int j=p; j<r;j++){
        if(A[j].value <= x.value){
            i++;
            Card temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    Card temp = A[i+1];
    A[i+1] = A[r];
    A[r] =temp;
    return i +1;
}
void quickSort(Card A[], int p, int r){
    if(p<r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main(){
    char S[10]; // 一時保存用
    int v;
    int stable=1;

    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s %d", S, &v);
        X[i].suit = Y[i].suit = S[0];
        X[i].value = Y[i].value = v;
    }

    mergeSort(X, 0, n); // マージは要素の1個外から
    
    quickSort(Y, 0, n-1);

    for(int i=0; i<n;i++){
        // マージソートとクイックソートの結果を比べる
        if(X[i].suit != Y[i].suit) stable = 0;
    }

    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");

    for(int i=0; i<n; i++){
        printf("%c %d\n", Y[i].suit, Y[i].value);
    }

    return 0;
}


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

using namespace std;

int h, w, n;
int x, y, cnt;
string s, t;

int main()
{
	cin >> h >> w >> n;
	cin >> x >> y;
	cin >> s;
	cin >> t;
	s = '#' + s;
	t = '#' + t;
	int q = 0;
	cnt = y;
	for ( int i = 1; i <= n; i ++ ){
		if( s[i] == 'R' )
			cnt ++;
		if( cnt > w ){
			cout << "NO";
			return 0;
		}
		if( t[i + q] == 'L' )
			cnt --;
		if( cnt < 1 )
			cnt = 1;
		
	}
	
	cnt = y;
	for ( int i = 1; i <= n; i ++ ){
		if( s[i] == 'L' )
			cnt --;
		if( cnt < 1 ){
			cout << "NO";
			return 0;
		}
		if( t[i + q] == 'R' )
			cnt ++;
		if( cnt > w )
			cnt = w;
		
	}
	
	cnt = x;
	for ( int i = 1; i <= n; i ++ ){
		if( s[i] == 'D' )
			cnt ++;
		if( cnt > h ){
			cout << "NO";
			return 0;
		}
		if( t[i + q] == 'U' )
			cnt --;
		if( cnt < 1 )
			cnt = 1;
		
	}
	
	
	cnt = x;
	for ( int i = 1; i <= n; i ++ ){
		if( s[i] == 'U' )
			cnt --;
		if( cnt < 1 ){
			cout << "NO";
			return 0;
		}
		if( t[i + q] == 'D' )
			cnt ++;
		if( cnt > h )
			cnt = h;
		
	}
	
	cout << "YES" << endl;
	
}


Measured memory_bytes: 904
def b():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    answer = min(a) + min(b)
    for m in range(M):
        x, y, c = map(int, input().split())
        candidate = a[x-1] + b[y-1] - c

        if answer > candidate:
            answer = candidate

    print(answer)


##########
if __name__ == "__main__":
    b()


Measured memory_bytes: 18612
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/
 
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll                          long long
#define ld                          long double
 
#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second
 
#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define  MN                           INT_MIN
#define  MX                           INT_MAX
bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
 
int32_t main()
{
	ll r,d,cur;
	cin >> r >> d >> cur;
	for(int i = 0; i < 10;i++)
	{
		cur = cur * r - d;
		cout << cur << endl;
	}
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n,x;
    cin >> n >> x;
    vector<int> L(n);
    for(int i=0;i<n;i++)cin >> L[i];

    int total=0;
    for(int i=0;i<n;i++){
        total += L[i];
        if(total>x){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n+1 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		int H = 0;
		for(int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		int j = 0;
		for(int i = 0; i <((N*(N-1))/2); i++) {
			j = i+1; 
			while(j < N) {
				int h = d[i] * d[j];
				H = h + H;
				j++;
			}
		}
		System.out.println(H);
	}
}

Measured memory_bytes: 23252
#include <iostream>

int a, b , c, d, e, f;
int main()
{
	std::cin >> a;
	
		
	
	f = a;	
	for(int i = 1; i < 10; i++)
	{
		if(a < 10)
		{
			e += a;
			break;
		}else
		{
			b = f % 10;
			c = f / 10;
			if(c == 10)
			{
				e += 1;
				e += b;
				break;
			}else if( c == 0)
			{
				e += f;
				break;
			}else
			{
				e += b;	
				f = c;
			}	
		}

	}
	//std::cout << e << std::endl;
	if( a % e == 0)
	{
		std::cout << "Yes";
	}else
	{
		std::cout << "No";
	}
	
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()


n,q = na()
g = [[] for i in range(n)]
c = [0]*n

for i in range(n-1):
    a,b = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)
for i in range(q):
    p,x = na()
    c[p-1] += x

def f(b,a,r):
    r += c[a]
    c[a] = r
    for i in g[a]:
        if i != b:
            f(a,i,r)

f(-1,0,0)
print(' '.join([str(s) for s in c]))


Measured memory_bytes: 238672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() {
    fastio
    ll x, k, d;
    cin>>x>>k>>d;

    ll temp = abs(x);
    if(temp > d) {
        ll val = temp/d;
        temp -= min(val, k)*d;
        k -= min(val, k);
    }

    ll sign = (x<0?-1:1);
    if(k%2) {
        cout<<abs(temp-d)<<endl;
    }
    else {
        cout<<abs(temp)<<endl;
    }
}

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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const int INF = 1 << 29;

signed main() {
	int h, w;
	while (cin >> h >> w && h) {
		V hs(h), ws(w);
		input(hs); input(ws);
		if (hs.size() < ws.size()) swap(hs, ws);
		sort(all(hs));
		sort(all(ws));
		int ans = 0;
		int idx = 0;
		rep(i, hs.size()) breakif(idx >= ws.size()) {
			while (hs[i] > ws[idx]) idx++;
			if (hs[i] == ws[idx]) {
				ws[idx] = 0;
			}
		}
		cout << accumulate(all(hs), 0) + accumulate(all(ws), 0) << endl;
	}
}

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

def f(X):
    return sum([X ^ a for a in A])

if K==0:
    print(f(0))
else:
    l = len(bin(K)[2:])
    a_bit = [N - 2*sum([(a>>i) & 1 for a in A]) for i in range(l)]
    k_bit = [a > 0 for a in a_bit]
    k = 0
    ans = f(0)
    for j in range(l):
        for i,b in enumerate(k_bit[::-1],1):
            if i==j:continue
            if b and (k + (1<<(l-i)) <= K):
                k += (1<<(l-i))
        ans = max(ans,f(k))
    print(ans)

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

using namespace std;

int N;

int main()
{
    cin >> N;
    vector<pair<int, int>> pi(N);

    for (int i = 0; i < N; i++)
    {
        cin >> pi[i].first;
        pi[i].second = i + 1;
    }

    sort(pi.begin(), pi.end());

    for (int i = 0; i < N; i++)
    {
        cout << pi[i].second << " ";
    }
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[55555];
        int c = 2;
        isNotPrime[0] = true;
        isNotPrime[1] = true;
        while (c < isNotPrime.length){
            for (int k = c;k < isNotPrime.length;k += c){
                isNotPrime[k] = true;
            }
            isNotPrime[c] = false;
            ++c;
            if(c >= isNotPrime.length){
                break;
            }
            //System.out.println(c);
            while (isNotPrime[c]){
                ++c;
                if(c >= isNotPrime.length){
                    break;
                }
            }
        }
        int now[] = new int[n];
        now[0] = 2;
        int k = 1;
        for (int i = 1;i < n;++i){
            while (true){
                k += 2;
                if(!isNotPrime[k]){
                    now[i] = k;
                    break;
                }
            }
        }
        while (true){
            k += 2;
            if(!isNotPrime[k]){
                break;
            }
        }
        search(n,isNotPrime);
        //sout
    }


    public static void search(int n,boolean[] isNotPrime){
        int[] ret = new int[n];
        ret[0] = 2;
        ret[1] = 11;
        int last = 11;
        for (int i = 2;i < n;++i){
            while (true){
                last += 5;
                if(!isNotPrime[last]){
                    ret[i] = last;
                    break;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0;i < ret.length;++i){
            sb.append(ret[i]);
            if(i + 1 != ret.length){
                sb.append(' ');
            }
        }
        System.out.println(sb.toString());
    }







}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  rep(i, 2 * k - 1) {
      cout << x - k + 1 + i << " ";
  }
  cout << endl;
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if( A - C >= -1 * D && A - C <= D ){
    cout << "Yes" << endl;
  }else{
    if( ( A-B >= -1*D && A-B <= D ) && ( B-C >= -1*D && B-C <= D ) ){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

#define    ll     long long int

int main( )
{
    int n, i, j;
    map<int, int> mp;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        mp[j]++;
        if (mp[j] == 2) {
            mp.erase(mp.find(j));
        }
    }
    cout << (int) mp.size() << '\n';
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    bool a=true;
    if(S.size()%2==1) a=false;
    else for(int i=0;i<S.size()/2;i++){
        if(S.at(i*2)!='h'||S.at(i*2+1)!='i') a=false;
    }
    if(a)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys

N = int(input())
li = list(map(int,input().split()))
li.reverse()

for i in range(N-1):
  if li[i+1] >= li[i]+2:
    print("No")
    sys.exit()
    
  elif li[i+1] == li[i]+1:
    li[i+1] = li[i]
    
  else: continue
    
print("Yes")

Measured memory_bytes: 14396
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
l = []


for i in range(len(a) - 1):
    if a[i + 1] < a[i]:
        l.append(a[i]-a[i + 1])
        a[i + 1] = a[i]


print(sum(l))



Measured memory_bytes: 32236
#include <stdio.h>

int main()
{

 int a, b, c, count;
 scanf("%d %d %d\n", &a, &b, &c);
 for(a; a <= b; a++)
 {
     if(c % a == 0)
     {
         count++;
     }
 }
 printf("%d\n", count);
 return 0;

}

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

int main(){
    string s; cin >> s;
    if(s.at(s.size()-1)=='3') cout << "bon" << endl;
    else if(s.at(s.size()-1)=='0' || s.at(s.size()-1)=='1' || s.at(s.size()-1)=='6' || s.at(s.size()-1)=='8')
    cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

using namespace std;

const int maxn = 2e5+10;

vector<int> grafo[maxn];

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

	int n;

	cin >> n;

	for(int i=2; i<=n; i++){
        int p;

        cin >> p;

        grafo[p].push_back(i);
	}

	for(int i=1; i<=n; i++){
        //if(i == 1) cout << grafo[i].size() << endl;
        cout << grafo[i].size() << endl;
	}

	return 0;
}


Measured memory_bytes: 14528
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a_first)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

vector<vector<ll> > Comb(int n){
  vector<vector<ll> > v(n+1,vector<ll>(n+1));
  for(int i=0;i<=n;i++) v[i][i] = v[i][0] = 1LL;
  for(int i=2;i<=n;i++) {
    for(int j=1;j<i;j++) v[i][j] = v[i-1][j] + v[i-1][j-1];
  }
  return v;
}

void Main() {
  vector<vector<ll> > v=Comb(66);
  ll n;
  while(R n&&n) {
    string ans="";
    ll x=0,t=2,xx,yy,zz;
    while(1) {
      REP(i,1,10) {
        ll x2=x;
        rep(j,t-1) {
          ll y=x+v[t-1][j]*9;
          if(y>=n) {
            zz=x2;
            xx=t;
            yy=i;
            ans+=(char)(i+'0');
            goto end;
          }
          x=y;
        }
      }
      t++;
    }
  end:;
    set<int> s;
    s.in(yy);
    rrep(l,xx) {
      if(!l) break;
      x=zz;
      if(s.size()<2) {
        rep(i,10) {
          if(l==1&&i==*s.begin()) continue;
          ll x2=x;
          rep(j,l) {
            ll y=x;
            if(i==*s.begin()) {
              if(j<l-1) y+=v[l-1][j]*9;
              else continue;
            } else y+=v[l-1][j];
            if(y>=n) {
              zz=x2;
              s.in(i);
              ans+=(char)(i+'0');
              goto next;
            }
            x=y;
          }
        }
      } else {
        tr(it,s) {
          ll x2=x;
          rep(j,l) {
            ll y=x+v[l-1][j];
            if(y>=n) {
              zz=x2;
              ans+=(char)(*it+'0');
              goto next;
            }
            x=y;
          }
        }
      }
    next:;
    }
    pr(ans);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 3236