akhauriyash/Code-Regression huggingface dataset:
import math

def get_divs(a):
	divs = [1, a]
	for n in range(2, int(a ** 0.5)):
		if a % n == 0:
			divs.append(n)
			divs.append(a // n)
	return divs

def main():
	N, M = map(int, input().split())

	divs = get_divs(M)
	divs.sort()
	divs.reverse()
	divs = filter(lambda x:x <= M // N, divs)

	for div in divs:
		if (M - N * div) % div == 0:
			print(div)
			break

main()


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    fsscan();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d);
    return 0;
}


Measured memory_bytes: 256
<?php
$N = trim(fgets(STDIN));

$array = str_split($N, 1);
if (preg_match('/[24579]/', end($array))) {
    echo 'hon';
} else if(preg_match('/[0168]/', end($array))){
    echo 'pon';
} else if(preg_match('/[3]/', end($array))) {
    echo 'bon';
}

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

int fn(int x){
  double a;
  a = x * 1.08;
  int ans = x;
  for(int i=0;i<=x;i++){
    ans++;
    if(ans == a){
      break;
    }
    else if(ans > a){
      ans--;
      break;
    }
  }
  
  return ans;
}

int main() {
  int n;
  cin >> n;
  int ans = -1;
  for(int i = n;i>0;i--){
    if(fn(i) == n){
      ans = i;
      break;
    }
  }
  
  if(ans >0) cout << ans << endl;
  else cout << ":(" << endl;

  return 0;
}
  

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

