jiahuimbzuai/CoQuIR huggingface dataset:
//  [swift]
import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}


func disco2020c() {
    let HWK = readLine()!.toIntList()
    let H = HWK[0]
    let W = HWK[1]
    var K = HWK[2]
    var G:[[String]] = []
    var ANS:[[Int]] = Array(repeating: Array(repeating: 0, count: W), count: H)
    for y in 1...H{
        let x = readLine()!.toList()
        G.append(x)
    }
    var isInStbY = false
    var width:[Int] = []
    var yLists:[[Int]] = []
    var list:[Int] = []

    var i = 0
    for y in 0..<H{
        if G[y].contains("#"){
            list.append(y)
            i = y+1
            break
        }
        list.append(y)
    }
    
    for y in i..<H{
        if G[y].contains("#"){
            yLists.append(list)
            list = [y]
        }else{
            list.append(y)
        }
    }
    if list.count > 0 {
        yLists.append(list)
    }
    
    func isInStrovery(_ yList:[Int],_ x:Int) -> Bool{
        for y in yList{
            if G[y][x].contains("#"){
                return true
            }
        }
        return false
    }
    for (index,yList) in yLists.enumerated(){
        var xLists:[[Int]] = []
        var xlist:[Int] = []
        var isInStbX = false
        
        var i = 0
        for x in 0..<W{
            if isInStrovery(yList, x){
                xlist.append(x)
                i = x+1
                break
            }
            xlist.append(x)
        }
        
        for x in i..<W{
            if isInStrovery(yList, x){
                xLists.append(xlist)
                xlist = [x]
            }else{
                xlist.append(x)
            }
        }
        if xlist.count > 0 {xLists.append(xlist)}
        
        
        for xlist in xLists{
            for x in xlist{
                for y in yList{
                    ANS[y][x] = K
                }
            }
            K -= 1
        }
    }
    
    for y in 0..<H{
        for x in 0..<W{
            print(ANS[y][x],terminator: " ")
        }
        print("")
    }
}

disco2020c()
//  [swift]


func disco2020c() {
    let HWK = readLine()!.toIntList()
    let H = HWK[0]
    let W = HWK[1]
    var K = HWK[2]
    var G:[[String]] = []
    var ANS:[[Int]] = Array(repeating: Array(repeating: 0, count: W), count: H)
    for _ in 1...H{ G.append(readLine()!.toList())}
    var yLists:[[Int]] = []
    var list:[Int] = []
    var i = 0
    for y in 0..<H{
        if G[y].contains("#"){
            list.append(y)
            i = y+1
            break
        }
        list.append(y)
    }
    for y in i..<H{
        if G[y].contains("#"){
            yLists.append(list)
            list = [y]
        }else{
            list.append(y)
        }
    }
    if list.count > 0 { yLists.append(list)}
    func isInStrovery(_ yList:[Int],_ x:Int) -> Bool{
        for y in yList{
            if G[y][x].contains("#"){
                return true
            }
        }
        return false
    }
    for yList in yLists{
        var xLists:[[Int]] = []
        var xl:[Int] = []
        var i = 0
        for x in 0..<W{
            if isInStrovery(yList, x){
                xl.append(x)
                i = x+1
                break
            }
            xl.append(x)
        }
        
        for x in i..<W{
            if isInStrovery(yList, x){
                xLists.append(xl)
                xl = [x]
            }else{
                xl.append(x)
            }
        }
        if xl.count > 0 {xLists.append(xl)}
        for xl in xLists{
            for x in xl{
                for y in yList{
                    ANS[y][x] = K
                }
            }
            K -= 1
        }
    }
    
    for y in 0..<H{
        for x in 0..<W{
            print(ANS[y][x],terminator: " ")
        }
        print("")
    }
}
import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}


disco2020c()
//  [typescript]
function main(input: string[]): void {
    const h = parseInt(input.shift(), 10);
    const w = parseInt(input.shift(), 10);
    const k = parseInt(input.shift(), 10);
    const s = [];
    let last = 1;
    let sr = [];
    let empties = 0;
    for (let y = 0; y < h; y++) {
        const row = input[y];
        sr = [];
        let empty = true;
        for (let x = 0; x < w; x++) {
            const cell = row[x];
            if (cell === '#') {
                if (!empty) {
                    last += 1;
                }
                empty = false;
                sr.push(last);
            } else {
                sr.push(last);
            }
        }
        if (empty) {
            empties += 1;
        } else {
            last += 1;
            for (var i = 0; i < empties + 1; i++)
                s.push(sr.join(' '));
            empties = 0;
        }
    }
    for (var i = 0; i < empties; i++)
        s.push(s[s.length - 1]);
    console.log(s.join('\n'));
}

