akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

typedef pair<int, int> Edge;

vector<vector<Edge> > g;
vector<vector<bool> > u;

int bfs(int s, int t){
  int n = g.size();

  vector<int> ans(n, -1);
  queue<int> q;
  ans[s] = 0; q.push(s);

  while(q.size()){
    int pos = q.front(); q.pop();
    int cost = ans[pos];
    REP(i,g[pos].size()){
      int next = g[pos][i].first;
      if(u[pos][i] && ans[next] == -1){
        if(next == t) return cost + 1;
        ans[next] = cost + 1;
        q.push(next);
      }
    }
  }

  return n + 1;
}

int main(){
  while(const int n = getInt()){
    const int s = getInt() - 1;
    const int t = getInt() - 1;
    const int m = getInt();
    vector<vector<int> > id(n);

    g = vector<vector<Edge> >(n);
    u = vector<vector<bool> >(n);

    REP(i,m){
      const int a = getInt() - 1;
      const int b = getInt() - 1;

      const size_t v1 = g[a].size();
      const size_t v2 = g[b].size();

      g[a].push_back(Edge(b, v2));
      g[b].push_back(Edge(a, v1));

      u[a].push_back(true);
      u[b].push_back(false);

      id[a].push_back(i + 1);
      id[b].push_back(i + 1);
    }

    pair<int, int> ans = make_pair(bfs(s, t), 0);

    REP(i,n) REP(j,g[i].size())
      if(u[i][j]){
        int to  = g[i][j].first;
        int rev = g[i][j].second;
        u[i][j] = false;
        u[to][rev] = true;
        ans = min(ans, make_pair(bfs(s, t), id[i][j]));
        u[i][j] = true;
        u[to][rev] = false;
      }

    printf("%d %d\n", ans.first, ans.second);
  }
  return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int A,B,C,D;cin >> A >> B >> C >> D;
    int E,F;cin >> E >> F;
    double ins = -1;
    int ans1,ans2;
    for(int a = 1;a <= F/A/100;a++){
        for(int b = 0;b <= F/B/100;b++){
            for(int c = 0;c <= F/C;c++){
                for(int d = 0;d <= F/D;d++){
                    double weight = 1.0*a*A*100 + b *B*100 + c * C + d * D;
                    if(F >= weight && weight >= 100*A && E >= 1.0*(c*C+d*D)/(a*A+b*B)){
                        if(1.0*(c*C + d*D)/(weight) >= ins){
                            ins = 1.0*(c*C + d*D)/(weight);
                            ans1 = c*C+d*D;
                            ans2 = weight;
                        }
                    }
                }
            }
        }
    }
    cout<<ans2 << " "<<ans1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int z[100005];
		int ans=0;
		for(int i=1;i<=n;i++)
		scanf("%d",&z[i]);
		sort(z,z+n+1);
		ans=(z[n/2+1]-z[n/2]);
		printf("%d\n",ans);//
	}
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

string s;

