akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;cin>>H>>W;
  for(int i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
  string s;
  for(int i=0;i<H;i++){
    cin>>s;
    cout<<"#"<<s<<"#"<<endl;
  }
  for(int i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

int n, m;
int cnt[MAXN];

int main(void) {
  scanf("%d %d",&n,&m);
  REP(i, m) {
    int u, v;
    scanf("%d %d",&u,&v);
    --u;
    --v;
    ++cnt[u];
    ++cnt[v];
  }

  bool ok = true;
  FOR(i, 1, n)
    if (cnt[i] & 1)
      ok = false;

  printf(ok ? "YES\n" : "NO\n");
  
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll a  ; 
  double b ; 
  
  cin >> a >> b  ;
  intll ib = b*100 + 0.5  ;
  
  intll ans = (a * ib) /100 ;
  
  cout << ans   ;

}
  


Measured memory_bytes: 3676
import numpy as np
N = int(input())
points = np.array(list(map(int, input().split())))


head_rm = points[1:]
tail_rm = points[0:len(points)-1]

amount = sum(abs(head_rm - tail_rm)) + abs(points[0]) + abs(points[-1])

points = np.insert(points, 0, 0)
points = np.insert(points, len(points), 0)

for i in range(1,len(points) - 1):
	if (points[i] <= points[i-1] and points[i-1] <= points[i+1]) or (points[i] >= points[i-1] and points[i-1] >= points[i+1]):
		print(amount - 2 * abs(points[i-1] - points[i]))
	elif (points[i] <= points[i+1] and points[i+1] <= points[i-1]) or (points[i] >= points[i+1] and points[i+1] >= points[i-1]):
		print(amount - 2* abs(points[i+1] - points[i]))
	else:
		print(amount)

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

using namespace std;

int main(void)
{
  int a, b, K;
  cin >> a >> b >> K;
  int x = max(a, b);
  int cnt = 0;
  int stc = 0;
  for(int i = x; i >= 1; i--){
    if(a % i == 0 && b % i == 0){
      cnt++;
      stc = i;
      if(cnt == K){
        break;
      }
    }
  }
  cout << stc << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 ll INF = ll(1e18)+1;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	ll l = -INF, r = INF;
	while(r - l > 1){
		ll x = (l + r) / 2;
		auto ok = [&]{
			ll tot = 0;
			rep(i,n){
				if(a[i] < 0){
					int l = -1, r = n;
					while(r - l > 1){
						int c = (l + r) / 2;
						if(a[c]*a[i] < x) r = c;
						else l = c;
					}
					tot += n - r;
				}
				else{
					int l = -1, r = n;
					while(r - l > 1){
						int c = (l + r) / 2;
						if(a[c]*a[i] < x) l = c;
						else r = c;
					}
					tot += r;
				}
				if(a[i]*a[i] < x) tot--;
			}
			tot /= 2;
			return tot < k;
		}();
		if(ok) l = x;
		else r = x;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int M = in.i();

        boolean[] possible = new boolean[N];
        possible[0] = true;

        int[] cnt = new int[N];
        Arrays.fill(cnt, 1);

        for (int i = 0; i < M; i++) {
            int x = in.i() - 1;
            int y = in.i() - 1;
            possible[y] |= possible[x];
            possible[x] &= cnt[x] != 1;
            cnt[y]++;
            cnt[x]--;
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (possible[i]) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 35236
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    LL N;
    string S;
    cin >> N >> S;
    int count = 0;
    int cnts = 0;
    int cnte = 0;
    for(int i = 0;i < N;i++){
        if(S[i] == '(') count++;
        else    count--;
        cnts = max(cnts, -count);
    }
    count = 0;
    for(int i = N-1;i >= 0;i--){
        if(S[i] == ')') count++;
        else    count--;
        cnte = max(cnte, -count);
    }
    for(int i = 0;i < cnts;i++) cout << '(';
    cout << S;
    for(int i = 0;i < cnte;i++) cout << ')';
}

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

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

using namespace std;

struct Edge{
    ll to;
    ll cost;
};
 
struct Node{
    ll pos;
    ll cost;
    bool operator< (const Node &r) const{
        return cost > r.cost;
    }
};
 

vector<ll> x(1e5+5);
vector<ll> y(1e5+5);
 
ll dijkstra(vector<Edge>* g, ll n){ 
    ll sum = 0;

    priority_queue<Node> que;
    que.push({0, 0});
    vector<ll> res(n, 1e10);
    ll cnt = 0;
    while(!que.empty() && cnt < n){
        Node n = que.top(); que.pop();
        if(res[n.pos] == 1e10){
            res[n.pos] = n.cost;
            cnt++;
        }
        else    continue;
        
        for(auto e : g[n.pos]){
            que.push({e.to, e.cost});
        }
    }

    for(auto e : res)   sum += e;
    
    return sum;
}
 
int main(){
    ll n;
    cin >> n;
    rep(i, n)   cin >> x[i] >> y[i];
 
 
    vector<Edge> g[n];

    vector<Node> xs;
    rep(i, n)   xs.push_back({i, x[i]});

    sort(xs.begin(), xs.end());
    rep(i, n-1){
        ll cost = abs(xs[i].cost - xs[i+1].cost);
        g[xs[i].pos].push_back({xs[i+1].pos, cost});
        g[xs[i+1].pos].push_back({xs[i].pos, cost});
    }

    vector<Node> ys;
    rep(i, n)   ys.push_back({i, y[i]});

    sort(ys.begin(), ys.end());
    rep(i, n-1){
        ll cost = abs(ys[i].cost - ys[i+1].cost);
        g[ys[i].pos].push_back({ys[i+1].pos, cost});
        g[ys[i+1].pos].push_back({ys[i].pos, cost});
    }
  
 
    cout << dijkstra(g, n) << endl;
 
 
    return 0;
}

Measured memory_bytes: 23152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int N = in.nextInt(), M = in.nextInt(), X = in.nextInt();
			int[] a = new int[M];
			for (int i = 0; i < M; i++) {
				a[i] = in.nextInt();
			}

			int c1 = 0, c2 = 0;
			for (int i = 0; i < M; i++) {
				if (a[i] < X) {
					c1++;
				} else if (a[i] > X) {
					c2++;
				}
			}

			out.println(Math.min(c1, c2));


		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 22996
import java.util.Scanner;
import java.util.TreeSet;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

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

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

    static void solve(Scanner scanner) {
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int Q = scanner.nextInt();
        TreeSet<Long> s1 = new TreeSet<>();
        TreeSet<Long> s2 = new TreeSet<>();
        for (int i = 0; i < A; i++) {
            s1.add(scanner.nextLong());
        }
        for (int i = 0; i < B; i++) {
            s2.add(scanner.nextLong());
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            long x = scanner.nextLong();
            long ans = Long.MAX_VALUE;
            Long s1l = s1.floor(x);
            Long s2l = s2.floor(x);
            Long s1r = s1.ceiling(x);
            Long s2r = s2.ceiling(x);
            if (s1l != null & s2l != null)
                ans = Math.min(ans, x - Math.min(s1l, s2l));
            if (s1r != null & s2r != null)
                ans = Math.min(ans, Math.max(s1r, s2r) - x);
            if (s1r != null & s2l != null)
                ans = Math.min(ans, s1r - s2l + Math.min(s1r - x, x - s2l));
            if (s1l != null & s2r != null)
                ans = Math.min(ans, s2r - s1l + Math.min(s2r - x, x - s1l));
            sb.append(ans);
            sb.append('\n');
        }
        System.out.println(sb);
    }

}



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

#define rep(i, N) for (ll i = 0; i < N; i++)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

int main() {
    int H,N, ans = MOD;
    int dp[20005];
    cin >> H >> N;
    vpi AB(N);
    vi ndMP(N);
    rep(i,N) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(), AB.end());

    rep(i, 20005) dp[i] = MOD;
    dp[0] = 0;
    rep(i, H+AB[N-1].first) {
        rep(j, N) {
            int index = (i+1) - AB[j].first;
            if(index < 0) dp[i+1] = min(dp[i+1], (((int)i+1 +AB[j].first-1)/AB[j].first)*AB[j].second);
            else dp[i+1] = min(dp[i+1], dp[index] + AB[j].second);
             
        }
    }

    rep(i, AB[N-1].first) {
        ans = min(ans, dp[H+i]);
    }

    
    //string ans = ( flag ? S : "UNRESTORABLE" );
    //printf("%.8lf\n", ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
def examA():
    H,A = LI()
    ans = (H-1)//A+1
    print(ans)
    return

def examB():
    H, N = LI()
    A = LI()
    if H>sum(A):
        print("No")
    else:
        print("Yes")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

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

public class Test
{
	public static void Main()
	{
		// your code goes here
		List<int> list = new List<int>();
		int N = int.Parse(Console.ReadLine());
		string[] line = Console.ReadLine().Split(' ');
		
		for(int i=0;i<N;i++)
		{
			list.Add(int.Parse(line[i]));
		}
		int Alice = 0, Bob = 0, a;
		
		for(int i=0;i<N;i++)
		{
			a = list.Max();
			if(0==i%2)
			{
				Alice += a;
			}
			else
			{
				Bob += a;
			}
			list.Remove(a);
		}
		Console.WriteLine(Alice-Bob);
	}
}

Measured memory_bytes: 13152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 100;


int main(){
  int N = in(), Y = in(), c;

  rep(a, N+1){
    for(int b = N - a; b >= 0; b--){
      c = N - a - b;
      if(10000*a + 5000*b + 1000*c == Y){
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(int i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(int i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(int)(b);++i)
#define rrep(i,n) for(int i=int(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define irep(i,n) for(int i=int(n);;++i)
#define all(n) begin(n),end(n)
inline auto gcd(auto A,auto B){return B?gcd(B,A%B):A;}
inline auto lcm(auto A,auto B){return A/gcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={-1,1,0,0,1,1,-1,-1};
const vector<lint> dy={0,0,-1,1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint n;
    cin>>n;
    vec a(n),b(n);
    vector<pair<lint,lint>>c(n);
    rep(i,n){
        cin>>a[i]>>b[i];
        c[i]=make_pair(a[i]+b[i],i);
    }
    sort(all(c));
    reverse(all(c));
    lint ans=0;
    rep(i,n){
        if(i%2==0)ans+=a[c[i].second];
        else ans-=b[c[i].second];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
ll func(ll a,ll b){
	ll ret = 1;
	for(int i=1;i<=b;i++){
		ret *= a;
	}
	return ret;
}
int main(void){
	int N,P;
	cin >> N >> P;
	vector<int> a(N);
	bool ok = 1;
	for(int i=0;i<N;i++){
		cin >> a[i];
		if(a[i]%2==1)ok = 0;
	}
	ll ans = 0;
	if(ok){
		if(P==0){
			ans = func(2,N);
		}else{
			ans = 0;
		}
	}else{
		ans = func(2,N-1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int alpha[26];
int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        int u =s[i]-'a';
        alpha[u]++;
    }
    rep(i,26){
        if(alpha[i]==0){
            cout<<char('a'+i)<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    
return 0;
}


Measured memory_bytes: 512
S = input()

def main(S):

    for i, s in enumerate(S):

        if i % 2 == 0:
            if s == 'h': continue
            else       : return "No"
        
        else:
            if s == 'i': continue
            else       : return "No"

    else: 
        if len(S) % 2 == 0:
            return "Yes"
        else:
            return "No"
    

if __name__ == "__main__":

    answer = main(S)
    print(answer)
    




Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#define int long long
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int test[123456];
signed main() {
	int n, m, a = 0, b = 0, ans = 0; double c = 0; cin >> n >> m;
	b = sqrt(gcd(n, m)); c = sqrt(gcd(n, m));
	for (int h = 1; h <= b; h++) {
		if (gcd(n, m) % h == 0) {
			if (h <= 2) { test[a] = h; a++; }
			else if (h % 2 == 0) true;
			else {
				int aa = 0;
				double ab = sqrt(h);
				for (int i = 3; i <= ab; i += 2) {
					if (h % i == 0) {
						aa++;
					}
				}
				if (aa == 0) {
					test[a] = h; a++;
				}
			}
		}
		if (gcd(n, m) % h == 0 && h != gcd(n, m)) {
			if (gcd(n, m) / h <= 2) { test[a] = h; a++; }
			else if (gcd(n, m) / h % 2 == 0)true;
			else {
				int aa = 0;
				double ab = sqrt(gcd(n, m) / h);
				for (int i = 3; i <= ab; i += 2) {
					if (gcd(n, m) / h % i == 0) {
						aa++;
					}
				}
				if (aa == 0) {
					test[a] = gcd(n, m) / h; a++;
				}
			}
		}
	}
	cout << a << endl;
}

Measured memory_bytes: 384
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, X = map(int, readline().split())
A = np.array(read().split(), np.int64)

INF = 10**18
dp = np.full((N, N + N), INF, np.int64)
dp[0] = np.concatenate((A, A))
for n in range(1, N):
    dp[n, 1:] = np.minimum(dp[n - 1, 1:], dp[n - 1, :-1])
dp = dp[:, N:]

x = dp.sum(axis=1) + X * np.arange(N)
print(x.min())

Measured memory_bytes: 89396
using System;

class main{
	static void Main(){
		int X = int.Parse(Console.ReadLine());
		bool[] is_pow = new bool[1001];
		for(int i = 1; i <= 1000; i++){
			is_pow[i] = false;
		}
		is_pow[1] = true;
		for(int i = 2; i * i <= 1000; i++){
			if(!is_pow[i]){
				int b = i;
				for(;;){
					b *= i;
					if(b > 1000) break;
					is_pow[b] = true;
				}
			}
		}
		for(int i = X; i >= 1; i--){
			if(is_pow[i]){
				Console.WriteLine(i);
				break;
			}
		}
	}
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N);
    var(string, s);
    int ans = 0;
    int n = 0;
    for (int c : s) {
        if (c == 'I') ++n;
        else --n;
        chmax(ans, n);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>

#define INF 1000000000LL

using namespace std;
using ll = long long int;

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

ll N;
vector<ll> graph[200001];
vector<ll> A(200001);
vector<ll> L(200001);
vector<ll> dp(200001, INF);

void solve(ll v, ll par, ll depth) {
  auto lb = lower_bound(dp.begin(), dp.begin() + depth, A[v]);
  ll old = *lb; // for roll-back
  *lb = A[v];
  L[v] = lower_bound(dp.begin(), dp.begin() + depth, INF) - dp.begin();

  for (ll cld : graph[v]) {
    if (cld == par) continue;
    solve(cld, v, depth + 1);
  }

  *lb = old;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cin >> N;
  rep(i, N) {
    cin >> A[i];
  }
  rep(i, N - 1) {
    ll u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }

  solve(0, -1, 1);

  rep(i, N) {
    cout << L[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 29892
import java.util.Scanner;

/**
 * Created by oka on 2018/06/23.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        if (n == k) {
            System.out.println(1);
            return;
        }

        System.out.println((n - k - 1) / (k - 1) + 2);
    }
}


Measured memory_bytes: 48624
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
//#define int long long
bool chck(int a,int b,int c,int k){
	if(k == 0){ return a < b and b < c;}
	return chck(2*a,b,c,k-1) or chck(a,2*b,c,k-1) or chck(a,b,2*c,k-1);
}
int32_t main()
{
  int a,b,c,k; cin >> a >> b >> c >> k;

  if( chck(a,b,c,k)) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
typedef vector<int> vi;
typedef long long ll;
const int inf = int(1e9);
const int mod = inf + 7;

void solve(){
	string s;
	cin>>s;
	int n=sz(s);
	while(n--)cout<<'x';

}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define x first 
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
    IOS
    ll N;
    cin >> N;
    if (N & 1) cout << fixed << setprecision(10) << (ld)(N / 2 + 1) / N;
    else cout << 0.5 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t Gcd(int64_t a,int64_t b){
    if(a%b==0) return b;
    Gcd(b,a%b);
}

int main(){
    int N; cin>>N;
    vector<int64_t> T(N);
    rep(n,0,N) cin>>T.at(n);

    int64_t g=T.at(0),l=g;
    rep(n,1,N){
        g=Gcd(l,T.at(n));
        l=l/g*T.at(n);
    }

    cout<<l<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define IT set<node>::iterator
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int F[N], siz[N];
int findz(int x) {
  return F[x] = F[x] == x ? x : findz(F[x]);
}
void Union(int x, int y) {
  int fx = findz(x), fy = findz(y);
  if(fx != fy) {
    if(siz[fx] < siz[y]) {
      swap(fx, fy);
    }
    F[fy] = fx;
    siz[fx] += siz[fy];
  }
}
int main() {
  int n, m; cin >> n >> m;
  for(int i = 1; i <= n; i++) F[i] = i, siz[i] = 1;
  for(int i = 1; i <= m; i++) {
    int x, y; cin >> x >> y;
    Union(x, y);
  }
  int x = -1;
  for(int i = 1; i <= n; i++) {
    x = max(x, siz[i]);
  }
  cout << x << "\n";
  return 0;
}


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

using namespace std;

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a+b+c >= 22){
		printf("bust");
	}else{
		printf("win");
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[300005], n;
int main() {
	cin >> n;
	for (int i = 1; i <= n*3; ++i) cin >> a[i];
	sort(a + 1, a + n*3 + 1);
	long long ans = 0;
	for (int i = 0; i < n; ++i) ans += a[3*n-1-i*2];
	cout << ans;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int main(){
    ll h,w,k;cin>>h>>w>>k;
    vector<vector<bool> >a(h,vector<bool>(w));
    ll sx,sy;
    rep(i,h){
        rep(j,w){
            char c;cin>>c;
            if(c=='#');
            else if(c=='S'){
                a[i][j]=1;
                sx=i;sy=j;
            }
            else a[i][j]=1;
        }
    }
    vector<vector<int> >depth(h,vector<int>(w,inf));
    depth[sx][sy]=0;
    queue<pii>q;
    q.push(mp(sx,sy));
    while(!q.empty()){
        pii n=q.front();
        q.pop();
        int x=n.first,y=n.second;
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w){
                if(depth[nx][ny]==inf&&a[nx][ny]){
                    q.push(mp(nx,ny));
                    depth[nx][ny]=depth[x][y]+1;
                }
            }
        }
    }
    ll mi=max(h,w);
    rep(i,h){
        rep(j,w){
            if(depth[i][j]<=k){
                mi=min(mi,i*1LL);
                mi=min(mi,(h-1-i)*1LL);
                mi=min(mi,j*1LL);
                mi=min(mi,(w-1-j)*1LL);
            }
        }
    }
    ll ans=1;
    if(mi==0);
    else ans+=(mi-1)/k+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

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

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    string S;
    cin >> S;

    int del = 0;
    int s = 0;
    REP(i, S.length()) {
        if (S[i] == 'S') {
            s++;
        }
        else {
            s--;
            if (s >= 0)del++;
            chmax(s, 0);
        }
    }

    cout << S.length() - del * 2 << endl;
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 200005;
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int v[n + 5] = {};
    f(k) {
        int x;
        cin >> x;
        while (x--) {
            int a;
            cin >> a;
            v[a] = 1;
        }
    }
    int ans = 0;
    f1(n) {
        if (!v[i]) {
            ans++;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,q,x;
cin>>n>>k>>q;
map<int,int> mp;
for(int i=0;i<q;i++)
{cin>>x;
mp[x]++;
}
int arr[n];
for(int i=0;i<n;i++){
    arr[i]=k+mp[i+1]-q;
    //cout<<arr[i]<<endl;
}
for(int i=0;i<n;i++){
    if(arr[i]>0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
}




Measured memory_bytes: 7552
N = int(input())
array_t = []
array_x = []
array_y = []
for i in range(N):
    t,x,y = map(int, input().split(" "))
    array_t.append(t)
    array_x.append(x)
    array_y.append(y)
flag = True
for i in range(N):
    if i ==0:
        added = abs(array_x[0])+abs(array_y[0])
        gap = array_t[0] - added
    else:
        added = abs(array_x[i]-array_x[i-1])+abs(array_y[i]-array_y[i-1])
        gap = array_t[i]-array_t[i-1] - added
    if gap>=0 and gap%2 == 0:
        continue
    else:
        print('No')
        flag = False
        break
if flag:
    print('Yes')


Measured memory_bytes: 11840
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: u64,
        B: u64,
        H: u64,
    }
    println!("{}", (A+B)*H/2);
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

bool palindromic(int32 n){
    string s = to_string(n);
    bool retval = true;
    REP(i,s.size()){
        if(s[i] != s[s.size() - i - 1]){
            retval = false;
            break;
        }
    }
    return retval;
}

int main()
{
    int32 a,b;
    cin >> a >> b;
    int32 ans = 0;
    FOR(i,a,b+1){
        if(palindromic(i))ans++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        k: i32,
        s: String,
    }

    if s.len() > k as usize {
        let p = &s[0..k as usize];
        println!("{}...", p);
    } else {
        println!("{}", s);
    }
}


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



int main() {

  int N,M;
  cin >> N >> M;

  vector<vector<int>> vec(N,vector<int>(0));

  for(int i = 0 ;i < M;i++) {
    int a,b;
    cin >> a >> b;
    vec.at(a).push_back(b);
  }

  for(int i = 0;i < vec.at(1).size();i++) {
    int a = vec.at(1).at(i);
    auto it = lower_bound(vec.at(a).begin(),vec.at(a).end(),N);
    if(it == vec.at(a).end()) continue;
    if(*it == N) {
      cout << "POSSIBLE" << endl;
      return 0;
    }

  }

  cout << "IMPOSSIBLE" << endl;
  
}




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

bool IsPrime(int num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main()
{
  long long X;
  cin >> X;

  long long ans;
  while (true)
  {
    if (IsPrime(X))
    {
      break;
    }
    X++;
  }

  cout << X << endl;
  return 0;
}

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

using namespace std;

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

	for(int i = 0; i < s.size(); ++i){
		if(i % 2 == 0 && s[i] == 'L'){
			cout << "No" << endl;
			return 0;
		}
		else if(i % 2 == 1 && s[i] == 'R'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);



int main() {
    ios_base::sync_with_stdio(false); 

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

    return 0;
}


Measured memory_bytes: 4044
N, Y = [int(n) for n in input().split()]
A = 10000
B = 5000
C = 1000

ar = -1
br = -1
cr = -1

if Y % C == 0 and Y / C >= N:
  for an in range(N+1):
    for bn in range(N+1):
      cn = N - an - bn 
      if cn < 0:
        break
      if Y == A * an + B * bn + C * cn:
        ar = an
        br = bn
        cr = cn

print(ar, br, cr)

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String S = sc.next();

		System.out.println("2018"+S.substring(4,10));
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 20692
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if (abs(a - c) <= d) {
		cout << "Yes" << endl;
		return 0;
	}
	else if ((abs(b - a) <= d) && (abs(b - c) <= d)) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
int a[5],k,res,b[]={0,1,0,-1};
signed main(){
	for(int i=1;i<=3;i++)	cin>>a[i];	cin>>k;
	for(int i=1;i<=3&&k;i++){
		int mi=min(k,a[i]);
		k-=mi;	res+=mi*b[i];
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        int a, b, c, d;
        a = in.nextInt();
        b = in.nextInt();
        c = in.nextInt();
        d = in.nextInt();

        if (a == 0 && d != 0)
            System.out.println("No");
        else if (c == 0 && d != 0)
            System.out.println("Yes");
        else {
            while(true) {
                c -= b;
                if (c <= 0) {
                    System.out.println("Yes");
                    return;
                }

                a -= d;
                if (a <= 0) {
                    System.out.println("No");
                    break;
                }
            }
        }

    }
}


Measured memory_bytes: 35796
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let r: usize = itr.next().unwrap().parse().unwrap();
    let s: usize = itr.next().unwrap().parse().unwrap();
    let p: usize = itr.next().unwrap().parse().unwrap();
    let t: Vec<char> = itr.next().unwrap().chars().collect();

    let mut ans = 0;
    let mut i = 0;
    // r <- p, s <- r, p <- s
    // p: 0, r: 1, s: 2
    for i in 0..k {
        let mut j = i;
        let mut te = 9;
        let mut wa = 0;
        while j < n {
            if t[j] == 'r' {
                if te == 0 {
                    te = 9;
                } else {
                    wa += p;
                    te = 0;
                }
            } else if t[j] == 's' {
                if te == 1 {
                    te = 9;
                } else {
                    wa += r;
                    te = 1;
                }
            } else {
                if te == 2 {
                    te = 9;
                } else {
                    wa += s;
                    te = 2;
                }
            }
            j += k;
        }
        ans += wa;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#define ll long long int

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
ll arr[N];
bool b[N];

int main() {

    ll n;
    cin >> n;
    string temp = "";
    while (n) {
        char c = ((26 + (n % 26) - 1)) % 26 + 'a';
        temp += c;
        n--;
        n /= 26;
    }

    reverse(temp.begin(), temp.end());
    cout << temp << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
// #include <set>
// #include <algorithm>
 
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int N;
	cin >> N;
	int64_t t = 1, a = 1;
	for (int i = 0; i < N; i++) {
		int64_t rt, ra;
		cin >> rt >> ra;
		int64_t x = max((t - 1)/rt, (a - 1)/ra) + 1;
		t = rt * x;
		a = ra * x;
	}
	cout << t + a << endl;
	return 0;
}


Measured memory_bytes: 256