akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPre
{
    class Program
    {
        static void Main(string[] args)
        {
             var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var P = A[0];
            var Q = A[1];
            var R = A[2];

            int[] B = new int[3] { P + Q, Q+R,P+R };

            Console.WriteLine(B.Min());

        }

    }
}

Measured memory_bytes: 13268
def div2_count(x, n):
    if x % 2 == 1:
        return n
    else:
        return div2_count(x // 2, n+1)


N = int(input())

ans = [0, 0]
for i in range(1, N+1):
    y = div2_count(i, 0)
    if ans[1] <= y:
        ans = [i, y]

print(ans[0])


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

#define MAX_N 1000000

int ans[MAX_N+10];
int oddAns[MAX_N+10];

void solve(int N){
  cout<<ans[N]<<" "<<oddAns[N]<<endl;
}

int main(){
  int res=0;
  int sum=0;
  vector<int> num;
  vector<int> oddNum;
  for(int i=1;i<=185;i++){
    sum+=i;
    res+=sum;
    if(res%2) oddNum.push_back(res);
    num.push_back(res);
  }

  for(int i=1;i<=MAX_N;i++){
    ans[i]=MAX_N;
    oddAns[i]=MAX_N;
  }

  for(int j=0;j<num.size();j++){
    for(int i=0;i<=MAX_N;i++){
      if(i+num[j]<=MAX_N) ans[i+num[j]]=min(ans[i+num[j]],ans[i]+1);
    }
    if(num[j]%2){
      for(int i=0;i<=MAX_N;i++){
        if(i+num[j]<=MAX_N) oddAns[i+num[j]]=min(oddAns[i+num[j]],oddAns[i]+1);
      }
    }
  }

  while(1){
    int N;
    cin>>N;
    if(N==0) break;
    solve(N);
  }

  return 0;
}



Measured memory_bytes: 10812
import bisect

def main():
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 29336
import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
ls_BC = []
for m in range(M):
    ls_BC.append(list(map(int,input().split())))
#print(ls_BC)
ls_BC = sorted(ls_BC, key=lambda x: x[1],reverse=True)
#print(ls_BC)
for B,C in ls_BC:
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))



Measured memory_bytes: 33876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int maxl = 0, minr = INF;
    rep(i, 0, m) {
        int l, r;
        cin >> l >> r;
        maxl = max(maxl, l);
        minr = min(minr, r);
    }

    cout << max(minr - maxl + 1, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static final int DONE_FLAG = '.';
    public static final int[] dx = { 0, 1, 0, -1 };
    public static final int[] dy = { -1, 0, 1, 0 };

    public static int h, w;
    public static char[][] map;

    public static void dfs(int x, int y, char c) {
        if (map[y][x] != c) {
            return;
        }

        map[y][x] = DONE_FLAG;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                continue;
            }

            dfs(nx, ny, c);
        }
    }

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

        while (true) {
            h = sc.nextInt();
            w = sc.nextInt();
            if (h == 0 && w == 0) {
                break;
            }
            map = new char[h][];
            for (int i = 0; i < h; i++) {
                map[i] = sc.next().toCharArray();
            }

            int count = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    char current = map[i][j];
                    if (current != DONE_FLAG) {
                        dfs(j, i, current);
                        count++;
                    }
                }
            }

            System.out.println(count);
        }

    }

}

Measured memory_bytes: 28812
bef = input()
aft = input()
answer = 0
count = 0
i = 1

    
for i in range(len(bef)):
  if bef[count] == aft[count]:
    count += 1
    i += 1
  else:
    answer += 1
    i += 1
    count += 1
print(answer)

Measured memory_bytes: 9320
import java.util.Scanner;

public class Main {

