akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
int[] ary = new int[3];
		ary[0] = sc.nextInt();
		ary[1] = sc.nextInt();
		ary[2] = sc.nextInt();
		
if(ary[0] > ary[1]){
int cap = ary[0];
ary[0] = ary[1];
ary[1] = cap;
}
if(ary[1] > ary[2]){
int cap = ary[1];
ary[1] = ary[2];
ary[2] = cap;
}
if(ary[0] > ary[1]){
int cap = ary[0];
ary[0] = ary[1];
ary[1] = cap;
}

int cost = 0;
cost += Math.abs(ary[1]-ary[0]);
cost += Math.abs(ary[2]-ary[1]);
System.out.println(cost);
	}
}

Measured memory_bytes: 21844
<?php
fscanf(STDIN, "%d", $N);

$inputs = trim(fgets(STDIN));
$inputs = array_map("intval", explode(" ", $inputs));
sort($inputs);
// var_dump($inputs);

$ans = 0;
if ($N < 3) {
    echo 0 . "\n";
    exit;
}
for ($i = 0; $i < $N-2; $i++) {
    for ($j = $i+1; $j < $N-1; $j++) {
        for($k = $j+1; $k < $N; $k++) {
            if ($inputs[$i] == $inputs[$j] ||  $inputs[$i] == $inputs[$k] || $inputs[$j] == $inputs[$k]) continue;
            if ($inputs[$i] + $inputs[$j]  > $inputs[$k] &&  $inputs[$i] + $inputs[$k] > $inputs[$j] && $inputs[$j] + $inputs[$k] > $inputs[$i]) {
                // echo $inputs[$i] . $inputs[$j] . $inputs[$k] . "\n";
                $ans++;
            }
        }
    }
}
echo $ans . "\n";

Measured memory_bytes: 16224
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 255001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

int n , a[N] , ans;

signed main(){
    cin >> n ;
    for(int i = 0 ; i < n<<1 ; i++)cin >> a[i];
    sort(a,a+((n)<<1));
    for(int i = 0 ; i < n ; i++)ans+=a[i<<1];
    cout << ans << endl;





}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())

# グラフをリストとして表現する
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

# 原点1からの距離を記録する
d = [0] + [-1] * (N-1)

que = deque()
que.append(0)

while que:
    p = que.popleft()
    for v in G[p]:
        if d[v] < 0:
            d[v] = p+1
            que.append(v)


if min(d[1:]) < 0:
    print('No')
else:
    print('Yes')
    for g in d[1:]:
        print(g)


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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)

int main(){
  ll n,sum = 0;// sum は数列 a の全要素の和
  cin >> n;
  vector<ll> a(n),s(2*n+2,0);
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }
  rep(i, 2*n) s[i+2] = s[i] + a[(i%n)];//累積和

  int m = n/2;
  rep(i, n){
    ll ans = sum;
    ans -= 2*(s[i+1+2*m]-s[i+1]);
    std::cout << ans << '\n';
  }
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int sum;
  while(cin >> str && str!="0"){
    sum = 0;
    for(int i=0,l=str.size();i<l;i++) sum += str[i]-'0';
    cout << sum << endl;
  }
}


Measured memory_bytes: 3200
# import math


def get_int_args():
    args = input().split()
    return list(map(int, args)), len(args)


def get_str_args():
    return input().split()


if __name__ == '__main__':
    a, b = input(), input()
    min = 1e10
    for i in range(len(a) - len(b) + 1):
        c = 0
        for j in range(len(b)):
            if a[i + j] != b[j]:
                c += 1
        if c < min:
            min = c
    print(min)

Measured memory_bytes: 9124
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  1000007
#define md 1000000007ll
///////////////////////////
///////////////////////////

int main(){
    int n;
    I(n);
    if(n <=999)cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;
    return 0;
}

Measured memory_bytes: 3636
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func blSprit(str string) []string {
        cols := strings.Split(str, "")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        spl := strSprit(line)

        H := parseInt(spl[0])
        W := parseInt(spl[1])

        r := make([][]string, H)
        o := [][]string{}
        fls := make([]bool, W)
        for i := 0; i < H; i++ {
                r[i] = make([]string, W)
                l := nextLine()
                r[i] = blSprit(l)
                fl := false

                for j := 0; j < W; j++ {
                        if r[i][j] == "#" {
                                fl = true
                                fls[j] = true
                        }
                }

                if fl {
                        o = append(o, r[i])
                }
        }

        for n := 0; n < len(o); n++ {
                for i, f := range fls {
                        if f {
                                fmt.Print(o[n][i])
                        }
                }
                fmt.Println()
        }

}