int main()
{
    int N, H;
    cin >> N >> H;
    int A[100005], mx_a = 0;
    vector<int> B(N + 5);
    for (int i = 1; i <= N; i++)
    {
        int b;
        cin >> A[i] >> b;
        B.push_back(b);
        mx_a = max(mx_a, A[i]); // mx_a以外のaは不要
    }

    sort(B.begin(), B.end(), greater<int>());

    int ans = 0;
    for (int j = 0; j < B.size(); j++)
    {
        if (B[j] >= mx_a)
        {
            H -= B[j];
            ans++;
        }
        else break;

        if (H <= 0) break;
    }

    if (H > 0)
    {
        ans += (H - 1) / mx_a + 1;
    }

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

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
static const long double pi = 3.141592653589793;

const int m = 10e6;
using namespace std;


int main() {


    ll n, q,tst;
    long double b;

   cin>>n>>b;
   ll c =n*b;
   cout<<c<<endl;

    return 0;
}


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

int main(){
    int x;
    cin >> x;
    ll i = 0;
    while((i+1)*i/2 < x){
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
package main

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

func solve() {
	_, _ = getInt(), getInt()
	_, d2 := getInt(), getInt()

	ans := 0
	if d2 == 1 {
		ans = 1
	}
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
	int x,y,z,hasil;
	z=500;
	hasil=x*y;
	scanf("%d %d", &x, &y);
	if((x*500)<y){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;	
} 


Measured memory_bytes: 3160
import java.io.PrintWriter
import java.math.BigDecimal
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val x = sc.nextLong()
    println(abc160b(x))
}

fun abc160b(x: Long): Long{
    val thou  = (x / 500)
    val five = (x-thou*500) / 5
    return thou*1000 + five * 5
}

fun abc160c(){}




fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



Measured memory_bytes: 29476
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    char a[l];
    int k=0,flag=0;
    for(int i=1;i<=l;i++)
    {
        a[i]=s[k];
        k++;
    }

    for(int i=1;i<=l;i=i+2)
    {
        if(a[i]=='L')
        {
            cout<<"No";
            flag=1;
            return 0;
        }
    }
    for(int i=2;i<=l;i=i+2)
    {
        if(a[i]=='R')
        {
            cout<<"No";
            flag=1;
            return 0;
        }
    }
    if(flag==0)
        cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
int main(){
    int n,w;
    scanf("%d %d",&n,&w);
    LL dp[100005];
    fill(dp,dp+100005,1e18);
    dp[0]=0;
    for(int i=1;i<=n;i++){
        int w,v;
        scanf("%d %d",&w,&v);
        for(int j=100000-v;j>=0;j--){
            dp[j+v]=min(dp[j+v],dp[j]+w);
        }
    }
    int ans=0;
    for(int i=1;i<=100000;i++){
        if(dp[i]<=w)
        ans=i;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1024
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <cassert>
#include <fstream>
using namespace std; 
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
const int N = 5;
double dp[N][N][N][N][N][N][N][N];
double prob[8][8];

double solve(int n,int now,const vector<int> &ord,const vector<int> &ori,vector<int> &st){
  if (ord.size() == now){
    return 1;
  }
  double &ret=dp[st[0]][st[1]][st[2]][st[3]][st[4]][st[5]][st[6]][st[7]];
  //cout <<"ret " << ret << endl;
  if (ret > -0.5)return ret;
  ret=0;
  rep(i,n){
    if (st[i]+1 > ori[i])continue;
    st[i]++;
    ret+=prob[ord[now]][i]*solve(n,now+1,ord,ori,st);
    st[i]--;
  }
  return ret;
}

main(){
  int n;
  int tc=1;
  while(cin>>n&&n){
    rep(i,n)rep(j,n)cin>>prob[i][j];
    rep(i0,5)rep(i1,5)rep(i2,5)rep(i3,5)rep(i4,5)rep(i5,5)rep(i6,5)rep(i7,5)
      dp[i0][i1][i2][i3][i4][i5][i6][i7]=-1;
    vector<int> a(8,0),b(8,0);
    vector<int> ord;
    rep(i,n){
      int tmp;
      cin>>tmp;
      vector<int> t(tmp,i);
      a[i]=tmp;
      copy(t.begin(),t.end(),back_inserter(ord));
    }
    double ans = solve(n,0,ord,a,b);
    if (ans == 0)printf("Case %d: -INFINITY\n",tc++);
    else printf("Case %d: %.8lf\n",tc++,log(ans));
  }
  return 0;
}

Measured memory_bytes: 0
inpl = lambda: list(map(int,input().split()))
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

N, A, B, C, D = inpl()
S = input()

ACarr = S[A-1:C]
BDarr = S[B-1:D]
ACseq = get_sequence(ACarr)[1]
ACrock = ACseq[1::2]
BDseq = get_sequence(BDarr)[1]
BDrock = BDseq[1::2]
if max(ACrock) > 1 or max(BDrock) > 1:
    print('No')
    exit()
elif C > D:
    if ((S[B-2]==S[B-1] and BDseq[0] >= 2)
        or (S[D]==S[D-1] and BDseq[-1] >= 2)
        or max(BDseq[::2]) >= 3):
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Measured memory_bytes: 74360
from fractions import gcd
A, B, C, D = map(int, input().split())
result = B+1 - A
def lcm(a, b):
    return (a * b) // gcd(a, b)
def wareru(min_num, max_num, waru):
    return (max_num)//waru - (min_num-1)//waru
result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C,D))
print(result)

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

typedef long long ll;

const int max_mon=2507;
const int max_V = 53;
const ll INF=1e17;
ll dp[max_V+2][max_mon+2];
struct edge {int to,a,b;};
typedef tuple <ll,int,int > mint;
vector<edge> g[max_V];
int money,i,j;
int C[max_V];
int D[max_V];
priority_queue<mint,vector<mint>,greater<mint>> q;

 void prin (ll x,int  v,int s)
{
 if(s<0) return;
   
 if(dp[v][s]<=x) return;

 
   dp[v][s]=x;
  
   q.push(mint(x,v,s));   
 
}
  
int main()
{
  int N,M;
  int c,r,y,h;
  cin >> N >> M >> money;
  money=min(money,max_mon);
  for(i=0;i<M;i++)
  {
    
    cin >> c >> r>> y >> h;
    c--;r--;
    g[c].push_back({r,y,h});
    g[r].push_back({c,y,h});
  }
  for(i=0;i<N;i++)
  {
    cin >> c >> r;
    C[i]=c;
    D[i]=r;
  }
  for(i=0;i<max_V+2;i++)
  {
     for(j=0;j<max_mon+2;j++)
     {
       dp[i][j]=INF;
     }
  }
 //cout << dp[1][0] << endl;
  prin(0,0,money);
 // cout << dp[1][0] << endl;
  
  while(!q.empty())
  {
    mint now=q.top();q.pop();
    ll x=get<0>(now);
    int v=get<1>(now);
    int s=get<2>(now);
    if(x!=dp[v][s])
    {
      continue;
    }
   // if(x+D[v]==0) cout << v << endl;
    prin(x+D[v],v,min(s+C[v],max_mon));
    int k=g[v].size();
    for(i=0;i<k;i++)
    {
      edge e=g[v][i];
     // if(x+e.b==0)  cout << e.to << endl;
      /*cout << e.b << endl;*/
      prin(x+e.b,e.to,s-e.a);
    }
  
  
  }

      
    for(i=1;i<N;i++)
    {
      ll ans=INF;
      for(j=0;j<max_mon+2;j++)
      {
        ans=min(ans,dp[i][j]);
        //cout << dp[i][j] << " " ;
      }
      cout << ans << endl;
     // cout << endl;
    }

 
}

    

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

int n, m, x, y;
std::vector<int> vec;

int main() {
  std::cin >> n;
  vec.assign(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> vec[i];
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += vec[i];
  }
  std::cin >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> x >> y;
    int ans = sum - (vec[x-1]) + y;
    std::cout << ans << std::endl; 
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

const int max_log_k = 61;
int nxt[max_log_k][2*100000];

int main() {
    int n;
    long long cnt;
    cin >> n >> cnt;
    vector<int> to(n);
    cin >> to;
    rep(i, n) to[i]--;

    rep(i, n) nxt[0][i] = to[i];

    rep(k, max_log_k - 1) {
        rep(i, n) nxt[k + 1][i] = nxt[k][nxt[k][i]];
    }

    int now = 0;
    rep(k, max_log_k) {
        if (cnt >> k & 1) {
            now = nxt[k][now];
        }
    }
    cout << now + 1 << endl;
}

Measured memory_bytes: 51836
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);
int a[MX], b[MX], c[MX];
signed main(){
    int n,ch;
    cin >> n >>ch;
    rep(i,n) {
        cin >> a[i] >> b[i] >> c[i];
    }
    int total = 200002;
    int tt[total];
    int sum[total];
    rep(i,ch) {
        rep(j,total) tt[j]=0;
        rep(j,n) {
            if(c[j]==i+1) {
                tt[a[j]*2-1]++;
                tt[b[j]*2]--;
                //cout << j+1<<" "<<a[j]<<" "<<b[j] << endl;
            }
        } 
        rep(j,total) tt[j+1]+=tt[j];
        rep(j,total) if(tt[j]>0) sum[j]++;
    }
    int ma=0;
    rep(i,total) ma = max(sum[i],ma);
    cout << ma << endl;
    return 0;
}



Measured memory_bytes: 9088
N = int(input())
A = [int(input()) for _ in range(N)]
a = sorted(set(A))
max_count = A.count(a[-1])

for i in range(N):
  if len(a) > 1:
    if A[i] != a[-1]:
      print(a[-1])
    else:
      if max_count > 1:
        print(a[-1])
      else:
        print(a[-2])
  else:
    print(a[-1])

Measured memory_bytes: 17168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005


int main() {

	LL n, arr[ 2* MAX], i, ans = 0, mx = 0, cnt = 0, mxi;

	cin>>n;

	for(i = 0; i < n ; i++ ){

		cin>>arr[i];
	}

	sort(arr, arr+n);
	mx = arr[n-1];
	cnt =1 ;
	mxi = n-1;

	for(i = n-2; i >= 0; i--) {

		ans += mx;
		cnt++;

		//cout<< mx <<endl;

		if(cnt == 2) {
			mxi--;
			mx = arr[mxi];
			cnt = 0;
		}
	}

	cout<<ans<<endl;

}

Measured memory_bytes: 5148
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,i,ans=0;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a[i];
    vector<int> b(n);
    for(i=0;i<n;i++) cin >> b[i];
    vector<int> c(n-1);
    for(i=0;i<n-1;i++) cin >> c[i];
    for(i=0;i<n;i++){
        ans+=b[a[i]-1];
        if(i>0 && a[i]==a[i-1]+1) ans+=c[a[i-1]-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static final long MODVAL = 1000000007L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int result = (a * (a-1))/2 + (b * (b-1))/2;
        System.out.println(result);
     }
}


Measured memory_bytes: 21972
#include <iostream>
using std::cin ;
using std::cout;

int main(){
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int N,K,Q; cin>>N>>K>>Q;
  int* member = new int[N];
  for (int i=0;i<Q;++i){
    int tmp; cin>>tmp;
    ++member[tmp-1];
  }
  for(int i=0;i<N;++i){
    if((member[i]+K)>Q){
      cout << "Yes" << std::endl;
    }else{
      cout << "No" << std::endl;
    }
  }
  return 0;
}


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


void solve()
{
    int n,w;
    cin>>n>>w;
    vector<int>weight(n);
    vector<int>value(n);
    for(int i=0 ; i<n ; i++)
    {
        cin>>weight[i]>>value[i];
    }

    vector<int>dp(w+1 , 0);

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=w ; j>=weight[i-1] ; j--)
        {
            dp[j] = max(dp[j] , dp[j-weight[i-1]]+value[i-1] );
        }
    }

    cout<<dp[w]<<endl;
}



int32_t main()
{
    int tests=1;
    //cin>>tests;
    while(tests--)
    {
        solve();
    }
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

struct State {
    int i, prev, sp; double cost;
};

bool operator>(const State& a, const State& b)
{
    return a.cost > b.cost;
}

const double INF = 1<<29;

int main()
{
    while (1) {
        int n, m, s, g; cin >> n >> m >> s >> g;
        if (!n) break;
        s--, g--;

        vector<vector<double>> dist(n, vector<double>(n, INF));
        vector<vector<int>> lim(n, vector<int>(n));

        while (m--) {
            int x, y, d, c; cin >> x >> y >> d >> c;
            x--, y--;
            dist[x][y] = dist[y][x] = d;
            lim[x][y] = lim[y][x] = c;
        }

        priority_queue<State, vector<State>, greater<State>> Q;
        Q.push({ s, 39, 0, 0 });

        int vis[40][40][40] = {};
        double ans = INF;
        while (Q.size()) {
            auto e = Q.top(); Q.pop();
            if (vis[e.i][e.sp][e.prev]) continue;
            vis[e.i][e.sp][e.prev] = 1;
            if (e.i == g && e.sp == 1) ans = min(ans, e.cost);
            loop (n, i) loop (3, d) {
                int sp = e.sp-1+d;
                if (dist[e.i][i] == INF || i == e.prev ||
                        sp < 1 || sp > lim[e.i][i]) continue;
                Q.push({ i, e.i, sp, e.cost + dist[e.i][i] / sp });
            }
        }
        if (ans != INF) cout << setprecision(12) << fixed << ans << endl;
        else cout << "unreachable" << endl;
    }
    return 0;
}

Measured memory_bytes: 21992
H, W = map(int, input().split())
a = [input() for _ in range(H)]

del_h = []
del_w = []

for i, h in enumerate(a):
    if "#" not in h:
        del_h.append(i)
for j in range(W):
    judge = True
    for k in range(H):
        if a[k][j] == "#":
            judge = False
    if judge:
        del_w.append(j)
for i in range(H):
    ans = ""
    for j in range(W):
        if i in del_h or j in del_w:
            pass
        else:
            ans += a[i][j]
    if len(ans) > 0:    
        print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>

using ll = long long;

char getOp(int i) {
    if (i == 0) {
        return '+';
    }
    else {
        return '-';
    }
}

int main() {
    std::string s;
    int a, b, c, d;
    std::cin >> s;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                int num = a;
                if (k == 0) {
                    num += b;
                }
                else {
                    num -= b;
                }
                if (j == 0) {
                    num += c;
                }
                else {
                    num -= c;
                }
                if (i == 0) {
                    num += d;
                }
                else {
                    num -= d;
                }
                if (num == 7) {
                    std::cout << a << getOp(k) << b << getOp(j) << c << getOp(i) << d << "=7" << std::endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = 0;
  FOR(i,0,N) {
    int l, r; cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(1) {
        if ( x > y ) break;
        x *= 2;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

b_min, isequal, total = 10**10, 0, 0
for _ in range(N):
    a, b = map(int, input().split())
    total += a
    if a > b:
        if b < b_min:
            b_min = b
    elif a == b:
        isequal += 1

if isequal == N:
    print(0)
else:
    print(int(total - b_min))

Measured memory_bytes: 3060
// ABC_108_A
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define forn for(int i = 0; i < (int)n; ++i)

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

	if(k % 2 == 0) {
		int ans = (k / 2) * (k / 2);
		cout << ans << "\n";
	}
	else {
		int ans = (k / 2) * (k / 2 + 1);
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long answer = 0;
        if(a % 2 == 0){
            answer = a;
        }else{
            answer = a*2;
        }
        System.out.println(answer);

    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
/*!* [bitutil] *!*/
/*+* ビット操作関連 *+*/
int PopCount(i64 x) {
    x = (x & 0x5555555555555555) + (x >>  1 & 0x5555555555555555);
    x = (x & 0x3333333333333333) + (x >>  2 & 0x3333333333333333);
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >>  4 & 0x0f0f0f0f0f0f0f0f);
    x = (x & 0x00ff00ff00ff00ff) + (x >>  8 & 0x00ff00ff00ff00ff);
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff);
    return int(x);
}
// 一番後ろに立っているビットの位置を取得
int LastBit(i64 x) {
    if (x == 0) return 0;
    for (int i = 0; i < 64; i++) if (x >> i == 1) return i + 1;
    return -1;
}
// O(HW2^H)
int main() {
    const int INF = 1e7;
    int H, W, K;
    cin >> H >> W >> K;
    vector2d<int> a(H, vector<int>(W, 0));
    for(int i = 0; i < H; i++) {
        string S;
        cin >> S;
        for(int j = 0; j < W; j++) {
            a[i][j] = S[j] == '1';
        }
    }
    int ans = INF;
    for (int b = (1 << H) - 1; b >= (1 << (H - 1)); b--) {
        int cand = PopCount(b) - 1;
        vector<int> x(H, 0);
        bool retry_flag = false;
        for(int j = 0; j < W; j++) {
            if(cand > ans) break;
            int n = 0;
            for(int i = 0; i < H; i++) {
                n += a[i][j];
                if(b & (1 << i)) {
                    x[i] += n;
                    n = 0;
                    if(x[i] > K) {
                        cand++;
                        j--; // retry counting this column
                        x = vector<int>(H, 0);
                        break;
                    }
                }
            }
        }
        ans = min(ans, cand);
    }
    cout << ans << endl;
    return 0;
}

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


int search(vector<int>&,int,int);

int main(){
	int n;
	int tmp;
	cin >> n;
	vector<int> s,t;
	int i = 0;
	while(i<n){
		cin >> tmp;
		if(tmp % 10 == 0)t.push_back(tmp);
		else s.push_back(tmp);
		i++;
	}
	tmp = 0;
	for(auto& v : s){
		tmp += v;
	}

	int result = search(s,s.size()-1,tmp);
	if(result){
		for(auto& v : t){
			result += v;
		}
	}
	cout << result << endl;

	getchar();
	return 0;
}

int search(vector<int> &s,int idx,int score){

	if(idx == -1){
		if(score % 10 == 0)return 0;
		else return score;
	}

	if(score % 10 == 0){
		score = max(search(s,idx - 1,score),search(s,idx - 1,score - s[idx]));
	}

	return score;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
vector<P> vec[100000];
vector<P> city;
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int p, y;
		cin >> p >> y;
		p--;
		vec[p].emplace_back(y, i);
	}
	city.resize(M);
	for (int i = 0; i < N; i++) {
		sort(vec[i].begin(), vec[i].end());
		for (int j = 0; j < vec[i].size(); j++) {
			city[vec[i][j].second] = P(i + 1, j + 1);
		}
	}
	for (int i = 0; i < M; i++) {
		printf("%06d%06d\n", city[i].first, city[i].second);
	}
}

Measured memory_bytes: 7808
import * as fs from 'fs';
 
export function Main(input: string) {
    input = parseInt(input).toString();   // ?
    const last = input[input.length - 1];   // ?
 
    let result = '';
    if (new Set(['2', '4', '5', '7', '9']).has(last)) {
        result = 'hon';
    } else if (new Set(['0', '1', '6', '8']).has(last)) {
        result = 'pon';
    } else {
        result = 'bon';
    }
 
 
    //output
 
    console.log(result);
}
 
// Don't edit this line!
Main(fs.readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29620
l, r = map(int, input().split())

result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
    for j in range(i + 1, min(i + 2019, r) + 1):
        mod = i * j % 2019
        if result is None or result > mod:
            result = mod
            if result == 0:
                break
    if result == 0:
        break
print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  if(s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  vl num(s.size());
  rep(i, s.size()) num[i] = s[i] - '0';
  ll ans = 0;
  rep(i, 1 << (num.size() - 1)) {
    vl tmp = num;
    int it = 0;
    rep(j, num.size() - 1) {
      if((i >> j) & 1)
        rep2(k, it, j + 1) tmp[k] *= 10;
      else
        it = j + 1;
    }
    for(ll a : tmp) ans += a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> dp(50, 0);

int fib(int n)
{
  if (n == 0 || n == 1)
    return dp.at(n) = 1;
  if (dp.at(n) != 0)
    return dp.at(n);
  return dp.at(n) = fib(n - 1) + fib(n - 2);
}

int main()
{
  int N;
  cin >> N;
  cout << fib(N) << endl;
}


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

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var gl = (n + 1) / 2;
		var gs = new int[gl].Select(_ => new List<int>()).ToArray();
		for (int i = 0; i < gl; i++)
		{
			gs[i].Add(i + (n + 1) % 2);
			gs[i].Add(n - i);
		}
		gs[0].Remove(0);

		var r = Enumerable.Range(0, gl == 2 ? 1 : gl).SelectMany(i => gs[i].SelectMany(x => gs[(i + 1) % gl].Select(y => $"{x} {y}"))).ToArray();
		Console.WriteLine(r.Length);
		Console.WriteLine(string.Join("\n", r));
	}
}


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

int main() {
  int N, x; cin >> N >> x;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int count=0;
  for (int i=0; i<N; i++) {
    x -= a[i];
    if (x<0) break;
    count++;
  }
  if (count==N && x>0) count--;
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int ans = 0 ;
        
        for(int i = a ; i <= b ; i++){
            if(c%i == 0){
                ans++;
            }
        }
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 26336
S = input()
n = len(S)

ans = [0] * n
cnt = 0

for i in range(n):
    if 'R' == S[i]:
        cnt += 1
        continue
    ans[i-1] += (cnt + 1) // 2
    ans[i] += cnt // 2
    cnt = 0

for i in range(n-1, -1, -1):
    if 'L' == S[i]:
        cnt += 1
        continue
    ans[i+1] += (cnt + 1) // 2
    ans[i] += cnt // 2
    cnt = 0
print(*ans)


Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23252
/*
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#define M 200100
#define ll long long
using namespace std;

int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}

char s[M];
int a[M];
int main() {
	//freopen(".in", "r", stdin), freopen(".out", "w", stdout);
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	ll ans = 0;
	for(int i = 1; i <= len; i++) {
		a[i] = s[i] == 'B';
	}
	ll s = 0;
	for(int i = 1; i <= len; i++) {
		if(a[i]) s++;
		else ans += s;
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int k = in.nextInt();
        int x=0,cnt=0;
        for(int i=0;i<n;i++){
            x = in.nextInt();
            if(x>=k) cnt++;
        }
        out.println(cnt);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 29920
#include <stdio.h>

int main(void) {
	long N;
	scanf("%ld", &N);
	for (long h = 1; h <= 3500; h++) {
		for (long n = 1; n <= 3500; n++) {
			if (4 * h * n - N * n - N * h <= 0) continue;
			if (N * h * n % (4 * h * n - N * n - N * h)) continue;
			long w = N * h * n / (4 * h * n - N * n - N * h);
			printf("%ld %ld %ld", h, n, w);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 5e5 + 5;
const int oo = 1e9 + 5;
const LL ooll = 1e18 + 5;
const int MOD = 1e9 + 7;

vector<vector<int>> fs, trie;
vector<int> sub;
int sz;
int construct_node() {
    ++sz;
    trie.push_back(vector<int>(26, -1));
    fs.push_back(vector<int>(26, 0));
    sub.push_back(0);
    return sz-1;
}

void solve() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<pair<int,int>> ord(n);
    for (int i=0;i<n;++i) {
        cin >> s[i];
        ord[i] = {-(int)s[i].size(), i};
    }
    sort(ord.begin(), ord.end());
    vector<string> ts = s;
    for (int i=0;i<n;++i) {
        s[i] = ts[ord[i].second];
        reverse(s[i].begin(), s[i].end());
    }
    sz = 0;
    construct_node();
    LL ans = 0;
    for (auto it : s) {
        int m = it.size();
        // cout << m << " " << it << '\n';
        int cur = 0;
        for (int i=0;i<m-1;++i) {
            cur = trie[cur][it[i]-'a'];
            if (cur == -1) break;
        }
        if (cur != -1) {
            // cout << it << " found\n";
            ans += fs[cur][it[m-1]-'a'];
        }

        vector<int> backtrack;
        cur = 0;
        int newp = m + 1;
        for (int i=0;i<m;++i) {
            backtrack.push_back(cur);
            int go = trie[cur][it[i]-'a'];
            if (go == -1) {
                newp = min(newp, i);
                go = construct_node();
                trie[cur][it[i]-'a'] = go;
            } 
            cur = go;
        }
        sub[cur]++;
        for (int i=m-1;i>=0;--i) {
            int pcur = cur;
            cur = backtrack[i];
            sub[cur]++;
            fill(fs[cur].begin(), fs[cur].end(), 0);
            for (int k=0;k<26;++k) {
                int nxt = trie[cur][k];
                if (nxt == -1) continue;
                for (int j=0;j<26;++j) if (j != k) {
                    fs[cur][j] += fs[nxt][j];
                }
                fs[cur][k] += sub[nxt];
            }
        }
    }

    cout << ans << '\n';
}   

int main() {
    // FASTIO;
    // tstmul();
    // return 0;
    int T = 1;
    // cin >> T;
    while(T--) {
        solve();
    }
    // cout << fixed << setprecision(10);
    // cout << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
    return 0;
} 

Measured memory_bytes: 275328
#include <cstdio>
#include <algorithm>
#include <functional>

#define N 25

using namespace std;

struct k_operafan
{
  int k;
  int operafan;
  bool operator< ( const struct k_operafan &x )
  const { return ( operafan < x.operafan ); }
};
typedef struct k_operafan k_operafan;

main ( )
{
  int i;

  for ( ; ; )
  {
    k_operafan d[ N ];
    int n, w = 0;

    scanf ( "%d", &n );
    if ( n == 0 ) break ;
    for ( i = 0; i < n; ++i ) scanf ( "%d%d", &d[ i ].k, &d[ i ].operafan );
    sort ( d, d + i );

    for ( i = 0; i < n; ++i )
    {
      w += d[ i ].k;
      if ( d[ i ].operafan < w ) break ;
    }
    puts ( i == n ? "Yes" : "No" );
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int mxn = 1e5+5;
bool isPrime(int n)
{
    if(n==1) return false;
    for(int i = 2; i <= sqrt(n) ; i++)
    {
        if(n%i==0) return false;
    }
    return true;
}
int check(int n)
{
    if(isPrime(n) && isPrime((n+1)/2)) return 1;
    return 0;
}
int f[mxn];
int main()
{
    for(int i = 1; i < mxn; i++)
    {
        f[i] = check(i);
    }
    f[0] = 0;
    for(int i = 1; i <mxn; i++)
    {
    f[i] = f[i] + f[i-1];
    }
    int q;
    cin>>q;
    int  l , r;
    while(q--)
    {
        cin>>l>>r;
        cout<<f[r]-f[l-1]<<endl;
    }
        return 0;
}


Measured memory_bytes: 1024
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
int sum=0;
vi v(n);cin>>v;
map<int,int> mp;
for(int i:v)
sum+=i,mp[i]++;
int q;cin>>q;
while(q--)
{
	int x,y;cin>>x>>y;
	if(mp.count(x))
	{
		sum+=(y-x)*mp[x];
		mp[y]+=mp[x];
		mp[x]=0;
		cout<<sum<<"\n";
	}
	else
	{
		cout<<sum<<"\n";
	}
}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 9300
#include <stdio.h>

int main()
{
    char ch;
    int  count[26];

    int j;
    for (j = 0;j < 26; j++) {
        count[j] = 0;
    }

    int ascii_A = 'A';
    int ascii_Z = 'Z';
    int ascii_a = 'a';
    int ascii_z = 'z';

    for (;;) {
        int ret = scanf("%c", &ch);
        if (ret == EOF) {
            break;
        } else if ((ascii_a <= ch)&&(ch <= ascii_z)) {
            j = ch - ascii_a;
            count[j]++;
        } else if ((ascii_A <= ch)&&(ch <= ascii_Z)) {
            j = ch - ascii_A;
            count[j]++;
        }
    }

    for (j = 0; j < 26; j++) {
        printf("%c : %d\n", ('a' + j), count[j]);
    }
    return 0;
}



Measured memory_bytes: 2044
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r,a[100000];

pair<LL, LL>bc;
vector<pair<LL, LL>>BC;
string s[2001];
LL dp[100001];
LL dfs(LL A) {
	if (A == N)return 1;
	if (dp[A] >= 0)return dp[A];
	if (dp[A] == -2)return 0;
	LL b = 0;
	for (int i = 1; i <= 2; i++) {
		b += dfs(A + i);
		b %= 1000000007;
	}
	return dp[A] = b;
}
int main() {

	cin >> N >>M;
	for (int i = 0; i < M; i++) {
		cin >> a[i];
	}
	for (int i = 0; i <= N; i++)dp[i] = -1;
	for (int i = 0; i < M; i++) {
		dp[a[i]] = -2;
	}

	cout << dfs(0) << endl;
	return 0;

}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << (n+1)/2 << endl;

  return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	int x1 = sum/n;
	int x2 = sum/n + 1;
	int ans1 = 0;
	int ans2 = 0;
	for(int i=0;i<n;i++){
		ans1 += pow(a[i] - x1,2);
		ans2 += pow(a[i] - x2,2);
	}
	cout << min(ans1,ans2) << endl;
	
	
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);
    double r;
    cin>>r;
    printf("%0.2lf\n",(r*2.0*3.1416));
    return 0;
}




Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastio;
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define elif else if
#define rep(i,n) for((int)(i)=0;(i)<(n);++(i))
#define str string
#define Cout(a) cout<<(a)<<endl;
int a,b,c,i,j,k,n,m,x,y,cnt=0,ans=0;
str s,t;

int main(){
  cin>>a>>b>>c;
  Cout((a+b)*c/2);
  return 0;
}


Measured memory_bytes: 256
import math

i = list(map(float, input().split()))
m=0

j=i[0]/0.08
k=math.ceil(j)

l=i[1]/0.10
n=math.ceil(l)

while n*0.10<math.ceil(i[1])+1:
	k=math.ceil(j)
	while k*0.08<math.ceil(i[0])+1:
		if k==n:
			m=1
			#print(k,n)
			break
		else:
			k+=1
			#print(k,n)
			continue
	else:
		n+=1
		#print(k,n)
		continue
	break
  
else:
	print('-1')

if m==1:
	print(k)

Measured memory_bytes: 3064
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll l, r; cin >> l >> r;
	set<ll> nums;
	forl(i, l, r+1) {
		ll val = i%2019;
		if(nums.count(val)) break;
		else nums.insert(val);
	}
	ll mn = INT_MAX;
	fore(e, nums) {
		fore(e2, nums) {
			if(e == e2) continue;
			mn = min(mn, (e*e2)%2019);
		}
	}
	println(mn);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string s[110];
int main(){
   int n,l;
   scanf("%d%d",&n,&l);
   for (int i=0;i<n;i++) cin >> s[i];
   sort(s,s+n);
   for (int i=0;i<n;i++) cout << s[i] ;
   cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    vi a(N);
    REP(i,N)cin>>a[i];
    sort(a.begin(),a.end());
    ll ans=-INF;
    auto it=a.begin();
    REP(i,N){
        it=upper_bound(it,a.end(),a[i]+2);
        ll index=it-a.begin();
        ans=max(ans,index-i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024