    public static void main(String... args) {
        int n;
        int [] a;
        try (Scanner cin = new Scanner(System.in)) {
            n = cin.nextInt();
            a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = cin.nextInt();
            }
        }
        int prev = a[0];
        int count = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] == prev) {
                count++;
                if (i + 1 < n && a[i + 1] == a[i]) i++;
            } else {
                prev = a[i];
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23764
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var as = toIntArr(input[1].split(' '));
	var ss = []; //累積和
	ss[-1] = 0;
	for(var i = 0; i < n; i++){
		ss[i] = ss[i-1]+as[i];
	}
	var l = 1;
	var r = n-1;
	var sumL;
	var _ans = [];
	var pqrs = [];
	var ls = [];
	var rs = [];
	for(var j = 2; j < n-1; j++){
		//L
		while(true){
			if(l === j-1){
				break;
			}
			if(abs(ss[j-1]-2*ss[l-1])<abs(ss[j-1]-2*ss[l])){
				break;
			}
			l++;
		}
		ls[j] = l;
	}
	for(var k = n-2; k > 1; k--){
		while(true){
			if(r === k+1){
				break;
			}
			if(abs((ss[n-1]-ss[k-1])-2*(ss[r-1]-ss[k-1]))<abs((ss[n-1]-ss[k-1])-2*(ss[r-2]-ss[k-1]))){
				break;
			}
			r--;
		}
		rs[k] = r;
	}
	var ans = 0,_ans = 0;
	for(var x = 2; x < n-1; x++){
		pqrs = [ss[ls[x]-1],ss[x-1]-ss[ls[x]-1],ss[rs[x]-1]-ss[x-1],ss[n-1]-ss[rs[x]-1]]; 
		_ans = max.apply(this,pqrs) - min.apply(this,pqrs);
		if(x===2){
			ans = _ans;
		}else if(ans > _ans){
			ans = _ans;
		}
	}
	console.log(ans);
}

Measured memory_bytes: 46964
defmodule Main do

  def main do
    [a, b] = IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)

    multiplication(a, b) |> IO.puts()
  end
  
  @doc """
  Multiplication

  ## Examples

      iex> Multiplication.multiplication(2, 5)
      10

  """
  def multiplication(a, b) do
    a * b
  end
end


Measured memory_bytes: 30840
input_num = gets.to_i
inputs = gets.split.map(&:to_i)
alice_sum = 0
bob_sum = 0

inputs.sort!.reverse!


(0..input_num-1).each do |i|
                if i%2 === 0
                                alice_sum = alice_sum + inputs[i]
                else
                                bob_sum = bob_sum + inputs[i]
                end
end

diff = alice_sum - bob_sum

if diff < 0
                puts (-1)*diff
else
                puts diff
end


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::vector;

using LL = long long;