import { readFileSync } from 'fs';
if (process.argv[1] == __filename) {
    const path = process.argv[2] || '/dev/stdin';
    const input = readFileSync(path, 'utf-8');
    main(input.split(/\s+/));
}
//  [typescript]
{
  const main = (input: string) => {
    const r = reader(input)
    const [H, W, K] = r.ns()
    const s: (number | string)[][] = r.lines.map(line => line.split(''))
    const a = [...s]

    let fillMaster = 0
    for (let y = 0; y < H; y++) {
      let fill = 0
      for (let x = 0; x < W; x++) {
        if (s[y][x] === '#') {
          fill += 1
        }
        if (fill > 0) {
          s[y][x] = fill + fillMaster
        } else {
          s[y][x] = 0
        }
      }
      if (fill === 0) {
        continue
      }
      for (let x = 0; x < W && s[y][x] === 0; x++) {
        s[y][x] = fillMaster + 1
      }
      fillMaster += fill
    }
    for (let y = 1; y < H; y++) {
      if (s[y][0] !== 0) {
        continue
      }
      s[y] = s[y - 1]
    }
    for (let y = H - 2; y >= 0; y--) {
      if (s[y][0] !== 0) {
        continue
      }
      s[y] = s[y + 1]
    }
    console.log(s.map(cs => cs.join(' ')).join('\n'))
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  main(require('fs').readFileSync('/dev/stdin', 'utf8'))
}
//  [python]
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
pqr = list(map(int,input().split()))

pqr.sort()

print(pqr[0]+pqr[1])
//  [python]
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    P, Q, R = map(int, input().split())
    lists = []
    lists.append(P + Q)
    lists.append(Q + R)
    lists.append(P + R)
    print(min(lists))


if __name__ == '__main__':
    main()
//  [python]
P,Q,R=map(int,input().split())
print(min(P+Q,Q+R,R+P))
//  [java]
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        final int P = sc.nextInt();
        final int Q = sc.nextInt();
        final int R = sc.nextInt();

        System.out.println(IntStream.of(P, Q, R).sorted().limit(2).sum());
    }
}
//  [java]
import java.util.*;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int P = scanner.nextInt();
		int Q = scanner.nextInt();
		int R = scanner.nextInt();
		scanner.close();
		List<Integer>list = Arrays.asList(P, Q, R);
		list = list.stream().sorted().collect(Collectors.toList());
		System.out.println(list.get(0)+list.get(1));
	}
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt(), q = sc.nextInt(), r = sc.nextInt();
        int sum = p + q + r;
        int[] hoge = {p, q, r};
        System.out.println(Arrays.stream(hoge).map(operand -> sum - operand).min().getAsInt());
    }
}
//  [cpp]
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

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

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}


int main()
{
	int p, q, r;
	cin >> p >> q >> r;
	cout << (min(p + q, min(q + r, p + r)));
}
//  [cpp]
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", MIN(a+b,MIN(b+c,c+a)));

    return;
}