int main()
{
    cin >> s;
    for (auto c : s)
    {
        if (c == '9')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
int n, k;
set<int> used;

void read() {
	cin >> n >> k;
	while (k--) {
		int x;
		cin >> x;
		while (x--) {
			int y;
			cin >> y;
			used.insert(y);
		}
	}	
	cout << n - used.size() << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 3664
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, L = map(int, input().split())
    T = []
    for _ in range(N):
        T.append(input())
    print("".join(sorted(T)))


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  bool a=false;
  for (int i=1;i<10;i++){
    for (int j=1;j<10;j++){
      if (N==i*j){
        a=true;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX = 400010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long PER(int n,int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] *  finv[n - k] % MOD;
}
int main(){
  ll i,n,k;
  COMinit();
  cin >> n >> k;
  if(n<=k){
    cout << COM(n+n-1,n) << endl;
    return 0;
  }
  ll ans=0;
  for(i=0;i<=k;i++){
    ans+=COM(n,i)%MOD*COM(n-1,i)%MOD;
  }
  ans=ans%MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12984
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		Arrays.parallelSort(a);

		int ans = 0;
		int cnt0 = 0;
		int cnt1 = 0;
		int cnt2 = 0;
		int base = a[0];
		int baseIdx = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == base) {
				cnt0++;
			} else if (a[i] == base + 1) {
				cnt1++;
			} else if (a[i] == base + 2) {
				cnt2++;
			} else {
				int sum = cnt0 + cnt1 + cnt2;
				ans = Math.max(ans, sum);
				baseIdx += cnt0;
				base = a[baseIdx];
				cnt0 = cnt1;
				cnt1 = cnt2;
				cnt2 = 0;
				i--;
			}
			if (i == n - 1) {
				int sum = cnt0 + cnt1 + cnt2;
				ans = Math.max(ans, sum);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50676
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int x;
	cin>>x;
	for(long long int i=-5000;i<=5000;i++)
	{
		for(long long int j=-5000;j<=5000;j++)
		{
			if((i*i*i*i*i-j*j*j*j*j)==x)
			{
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

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

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

    int x[n]; 
    rep(i,0,n) cin >> x[i];
    int y[m]; 
    rep(i,0,m) cin >> y[i];

    int sumx = 0;
    int sumy = 0;

    rep(i,0,n) sumx = (sumx + (i * 2 + 1 - n) * x[i]) % mod;
	rep(i,0,m) sumy = (sumy + (i * 2 + 1 - m) * y[i]) % mod;

    cout << sumx * sumy % mod << endl;
    return 0;


}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc045/tasks/abc045_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length() - 1;
    int sum = 0;
    REP(bit, (1LL << len)) {
        string t = s.substr(0, 1);
        REP(i, len) {
            if (bit & (1LL << i)) {
                sum += stoll(t);
                t = "";
            }
            t += s[i + 1];
        }
        if (t != "") {
            sum += stoll(t);
        }
    }
    cout << sum << endl;
    return 0;
}


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

#ifdef ONLINE_JUDGE
    #undef DBG
#endif

#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; ++i)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fr first
#define sc second

using ll = long long;


const int N = 111;
char s[N];



int main() {
    scanf("%s", s );
    for (int i = 0; i < (int) strlen(s); ++i) {
        if ((i + 1) % 2 == 1) {
            if (s[i] == 'L') 
                return !printf("No\n");
        }
        else { 
            if (s[i] == 'R')
                return !printf("No\n");
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace DSL1_A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var Q = sr.Next<int>();
            var query = sr.Next<int>(Q, 3).Select(a => new {com = a[0], x = a[1], y = a[2]}).ToArray();

            var uf = new UnionFind(N);
            foreach(var q in query){
                if(q.com == 0){
                    uf.Unite(q.x, q.y);
                }
                if(q.com == 1){
                    Console.WriteLine(uf.IsSameSet(q.x, q.y) ? 1 : 0);
                }
            }

            //---------------------------------
        }
    }

    public class UnionFind{
        private readonly int[] _rank;
        private readonly int[] _p;

        public UnionFind(int size){
            _rank = new int[size];
            _p = new int[size];

            for(var i = 0; i < size; i++){
                _rank[i] = 0;
                _p[i] = i;
            }
        }

        public void Unite(int x, int y){
            x = FindSet(x);
            y = FindSet(y);

            if(_rank[x] > _rank[y]) _p[y] = x;
            if(_rank[x] < _rank[y]) _p[x] = y;
            if(_rank[x] == _rank[y]){
                _p[x] = y;
                _rank[y]++;
            }
        }

        public bool IsSameSet(int x, int y){
            return FindSet(x) == FindSet(y);
        }

        public int FindSet(int x){
            if(_p[x] == x) return x;
            return _p[x] = FindSet(_p[x]);
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 23268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int L1, L2, R1, R2;
  cin >> L1 >> L2 >> R1 >> R2;
  
  if(L1 + L2 < R1 + R2){
    cout << "Right" << endl;
  }
  else if(L1 + L2 == R1 + R2){
    cout << "Balanced" << endl;
  }
  else{
  cout << "Left" << endl;
  }
}

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

int main(void){
    string s;
    stack<int> stk;
    while(cin>>s){
        int a,b;
        if(*s.begin()=='+'){
            b=stk.top();
            stk.pop();
            a=stk.top();
            stk.pop();
            a+=b;
        }
        else if(*s.begin()=='-'){
            b=stk.top();
            stk.pop();
            a=stk.top();
            stk.pop();
            a-=b;
        }
        else if(*s.begin()=='*'){
            b=stk.top();
            stk.pop();
            a=stk.top();
            stk.pop();
            a*=b;
        }
        else{
            a=stoi(s);
        }
        stk.push(a);
    }
    cout << stk.top() <<endl;
    
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s;
	cin >> s;
	cout << s.front() << s.size()-2 << s.back() << endl;

	rtn 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

namespace ConsoleApp_ITP1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> inputList = new List<int>();

            for(int i = 1; i <= 10000; i++)
            {
                int input = int.Parse(Console.ReadLine());

                if (input == 0)
                {
                    break;
                }
                else
                {
                    inputList.Add(input);
                }
            }
            for(int i = 0; i<inputList.Count;i++)
            {
                Console.WriteLine("Case {0}: {1}",i+1 ,inputList[i]);
            }
        }
    }
}


Measured memory_bytes: 9424
fun main(args: Array<String>) {
    var S = readLine()!!.toString()
    var ans = S.toLong()
    
    for(i in 1..Math.pow(2.0,(S.length-1).toDouble()).toInt()-1){
        var str = ""
        var plus:MutableList<String> = mutableListOf()
        var j = i
        var t = ""
        for(s in S){
            str += s
            if(j%2 != 0) str += '+'
            j /= 2
        }
        
        for(k in str){
            if(k == '+'){ 
                plus.add(t)  
                t = ""
            }
            else t += k
        }
        plus.add(t)
        
        ans += plus.map{x->x.toLong()}.sum()
    }
    println(ans)
}


Measured memory_bytes: 33764
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const long long INF=1e18+10;
long long a[N];
long long dp[N];
long long b[N];
int main()
{
    long long n,w,sum=0;
    scanf("%lld%lld",&n,&w);

    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
        sum+=b[i];
    }
    dp[0]=0;
    for(int i=1;i<=sum;i++)
        dp[i]=INF;

        for(int i=0;i<n;i++){
            for(int j=sum-b[i];j>=0;j--){
                dp[b[i]+j]=min(dp[b[i]+j],dp[j]+a[i]);
            }
        }
        long long ans=0;

        for(long long i=0;i<=sum;i++)
            if(dp[i]<=w)
            ans=max(ans,i);

        printf("%lld",ans);
}


Measured memory_bytes: 6400
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    if (b < a) cout << a - 1 << "\n";
    else cout << a << "\n";
    return 0;
}

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, D) = get!(usize, usize);
    let Xs = get!(isize | N);
    let mut cnt = 0usize;
    let Xs2 = Xs.clone();
    for (i, Xi) in Xs.iter().enumerate() {
        for Xj in Xs2.iter().take(i) {
            let mut d2 = 0isize;
            for k in 0..Xi.len() {
                d2 += (Xi[k] - Xj[k])*(Xi[k] - Xj[k]);
            }
            let d = ((d2 as f64).sqrt() as isize);
            if d*d == d2 {
                cnt += 1;
            }
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char s[105], t[105], c;
int mn=99;

int f(char p[], char q) {
	int i, n=strlen(p);
	for(i=0; i<n; i++) if(p[i] != p[0]) break;
	if(i==n) return 0;
	for(i=0; i<n; i++) if(p[i+1]==q) p[i]=q;
	p[n-1] = '\0';
	return f(p, q) + 1;
}

int main() {
	cin>>s;
	for(c='a'; c<='z'; c++) {
		strcpy(t, s);
		mn = min(mn, f(t, c));
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	int x = sc.nextInt();
    	int t = sc.nextInt();

    	int ans = x-t;
    	if(ans < 0){
    		ans = 0;
    	}
    	// 出力
    	System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

Measured memory_bytes: 15612
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;

int main() {
	int n;
	int tmp1=0,tmp2=0;
	int* num;
	int cnt = 0;
	cin >> n;
	vector <int> v;
	int mi = INT_MAX;
	num = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> num[i];
		mi = min(mi, num[i]);
		if (mi == num[i]) {
			cnt++;
		}

	}
	
	cout << cnt<< endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll mi = min(n, b- 1);
    ll ans = floor(a*mi/b) - a*floor(mi/b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++)
    cin>>v[i];
sort(v.begin(),v.end());
int ans=0;
for(int i=n-1;i>=n-k;i--)
    ans+=v[i];
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int[] W=new int[N+1];
		for(int i=1; i<=N; i++) {
			W[i]=sc.nextInt();
		}
		for(int i=1; i<=N; i++) {
			W[i]=W[i]+W[i-1];
		}
		int MIN=114514810;
		for(int i=1; i<N; i++) {
			MIN=Math.min(MIN, Math.abs((W[N]-W[i])-W[i]));
		}
		pl(MIN);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

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

    VI v(n);
    REP(i,n){
        cin >> v[i];
    }

    SORT(v);

    int cnt = n - k;
    long long sum = 0;
    REP(i, cnt)
    {
        sum += v[i];
    }

    ANS(sum);
    return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
mod = 10 ** 9 + 7

XS = 0
for i, x in enumerate(X, start=1):
    XS += (x * ((i - 1) - (N - i))) % mod
YS = 0
for i, y in enumerate(Y, start=1):
    YS += (y * ((i - 1) - (M - i))) % mod

print(XS * YS % mod)


Measured memory_bytes: 18624
import math

d, g = map(int, input().split())
p = [0]*d
c = [0]*d

for i in range(d):
  p[i], c[i] = map(int, input().split())

point =[i*100 for i in range(1, d+1)]
ans = float("inf")

for i in range(1<<d):
  score = 0
  cnt = 0
  for j in range(d):
    if i>>j &1:
      cnt += p[j]
      score += point[j]*p[j] + c[j]
  if score >= g:
    ans = min(ans, cnt)
    continue
  for j in range(d)[::-1]:
    if i >> j &1:
      continue
    x = min(math.ceil((g-score)/point[j]), p[j]-1)
    cnt += x
    score += point[j]*x
    if score >= g:
      ans =min(ans, cnt)
      break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  int A, B, C;
  int flag = 0;//存在すれば1，存在しなければ0

  scanf("%d %d", &A, &B);

  for(C = 1; C <= 3; C++){
    if((A*B*C)%2 == 1){
      flag = 1;
      break;
    }
  }

  if(flag == 1){
    printf("Yes\n");
  }else if(flag == 0){
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}
int main()
{
    int n; cin >> n;
    string name[n];
    
    rep(i,n) cin >> name[i];
    
    long long a[5] = {0,0,0,0,0};
    string c = "MARCH";
    
    rep(i,n) {
        rep(j,5){
            if(name[i][0]==c[j]) a[j]++;
        }
    }
    
    long long ans = 0;
    rep(i,3){
        Rep(j,i+1,4){
            Rep(k,j+1,5){
                ans += a[i]*a[j]*a[k];
            }
        }
    }
    
    cout << ans << endl;
        
        
}



Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


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

	if (A[0] != 0) co(-1);
	else {
		ll kotae = 0;
		int OK = 1;
		
		for (int i = N - 1; i >= 0; i--) {
			if (A[i] != 0) {
				int kari = A[i];
				if (i < kari) {
					OK = 0;
					break;
				}
				rep1(j, kari - 1) {
					if (A[i - 1] < kari - j) {
						OK = 0;
						break;
					}
					else if (A[i - 1] == kari - j) {
						i--;
					}
					else break;
				}
				kotae += kari;
			}
		}

		if (OK) co(kotae);
		else co(-1);
	}

	Would you please return 0;
}

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

int main(){
  string s;
  int k;
  cin >> k >> s;
  if(s.size()<=k){
    cout << s << endl;
  }else{
    for(int i=0;i<k;i++)
      cout << s.at(i);
    cout << "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m,k = mi()

mod = 998244353

dp = [0]*n

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

'''
ここは任意
'''
N = 2*(10**5)

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

dp[0] = m
for i in range(1,n):
    dp[i] = dp[i-1]*(m-1) % mod

ans = 0
for i in range(k+1):
    tmp = cmb(n-1,i,mod)*dp[n-1-i] % mod
    ans += tmp
    ans %= mod
print(ans)

Measured memory_bytes: 40628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

vector<vector<int>> make_imos(vector<vector<int>>& src)
{
	int n = src.size();
	int m = src[0].size();

	vector<vector<int>> imos;
	imos.resize(n);
	for(auto& x : imos) x.resize(m);

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			int& v = imos[i][j];
			v = src[i][j];
			if(i > 0) v += imos[i-1][j];
			if(j > 0) v += imos[i][j-1];
			if(i > 0 && j > 0) v -= imos[i-1][j-1];
		}
	}

	return imos;
}

int compute_sum(int sx, int sy, int tx, int ty, vector<vector<int>>& imos)
{
	int s = imos[tx][ty];
	if(sx > 0) s -= imos[sx-1][ty];
	if(sy > 0) s -= imos[tx][sy-1];
	if(sx > 0 && sy > 0) s += imos[sx-1][sy-1];
	return s;
}

int main()
{
	vector<vector<int>> nodes, edges;
	int n, m, q;

	scanf("%d%d%d", &n, &m, &q);
	nodes.resize(n);
	for(auto& x : nodes) x.resize(m);
	edges.resize(n * 2);
	for(auto& x : edges) x.resize(m * 2);

	for(int i = 0; i < n; ++i) {
		char buf[2048];
		scanf("%s", buf);
		for(int j = 0; j < m; ++j)
			nodes[i][j] = (buf[j] == '1' ? 1 : 0);
	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			if(nodes[i][j] != 1)
				continue;
			if(i < n - 1 && nodes[i+1][j] == 1)
				edges[i*2 + 1][j*2] = 1;
			if(j < m - 1 && nodes[i][j+1] == 1)
				edges[i*2][j*2 + 1] = 1;
		}
	}

	vector<vector<int>> imos_nodes = make_imos(nodes), imos_edges = make_imos(edges);

	for(int query = 0; query < q; ++query) {

		int sx, sy, tx, ty;

		scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
		sx -= 1; sy -= 1; tx -= 1; ty -= 1;

		int x = compute_sum(sx, sy, tx, ty, imos_nodes);
		int y = compute_sum(sx * 2, sy * 2, tx * 2, ty * 2, imos_edges);
		int ans = x - y;
		printf("%d\n", ans);

		/*printf("x: %d, y: %d\n", x, y);

		for(int i = sx; i <= tx; ++i) {
			for(int j = sy; j <= ty; ++j) {
				printf("%d%c", nodes[i][j], j == ty ? '\n' : ' ');
			}
		}

		for(int i = sx * 2; i <= tx * 2; ++i) {
			for(int j = sy * 2; j <= ty * 2; ++j) {
				printf("%d%c", edges[i][j], j == ty * 2 ? '\n' : ' ');
			}
		}*/
	}

	return 0;
}

/* waffle */


Measured memory_bytes: 159616
#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

ll c(ll N) {
	stringstream ss;
	ss << N;
	string s = ss.str();
	ll ret = 0;
	for (int i = 0; i < s.size(); i++) {
		ret += s[i] - '0';
	}
	return ret;
}

int main() {
	ll N;
	cin >> N;
	ll ans = 1LL << 62;
	for (ll a = 1; a < N; a++) {
		ll b = N - a;
		ans = min(ans, c(a) + c(b));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
fn addll(llfrom: &Vec<i64>, llto: &mut Vec<i64>) {
    for ll in llfrom {
        let last = ll % 10;
        for i in -1..2 {
            let li = last + i;
            if 0 <= li && li <= 9 {
                llto.push(ll * 10 + li);
            }
        }
    }
}

fn main() {
    let n = read::<usize>();
    let mut lls = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
    let mut llv = lls.clone();
    loop {
        let mut llv2 = vec![];
        addll(&mut llv, &mut llv2);
        let mut llv3 = llv2.clone();
        lls.append(&mut llv3);
        llv = llv2;

        if lls.len() >= 100000 {
            break;
        }
    }
    //println!("{:?}", &lls[..100]);

    println!("{}", lls[n - 1]);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 12540
import java.util.*;

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

  int[] a;
  int ans;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new int[6];
      for (int i = 0; i < 5; i++) {
        int x = sc.nextInt();
        a[x]++;       
      }
    } finally {
      sc.close();
    }
  }
  
  void solve() {
    for (int i = 1; i <= 5; i++) if (a[i] == 0) ans = i;
  }

  void show() {
    System.out.println(ans);
  }
}


Measured memory_bytes: 35624
#include <bits/stdc++.h>
#define eps 1e-9
#define pi acos(-1)
#define nmax 1000000
#define f(c,a,b) for(int c=a; c<=b; c++)

using namespace std;
typedef double db;
struct P{
    db x, y;
    P(){}
    P(db x, db y) : x(x) , y(y) {}
    P operator - (P a){ return P(x-a.x, y-a.y); }
    db dot(P a){ return x*a.x+y*a.y; }
    db clen() { return sqrt(x*x+y*y); }
    db times(P a){ return x*a.y-y*a.x; }
}po[nmax];
typedef P V;
int n;

int sign(db x){ return x<-eps ? -1 : x>eps; }

db Diameter(){
    int lm=0, rm=1;
    f(i,0,n-1){
        if(po[lm].x > po[i].x) lm=i;
        if(po[rm].x < po[i].x) rm=i;
    }
    int i=rm, j=lm;
    //printf("now rm=%d,lm=%d\n",rm,lm);
    db ans = 0;
    int cnt=0;
    while(i!=lm || j!=rm){
        cnt++;
        //if(cnt<11) printf("i=%d  j=%d\n",i,j);
        ans = max(ans, (po[j]-po[i]).clen());
        if( (po[(i+1)%n]-po[i]).times(po[(j+1)%n]-po[j])<=0 ) i=(i+1)%n; else j=(j+1)%n;
    }
    return ans;    
}

int main(){
    //freopen("owo.in","r",stdin);
    cin >> n;
    f(i,0,n-1) scanf("%lf%lf", &po[i].x, &po[i].y);
    printf("%.12f", Diameter() );
    return 0;
}


Measured memory_bytes: 4456
#!/usr/bin/env run-cargo-script

#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(a: Vec<(u64)>) -> usize {
    let mut set = BTreeSet::new();
    for x in a.into_iter() {
        if set.contains(&x) {
            set.remove(&x);
        } else {
            set.insert(x);
        }
    }
    set.len()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let n = sc.next();
    println!("{}", solve(sc.vec(n)));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  char N[3];
  cin >> N;
  rep(i,3){
    if(N[i]=='7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" <<endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a,b,c;
   cin>>a>>b>>c;
   if(b<a){
     swap(a,b);
   }
   if(a<=c && c<=b) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);
  int q;
  cin >> q;
  vecll b(q), c(q);
  rep(i,q){
    cin >> b[i] >> c[i];
  }
  vec ct(100001, 0);

  rep(i,n){
    ct[a[i]]++;
  }
  ll ans=0;
  REP(i,1,100001){
    ans+= i*ct[i];
  }

  rep(i,q){
    int tmp = ct[b[i]];
    ct[c[i]] += tmp;
    ct[b[i]] = 0;
    ans += c[i]*tmp - b[i]*tmp;
    prt(ans);
  }



}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  cin >> n;
  cout << "ABC" << n <<endl;
}

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

using namespace std;

int memo[10][10][10][10][2];

int solve(int iL, int iR, int nL, int nR, int t)
{
    int &res = memo[iL][iR][nL][nR][t];
    if (res != 0) return res;
    
    if (iL >= 5 && iR >= 5) return 2;
    if (nL >= 5 && nR >= 5) return 1;
    
    res = (t == 0 ? 2 : 1);
    if (t == 0) {
        if (iL < 5) {
            if (nL < 5) res = min(res, solve(iL, iR, iL + nL, nR, 1));
            if (nR < 5) res = min(res, solve(iL, iR, nL, iL + nR, 1));
        }
        if (iR < 5) {
            if (nL < 5) res = min(res, solve(iL, iR, iR + nL, nR, 1));
            if (nR < 5) res = min(res, solve(iL, iR, nL, iR + nR, 1));
        }
    } else {
        if (nL < 5) {
            if (iL < 5) res = max(res, solve(iL + nL, iR, nL, nR, 0));
            if (iR < 5) res = max(res, solve(iL, iR + nL, nL, nR, 0));
        }
        if (nR < 5) {
            if (iL < 5) res = max(res, solve(iL + nR, iR, nL, nR, 0));
            if (iR < 5) res = max(res, solve(iL, iR + nR, nL, nR, 0));
        }
    }
    return res;
}

int main()
{
    int iL, iR, nL, nR;
    cin >> iL >> iR >> nL >> nR;
    cout << (solve(iL, iR, nL, nR, 0) == 1 ? "ISONO" : "NAKAJIMA") << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    int v = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == v) {
            v++;
        }
    }
    if(v == 0) {
        cout << -1 << endl;
    } else {
        cout << n - v << endl;
    }
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.buffer.readline

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

def dist(xy1, xy2):
  x1, y1 = xy1
  x2, y2 = xy2
  return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

answer = 0
for i in range(N):
  for j in range(i + 1, N):
    answer += dist(XY[i], XY[j]) / (N / 2)

print(answer)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

mod = 998244353
N = int(input())
XD = [tuple(map(int, input().split())) for _ in range(N)]
XD.sort(key=lambda x : x[0])
children = [[] for _ in range(N)]
stack = []
for i, (x, d) in list(enumerate(XD))[::-1]:
    while stack and stack[-1][0] < x + d:
        y, j = stack.pop()
        children[i].append(j)
    stack.append((x, i))
val = [0] * N
for i in range(N)[::-1]:
    res = 1
    for j in children[i]:
        res = res * val[j] % mod
    val[i] = res + 1
ans = 1
for x, i in stack:
    ans = ans * val[i] % mod
print(ans)

Measured memory_bytes: 112808
#include<stdio.h>
#include<algorithm>
using std::sort;
int x[1000000],i,n,sum,y[1000000];
main(){
    while(scanf("%d",&n)!=EOF){
        sum=0;
        for(i=0;i<n;i++){
            scanf("%d",&x[i]);
            y[i]=x[i]+y[i-1];
        }
        sort(x,x+n);
        for(i=0;i<n;i++){
            sum+=x[i]*(n-i);
        }
        printf("%d\n",sum);
    }
}

Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <climits>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;


int main() {
	int n; cin >> n;
	vll a(n), b(n), c(n);
	Loop(i, n) cin >> a[i];
	Loop(i, n) cin >> b[i];
	Loop(i, n) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	vll x(n, 0), y(n, 0);
	int j = n - 1;
	Loopr(i, n) {
		while (j >= 0 && b[i] < c[j]) {
			y[i]++;
			j--;
		}
		if (i > 0) y[i - 1] = y[i];
	}
	j = n - 1;
	Loopr(i, n) {
		while (j >= 0 && a[i] < b[j]) {
			x[i]+=y[j];
			j--;
		}
		if (i > 0) x[i - 1] = x[i];
	}
	ll sum = 0;
	Loop(i, n) {
		sum += x[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4732