int main() {
  int n;
  cin >> n;
  vector<LL> ds(n);
  for (int i = 0; i < n; i++) {
    cin >> ds[i];
  }

  LL sum = 0;
  for (int i = 0; i < n; i++) {
    sum += ds[i];
  }

  LL subSum = 0;
  for (int i = 1; i <= n - 2; i += 2) {
    subSum += 2 * ds[i];
  }

  // cout << sum << " " << subSum << endl;

  vector<LL> xs(n);
  xs[0] = sum - subSum;
  for (int i = 1; i < n; i++) {
    xs[i] = (ds[i - 1] - xs[i - 1] / 2) * 2;
  }

  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << xs[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*
    vector<ll> X(N);
    string s,t;
    in >> s >> t;
    vector<string> s,t;
    s.resize(N);
    ll N;
    in >> N;
    */

   vector<ll> X(5);
   REP(i,5){
       in >> X[i];
       if(X[i]==0){
           out << i+1 << endl;
           break;
       }
   }

    
    

    
    
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
   
    int ans = 0;
    for (int i = 0; i < A.size(); i++) {
        for (int j = i+1; j < A.size(); j++) {
            int value = abs(A[i] - A[j]);
            ans = max(ans, value);
        }
    }
    print(ans);

}

signed main() {
    solve();
}


Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$a = array_map("intval", explode(" ", fgets(STDIN)));
sort($a);
$size = 0;
$start = 0;
foreach($a as $i => $b){
  if($size * 2 < $b)$start = $i;
  $size+=$b;
}
echo $n - $start,"\n";

Measured memory_bytes: 17140
args = []
args = input()

count_5 = 0
count_7 = 0

for i in args:
    if i == '5':
        count_5+=1
    if i == '7':
        count_7+=1

if count_5 == 2 and count_7 == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>

int snuke[200][2];
int main(){
	int n,k,i,j,num_belonger,bianhao,count=0;
  
  scanf("%d%d",&n,&k); 
  for(i=1;i<=k;i++)
  {
  	scanf("%d",&num_belonger);
  	for(j=1;j<=num_belonger;j++)
  	{
  		scanf("%d",&bianhao);
  		snuke[bianhao][0]=1;
	}
	
  }
  for(i=1;i<=n;i++){
  	if(snuke[i][0]==0) count++;
  }
  printf("%d",count);
return 0;
}
  

Measured memory_bytes: 1688
#include <stdio.h>
#include <stdlib.h>
int H;

int left(int i) {
  return 2 * i;
}

int right(int i) {
  return 2 * i + 1;
}

void maxHeapify(int A[],int i) {
  int l,r,tmp,largest;
  l = left(i);
  r = right(i);
  if(l <= H && A[l] > A[i]) {
    largest = l;
  }
  else {
    largest = i;
  }
  if(r <= H && A[r] > A[largest]) {
    largest = r;
  }
  if(largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}
void buildMaxHeap(int A[]) {
  int i;
  for(i =H/2;i > 0;i--) {
    maxHeapify(A, i);
	  }
}

int main() {
  int i;
  int *A;

  scanf("%d",&H);
  A = (int *)malloc(sizeof(int)*H);
  for(i=1;i<=H;i++) {
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1;i<=H;i++) {
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
--prewritten code: https://github.com/antma/algo
{-# LANGUAGE BangPatterns #-}
{-# Options_GHC -O2 #-}
import Data.ByteString.Builder
import Data.Monoid
import System.IO
import qualified Data.ByteString.Char8 as C
import Data.Char
import qualified Data.IntSet as S
import Data.List

ru, ri :: C.ByteString -> Int

ru = C.foldl' (\a c -> a * 10 - 48 + ord c) 0
ri s
  | C.head s == '-' = negate $ ru $ C.tail s
  | otherwise = ru s

solve :: [Int] -> Int
solve (n:b) = S.findMax s'
  where
    (x:y:t) = take n b
    (s', _) = foldl' (\ (st, g) !j -> (S.insert g $ S.map (gcd j) st, gcd g j)) (S.fromList [x, y], gcd x y) t  

main :: IO ()
main = print . solve . map ri . C.words =<< C.getContents


Measured memory_bytes: 28028
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c;
		if((b-1)%(a-1)== 0){
			c = (b-1)/(a-1);
		}
		else{
			c = (b-1)/(a-1) + 1;
		}
		System.out.print(c);
	}

}


Measured memory_bytes: 21972
/*
 * main.cpp
 *
 *  Created on: 2020/04/10
 *      Author: SkAaO
 */

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	string S;
	string S_reverse;

	int count = 0;
	for(int i = A; i <= B; i++){
		S = to_string(i);
		S_reverse = S;
		reverse(S.begin(), S.end());

		if(S == S_reverse){
			count++;
		}
	}

	cout << count << endl;

	return 0;
}




Measured memory_bytes: 256
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor:GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple:LCM)を求める
    計算量: O(log(min(a, b)))"""
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める
    計算量: O(Nlog)
    """
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


def multi_lcm(array: list) -> int:
    """arrayのLCMを求める"""
    ans = array[0]
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
    return ans

  
n, k = map(int, input().split())
a = list(map(int, input().split()))

gcd_ = multi_gcd(a)
max_a = max(a)
if max_a < k:
    print("IMPOSSIBLE")
elif k % gcd_ == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 62576
#include <iostream>
#include <cmath>

#include <set>
#include <string>
#include <bits/stdc++.h>
#include <string>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(2)<<(x)
#define MAX 100
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF INT_MAX
#define ll long long
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define ull unsigned long long;


using namespace  std;

void sol() {
    int n;
	cin>>n;
	vector<ll> a(n);
	for(auto &x : a){
		cin>>x;
	}
	sort(a.begin(), a.end());
	if(a[0] == 0){
		cout<<0<<endl;
		exit(0);
	}
	ll ans = 1;
	ll tmp;
	for(auto x : a){
		if(__builtin_mul_overflow(ans, x, &tmp)){
			cout<<-1<<endl;
			exit(0);
		}
		ans = ans*x;
	}
	if(ans > (ll)1000000000000000000){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}

}
int main() {
    fast;
    sol();


}




Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
   cin >> N;
  vector<int>L(2 * N);
  for(int i=0; i < 2*N; i++){
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  int sum = 0;
 for(int i=0; i < 2 * N; i++){
   if(i%2 == 0){
     sum += L.at(i);
   }
 }
   cout << sum << endl;
 }
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 7368800
int a[M];
int main(){
  int i,j,n,m;
  while(cin>>n>>m,n,m){
   int c=0;
   for(i=0;i<M;i++)a[i]=0;
    for(i=0;i<n;i++)a[i]++;
    for(i=0;i<m;i++){
      while(a[c])c++;
      for(j=c;j<M;j+=c)a[j]++;
    }
  for(;a[c];c++){}
    cout<<c<<endl;
  }
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll A[200005];
ll xorsum[200005];
ll sum[200005];
ll bit[200005][25];
ll in[25][200005];
ll dp[200005];
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,N) cin>>A[i];

sum[0]=A[0];
xorsum[0]=A[0];
rep1(i,N){
	sum[i]=sum[i-1]+A[i];
	xorsum[i]=xorsum[i-1]^A[i];
}


stringstream ss;
ss << bitset<21>(A[0]);
string s = ss.str();
rep(j,21){
	if(s[j]=='1'){
		bit[0][20-j]=1;
		in[20-j][1]=0;
	}else{
		in[20-j][0]=0;
	}
}

rep1(i,N){
	stringstream ss1;
	ss1 << bitset<21>(A[i]);
	string s1 = ss1.str();
	rep(j,21){
		if(s1[j]=='1'){
			bit[i][20-j]+=bit[i-1][20-j]+1;
			in[20-j][bit[i][20-j]]=i;
		}else{
			bit[i][20-j]+=bit[i-1][20-j];
		}
		
	}
}

rep(i,N){
	if(sum[i]==xorsum[i]) dp[i]++;
}

rep(i,N){
	ll imax=0;
	rep(j,21){
		if(bit[i][j]-1>=0){
			imax=max(imax,in[j][bit[i][j]-1]);
		}
	}
	dp[i]+=i-imax;
}

rep(i,N){
	ans+=dp[i];
	
}

cout<<ans<<endl;

}
	


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

using namespace std;

const long long inf = 1e18;

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

    long long k, a, b;
    cin >> k >> a >> b;
    if (b - a < 2) {
        cout << ++k;
        return 0;
    }
    if (k < a - 1) {
        cout << ++k;
        return 0;
    }
    k -= a - 1;
    cout << a + (b - a) * (k >> 1) + (k & 1);
}


Measured memory_bytes: 256
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    traveling_plan();
}