int main(int argc, char* argv[])
{
    solve();

	return 0;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
    int p,q,r;
    cin >> p >> q >> r;

    cout << p+q+r-max(max(p,q),r) << endl;


  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
int main(){
	int i, j, aux;
	int n=3;
	int arr[n];
	for(i=0;i<n;i++){
    	scanf("%i",&arr[i]);
	}
	for(i=0; i<=n; i++){
		for(j=0; j<n-1; j++){
			if(arr[j]>=arr[j+1]){
				aux= arr[j];
				arr[j] = arr[j+1];
				arr[j+1]=aux;
			}
		}
	}
	int resultado= arr[0]+arr[1];
	printf("%i", resultado);
}
//  [c]
#include <stdio.h>
int main(void){
    int p, q, r, ans = 0;
    
    scanf("%d %d %d", &p, &q, &r);
    
    if(p+q <= (p+r) && p+q <= (q+r)){
        ans = p + q;
    }else if(p + r <= (p+q) && p + r <= (q+r)){
        ans = p + r;
    }else if(q + r <= (p+q) && q + r <= (p+r)){
        ans = q + r;
    }
    
    printf("%d\n", ans);
}
//  [c]
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	
	if(a>=b&&a>=c)
	printf("%d",b+c);
	
	else if(b>=a&&b>=c)
	printf("%d",a+c);
	
	else
	printf("%d",a+b);
	
	return 0;
}
//  [javascript]
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3);t.exports=class{constructor(t){this.inp=new r(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(t){this.inp.enq(t)}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e,n){"use strict";t.exports=function(t){var e=[t.in(),t.in(),t.in()];e.sort(function(t,e){return t-e}),console.log(e[0]+e[1])}}]);
//  [javascript]
function main(input){
  const lines = input.split('\n')
  const nums = lines[0].split(' ').map(x => parseInt(x));
  var result = Math.min(nums[0]+nums[1], nums[1]+nums[2], nums[0]+nums[2])

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict'

function Main(input) {
  const P = Number(input.split("\n")[0].split(" ")[0])
  const Q = Number(input.split("\n")[0].split(" ")[1])
  const R = Number(input.split("\n")[0].split(" ")[2])

  const max = Math.max(P, Q, R)
  console.log(P + Q + R - max)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())
//  [go]
package main

import (
	"fmt"
	"sort"
)

func main() {
	var P, Q, R int
	fmt.Scan(&P, &Q, &R)

	list := []int{P, Q, R}
	sort.Sort(sort.IntSlice(list))

	fmt.Println(list[0] + list[1])
}
//  [go]
package main

import "fmt"

func main() {
	var p, q,r int
	fmt.Scan(&p, &q, &r)


	fmt.Println(p+q+r-max(p, q, r))
}
func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		if res < nums[i] {
			res = nums[i]
		}
	}
	return res
}
//  [ruby]
eval'A='+`tr ' ' ,`
p A.sum-A.max
//  [ruby]
p, q, r = gets.split.map &:to_i
puts [p+q, q+r, r+p].min
//  [ruby]
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

P, Q, R = get_ints

pq = P + Q
qr = Q + R
rp = R + P

puts [pq, qr, rp].min
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        p:usize,q:usize,r:usize
    }
    println!("{}", p + q + r - max(max(p, q), r));
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
    p: usize,
    q: usize,
    r: usize
    }
    let ans = min(p + q, min(q + r, r + p));
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut a:usize = read!();
    let mut b:usize = read!();
    let mut c:usize = read!();
    println!("{}",min(a+b,min(b+c,c+a)));
}
//  [swift]
let tmp = readLine()!.characters.split(" ").map{Int(String($0))!}.sort()
print((0..<2).reduce(0){$0 + tmp[$1]})
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // 2つの条件に優先順位をつけてソート

/*************** メインプログラム ***************/

var time = readIntSplit(by: " ")
time.sort()
print(time[0] + time[1])
//  [swift]
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let P = Int(split[0])!
let Q = Int(split[1])!
let R = Int(split[2])!
 
let value1 = P + Q
let value2 = P + R
let value3 = Q + R

if value1 <= value2 && value1 <= value3 {
    print(value1)
} else if value2 <= value3 {
    print(value2)
} else {
    print(value3)
}
//  [typescript]
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (n) => {
  const a = n.sort((a, b) => a - b)
  return a[0] + a[1]
  // ...
}
const main = (input) => {
  const n = input.split(" ").map(Number)
  return solve(n)
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}
//  [typescript]
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const [p, q, r]: number[] = input[0].split(' ').map((x: string): number => +x);

console.log(p+q+r-Math.max(p,q,r));
//  [typescript]
import { readFileSync } from 'fs'

function main(input: string) {
  const [a, b] = input.split(' ').map(Number).sort((a, b) => a - b)

  console.log(a + b)
}

main(readFileSync('/dev/stdin', 'utf8').trim())
//  [python]
n = int(input())
data = list(map(int, input().split()))
q = int(input())
d = {}
big = 10**5+100

for i in range(big):
  d[i+1] = []
for i in data:
  d[i].append(i)

ans = sum(data)
for i in range(q):
  a, b = map(int, input().split())
  #print(len(d[a]))
  ans += len(d[a]) * (b-a)
  d[b] = d[b] + d[a]
  d[a] = []
  print(ans)
//  [python]
def _calc_sum(cache):
    sum_value = 0
    for v, indices in cache.items():
        sum_value += v * len(indices)
    return sum_value


def _main(N, A_list, Q, BC_list):
    cache = {}
    for i, a in enumerate(A_list):
        cache.setdefault(a, []).append(i)

    sum_value = _calc_sum(cache)

    for b, c in BC_list:
        indices = cache.get(b, [])
        cache[b] = []
        sum_value -= b * len(indices)
        cache.setdefault(c, []).extend(indices)
        sum_value += c * len(indices)
        print(sum_value)