Measured memory_bytes: 1280
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <deque>

#include <algorithm>

#include <cfenv>
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;
int main()
{

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<ll> As(A);
    vector<ll> Bs(B);
    vector<ll> Cs(C);

    vector<ll> Ds(0);

    for (int i = 0; i < A; i++)
    {

        cin >> As[i];
    }

    for (int i = 0; i < B; i++)
    {

        cin >> Bs[i];
    }

    for (int i = 0; i < C; i++)
    {

        cin >> Cs[i];
    }

    sort(As.begin(), As.end(), greater<ll>());
    sort(Bs.begin(), Bs.end(), greater<ll>());
    sort(Cs.begin(), Cs.end(), greater<ll>());

    ll sum = 0;

    for (int i = 0; i < X; i++)
    {

        sum += As[i];

        Ds.push_back(As[i]);
    }

    for (int i = 0; i < Y; i++)
    {

        sum += Bs[i];

        Ds.push_back(Bs[i]);
    }

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

    for (int i = 0; i < Y + X; i++)
    {

        if (i == C)
        {

            break;
        }

        if (Ds[i] <= Cs[i])
        {

            sum = sum + Cs[i] - Ds[i];
        }
        else
        {
            break;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 7656
/*g++ main.cpp -o main.out*/
/*./main.out*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if((a[0]==a[1]&&a[1]!=a[2])||(a[2]==a[1]&&a[1]!=a[0]))
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
from collections import deque
N = int(input())
a = list(map(int, input().split()))
d = deque(a)

cnt = 0
tmp = 1
i = 0
for _ in range(N):
  D = d.popleft()
  if D == tmp:
    tmp += 1
    i = 1
  else:
    cnt += 1
    
if i != 1:
  print(-1)
else:
  print(cnt)


  

Measured memory_bytes: 26780
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<string.h>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<map>
#include<stack>
#include<list>
#include<assert.h>
#define INF 0x3f3f3f3f
#define LLINF 1e16
#define pii pair<int, int>
#define pll pair<LL, LL>
#define pil pair<int, LL>
#define pli pair<LL, int>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9+7;
const int HMOD = 999959;
const int VMOD = 5000000;
const int MAXN = 1e4+10;
const int INV = 500000004;
const double eps = 1e-8;
int Next[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};

LL xr[MAXN], a[MAXN];
int n;
char s[210];

int main()
{
#ifdef LOCAL_JUDGE
	freopen("test.in", "r", stdin);
	//freopen("test.out", "w", stdout);
#endif
IOS;
	int t;
	scanf("%d", &t);
	while (t--)
	{
		memset(xr, 0, sizeof(xr));
		scanf("%d", &n);
		for (int i = 1;i <= n; ++i)
			scanf("%lld", &a[i]);
		scanf("%s", s+1);
		bool ok = 1;
		for (int i = n; i >= 1; --i)
		{
			if (s[i] == '0')
			{
				for (int j = 60;j >= 0; --j) if ((a[i] >> j) & 1)
				{
					if (xr[j] == 0)
					{
						xr[j] = a[i];
						break;
					}
					a[i] ^= xr[j];
				}
			}
			else
			{
				for (int j = 60;j >= 0; --j) if ((a[i] >> j) & 1)
					a[i] ^= xr[j];
				if (a[i]) ok = 0;
			}
		}
		printf("%d\n", ok ? 0 : 1);
	}


	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int x,a,b;

	scanf("%d %d %d",&x,&a,&b);

	if(b-a <= 0){

		printf("delicious\n");

	}else if(b-a <= x){

		printf("safe\n");

	}else{

		printf("dangerous\n");
	}

	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> eratosthenes(10'000'000,0);
    eratosthenes[0] = eratosthenes[1] = 1;
    for(int i=2; i<10'000'000; i++){
        if(eratosthenes[i]==0){
            for(int j=i+i; j<10'000'000; j+=i){
                eratosthenes[j] = 1;
            }
        }
    }
    vector<int> sosu;
    for(int i=0; i<10'000'000; i++){
        if(eratosthenes[i] == 0) sosu.push_back(i);
    }
    int N,p;
    cin >> N >> p;
    while(N != -1){
        int pos = upper_bound(sosu.begin(),sosu.end(),N) - sosu.begin();
        vector<int> vec;
        for(int i=0; i<p; i++){
            for(int j=i; j<p; j++){
                vec.push_back(sosu[pos+i]+sosu[pos+j]);
            }
        }
        sort(vec.begin(),vec.end());
        cout << vec[p-1] << endl;
        cin >> N >> p;
    }
    return 0;
}


Measured memory_bytes: 45960
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ans=0
res=float('inf')
for i in range(n):
  if abs(t-h[i]*float(0.006)-a)<res:
    res=abs(t-h[i]*float(0.006)-a)
    ans=i+1
print(ans)

Measured memory_bytes: 9268
import qualified Data.IntMap as IM

main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine
  bm <- IM.fromList . zip [1..] . map read . words <$> getLine
  cm <- IM.fromList . zip [1..] . map read . words <$> getLine
  print $ solve bm cm as

solve :: IM.IntMap Int -> IM.IntMap Int -> [Int] -> Int
solve bm cm as = sb + sc
  where
    sb = sum [ bm IM.! a | a <- as ]
    sc = sum [ cm IM.! a | a <- [ a1 | (a1, a2) <- zip as (tail as), a2 == a1 + 1 ] ]


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,a,b;
  cin>>n>>m;
  vector<int> vec(n,0);
  for(int i=0; i<m; i++){
    cin>>a>>b;
    for(int j=1; j<=2*n; j++){
      if(j==a|j==b){
        vec.at(j-1)++;
      }
    }
  }
  
  for(int i=0; i<n; i++){
    cout<<vec.at(i)<<endl;
  }
}

Measured memory_bytes: 256
n=int(input())
l=[[0]*10 for i in range(10)]

for i in range(1,min(10,n+1),1):
    l[i][i]+=1

if len(str(n))>=2:
    for k in range(2,len(str(n)),1):
        for i in range(1,10,1):
            for j in range(1,10,1):
                l[i][j]+=10**(k-2)

    for i in range(1,int(str(n)[0]),1):
        for j in range(1, 10, 1):
            l[i][j] += 10**(len(str(n))-2)
    if len(str(n))>=3:
        for j in range(1, 10, 1):
            if j<=int(str(n)[-1]):
                l[int(str(n)[0])][j]+=int(str(n)[1:-1])+1
            else:
                l[int(str(n)[0])][j] += int(str(n)[1:-1])
    else:
        for j in range(1, 10, 1):
            if j<=int(str(n)[-1]):
                l[int(str(n)[0])][j]+=1

t=0
for i in range(1,10,1):
    for j in range(1,10,1):
        t+=l[i][j]*l[j][i]

print(t)

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

int main () {
    string wea;
    cin >> wea;
    
    if(wea == "RRS") cout << 2 << endl;
    else if(wea == "SRR") cout << 2 << endl;
    else if(wea == "RRR") cout << 3 << endl;
    else if(wea == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 924844033;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 2010
ll dp[N], dp2[2][N][2], n, k;

ll inv[N], fact[N], ifact[N];
 
void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n; i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

int main(){
	init_fact();
	cin>>n>>k;
	dp[0] = 1;
	rep(i, min(2*k, n)){
		mset(dp2, 0);
		dp2[0][0][i<k] = 1;
		int t = 0;
		for(int j = i; j < n; j+=2*k){
			t = !t;
			mset(dp2[t], 0);
			for(int l = n/k+2; l >= 0; l--){
				(dp2[t][l][0]+=dp2[!t][l][0]+dp2[!t][l][1])%=mod;
				(dp2[t][l+1][0]+=dp2[!t][l][0])%=mod;
				if(j+k<n) (dp2[t][l+1][1]+=dp2[!t][l][0]+dp2[!t][l][1])%=mod;
			}
		}
		for(int j = n; j > 0; j--){
			for(int l = 1; l <= min<ll>(j, n/k+2); l++){
				(dp[j]+=dp[j-l]*(dp2[t][l][0]+dp2[t][l][1]))%=mod;
			}
		}
	}
	ll res = 0;
	rep(i, n+1){
		(res+=dp[i]*fact[n-i]*(i%2?-1:1))%=mod;
	}
	(res+=mod)%=mod;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			System.out.println(Math.max(a + b, Math.max(a - b, a * b)));
		}
	}
}


Measured memory_bytes: 35540
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	cout << n*(n+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
D=dict()
s=0
for i in A:
  s+=i
  if i in D:
    D[i]+=1
  else:
    D[i]=1
for _ in range(Q):
  b,c=map(int,input().split())
  if b in D:
    s+=(c-b)*D[b]
    if c in D:
      D[c]+=D[b]
    else:
      D[c]=D[b]
    del D[b]
  print(s)

Measured memory_bytes: 20848
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main() {
    LL a, result;
    string b;
    int intb;

    cin >> a >> b;

    intb = 0;
    for (int i = 0; i < b.length(); i++) {
        if (b[i] != '.')
            intb = 10*intb + (b[i] - '0');
    }

    result = a * intb;

    cout << result/100 << endl;
}


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

int main()
{
	int num;
	cin >> num;

	long long A[101] = {};
	long long B[100] = {};

	for (int i = 0; i < num-1; i++)
	{
		cin >> B[i];
	}

	for (int i = 0; i < num; i++)
	{
		if (i == 0)
		{
			A[i] = B[i];
		}
		else if (i == num - 1)
		{
			A[i] = B[i - 1];
		}
		else
		{
			if (B[i] < B[i - 1])A[i] = B[i];
			else A[i] = B[i - 1];
		}
	}

	int sum = 0;
	for (int i = 0; i < num; i++)
	{
		sum += A[i];
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

std::vector<std::vector<int>> edges_from;
std::vector<bool> visited;
int n,k;
ll ans;

void dfs(int nd, int possibility, int depth){

    visited[nd] = true;

    rep(i,edges_from[nd].size()){
        int next_nd = edges_from[nd][i];
        if(visited[next_nd]) continue;


        possibility -= 1;
        //cout << next_nd << " " << possibility << endl;
        ans *= possibility;
        ans %= MOD;

        dfs(next_nd, k-1, depth+1);

    }

    return;
}

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

    cin >> n >> k;
    edges_from = std::vector<std::vector<int>>(n);
    visited = std::vector<bool>(n, false);

    rep(i,n-1){
        int a,b; cin >> a >> b; a--; b--;
        edges_from[a].push_back(b);
        edges_from[b].push_back(a);
    }

    ans = k;

    dfs(0,k,0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long solve(vector<vector<long>>& dp,vector<vector<int>>& edge,int root,int colour,int ptr){
    if(dp[root][colour]!=-1){
        return dp[root][colour];
    }
    long w1 = 1;
    long w2 = 1;
    long ans = 0;
    for(int i=0;i<edge[root].size();i++){
        if(edge[root][i]!=ptr)
        {
        w1 = ((w1%mod)*(solve(dp,edge,edge[root][i],0,root)%mod))%mod;
        }
    }
    ans = (ans%mod + w1%mod)%mod;
    //int w2 = 1;
    if(colour==0){
      for(int i=0;i<edge[root].size();i++){
        if(edge[root][i]!=ptr)
        {
        w2 = ((w2%mod)*(solve(dp,edge,edge[root][i],1,root)%mod))%mod;
        }
    }
    ans = (ans%mod +  w2%mod)%mod;
    }
    return dp[root][colour] = ans%mod;
}
int main() {
	int n;
	cin>>n;
	vector<vector<int>> edge(n+1);
	for(int i=0;i<n-1;i++){
	    int a,b;
	    cin>>a>>b;
	    edge[a].push_back(b);
	    edge[b].push_back(a);
	}
// 	for(int i=1;i<=n;i++){
// 	    for(auto m: edge[i]){
// 	        cout<<i<<' '<<m<<'\n';
// 	    }
// 	}
	vector<vector<long>> dp(n+1,vector<long>(2,-1));
	//vector<int> vis(n+1,0);
	cout<<solve(dp,edge,1,0,-1)<<'\n';
	return 0;
}


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

int n, k;
int a[100001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    if (n == k)
        cout << 1 << endl;
    else {
        
        int ans = 1;
        for (int i = k; i < n;) {
            ans++;
            i += (k-1);
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 256
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
import math
import sys
# input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

n,k=map(int, input().split())
path = inlt()
dp = [float('inf')] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i + k + 1):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(path[j] - path[i]))
print(dp[n - 1])

Measured memory_bytes: 55608
N, M = map(int, input().split())
Hs = input().split()
lis = []
for i in range(N):
  lis.append([])
for m in range(M):
  A, B = map(int, input().split())
  lis[A-1].append(B-1)
  lis[B-1].append(A-1)

score = 0

for i in range(N):
  break_flag = 0
  base_h = int(Hs[i])
  #print('base',base_h)
  hikaku = lis[i]
  #print('hikaku', hikaku)
  for j in range(len(hikaku)):
    #print('hikaku', hikaku[j])
    if int(Hs[hikaku[j]]) >= base_h:
      break_flag = 1
  if break_flag != 1:
    score += 1
print(score)

Measured memory_bytes: 32940
S=input()
flg=0

for i in range(len(S)):
    if i%2 == 0:
        if S[i] == 'L':
            flg=1
    else:
        if S[i] == 'R':
            flg=1
if flg == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn is_pali(x: u64) -> bool{
    let mut v = vec![];
    let mut x = x;

    while x > 0{
        v.push(x%10);
        x /= 10;
    }

    let rev = v.clone();
    v.reverse();
    return rev == v;
}

fn main(){
    let line = read_as_vec::<u64>();
    let (a, b) = (line[0], line[1]);

    let mut ans = 0;
    for i in a..b+1{
        if is_pali(i){
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

int main() {
  int N;
  cin >> N;
  if (((N / 1000 == (N % 1000) / 100) && ((N % 1000) / 100 == (N % 100) / 10)) ||
     (((N % 1000) / 100 == ((N % 100) / 10)) && ((N % 100) / 10 == N % 10))) {
    cout << "Yes" << endl;
    }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if (a < b && a < c) {
        if (b < c) {
            cout << a << " " << b << " " << c << "\n";
        } else {
            cout << a << " " << c << " " << b << "\n";
        }
    } else if (b < c) {
        if (a < c) {
            cout << b << " " << a << " " << c << "\n";
        } else {
            cout << b << " " << c << " " << a << "\n";
        }
    } else {
        if (a < b) {
            cout << c << " " << a << " " << b << "\n";
        } else {
            cout << c << " " << b << " " << a << "\n";
        }
    }
    
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  std::string S;
  std::cin >> S;
  int Q;
  scanf("%d", &Q);
  //printf("Q=%d\n",Q);
  std::vector<int > T(Q), F(Q);
  std::vector<char > C(Q);
  for (int i=0; i<Q; i++){
    //printf("i=%d\n", i);
    scanf("%d", &T[i]);
    if (T[i]==1){
      F[i]=-1;
      C[i]='?';
    } else {
      std::cin >> F[i] >> C[i];
      //scanf("%d", &F[i]);
      //scanf("%c", &C[i]);
    }
    //printf("F[%d]=%d\n", i, F[i]);
    //printf("C[%d]=%c\n", i, C[i]);
  }
  std::vector<char > ans;
  std::vector<char > ans_inverse;
  for (int i=0; i<S.length(); i++){
    ans.push_back(S[i]);
  }
  int order = 1;
  for (int i=0; i<Q; i++){
    if (T[i]==1){
      order *= -1;
    } else {
      if ((F[i]==2 && order==1)||(F[i]==1 && order==-1)){
        ans.push_back(C[i]);
      } else {
        ans_inverse.push_back(C[i]);
      }
    }
  }
  std::string output;
  if (order==1){
    for (int i=ans_inverse.size()-1; i>=0; i--){
      output+=ans_inverse[i];
    }
    for (int i=0; i<ans.size(); i++){
      output+=ans[i];
    }
  } else {
    for (int i=ans.size()-1; i>=0; i--){
      output+=ans[i];
    }
    for (int i=0; i<ans_inverse.size(); i++){
      output+=ans_inverse[i];
    }
  }
  std::cout << output << std::endl;
  return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

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

using namespace std;
int mod = 1000000007;

int N;
int main() {
  cin >> N;
  vector<bool> F[N];
  vector<int> P[N];
  rep(i, N) {
    rep(j, 10) {
      int f;
      cin >> f;
      F[i].push_back(f);
    }
  }
  rep(i, N) {
    rep(j, 11) {
      int p;
      cin >> p;
      P[i].push_back(p);
    }
  }

  int ans = INT_MIN;
  vector<int> S(N);
  for (int i=1; i<1024; i++) {
    rep(j, 10) {
      rep(k, N) {
        if (i >> j & 1) {
          if (F[k].at(j)) {
            S.at(k)++;
          }
        }
      }
    }
    // cout << S.at(0) << "," << S.at(1) << endl;
    int now = 0;
    rep(k, N) {
      now += P[k].at(S.at(k));
      S.at(k) = 0;
    }
    ans = max(ans, now);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

n_buf = [0 for i in range(n)]
path_buf = []

now = 1
while True:
    n_buf[now - 1] = 1
    _next = a[now - 1]
    path_buf.append(now)
    if n_buf[_next - 1] == 1:
        path_buf.append(_next)
        break

    now = _next

index = path_buf.index(path_buf[-1])
sa = len(path_buf) - index - 1


if k >= len(path_buf):
    ans = (k - len(path_buf) + 1) % sa
    ans = path_buf[-sa-1:-1][ans]

    print(ans)
else:
    ans = path_buf[k]
    print(ans)

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

int main(){
    string T;
    cin >> T;
    int i;
    for(i=0; i<T.length(); i++){
        if(T[i]=='?'){
            cout << 'D';
        }else{
            cout << T[i];
        }
    }
    cout << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, pii> plp;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    lint a[n];
    rep(i, n) scanf("%lld", &a[i]);
    
    lint b[n][32];
    lint t = 1;
    rep(i, 32){
        rep(j, n){
            b[j][i] = a[j] / t;
        }
        t *= 2;
    }
    
    priority_queue<plp> que;
    rep(i, n) que.push(plp(b[i][0] - b[i][1], pii(i, 0)));
    while(m--){
        plp p = que.top(); que.pop();
        lint d = p.fi;
        int i = p.se.fi;
        int j = p.se.se;
        if(d == 0) break;
        que.push(plp(b[i][j+1] - b[i][j+2], pii(i, j+1)));
    }
    
    lint ans = 0;
    while(!que.empty()){
        plp p = que.top(); que.pop();
        int i = p.se.fi;
        int j = p.se.se;
        ans += b[i][j];
    }
    
    printf("%lld\n", ans);
}

Measured memory_bytes: 28148
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]){
    cout << "Yes\n";
    return 0;
  }
  if(s[1] == s[2] && s[2] == s[3]){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    vector<int> plus = {a[0]};
    vector<int> minus = {a[n-1]};
    for(int i=1;i<n-1;i++){
        if(a[i] > 0) plus.push_back(a[i]);
        else minus.push_back(a[i]);
    }
    int c = 0;
    int ans = 0;
    vector<P> xy(n-1);
    if(plus.size() == 1){
        xy[c++] = P(plus[0],minus[0]);
        ans = plus[0] - minus[0];
        for(int i=1;i<minus.size();i++){
            xy[c++] = P(ans,minus[i]);
            ans -= minus[i];
        }
    }else{
        xy[c++] = P(minus[0],plus[0]);
        ans = minus[0] - plus[0];
        for(int i=1;i<plus.size()-1;i++){
            xy[c++] = P(ans,plus[i]);
            ans -= plus[i];
        }
        xy[c++] = P(plus.back(),ans);
        ans = plus.back() - ans;
        for(int i=1;i<minus.size();i++){
            xy[c++] = P(ans,minus[i]);
            ans -= minus[i];
        }
    }
    cout << ans << endl;
    rep(i,n-1) cout << xy[i].first << " " << xy[i].second << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <atcoder/math>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace atcoder;

vector<pair<ll,ll>> primeFactorDecomp(ll n){
      vector<pair<ll,ll>> ret;
      ll m=n;
      for(ll i=2;i*i<=m;i++){
            if(n%i!=0) continue;
            int cnt=0;
            while(n%i==0){
                  cnt++;
                  n/=i;
            }
            ret.push_back({i,cnt});
      }
      if(n>1){
            ret.push_back({n,1});
      }
      return ret;
}

ll s[200020];

ll solve(ll n){
  if(n==1)return 1;
  vector<pair<ll,ll>> v=primeFactorDecomp(n);
  if(v.size()==1){
    if(v[0].first==2){
      return 2*n-1;
    }else{
      return n-1;
    }
  }
  ll ret=longinf;
  ll num=v.size();
  ll x=1;
  rep(i,num)x*=2;
  for(ll i=1;i<x;i++){
    vector<ll> r,m;
    ll M=1;
    rep(j,num){
      M=1;
      rep(_,v[j].second){
        M*=v[j].first;
      }
      if(i & (1 << j)){
        r.push_back(0);
        m.push_back(solve(M)+1);
      }else{
        r.push_back((solve(M)+1+solve(M))%(solve(M)+1));
        m.push_back(solve(M)+1);
      }
    }
    if(crt(r,m).first==0){
      ret=min(ret,crt(r,m).second);
    }else{
      ret=min(ret,crt(r,m).first);
    }
//    cout << r[0] << ' ' << m[0] << endl;
//    cout << r[1] << ' ' << m[1] << endl;
//   cout << crt(r,m).second << ' ' << crt(r,m).first << endl;
  }
  return ret;
}

int main(){
  ll n;
  cin >> n;
  cout << solve(n) << endl;
  
return 0;}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
    int k,n,sum=0;
    cin>>n>>k;
    vector<int> fruit(n);
    for (int i = 0; i < n; i++)
    {
        cin>>fruit[i];
    }
    sort(fruit.begin(),fruit.end());
    if (n<k)
    {
        sum=(k/n)*accumulate(fruit.begin(),fruit.end(),0);
        for (int i = 0; i < (k%n)-1; i++)
        {
            sum=sum+fruit[i];
        }
        
    }else{
        for (int i = 0; i < k; i++)
        {
         sum=sum+fruit[i];   
        }
        
    }
    cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;

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

		String s = sc.next();

		boolean f = true;

		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				if (s.substring(i, i + 1).equals("L")) {
					f = false;
				}
			} else {
				if (s.substring(i, i + 1).equals("R")) {
					f = false;
				}
			}
		}

		if (f) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//以上テンプレ
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}


int main(){
    long double a,b,c;
    cin>>a>>b>>c;
    long double ra=sqrt(a);
    long double rb=sqrt(b);
    if(a+b+2*ra*rb<c){
        cY;
    }else{
        cN;
    }
    }


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

int main(){
  int h,n;
  cin>>h>>n;
  vector<int> dp(h+1,200000000);
  dp[0] = 0;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    rep(j,h+1){
      dp[j] = min(dp[j],dp[max(0,j-a)]+b);
    }
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
ll INF = 10010001010;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int M;
    cin >> M;
    cout << (24 - M) + 24 << endl;
}


Measured memory_bytes: 256
s=["","",""]
s[0]=input()
s[1]=input()
s[2]=input()
c={"a":0,"b":1,"c":2,0:"a",1:"b",2:"c"}
def f(i):
    
    k = c[s[i][:1]]
    s[i] = s[i][1:]
    if len(s[k])==0:
        print(c[k].upper())
        return 
    f(k)

f(0)


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

int main() {
    int A, B;
    cin >> A;
    cin >> B;

    if(A+B >= A-B && A+B >= A*B){
        cout << A+B << endl;
    }

    else if(A-B >= A+B && A-B >= A*B){
        cout << A-B << endl;
    } 

    else if(A*B >= A+B && A*B >= A-B){
        cout << A*B << endl;
    }
}

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

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

	int lim = min(n,k);
	int ans = 0;
	for(int l=0; l<=lim; l++){
		for(int r=0; r<=lim-l; r++){
			int d = k-l-r;
			int point = 0;
			vector<int> s;

			for(int i=0; i<l; i++){
				s.push_back(v[i]);
				point += v[i];
			}
			for(int j=0; j<r; j++){
				s.push_back(v[n-1-j]);
				point += v[n-1-j];
			}

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

			for(int i=0; i<d; i++){
				if(i >= s.size()) break;
				if(s[i] > 0) break;
				point -= s[i];
			}

			ans = max(ans,point);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int w = sc.nextInt();
			int d = sc.nextInt();
			if (w == 0) {
				break;
			}
			int[] hw = new int[w];
			int[] hd = new int[d];
			for(int i=0;i<w;i++) {
				hw[i] = sc.nextInt();
			}
			for(int i=0;i<d;i++) {
				hd[i] = sc.nextInt();
			}
			boolean[] ok = new boolean[w];
			int cost = 0;
			for(int i=0;i<d;i++) {
				for(int j=0;j<w;j++) {
					if (hd[i] == hw[j] && !ok[j]) {
						ok[j] = true;
						break;
					}
				}
				cost += hd[i];
			}
			for(int j=0;j<w;j++) {
				if (!ok[j]) {
					cost += hw[j];
				}
			}
			System.out.println(cost);
		}

	}

}

Measured memory_bytes: 29832
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,l;
    cin >> n>>l;
    string s[n];
    rp(i,n) cin >> s[i];
    sort(s,s+n);
    rp(i,n) cout << s[i];


    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
from collections import deque
def main():
    N, M = (int(_) for _ in input().split())
    AB = [[int(_) for _ in input().split()] for __ in range(M)]
    edg = {}
    for ab in AB:
        a, b = ab
        if a in edg.keys():
            edg[a].append(b)
        else:
            edg[a] = [b]
        if b in edg.keys():
            edg[b].append(a)
        else:
            edg[b] = [a]

    def ikeru(i, j):
        visited = [False] * (N+1)
        d = deque()
        visited[i] = True
        for k in edg[i]:
            if k != j:
                d.append(k)
        while d:
            p = d.popleft()
            visited[p] = True
            for k in edg[p]:
                if not visited[k]:
                    d.append(k)
        return visited[j]

    ret = 0
    for i in range(M):
        a, b = AB[i]
        ret += not ikeru(a, b)
    print(ret)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,f=0,cnt=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b)cnt++;
		else cnt=0;
		if(cnt==3)f=1;
	}
	if(f)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3760
a,b,c,x,y = (int(i) for i in input().split())
if x<y:
	print(min(c*2*x+b*(y-x),c*2*y,a*x+b*y))
else:
	print(min(c*2*y+a*(x-y),c*2*x,a*x+b*y))

Measured memory_bytes: 3316
def main():
    
    n,d = map(int,input().split())
    count = 0
    
    xy = [map(int, input().split()) for _ in range(n)]
    x, y = [list(i) for i in zip(*xy)]
    
    for i in range(n):
        ans = x[i]**2 + y[i]**2
        if ans <= d**2:
            count = count+1 
    
    print(count)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 116576
<?php
list($n, $k) = explode(' ', trim(fgets(STDIN)));

$probability = 0;
for ($i = 1; $i <= $n; $i++) {
	$now = $i;
    $tmp = 1.0 / $n;
  	while ($now < $k) {
    	$now *= 2;
        $tmp *= 0.5;
    }
  
  	$probability += $tmp;
}

echo $probability, PHP_EOL;

Measured memory_bytes: 4732
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する

ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

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


int main() {
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,0,N){
        cin >> A[i];
    }

    ll gc = A[0];

    REP(i,0,N){
        gc = gcd(A[i],gc);
    }

    REP(i,0,N){
        if(A[i] - K >= 0){
            if((A[i] - K) % gc == 0){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

int main() {
    int N;
    set<int> s;
    cin >> N;
    for(int i = 0; i < N; ++i){
    	int a;
    	cin >> a;
    	s.insert(a);
    }

    cout << s.size() << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	char x, y;
	cin >> x >> y;
	if (x > y)
		cout << ">" << "\n";
	else if (x < y)
		cout << "<" << "\n";
	else
		cout << "=" << "\n";
}

Measured memory_bytes: 3548
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple


int n, ans = inf, sum[302020], sumr[303030];
string s;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n >> s;

rep(i, 0, n-1){
if(s[i]=='W')sum[i+1]+=sum[i]+1;
else sum[i+1]=sum[i];
}

rep1(i, n-1, 0){
if(s[i]=='E')sumr[i+1]+=sumr[i+2]+1;
else sumr[i+1]=sumr[i+2];
}


rep(i, 1, n){
ans = min(ans, sum[i-1]+sumr[i+1]);
}

cout << ans << endl;

return 0;}
///.... Maria Otonashi


Measured memory_bytes: 3092