fn traveling_plan() {
    let n: usize = read();
    let mut a: Vec<i64> = read_spc();
    let mut v: Vec<i64> = vec![];
    a.insert(0, 0);
    a.push(0);// len(a) == n + 2
    let mut sum = 0;
    for i in 0..n + 1 {
        sum += abs(a[i] - a[i + 1]);
    }
    for i in 1..(n + 1) {
        let mut m = 0;
        m += sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
        v.push(m);
    }
    for vi in v {
        println!("{}", vi);
    }
}

fn abs(n: i64) -> i64 {
    match n {
        n if n < 0 => - n,
        _          => n
    }
}

Measured memory_bytes: 9340
#include <cstdio>
#include <vector>

int main() {
  int N;
  scanf("%d", &N);

  int res=0;
  std::vector<int> B(1e5+1);
  for (int i=0; i<N; ++i) {
    int a;
    scanf("%d", &a);
    if (B[a]++)
      ++res;
  }

  printf("%d\n", N-(res+1)/2*2);
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int X = reader.nextInt();
		int Y = reader.nextInt();
		int Z = reader.nextInt();
		int K = reader.nextInt();
		long[] A = new long[X];
		long[] B = new long[Y];
		long[] C = new long[Z];
//		long[] arr = new long[X * Y * Z];
		ArrayList<Long> list = new ArrayList<Long>();
		for (int i = 0; i < X; i++) {
			A[i] = reader.nextLong();
		}
		for (int i = 0; i < Y; i++) {
			B[i] = reader.nextLong();
		}
		for (int i = 0; i < Z; i++) {
			C[i] = reader.nextLong();
		}
		Arrays.sort(A);

		Arrays.sort(B);

		Arrays.sort(C);
		for (int i = 1; i <= Math.min(X, K); i++) {
			for (int j = 1; j <= Math.min(Y, K); j++) {
				for (int k = 1; k <= Math.min(Z, K); k++) {
					if (i*j*k > K) {
						break;
					}
					list.add(A[X-i] + B[Y-j] + C[Z-k]);
				}
			}
		}
		Collections.sort(list);
		int size = list.size();
		for (int i = 1; i <= K; i++) {
			System.out.println(list.get(size - i));
		}


		reader.close();
	}
}