def _entry():
    N = int(input())
    A_list = list(map(int, input().split()))
    Q = int(input())
    BC_list = []
    for i in range(Q):
        B, C = map(int, input().split())
        BC_list.append((B, C))
    _main(N, A_list, Q, BC_list)


if __name__ == "__main__":
    _entry()
//  [python]
class BIT:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*-~n
    def sum(self,i):
        s=0
        while i:
            s+=self.tree[i]
            i-=i&-i
        return s
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i
def main():
    n=int(input())
    bit=BIT(10**5)
    for a in map(int,input().split()):
        bit.add(a,a)
    for _ in range(int(input())):
        b,c=map(int,input().split())
        t=bit.sum(b)-bit.sum(b-1)
        bit.add(b,-t)
        bit.add(c,t//b*c)
        print(bit.sum(10**5))
main()
//  [java]
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		BigInteger sum = BigInteger.ZERO;
		BigInteger[] nums = new BigInteger[100001];
		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (nums[num] == null) {
				nums[num] = BigInteger.ONE;
			} else {
				nums[num] = nums[num].add(BigInteger.ONE);
			}
			sum = sum.add(BigInteger.valueOf(num));
		}
		sc.nextLine();
		int q = sc.nextInt();
		List<BigInteger> sumList = new ArrayList<BigInteger>();
		for (int i = 0; i < q; i++) {
			sc.nextLine();
			int b = sc.nextInt();
			int c = sc.nextInt();
			BigInteger bigB = BigInteger.valueOf(b);
			BigInteger bigC = BigInteger.valueOf(c);
			BigInteger cnt = nums[b] == null ? BigInteger.ZERO : nums[b];
			sum = sum.add(bigC.multiply(cnt));
			sum = sum.subtract(bigB.multiply(cnt));
			sumList.add(sum);
			
			if (nums[c] == null) {
				nums[c] = cnt;
			} else {
				nums[c] = nums[c].add(cnt);
			}
			nums[b] = BigInteger.ZERO;
		}
		
		for (BigInteger i : sumList) {
			System.out.println(i);
		}
	}
}
//  [java]
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			long[]A = new long[N];
			Map<Long,Long>map = new TreeMap<Long,Long>();
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				if(map.containsKey(A[i])) {
					map.put(A[i], map.get(A[i])+1);
				}else {
					map.put(A[i], (long)1);
				}
			
			}
			int Q = scan.nextInt();
			long []B = new long[Q];
			long []C = new long[Q];
			
			for(int i = 0;i<Q;i++) {
				B[i] = scan.nextLong();
				C[i] = scan.nextLong();	
			}
			
			long goukei = 0;
			for(int i = 0;i<N;i++)goukei+=A[i];
			
			
			for(int i = 0;i<Q;i++) {
				
				if(!map.containsKey(B[i])) {
					System.out.println(goukei);
					continue;
				}
				
				long kosuu = map.get(B[i]);
				
				long sa = C[i]*kosuu-B[i]*kosuu;
				
				goukei+=sa;
				System.out.println(goukei);
				
				map.put(B[i], (long)0);
				
				if(map.containsKey(C[i])) {
					map.put(C[i], map.get(C[i])+kosuu);
				}else {
					map.put(C[i], kosuu);
				}
				
				
				
				
			}
			
			
			
		}
		
		
	}
		

}
//  [java]
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        Map<Integer, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            map.put(a[i], map.getOrDefault(a[i], 0L) + 1);
            sum += a[i];
        }
        int q = sc.nextInt();
        int[] b = new int[q];
        int[] c = new int[q];
        for (int i = 0; i < q; i++) {
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        for (int i = 0; i < q; i++) {
            if (!map.containsKey(b[i])) {
                map.put(b[i], 0L);
            }
            long bcnt = map.get(b[i]);
            if (!map.containsKey(c[i])) {
                map.put(c[i], 0L);
            }
            long ccnt = map.get(c[i]);
            map.put(b[i], 0L);
            map.put(c[i], ccnt + bcnt);
            sum += c[i] * bcnt - b[i] * bcnt;
            System.out.println(sum);
        }

    }

}
//  [cpp]
#include <iostream>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main(){
  int N, B, C, Q, tmp;
  cin >> N;
  unordered_map<int, list<int>> hash;
  ll sum = 0;
  for (int i=0; i<N; i++){
    cin >> tmp;
    hash[tmp].push_back(tmp);
    sum += (ll)tmp;
  }
  cin >> Q;
  for (int i=0; i<Q; i++){
    cin >> B >> C;
    if (hash[B].size() > 0){
      sum += (ll)(C - B) * (ll)hash[B].size();
      hash[C].merge(hash[B]);
      hash.erase(B);
    }
    cout << sum << "\n";
  }
  

  return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") 
#include <bits/stdc++.h> 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define PI 3.1415926535897932384626 
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 rep(i, a) for (int i=0; i<(a); i++)
#define Dep(i,a,b) for (int i = (b)-1; i >= a; i--)
#define dep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for(auto& a : x)
 
#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 ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Random No.
 
const int MOD = 1000000007;
const char nl = '\n';

void sol() {
    int N ;
    cin >> N;
    int ar[N];
    ll sum =0;
    set<int> s;
    rep(i, N){
        cin >> ar[i] ;
        sum += ar[i];
        s.insert(ar[i]);
    }

    map <ll, ll> m;
    trav(x, s){
        int countt= count(ar , ar + N , x);
        m[x] = countt;
    }

    int Q;
    cin >> Q;
    while(Q--){
        int B , C;
        cin >> B >> C;
        sum += (C - B)*(m[B]);

        auto it = m.find(C);
        if(it != m.end()){
            m[C] = m[C] + m[B];
            m.erase(B);
        }
        else{
            m[C] = m[B];
            m.erase(B);
        }
        cout << sum << nl;

    }



}               

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

    #ifndef ONLINE_JUDGE
    	freopen("inputD.txt", "r", stdin);
	  #endif    
	
    int T=1;
    while(T--) {            
        sol();                
    }
	
	return 0;
}
//  [cpp]
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    vector <int> v[100001];
    int n,c,b,q,sum=0; 
    cin>>n; 
    vi a(n+1);
    for (int i=1;i<=n;i++){
        cin >> a[i]; 
        v[a[i]].pb(i);
        sum += a[i];
    } 
    cin >> q;
    while (q--){
        cin >> b >> c ; 
        for (int i=0;i<sz(v[b]);i++){
            sum -= a[v[b][i]];
            a[v[b][i]]=c;
            v[c].pb(v[b][i]);
            sum += a[v[b][i]];
        }
        v[b].clear();
        cout << sum << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
//  [c]
//map made in C
//ABC171-D
//https://atcoder.jp/contests/abc171/tasks/abc171_d
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<sys/time.h>
#define hsize 4194304 //must be 2^N

unsigned long long seed;

unsigned long long xorshift(){
  seed=seed^(seed<<13);
  seed=seed^(seed>>7);
  seed=seed^(seed<<17);
  return seed;
}

long long hash[hsize];
long long inhfl=1;
bool hashfl[hsize]={0};

long long hbase[8][256];

long long reshash(){
  srand(time(0));
  struct timeval tv;
  gettimeofday(&tv, NULL);
  seed=(tv.tv_sec*1000000+tv.tv_usec);
  long long i,j;
  for(i=0;i<100;i++){xorshift();}
  for(i=0;i<8;i++){
    for(j=0;j<256;j++){
      hbase[i][j]=((xorshift()%hsize)^(rand()%hsize));
    }
  }
  if(inhfl==0){for(i=0;i<hsize;i++){hashfl[i]=false;}}
  inhfl=0;
}

long long gbhash(long long x){
  long long r=0,i;
  for(i=0;i<8;i++){
    r^=hbase[i][(x&(255ll))];
    x>>=8;
  }
  return r;
}

long long access(long long x){
  long long p=gbhash(x);
  while(1){
    if((!hashfl[p]) || hash[p]==x){
      hash[p]=x;
      hashfl[p]=true;
      return p;
    }
    p++;
    if(p==hsize){p=0;}
  }
}

int main(){
  reshash();
  long long n,a[131072],q,b,c,s=0,i,j;
  long long mpb[hsize]={0};
  long long bh,ch;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    s+=a[i];
    mpb[access(a[i])]++;
  }
  scanf("%lld",&q);
  for(i=0;i<q;i++){
    scanf("%lld%lld",&b,&c);
    bh=access(b);
    ch=access(c);
    s-=b*mpb[bh];
    s+=c*mpb[bh];
    mpb[ch]+=mpb[bh];
    mpb[bh]=0;
    printf("%lld\n",s);
  }
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<sys/time.h>
#define hsize 4194304 //must be 2^N

unsigned long long seed;

unsigned long long xorshift(){
  seed=seed^(seed<<13);
  seed=seed^(seed>>7);
  seed=seed^(seed<<17);
  return seed;
}

long long hash[hsize];
long long inhfl=1;
bool hashfl[hsize]={0};

long long hbase[8][256];

long long reshash(){
  srand(time(0));
  struct timeval tv;
  gettimeofday(&tv, NULL);
  seed=(tv.tv_sec*1000000+tv.tv_usec);
  long long i,j;
  for(i=0;i<100;i++){xorshift();}
  for(i=0;i<8;i++){
    for(j=0;j<256;j++){
      hbase[i][j]=((xorshift()%hsize)^(rand()%hsize));
    }
  }
  if(inhfl==0){for(i=0;i<hsize;i++){hashfl[i]=false;}}
  inhfl=0;
}

long long gbhash(long long x){
  long long r=0,i;
  for(i=0;i<8;i++){
    r^=hbase[i][(x&(255ll))];
    x>>=8;
  }
  return r;
}

long long access(long long x){
  long long p=gbhash(x);
  while(1){
    if((!hashfl[p]) || hash[p]==x){
      hash[p]=x;
      hashfl[p]=true;
      return p;
    }
    p++;
    if(p==hsize){p=0;}
  }
}

int main(){
  reshash();
  long long n,a[131072],q,b,c,s=0,i,j;
  long long mpb[hsize]={0};
  long long bh,ch;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    s+=a[i];
    mpb[access(a[i])]++;
  }
  scanf("%lld",&q);
  for(i=0;i<q;i++){
    scanf("%lld%lld",&b,&c);
    bh=access(b);
    ch=access(c);
    s-=b*mpb[bh];
    s+=c*mpb[bh];
    mpb[ch]+=mpb[bh];
    mpb[bh]=0;
    printf("%lld\n",s);
  }
  return 0;
}
//  [c]
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VAL_MAX		100005									// 最大値

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Cnt[D_VAL_MAX];									// 個数
static long long slSum;											// 合計

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1Cnt, 0, sizeof(si1Cnt));
	slSum = 0;

	// 配列数 - 取得
	int liACnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liACnt);

	// 配列 - 取得
	for (i = 0; i < liACnt; i++) {
		int liVal;
		fscanf(szpFpI, "%d", &liVal);

		// 個数 - 加算
		si1Cnt[liVal]++;

		// 合計 - 加算
		slSum += liVal;
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// クエリ数 - 取得
	int liQCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liQCnt);

	// クエリ - 取得
	for (i = 0; i < liQCnt; i++) {
		int liBefore, liAfter;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liBefore, &liAfter);

		// 合計 - 加算
		slSum += (long long)(liAfter - liBefore) * (long long)si1Cnt[liBefore];

		// 個数 - 加算
		si1Cnt[liAfter] += si1Cnt[liBefore];
		si1Cnt[liBefore] = 0;

		// 出力
		sprintf(lc1Buf, "%lld\n", slSum);
		fOutLine(lc1Buf);
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}
//  [javascript]