Measured memory_bytes: 34316
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<4;i++)
	a[i+1]=s[i]-'0';
	int x=a[1]*10+a[2],y=a[3]*10+a[4];
	int q1=0,q2=0,q3=0;
	if(x>=1&&x<=12) q1=1;
	if(y>=1&&y<=12) q2=1;
	if(q1&&!q2) cout<<"MMYY"<<endl;
	if(!q1&&q2) cout<<"YYMM"<<endl;
	if(q1&&q2) cout<<"AMBIGUOUS"<<endl;
	if(!q1&&!q2) cout<<"NA"<<endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
  	unordered_map<ll, ll> l, r;
    for(int i = 0; i < n; i++){
        cin >> a[i];
      	ll tmpl, tmpr;
      	tmpl = i - a[i];
        tmpr = i + a[i];
        l[tmpl]++;
        r[tmpr]++;
    }
  
    ll ans = 0;
    for(auto x : l){
        ans += x.second * r[x.first];
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27932
N, A, B, C, D = map(int, input().split())
S = input()

ans = "Yes"
#岩が2個続いてたらダメ
for i in range(A - 1, max(C, D)):
  if i >= A and S[i] == "#" and S[i - 1] == "#":
    ans = "No"
    break

#途中で追い越しが必要な場合
if D < C:
  #岩無しが何個続いてるかカウント
  cnt = 0
  tmp = 0
  for i in range(B - 2, min(D + 1, N)):#BがDに到着するまでに追い越す
    if S[i] == ".":
      tmp += 1
    else:
      cnt = max(cnt, tmp)
      tmp = 0
  cnt = max(cnt, tmp)
  #岩無しのスペースが3個続かなきゃダメ
  if cnt < 3:
    ans = "No"
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
const int MAXN = -1;

int n;
vector<int> ANS;

int main(){
	while(scanf("%d", &n) == 1){
        if(n%2){
            if(n == 3){ printf("2 5 63\n"); continue; }
            ANS = {2, 4, 6, 3, 9};
            int p = 8; while(ANS.size() < n && p+2 <= 30000){ANS.pb(p); ANS.pb(p+2); p+=6;}
            p = 15; while(ANS.size() < n && p+6 <= 30000){ANS.pb(p); ANS.pb(p+6); p+=12;}
            p = 12; while(ANS.size() < n){ANS.pb(p); p+= 6;}
        }
        else{
            ANS = {2, 4, 3, 9};
            int p = 8; while(ANS.size() < n && p+2 <= 30000){ANS.pb(p); ANS.pb(p+2); p+=6;}
            p = 15; while(ANS.size() < n && p+6 <= 30000){ANS.pb(p); ANS.pb(p+6); p+=12;}
            p = 6; while(ANS.size() < n){ANS.pb(p); p+= 6;}
        }
//        sort(ANS.begin(), ANS.end());
        forn(i, ANS.size()){
            if(i)printf(" ");
            printf("%d", ANS[i]);
        }puts("");
    }
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    ll K; cin >> K;
    if (K%2 == 0 || K%5 == 0) {
        cout << -1 << '\n';
        return 0;
    } else if (K%7 == 0) {
        K /= 7;
    }
    ll now = 0;
    ll power = 1;
    int ans = -1;
    rep(i,K + 1) {
        now += power;
        now %= K;
        if (now == 0) {
            ans = i + 1;
            break;
        } 
        power *= 10;
        power %= K;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<vector>
using namespace std;
int n;
const int MAXN=1e5+5;
vector<int>neigh[MAXN];
int cnt[MAXN],L[MAXN],P[MAXN];
void Traverse(int v){
	cnt[v]=1;
	for(int i=0;i<neigh[v].size();i++){
		int u=neigh[v][i];
		if(P[v]==u)continue;
		L[u]=L[v]+1;P[u]=v;
		Traverse(u);
		cnt[v]+=cnt[u];
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;scanf("%d%d",&a,&b);
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}
	Traverse(1);
	int up=(L[n]-1)/2;
	int v=n;
	while(up--)v=P[v];
	if(cnt[v]>=n-cnt[v])printf("Snuke\n");
	else printf("Fennec\n");
	return 0;
}

Measured memory_bytes: 13184
#include <iostream>

using namespace std;

int main()
{
	long long i, j, k, N, K, l[50], ans = 0;

	cin >> N; cin >> K;
	for (i = 0; i < N; i++) {
		cin >> l[i];
	}

	int temp;
	for (i = N-1; i >= 0; i--) {
		for (j = i - 1; j >= 0; j--) {
			if (l[i] > l[j]) {
				temp = l[i];
				l[i] = l[j];
				l[j] = temp;
			}
		}
	}


	for (i = 0; i < K; i++) {
		ans += l[i];
	}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
  char s[200001],t[200001];
  scanf("%s",s);
  scanf("%s",t);
  int c=0;
  for(int i=0;i<strlen(s);i++){
    if(s[i]!=t[i]){
      t[i]=s[i];
      c++;
    }
  }
  printf("%d",c);
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef  unsigned int uint;
typedef  long double ld;


int main()
{

	// #ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	// #endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int x;
	cin >> x;
	cout << 1000 * (x / 500) + ((x % 500) / 5) * 5 << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
struct data{
	int r,w;
	data(){}
	data(int rr,int ww){
		r=rr;
		w=ww;
	}
	bool operator<(const data d1)const{
		return r>d1.r;
	}
};
int n;
data dat[1005];
bool dp[1005][2001];

int main(void){
		while(1){
		scanf("%d",&n);
		if(n==0)break;
		int allr=0,allw=0;
		for(int i=0;i<n;i++){
			scanf("%d %d",&dat[i].r,&dat[i].w);
			allr+=dat[i].r;
			allw+=dat[i].w;
		}
		sort(dat,dat+n);
		if(dat[0].r<=allr-dat[0].r){
			printf("%d\n",allr+allw);
		}else{
			int wait=dat[0].r-(allr-dat[0].r);
			memset(dp,false,sizeof(dp));
			dp[1][0]=true;
			for(int i=1;i<n;i++){
				for(int j=0;j<=wait;j++){
					if(dp[i][j]){
						dp[i+1][j]=true;
						dp[i+1][j+dat[i].w]=true;
					}
				}
			}
			int val=0;
			for(int i=0;i<=wait;i++){
				if(dp[n][i])val=i;
			}
			printf("%d\n",dat[0].r*2+allw-val);
		}
	}
	return 0;
}

Measured memory_bytes: 3168
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int d= in.nextInt();
        int cover = d*2+1;
        int ans = n/cover;
        if(n%cover==0)
            System.out.println(ans);
        else if(n>d && n%cover>0){
            ans++;
            System.out.println(ans);
        }
        else
            if(n<=d){
                System.out.println(1);
            }

    }
}


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

using namespace std;

constexpr int MAX_V = 5252;
constexpr int INF   = (1 << 29);

struct Edge {
    int to, cap, rev;
    Edge(int to, int cap, int rev) :
        to{to}, cap{cap}, rev{rev} {}
};
 
vector<Edge> G[MAX_V];
int level[MAX_V], iter[MAX_V];
 
void add_edge(int from, int to, int cap)
{
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size() - 1));
}
 
void bfs(int s)
{
    memset(level, -1, sizeof(level));
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
        int v = Q.front(); Q.pop();
        for (int i = 0; i < (int)G[v].size(); i++) {
            Edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                Q.push(e.to);
            }
        }
    }
}
 