function makeHist(numbers) {
    const hist = new Map()

    for (const n of numbers) {
        if (hist.has(n)) {
            hist.set(n, hist.get(n) + 1)
        }
        else {
            hist.set(n, 1)
        }
    }

    return hist
}

function main(lines) {
    const [N] = parseNumberLine(lines[0])
    const numbers = parseNumberLine(lines[1])
    const [Q] = parseNumberLine(lines[2])
    const operationLines = lines.slice(3)

    const hist = makeHist(numbers)

    let result = 0
    hist.forEach((v, k) => {
        result += k * v
    })

    for (let i = 0; i < Q; ++i) {
        const [B, C] = parseNumberLine(operationLines[i])

        if (hist.has(B)) {
            const count = hist.get(B)
            hist.delete(B)

            if (hist.has(C)) {
                hist.set(C, hist.get(C) + count)
            }
            else {
                hist.set(C, count)
            }
            result += (C - B) * count
        }

        console.log(result)
    }
}

function parseNumberLine(line, radix = 10) {
    return line.split(/\s+/).map(_ => parseInt(_, radix))
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"))
//  [javascript]
console.log(function(args){
  const [[N],A,[Q],...tmp] = args.trim().split('\n').map( r=>r.split(' ').map( v=>v|0 ) );
  const sum = Array(Q+1).fill(0);
  sum[0] = 0;
  const a = new Map();
  for ( let i = 0; i < N; i++ ) {
    a.set(A[i], (a.get(A[i])|0) + 1 );
    sum[0] += A[i];
  }
  for ( let i = 0; i < Q; i++ ) {
    const [B,C] = tmp[i];
    if ( a.has(B) ) {
      const b = a.get(B);
      const c = a.has(C) ? a.get(C) : 0;
      sum[i+1] = sum[i] + b*C - b*B;
      a.set( C, c + b );
      a.delete( B );
    } else sum[i+1] = sum[i];
  }
  return sum.slice(1).join('\n');
}(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
'use strict';

function Main(input) {
    // N
    // A1 A2 A3...An
    // Q
    // B1 C1
    // B2 C2
    // ...
    // BQ CQ
    let tmp = input.trim().split('\n');
    const N = Number(tmp[0]);
    let A = tmp[1]
        .split(' ')
        .sort((a, b) => a - b)
        .map((v) => BigInt(v));
    const Q = Number(tmp[2]);
    const BC = tmp.splice(3).map((v) => v.split(' ').map((v) => BigInt(v)));

    let arr = new Array(100001).fill(0n);
    for (const v of A) {
        arr[v] += 1n;
    }

    let result = arr.reduce((sum, v, i) => sum + v * BigInt(i));

    for (const [b, c] of BC) {
        const diff = (c - b) * arr[b];
        result += diff;
        console.log(String(result));
        arr[c] += arr[b];
        arr[b] = 0n;
    }

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, 100001)
	sum := 0
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		a[tmp] += 1
		sum += tmp
	}
	var q int
	fmt.Scan(&q)
	var ans []int
	for i := 0; i < q; i++ {
		var b, c int
		fmt.Scan(&b, &c)
		cnt := a[b]
		a[b] = 0
		a[c] += cnt
		sum += cnt * (c - b)
		ans = append(ans, sum)
	}
	len := len(ans)
	for i := 0; i < len; i++ {
		fmt.Print(ans[i])
		fmt.Print("\n")
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	z := make([]int, 100001)

	var n int
	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)

		z[a] = z[a] + 1
	}

	sum := 0
	for i := 0; i < len(z); i++ {
		if z[i] != 0 {
			sum = sum + (i * z[i])
		}
	}

	var q int
	fmt.Scanf("%d", &q)

	ans := make([]int, q)
	var b1, b2 int
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &b1)
		fmt.Scanf("%d", &b2)

		if z[b1] > 0 {
			sum = sum - (b1 * z[b1] - b2 * z[b1])
			z[b2] = z[b2] + z[b1]
			z[b1] = 0
		}
		ans[i] = sum
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}
//  [go]
package main