int dfs(int v, int t, int f)
{
    if (v == t) return f;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
        Edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
 
int max_flow(int s, int t)
{
    int flow = 0;
    for (;;) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}

void init()
{
    for (int i = 0; i < MAX_V; i++) {
        G[i].clear();
    }
}

int main()
{
    int N, sum = 0;
    cin >> N;
    vector<int> p(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        sum += 2 * p[i];
    }
    int S = N, T = S + 1;
    int m1 = p[0], m2 = p[N - 1], res = INF;
    const int di[2] = {-1, 1};
    
    for (int s = 0; s <= m1; s++) {        
        p[0] -= s;
        for (int t = 0; t <= m2; t++) {
            p[N-1] -= t;
            init();
            for (int i = 0; i < N; i++) {
                if (i % 2 == 0) {
                    add_edge(S, i, p[i] * 2);
                    for (int j = 0; j < 2; j++) {
                        int ni = i + di[j];
                        if (0 <= ni && ni < N && p[ni] > 0) {
                            add_edge(i, ni, INF);
                        }                
                    }
                } else {
                    add_edge(i, T, p[i] * 2);
                }
            }
            res = min(res, sum - max_flow(S, T) - (s + t));
            p[N-1] += t;
        }
        p[0] += s;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

#define MOD (1000000007)

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

    ll result = 0;
    for (int i = 0; i < 60; i++) {
        ll oneCount = 0;
        for (int j = 0; j < n; j++) {
            if ((a[j] >> i) & 1) {
                oneCount++;
            }
        }
        ll zeroCount = n - oneCount;
        ll tmpRes = oneCount * zeroCount;
        for (int k = 0; k < i; k++) {
            tmpRes = (tmpRes * 2) % MOD;
        }
        result = (result + tmpRes) % MOD;
    }
    cout << result << endl;
}


Measured memory_bytes: 2560
s = int(input())
array = [s]
i = 0
flag = True
while flag:
    x = 0
    if array[i]%2==0:
        x = array[i]//2
    else:
        x = 3*array[i]+1
    if x in array:
        print(i+2)
        flag = False
    else:
        array.append(x)
        i += 1
    

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

/*  using namespace  */
using namespace std;

/*  local var  */

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)

/*  typedef  */
typedef long long ll;

/*  function  */
//None

/*  main program  */
int main()
{	
	ll N;
	cin>>N;
	cout<<3*N*N<<endl;
}

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

X = INT()
ans = 0
tmp = 0
for i in range(1, 45721):
	ans += i
	if ans == X:
		print(i)
		break
	elif X < ans:
		print(i)
		break


Measured memory_bytes: 13832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

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

    string s; cin >> s;
    reverse(all(s));
    
    ll num = 0, power = 1;
    map<int, int> mp;
    vector<int> a(sz(s));
    rep(i, sz(s)) {
        int x = s[i]-'0';
        num += power*x;
        mp[num%2019]++;
        debug(x, num);
        a[i] = num%2019;
        power *= 10;
        power %= 2019;
        num %= 2019;
    }
    debug(a);

    int ans = 0;
    for(const auto& m: mp) {
        debug(m. fi , m.se);
        //if (m.fi==0) ans += m.se;
        if (m.se>1) ans += (m.se*(m.se-1))/2;
    }
    ans += mp[0];
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

    int n, m, c;
    cin >> n >> m >> c;

    int b[m], a[m], counter = 0;
    FOR(i, m){
        cin >> b[i];
    }

    FOR(i, n){
        int sum = 0;
        FOR(j, m){
            cin >> a[j];
            sum += a[j]*b[j];
        }

        if(sum+c > 0){
            counter++;
        }
    }

    cout << counter;
    return 0;
}


Measured memory_bytes: 256
S = input()
s0 = S[:len(S)//2]
s1 = S[len(S)//2+1:]
def f(s):
    n = len(s)
    halfn = n//2
    result = True
    for i in range(halfn):
        if s[i] != s[-(i+1)]:
            result = False
    return result
ans = 'Yes'
if not f(S):
    ans = 'No'
elif not f(s0):
    ans = 'No'
elif not f(s1):
    ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define Dim 200009
using namespace std;
ifstream f("A.in");
int x,N,B[Dim];
unsigned long long ans;

pair<int,int> A[Dim];

multimap < int,int > S;

int CB(int st,int dr,int x,int poz)
{
    int sol=0;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if( A[mij].first > x ) dr=mij-1;
        else
        if( A[mij].first < x ) st=mij+1;
        else
        if( A[mij].first==x && mij > poz ) dr=mij-1;
        else
        if( A[mij].first==x && mij <= poz )
        {
            if( mij > sol ) sol=mij;
            st=mij+1;
        }

    }
    return sol;
}

bool cmp(pair<int,int>X,pair<int,int>Y)
{
    if(X.first<Y.first) return 1;
    else
    if(X.first==Y.first)
    {
        if(X.second<Y.second) return 1;
        else return 0;
    }
    else return 0;
}

int CB1(int st,int dr,int x,int poz)
{
    int sol=-1;
    while(st<=dr)
    {
        int mij=(st+dr)/2;

        if( A[mij].first >= x )
        {
            dr=mij-1;
            if(A[mij].first == x) sol=mij;
        }
        else
        if( A[mij].first < x ) st=mij+1;

    }
    if(sol>=poz||sol==-1) return 0;
    return sol;
}

int main()
{

     cin>>N;
     for(int i=1;i<=N;i++)
     {
         cin>>x;
         A[i].first=x+i;
         A[i].second=i;
         B[i]=i-x;
     }
     sort(A+1,A+N+1,cmp);
   //  for(int i=1;i<=N;i++) cout<<A[i].first<<' ';cout<<'\n';
//for(int i=1;i<=N;i++) cout<<A[i].second<<' ';cout<<'\n';
     for(int i=2;i<=N;i++)
     {
         int poz1=CB1(1,i-1,B[i],i-1);
         int poz2=CB(1,i-1,B[i],i-1);
         //cout<<B[i]<<' '<<i-1<<' '<<poz1<<' '<<poz2<<'\n';
         if(poz1!=0&&poz2!=0)
         ans+=poz2-poz1+1;
     }
     cout<<ans;

    return 0;
}


Measured memory_bytes: 5976
while True:
    a, op, b = input().split()
    if op == '+':
        print(int(a) + int(b))
    elif op == '-':
        print(int(a) - int(b))
    elif op == '*':
        print(int(a) * int(b))
    elif op == '/':
        print(int(a) // int(b))
    elif op == '?':
        break


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

int main() {
	int N; cin >> N;
	int u = 0, l = 0, back = 0;
	int ans = 0;
	rep(i, N) {
		int a; cin >> a;
		if (i == 0) {
			back = a; continue;
		}
		if (a == back) continue;
		if (u == 0 && l == 0) {
			if (a > back) u = 1;
			else l = 1;
		} else if (u == 1) {
			if (a < back) {
				ans++; u = 0; l = 0;
			}
		} else {
			if (a > back) {
				ans++; u = 0; l = 0;
			}
		}
		back = a;
	}
	ans++;
	cout << ans << endl;
}

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

int main() {
	int A, B;
	string S;
	cin >> A >> B;
	cin >> S;
	for (int i = 0; i < A; i++)
	{
		if ('0' <= S[i] && S[i] <= '9')
		{
			;
		}
		else
		{
			cout << "No";
			return 0;
		}
	}
	if (S[A] == '-')
	{
		;
	}
	else
	{
		cout << "No";
		return 0;
	}
	for (int i = A+1; i < A+B+1; i++)
	{
		if ('0' <= S[i] && S[i] <= '9')
		{
			;
		}
		else
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll n,q,b,c,sum=0;
  cin>>n;
  vector<ll>a(n);
  map<ll,ll>rep;
  for(int i=0;i<n;i++){
    cin>>a[i];
    rep[a[i]]++,sum+=a[i];
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>b>>c;
    sum+=(c-b)*rep[b];
    rep[c]+=rep[b],rep[b]=0;
    cout<<sum<<endl;
  }
  return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int main() {
	ll E = 1e9;
	ll s;
	scanf("%lld", &s);
	ll y1 = s/E;
	if (y1*E<s) y1++;
	ll y2 = y1*E-s;
	printf("0 0 1000000000 %lld 1 %lld\n", y2, y1);
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
  return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
    basic_ostream<charTDummy, traitsDummy> &(
      basic_ostream<charTDummy, traitsDummy> &)) {
  return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
  cout << "YES" << endl;
#else
  cout << "Yes" << endl;
#endif
  if (ex)
    exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
  cout << "NO" << endl;
#else
  cout << "No" << endl;
#endif
  if (ex)
    exit(0);
}

const ll infLL = LLONG_MAX / 3;

#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif

signed main() {
  int N = read();

  long double ans = 0.0, value;
  string currency;
  REP(i, N) {
    cin >> value >> currency;
    if ( currency == "JPY" ) {
      ans += value;
    } else {
      ans += value * 380000;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int n;
string s;
vector<string> cand;

int main() {
    cin >> n >> s;

    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                string x = "";
                x += '0' + i;
                x += '0' + j;
                x += '0' + k;
                cand.emplace_back(x);
            }
        }
    }

    int ans = 0;
    for (auto target: cand) {
        int j = 0;
        rep(i, n) {
            if (s[i] == target[j]) {
                j++;
            }
        }
        if (j == 3) {
            // cout << target << endl;
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
  int N; cin >>N;
  int a[N],b[N],c[N];
  for(int i=0;i<N;i++){
    cin >>a[i] >>b[i] >>c[i];
  }

  int dp[100010][3];
  dp[0][0]=a[0]; dp[0][1]=b[0]; dp[0][2]=c[0];

  for(int i=1;i<N;i++){
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
  }

  cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;
  return 0;
}


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

int isprime[1000000];

void hurui() {
    isprime[0] = isprime[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        isprime[i] = 1;
    }
    for (int i = 0; i < 1000000; i++) {
        if (isprime[i]) {
            for(int j = i * 2; j < 1000000; j+=i) {
                isprime[j] = 0;
            }
        }
    }
}

int main() {
    hurui();

    int N;
    while(cin >> N) {
        int count = 0;
        for (int i = 0; i <= N; i++) {
            if (isprime[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 5064
import java. util.*;

public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner  (System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a < b && b < c) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}

Measured memory_bytes: 26340
/*------------------------------------
.....Bismillahir Rahmanir Rahim.......
created by muslim.time: 2:24:23 pm....
------------------------------------*/
#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  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

inline void solve(){ 
    map <string,int> mp; 
    int n,m; cin>>n>>m;
    string s;
    for (int i=0;i<n;i++) {
        cin>>s;
        mp[s]++;
    }
    for (auto it: mp) {
        int i=0;
        while (i<it.ss){
            cout<<it.ff;
            i++;
        }
    }
    cout << endl; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    int a,b;scanf("%d %d",&a,&b);
    for(int i=1;1;i++){
        double x=(double)i*0.08;
        double y=(double)i*0.1;
        if(x>100||y>100)break;
        if((int)x==a&&(int)y==b){
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 128