import "fmt"

func main() {
	var n, a, total int
	fmt.Scanf("%d\n", &n)
	bucket := make([]int, 100000)

	for i := 0; i < n; i++ {
		if i != n-1 {
			fmt.Scanf("%d", &a)
		} else {
			fmt.Scanf("%d\n", &a)
		}
		bucket[a-1]++
		total += a
	}

	var q, b, c int
	fmt.Scanf("%d\n", &q)
	out := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d\n", &b, &c)
		total += (c - b) * bucket[b-1]
		out[i] = total
		bucket[c-1] += bucket[b-1]
		bucket[b-1] = 0
	}

	for _, j := range out {
		fmt.Println(j)
	}

}
//  [ruby]
N = gets.to_i
A = {}
sum = 0
line = gets.split(' ').map(&:to_i)

for num in 0..N-1 do
    n = line[num]
    A.store(n, A[n].to_i+1);
    sum += n
end

Q = gets.to_i
q_lines = []
for num in 0..Q-1 do
    line = gets
    q_lines << line.chomp.split(' ').map(&:to_i)
end

for num in 0..Q-1 do
    B = q_lines[num][0].to_i
    C = q_lines[num][1].to_i
    b = A[B].to_i
    A[B] = 0
    sum += b * (C - B) 
    if !A[C]
        A[C] = 0
    end
    A[C] += b
    puts sum
end
//  [ruby]
N = gets.to_i
A = []
sum = 0
line = gets.split(' ').map(&:to_i)

for num in 0..N-1 do
    n = line[num]
    A[n] ||= 0
    A[n] += 1
    sum += n
end

Q = gets.to_i
q_lines = []
for num in 0..Q-1 do
    line = gets
    q_lines << line.chomp.split(' ').map(&:to_i)
end

for num in 0..Q-1 do
    B = q_lines[num][0].to_i
    C = q_lines[num][1].to_i
    b = A[B].to_i
    A[B] = 0
    sum += b * (C - B) 
    A[C] ||= 0
    A[C] += b
    puts sum
end
//  [ruby]
N = gets.to_i
A = Array.new(100001, 0)
sum = 0
line = gets.split(' ').map(&:to_i)

for num in 0..N-1 do
    n = line[num]
    A[n] += 1
    sum += n
end

Q = gets.to_i
q_line = []

for num in 0..Q-1 do
    q_line = gets.chomp.split(' ').map(&:to_i)
    B = q_line[0]
    C = q_line[1]
    b = A[B].to_i
    A[B] = 0
    sum += b * (C - B)
    A[C] += b
    puts sum
end
//  [rust]
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::HashMap;

fn main() {
    scan!(_n; usize);
    scan!(array; Vec<i128>);

    let mut book: HashMap<i128, i128> = HashMap::new();
    let mut sum: i128 = 0;
    for &a in array.iter() {
        sum += a;
        let elm = book.entry(a).or_insert(0);
        *elm += 1;
    }

    scan!(q; usize);

    for _ in 0..q {
        scan!(b, c; i128);

        let b_num = match book.get(&b) {
            Some(v) => *v,
            None => 0,
        };
        sum -= b_num * b;
        sum += b_num * c;
        let c_num = match book.get(&c) {
            Some(v) => *v,
            None => 0,
        };
        book.insert(b, 0);
        book.insert(c, b_num + c_num);

        println!("{}", sum);
    }
}
//  [rust]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut a = vec![0isize; 100001];
    for _ in 0..n {
        let ai: usize = read!();
        a[ai] += 1;
    }

    let mut now_sum = a
        .iter()
        .enumerate()
        .map(|(index, &amount)| index as isize * amount)
        .sum::<isize>();

    let q: usize = read!();
    for _ in 0..q {
        let b: isize = read!();
        let c: isize = read!();

        let change = a[b as usize];
        a[b as usize] = 0;
        a[c as usize] += change;
        now_sum += change * (c - b);
        println!("{}", now_sum);
    }
}
//  [swift]
_ = Int(readLine()!)!
let AN = readLine()!.split(separator: " ").compactMap { Int($0) }
let Q = Int(readLine()!)!
let BCQ: [(Int, Int)] = (1...Q).map { _ in
    let bc = readLine()!.split(separator: " ").compactMap { Int($0) }
    return (bc[0], bc[1])
}

var dict = [Int: Int]()
for an in AN {
    if dict[an] == nil {
        dict[an] = 1
    } else {
        dict[an]! += 1
    }
}

var sum = dict.reduce(0) { $0 + ($1.key * $1.value) }
for bc in BCQ {
    if dict[bc.0] != nil {
        let diff = (bc.1 - bc.0) * dict[bc.0]!
        sum += diff

        if dict[bc.1] != nil {
            dict[bc.1]! += dict[bc.0]!
        } else {
            dict[bc.1] = dict[bc.0]
        }
        dict[bc.0] = 0
    }
    print(sum)
}
//  [swift]
let N = Int(readLine()!)!
let A = readLine()!.split(separator: " ").map { Int($0)! }
let Q = Int(readLine()!)!

var table: [Int: Int] = [:]

var sum = 0
for num in A {
  sum += num
  table[num, default: 0] += 1
}

for _ in 0..<Q {
  let inputs = readLine()!.split(separator: " ").map { Int($0)! }
  
  let from = inputs[0]
  let to = inputs[1]
  
  if let count = table[from] {
    let diff = (to - from) * count
    sum += diff
    table[from] = nil
    table[to, default: 0] += count
  }
  print(sum)
}
//  [swift]
var n = readInt()
var An = readInts()
var q = readInt()
let query: [(Int, Int)] = (1...q)
    .map { _ in let a = readInts(); return (a[0], a[1]) }

var array = Array(repeating: 0, count: 100005)
for a in An {
    array[a] += 1
}

var sum = An.reduce(0, +)

for (b, c) in query {
    let count = array[b]
    array[b] = 0
    array[c] += count
    
    sum -= b * count
    sum += c * count
    print(sum)
}


// MARK: -----------------------------------------------------------------------


func readInt() -> Int {
    Int(readLine()!)!
}

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func mapToTuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating get {
            if let note = dictionary[argument] {
                return note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                return result
            }
        }
    }
}