akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int R = in.nextInt();
            int S = in.nextInt();
            int P = in.nextInt();
            String T = in.next();

            long score = 0;
            for (int i = 0; i < K; i++) {
                char hand = ' ';
                for (int j = i; j < N; j += K) {
                    char c = T.charAt(j);
                    if (c == 'r') {
                        if (hand == 'p') {
                            hand = ' ';
                        } else {
                            hand = 'p';
                            score += P;
                        }
                    } else if (c == 's') {
                        if (hand == 'r') {
                            hand = ' ';
                        } else {
                            hand = 'r';
                            score += R;
                        }
                    } else if (c == 'p') {
                        if (hand == 's') {
                            hand = ' ';
                        } else {
                            hand = 's';
                            score += S;
                        }
                    }
                }
            }
            out.println(score);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 24532
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]


def solve(a):
    
    s=set()
    for i in a:
        s.add(i)
    s=sorted(list(s))[::-1]
    L=1080
    #L=10000
    k=[0]*(L)
    ak=[0]
    ans=0
    for i in a:
        k[i]+=1
    for i in range(L):
        ak.append(ak[-1]+k[i])
    a1,a2,a3,a4=0,0,0,0
    un=len(s)
    for i in range(un):
        c=s[i]
        if k[c]>=3:
            a1+=k[c]*(k[c]-1)*(k[c]-2)//6
        if k[c]>=2:
            a2+=ak[c]*k[c]*(k[c]-1)//2
        for j in range(i+1,un):
            #show('i,j,s[i],s[j],mm',i,j,'|',s[i],s[j],s[i]-s[j]+1,'|',ak[s[i]-s[j]],ans)
            
            sc=s[j]
            a3+=(1 if 2*sc>c else 0)*k[c]*k[sc]*(k[sc]-1)//2
            if ak[sc]==0:
                break
            mm=c-sc+1
            if mm<0:
                continue
            elif mm>sc:
                continue # break
            else:
                a4+=k[c]*k[sc]*(ak[sc]-ak[mm])
            #show('ans+=',k[sc]*(k[sc]-1)//2+ak[sc]-ak[mm])
    
    ans=a1+a2+a3+a4
    #print(ans)
    return ans,a1,a2,a3,a4

def naive(a):
    b=sorted(a)[::-1]
    n=len(b)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if b[j]+b[k]>b[i]:
                    ans+=1
    return ans

print(solve(a)[0])

Measured memory_bytes: 41712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    if (A >= 10 || B >= 10) {
        cout << -1 << endl;
    } else {
        cout << A * B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main() {
	ll n, mi = 10000000000, ma = 0, ans = 0, A[10101];
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		mi = min(A[i], mi);
		ma = max(A[i], ma);
	}
	cout << ma - mi << endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a <= b <= c:
  print(a, b, c)
elif a <= c <= b:
  print(a, c, b)
elif b <= a <= c:
  print(b, a, c)
elif b <= c <= a:
  print(b, c, a)
elif c <= a <= b:
  print(c, a, b)
elif c <= b <= a:
  print(c, b, a)


Measured memory_bytes: 5596
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 123456;

long long fac[MAX], finv[MAX], inv[MAX];

inline void add(long long &x, long long y) {
  x += y;
  if(x >= mod) x -= mod;
}

inline void sub(long long &x, long long y) {
  x -= y;
  if(x < 0) x += mod;
}

inline long long mul(long long x, long long y) {
  return x % mod * y % mod;
}

inline long long inverse(long long x) {
  x = (x % mod + mod) % mod;
  long long y = mod, u = 1, v = 0;
  while(y) {
    long long t = x / y;
    x -= t * y; swap(x, y);
    u -= t * v; swap(u, v);
  }
  return (u % mod + mod) % mod;
}

inline long long power(long long x, long long y) {
  long long res = 1;
  while(y) {
    if(y & 1) res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}

inline void pre_mod_nCk() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = mod - mul(inv[mod % i], mod / i);
    finv[i] = mul(finv[i - 1], inv[i]);
  }
}

inline long long nCk(int n, int k) {
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return mul(fac[n], mul(finv[k], finv[n - k]));
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  pre_mod_nCk();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt[26] = {};
  for (char c : s) cnt[c - 'a']++;
  long long ans = 0;
  for (char c : s) {
    long long t = 1;
    cnt[c - 'a']--;
    for (int i = 0; i < 26; i++) {
      if (i + 'a' == c) continue;
      t *= cnt[i] == 1 ? 2LL : nCk(cnt[i], 1) + 1;
      t %= mod;
    }
    ans += t;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;	
}

Measured memory_bytes: 3456
#include<cstdio>

int main(void){
    int a=0,b=0,change=0;
    while(true){
        scanf("%d %d",&a,&b);
        if((a==0)&&(b==0)){
            break;
        }
        if(b<a){
            change=a;
            a=b;
            b=change;
        }
        printf("%d %d\n",a,b);
        
    }
    return 0;
}


Measured memory_bytes: 2612
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#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 rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(int&a,int b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

int H, W;
int d[10][10];

signed main()
{
	cin >> H >> W;
	rep(i, 10) rep(j, 10) {
		cin >> d[i][j];
	}

	rep(k, 10) rep(i, 10)  rep(j, 10) {
		chmin(d[i][j], d[i][k]+d[k][j]);
	}

	int ans = 0;

	rep(i, H) rep(j, W) {
		int a; cin >> a;
		if (~a) {
			ans += d[a][1];
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
  int n;
  cin>>n;
  vector<double>v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  while(v.size()!=1){
    int i=0;
    v[i]=(v[i]+v[i+1])/2;
    v.erase(v.begin()+1);
    while(v[i]>v[i+1]){
      int temp=v[i+1];
      v[i]=temp;
      v[i+1]=v[i];
      i++;
    }
  }
  printf("%.16f",v[0]);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int main() {
    int n, m; cin >> n >> m;
    int c[m]; rep(i, m) cin >> c[i];
    const int LIM = 50001;
    int dp[LIM]; rep(i, LIM) dp[i] = inf; dp[0] = 0;
    rep(i, LIM) {
        rep(j, m) {
            if (i + c[j] >= LIM) break;
            chmin(dp[i + c[j]], dp[i] + 1);
        }
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 3312
#include<bits/stdc++.h>
using namespace std; 
int n, x[105], p[105];
string s[105];
int main()
{
cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>s[i]>>p[i];
    x[i]=i;
  }

sort(x+1,x+n+1,[](const int &x, const int &y) 
{
  return s[x]<s[y] or (s[x]==s[y] and p[x]>p[y]);
}   
    );

  for(int i=1;i<=n;i++)
    cout<<x[i]<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    const double PI = 3.14159265359;
    double r, a, b;
    
    cin  >> r;
    a = r * r * PI;
    b = 2 * r * PI;
    
    cout << fixed << showpoint << setprecision(6)
         << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - '0';}
char myitoc(int N) {return '0' + N;}

struct edge
{
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

signed main()
{
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<edge>> G(N);
  for (int i = 0; i < M; i++)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G.at(a).push_back(edge(b, P - c));
  }

  vector<int> d(N, INF);
  d.at(0) = 0;
  for (int i = 0; i < 2 * N; i++)
  {
    for (int v = 0; v < N; v++)
    {
      for (int k = 0; k < G.at(v).size(); k++)
      {
        edge e = G.at(v).at(k);
        if (d.at(v) != INF && chmin(d.at(e.to), d.at(v) + e.cost))
        {
          if (i >= N - 1)
          {
            d.at(e.to) = -INF;
          }
        }
      }
    }
  }

  if (d.at(N - 1) <= -INF)
    cout << -1 << endl;
  else
    cout << max((int)0, -d.at(N - 1)) << endl;
}

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


int main() {
  
  int H,A;
  
  cin>>H>>A;
  
  int sw;
  
  if(H%A==0){
    sw=H/A;
  }else{
    sw=H/A+1;
  }
  
 // sw=H/A+1;
  
  cout<<sw<<endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), res(n);
  ll ans1 = 0;
  ll ans2 = 0;
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  if(n == 2){
    cout << a[1] - a[0] << endl;
    return 0;
  }
  res[0] = -1;
  res[n - 1] = -1;
  if(n % 2 == 0)res[n-1] = 1;
  int plus = 1;
  for (int i = 1; i < n - 1; i++){
    if(plus)res[i] = 2;
    else res[i] = -2;
    plus = plus ^ 1;
  }
  sort(ALL(res));
  rep(i, n){
    ans1 += a[i] * res[i];
  }
  rep(i, n){
    ans2 += -1 * a[i] * res[n - 1 - i];
  }
  cout << max(ans1, ans2) << endl;
}

Measured memory_bytes: 4848
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

ull min(ull a, ull b){
    return a < b? a : b;
}

int main(){
    ull N, M;
    scanf("%llu %llu", &N, &M);
    printf("%llu\n", min(M / 2, (2 * N + M) / 4));
    return 0;
}

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

const int maxn = 100010;

typedef long long ll;

int n;
ll a[maxn];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%lld", &a[i]);
	ll s1 = accumulate(a, a + n, 0ll);
	ll s0 = 1ll * n * (n + 1) / 2;
	if(s1 % s0) { puts("NO"); return 0; }
	ll m = s1 / s0;
	a[n] = a[0];
	for(int i = 0; i < n; ++i) a[i] = a[i + 1] - a[i] - m;
	for(int i = 0; i < n; ++i) if(a[i] > 0 || a[i] % n) { puts("NO"); return 0; }
	ll s = 0;
	for(int i = 0; i < n; ++i) s += -a[i] / n;
	if(s != m) { puts("NO"); return 0; }
	puts("YES");
	return 0;
}


Measured memory_bytes: 1024
import java.io.*;

class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        while((str= br.readLine()) != null){

            //????¨??????\??????????????????int????????????
            String[] str2 = str.split(" ");
            int a = Integer.parseInt(str2[0]);
            int b = Integer.parseInt(str2[1]);
            int a2 = a;
            int b2 = b;

            //???????????????????????????????????§gcd????±???????
            while(a2 % b2 != 0){
                int tmp = b2;
                b2 = a2 % b2;
                a2 = tmp;
            }
            int gcd = b2;

            // "gcd(a,b) x lcm(a,b) = ab" ?????¬???????????£???????°???¬?????°????±???????  
            long lcm = (long) a*b / gcd;

            System.out.println(gcd +" "+ lcm);

        }
    }
}

Measured memory_bytes: 24132
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,i,sum=0,j;
    cin>>n>>k;
    long long int a[n],age[n],pichhe[n];
    long long int rem=1000000007;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        age[i]=0;
        pichhe[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]>a[j] && i>j)
            {
                pichhe[i]++;
            }
            else if(a[i]>a[j] && i<j)
            {
                age[i]++;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        //cout<<age[i]<<" "<<pichhe[i]<<"\n";
        sum=((sum%rem)+(age[i]*((((k%rem)*((k+1)%rem))/2)%rem))+(pichhe[i]*((((k%rem)*((k-1)%rem))/2)%rem)))%rem;
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define pb emplace_back
#define em emplace
#define fi first
#define se second
#define USE1(...) template <typename __VA_ARGS__> inline
#define USE2(T, ...) USE1(T, typename __VA_ARGS__)
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
using ll = long long;
template<typename T> using vec = std::vector<T>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE2(T=int,V=vec<T>)V reserved(int n){V v;v.reserve(n);return v;}
USE1(T=int)vec<T>in(int n){auto v=reserved<T>(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=std::pair<T,int>)vec<U>enume(const vec<T>&x,int s=0){int N=x.size();auto v=reserved<U>(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE2(T,U)void prif(bool b,T t,U f){if(b)pr(t);else pr(f);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(20);
    std::cout.setf(std::ios::fixed);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int N = in();
  auto A = in(N);

  int ans = 0;
  int type = 0; // 0: eq, 1: asc, 2: desc
  int pre = A[0];
  rep(i, 1, N) {
    if (type == 0) {
      if (pre < A[i]) {
        type = 1;
      } else if (pre > A[i]) {
        type = 2;
      }
    } else {
      if (type == 1) {
        if (pre > A[i]) {
          ans++;
          type = 0;
        }
      } else {
        if (pre < A[i]) {
          ans++;
          type = 0;
        }
      }
    }
    pre = A[i];
  }
  ans++;
  pr(ans);
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  
  ll n;cin>>n;
  ll a[n];
  
  for(ll i=0;i<n;i++)cin>>a[i];
  
  ll q;cin>>q;
  
  ll b[q],c[q];
    
  for(ll i=0;i<q;i++)cin>>b[i]>>c[i];
  
  map<ll,ll> mp;
  
  ll sum=0;
  for(ll i=0;i<n;i++){mp[a[i]]++;sum+=a[i];}
  
  for(ll i=0;i<q;i++)
  {
    sum+=( -b[i]*mp[b[i]] + c[i]*mp[b[i]] );
    cout<<sum<<endl;
    mp[c[i]]+=mp[b[i]];
    mp[b[i]] = 0;
  }
  
  
  return 0;
}

Measured memory_bytes: 11844
#include <iostream>
#include <string>
using namespace std;
int c[8];
class DICE{
    public:
    void setdice(char a);
};
 
void DICE::setdice(char a){
    if(a=='S'){
        c[7]=c[1];
        c[1]=c[5];
        c[5]=c[6];
        c[6]=c[2];
        c[2]=c[7];
    }
    else if(a=='W'){
        c[7]=c[1];
        c[1]=c[3];
        c[3]=c[6];
        c[6]=c[4];
        c[4]=c[7];
    }
    else if(a=='N'){
        c[7]=c[1];
        c[1]=c[2];
        c[2]=c[6];
        c[6]=c[5];
        c[5]=c[7];
    }
    else{
        c[7]=c[1];
        c[1]=c[4];
        c[4]=c[6];
        c[6]=c[3];
        c[3]=c[7];
    }
}
int main(void){
    DICE dice;
    int n,a,b;
    for(int i=1;i<=6;i++){
        cin>>c[i];
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(a==c[3] || a==c[4]){
            while(c[1] !=a) dice.setdice('E');
        }
        else{
            while(c[1] !=a) dice.setdice('S');
        }
        dice.setdice('N');
        while(c[1] !=b) dice.setdice('W');
        dice.setdice('S');
        cout<<c[3]<<endl;
    }
}


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

int main(){
 	int n;
	cin >>n;
	int a,t;
	cin >> t >> a;
	
	vector<int> h(n);
	
	int c;
	double min = 1E9;
	for(int i = 0; i < n; i++) {
		cin >> h[i];
		if(abs(a - (double)(t - (double)h[i] * 0.006 ))< min)
		{
			min = abs( a -  (double)(t - (double)h[i] * 0.006 ));
			c = i+1;
		}
	}
	cout << c << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    multiset<int> st;
    st.insert(A[N-1]);
    for(int i = N-2; i >= 0; i--){
        auto it = st.upper_bound(A[i]);
        if(it == st.end()){
            st.insert(A[i]);
            continue;
        }
        if(*it > A[i]) st.erase(it);
        st.insert(A[i]);
    }

    cout << st.size() << endl;
}



Measured memory_bytes: 8288
#include<iostream>
#include <string.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  size_t l = s.length();
  for (size_t i = 0; i < l; i++) {
    if (s[i] + n > 'Z') {
      cout << (char)(s[i] + n-26);
    } else {
      cout << (char)(s[i] + n);
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main(void){
    int n,W,H;
    vector<P> px,py;
    cin>>n>>W>>H;
    for(int i=0;i<n;i++){
        int x,y,w;
        cin>>x>>y>>w;
        px.push_back({max(0,x-w),min(W,x+w)});
        py.push_back({max(0,y-w),min(H,y+w)});
    }
    
    sort(px.begin(),px.end());
    sort(py.begin(),py.end());
    
    int maxx = 0, maxy = 0;
    

    for(int i=0;i<n;i++){
        if(maxx < px[i].first) break;
        maxx = max(maxx,px[i].second);
    }
    
    for(int i=0;i<n;i++){
        if(maxy < py[i].first) break;
        maxy = max(maxy,py[i].second);
    }    
    
    if(maxx == W || maxy == H) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
}




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

int main()
{
  int n;
  cin >> n;
  vector<int64_t> a(n);
  int64_t sum = 0;
  for (auto&& e : a) {
    cin >> e;
    sum += e;
  }
  int64_t x = 0;
  for (int i = 1; i < n - 1; i += 2) {
    x += a[i];
  }
  x = sum - x * 2;
  cout << x;
  for (int i = 0; i < n - 1; i++) {
    x = a[i] * 2 - x;
    cout << ' ' << x;
  }
  cout << endl;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll fc(vector<int> &ld, vector<int> &c, int d){
  ll ret = 0;
  rep(i, 26){
    ret += (ll)c.at(i)*(d - ld.at(i));
  }
  return ret;
}

ll ret(vector<int> &c, vector<vector<int>> &s, vector<int> &ld, int t, int day, bool f){
  ll ans = 0;
  int tmp = ld.at(t);
  ld.at(t) = day;
  ans += s.at(day).at(t);
  ans -= fc(ld, c, day);
  if(f == false)ld.at(t) = tmp;
  return ans;
}

int main(){
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c.at(i);
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D){
    rep(j, 26){
      int in;
      cin >> in;
      s.at(i).at(j) = in;
    }
  }
  vector<int> t(D);
  rep(i, D){
    cin >> t.at(i);
    t.at(i)--;
  }
  int m;
  cin >> m;
  rep(i, m){
    int d, q;
    cin >> d >> q;
    d--;
    vector<int> ld(26, -1);
    t.at(d) = q-1;
    ll ans = 0;
    rep(j, D){
      ans += ret(c, s, ld, t.at(j), j, true);
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    int t = 1;
    while(t--)
    {
    	int n;
    	cin >> n;
    	int value[n][3];
    	for(int i = 0; i < n; i++)
    	    cin >> value[i][0] >> value[i][1] >> value[i][2];
    	int dp[n+1][3];
        dp[0][0] = dp[0][1] = dp[0][2] = 0;
        for(int i = 1; i <= n; i++)
        {
            dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + value[i-1][0];
            dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + value[i-1][1];
            dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + value[i-1][2];
        }
        cout << max({dp[n][0], dp[n][1], dp[n][2]});
    }
	return 0;
}

Measured memory_bytes: 5892
#include<iostream>
#include<cstring>
using namespace std;
int H,W,N,cl[10001],h[101][101];
int xx,yy,ff;
int main()
{
	memset(h,0,sizeof(h));
	cin>>H>>W>>N;
	for(int i=1;i<=N;i++)
		cin>>cl[i];
	xx=0,yy=0,ff=0;
	for(int i=1;i<=N;i++)
	{
		while(cl[i]>0)
		{
			h[xx][yy]=i;
			if (ff==0)
			{
				if(yy+1<W&&h[xx][yy+1]==0)yy++;
				else {ff=1;xx++;}
			}
			else if (ff==1)
			{
				if(xx+1<H&&h[xx+1][yy]==0)xx++;
				else {ff=2;yy--;}
			}
			else if (ff==2)
			{
				if(yy>0&&h[xx][yy-1]==0)yy--;
				else {ff=3;xx--;}
			}
			else if (ff==3)
			{
				if(xx>0&&h[xx-1][yy]==0)xx--;
				else {ff=0;yy++;}
			}
			cl[i]--;
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			if(j!=0)printf(" ");
			printf("%d",h[i][j]);
		}
		printf("\n");
	}

}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll n;

void dfs(string s,char m){
 if(s.length()==n) cout << s << endl;
 else {
   for(char c='a';c<=m;c++){
     if(c==m) dfs(s+c,m+1);
     else dfs(s+c,m);
   }
 }
}


int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  cin >> n;
  
  dfs("",'a');
}


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

const string com[16] = { "123", "234", "345", "456", "567", "678", "789",
	"111", "222", "333", "444", "555", "666", "777", "888", "999" };

bool sub(string& str, string tar)
{
	bool f = 1;
	string::iterator it;
	for (int i=0; i<tar.size(); i++)
		if ((it=find(str.begin(), str.end(), tar[i])) == str.end())
		{
			f = 0; break;
		}
		else
			str.erase(it);

	return f;
}

bool check(string str)
{
	bool ok=0, f=1;
	for (int i=1; i<10; i++)
	{
		string p(2, '0'+i);
		string tmp = str;
		if (!sub(tmp, p))
			continue;

		for (int k=0; f&&k<16; k++)
		{
			string t1 = tmp;
			if (!sub(t1, com[k]))
				continue;
			for (int l=0; f&&l<16; l++)
			{
				string t2 = t1;
				if (!sub(t2, com[l]))
					continue;
				for (int m=0; f&&m<16; m++)
				{
					string t3 = t2;
					if (!sub(t3, com[m]))
						continue;
					for (int n=0; f&&n<16; n++)
					{
						string t4 = t3;
						if (!sub(t4, com[n]))
							continue;

						if (t4 == "")
						{
							f=0; ok=1; break;
						}
					}
				}
			}
		}
	}

	return ok;
}

int main()
{
	string str;
	while (cin >> str)
	{
		bool v[10] = {0};
		for (int i=1; i<10; i++)
			if (count(str.begin(), str.end(), '0'+i) == 4)
				v[i] = 1;

		vector<int> ans;
		for (int i=1; i<10; i++)
		{
			if (v[i]) continue;
			string tmp = str;
			tmp.push_back('0'+i);
			if (check(tmp))
				ans.push_back(i);
		}

		if (ans.size())
			for (int i=0; i<ans.size(); i++)
			{
				cout << ans[i];
				if (i < ans.size()-1)
					cout << ' ';
				else
					cout << endl;
			}
		else
			cout << 0 << endl;
	}
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	char a, b;
	cin>>a>>b;
	if(a<b)cout<<"<"<<endl;
	else if(a>b) cout<<">"<<endl;
	else cout<<"="<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



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

string abc="abcdefghijklmnopqrstuvwxyz";

int main() {
  char C;
  cin >> C;

  char answer;
  for (int i = 0; i < abc.size(); i++) {
    if (abc[i] == C) {
      answer = abc[i+1];
      break;
    }
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi pair<int,int>
#define pb push_back
#define pll pair<ll,ll>
#define inf 1e16
using namespace std;
typedef long long ll;

const int N = 109;

bool f(ll a,ll b,ll c)
{
    //cout<<a+c<<" "<<b<<endl;
    if(a==c || a==b || b==c)return 0;
    if(a+b>c && a+c>b && b+c>a) return 1;
    return 0;
}

void slv()
{
    ll n;
    cin >> n;
    ll a[n+3];
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    ll cnt=0LL;
    set< pair<ll, pair<ll,ll> > >s; //cout<<"f "<<f(4,5,4)<<endl;
    for(ll i=0;i<n;i++) {
        for(ll j=i+1;j<n;j++) {
            for(ll k=j+1;k<n;k++) {
                if(f(a[i],a[j],a[k])) {
                    vector<ll>tmp;
                    //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
                    tmp.pb(i);
                    tmp.pb(j);
                    tmp.pb(k);
                    sort(tmp.begin(),tmp.end());
                    s.insert({tmp[0], {tmp[1],tmp[2]}});
                }
            }
        }
    }
    cnt=s.size();
    cout<<cnt<<endl;
}
int main()
{
    int t;
    t=1;
    for(int cs=1;cs<=t;cs++)
    {
        //printf("Case #%d: ",cs);
        slv();
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}

int power(int x, int y, int mod) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1, mod);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

const int mod = 998244353;
const int inf = 1'000'000'007;

void solve() {
  int n;
  ll a, b;
  cin >> n >> a >> b;
  if (a > b) {
    swap(a, b);
  }
  vector<ll> s(n + 1);
  vector<int> dp(n + 1);
  vector<int> pref(n + 1);
  vector<int> bad(n + 1, 0);


  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }

  bad[0] = 0;
  s[0] = s[1] - b - 1;

  for (int i = 1; i <= n; ++i) {
    if (i + 2 <= n && s[i + 2] - s[i] < a) {
      cout << "0\n";
      return;
    }
    if (s[i] - s[i - 1] < a) {
      bad[i] = i;
    } else {
      bad[i] = bad[i - 1];
    }
  }


  dp[0] = 1;
  pref[0] = 1;

  for (int i = 1; i <= n; ++i) {
    int pos = lower_bound(s.begin(), s.end(), s[i] - b + 1) - s.begin();
    --pos;
    int z = bad[i - 1] - 1;
    if (z > pos) {
      dp[i] = 0;
    } else {
      dp[i] = pref[pos] - (z <= 0 ? 0 : pref[z - 1]);
      if (dp[i] < 0) {
        dp[i] += inf;
      }
    }
    pref[i] = (pref[i - 1] + dp[i]) % inf;
  }

  int ans = 0;
  for (int i = bad[n] - 1; i <= n; ++i) {
    if (i > 0 && i < n && s[i + 1] - s[i - 1] < a) {
      continue;
    }
    (ans += dp[i]) %= inf;
  }

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

int main() {
  #ifndef LOCAL58
    // don't forget to remove if interactive
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

  int t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 5288
#include<iostream>
using namespace std;
int main() {
	long long int A, B, K;
	cin >> A >> B >> K;
	if (A > K) {
		cout << A - K << " " << B << endl;
	}
	else if (A + B > K) {
		cout << 0 << " " << A + B - K << endl;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}
	return 0;
}

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

int main() {
 int n;
 string s;
 
 cin >> n >> s;
 int maxnum = 0;
 
 
 for(int i = 1; i < n; i++) {
     int count = 0;
     
     for(char c = 'a'; c <= 'z'; c++) {
      bool left = false,right = false;
       for(int j = 0; j < i; j++) 
           
        if(s[j] == c) {
         left = true;
        }
         
           for(int j = i; j < n; j++)
        if(s[j] == c){
         right = true;
        }
         
         if(left && right) {
          count++;
         }
         if(maxnum < count) {
         maxnum = count;
         }
     }
 }
  cout << maxnum;
}

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

void insertionSort(int A[], const int n, const int g, int *cnt) {
    for( int i = g; i < n; ++i ) {
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ) {
            A[j+g] = A[j];
            j -= g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n) {
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if(i==0) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if(G[i]<0){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main() {
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);
        
    shellSort(A, n);
    return 0;
}



Measured memory_bytes: 7056
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
//#include<unordered_map>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 100005;
#define rep( i , a , b ) for ( int i = a ; i < b ; ++ i )
#define CLR(a) memset(a,0,sizeof a)
#define repf( i , a , b ) for ( int i = a ; i <= b ; ++ i )
template <class T>
void in(T& x) {
	static char ch; static bool neg;
	for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar());
	for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar());
	x = neg ? -x : x;
}


ll a[MAXN];
int main()
{
	//freopen("in.txt", "r", stdin);
	ll n;
	in(n);
	rep(i, 0, n)in(a[i]);
	bool ok = 1;
	a[0] -= 1;
   rep(i,1,n)
	{
		if (a[i]-1 >= a[i -1])a[i] -= 1;
		if (a[i] < a[i -1])
		{
			ok = 0;
			break;
		}
	}if (ok)puts("Yes");
	else puts("No");



	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
char s[100001];
int chars[30] = {};
int main() {
    scanf("%s", s);
    int len = strlen(s);
    if (s[0] == s[1]) {
        puts("1 2");
        return 0;
    }
    chars[s[0]-'a']++, chars[s[1]-'a']++;
    for (int i=2; i<len; i++) {
        if ((++chars[s[i]-'a']) > 1) {
            printf("%d %d\n", i-1, i+1);
            return 0;
        }
        chars[s[i-2]-'a']--;
    }
    puts("-1 -1");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 100010;

int n, e; 
int heights[maxn];
vector <int> adjlist[maxn];

int32_t main() {
	FAST	
	cin >> n >> e;
	for (int i = 1; i<= n;i++) cin >> heights[i];
	for (int i =0;i<e;i++) {
		int a,b; cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	
	int ans = 0;
	for (int i =1;i<=n;i++) {
		bool yes = true;
		for (auto j: adjlist[i]) {
			if (heights[j] >= heights[i]) yes = false;
		}
		if (yes) ans++;
	}
	
	cout << ans;
	
}



Measured memory_bytes: 10248
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > mat;

int main()
{
  int d, g;
  cin >> d >> g;
  int p[10], c[10];
  for (int i = 0; i < d; i++)
  {
    cin >> p[i] >> c[i];
  }

  int ans = 1010;

  for (int s = 0; s < (1 << d); s++)
  {
    int num = 0;
    int check = 0;
    int resmax = 0;
    for (int i = 0; i < d; i++)
    {
      if ((s >> i) % 2 == 1)
      {
        num += p[i];
        check += 100 * (i + 1) * p[i] + c[i];
      }
      else
      {
        resmax = i;
      }
    }
    if (check < g)
    {
      if ((g - check) > 100 * (resmax + 1) * p[resmax])
      {
        continue;
      }
      else
      {
        num += (g - check - 1) / (100 * (resmax + 1)) + 1;
      }
    }
    ans = min(ans, num);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = in.nextToken();
        int k = in.nextInt();

        Set<String> set = new HashSet<>();
        for (int i = 0; i < s.length() ; i++) {
            for (int j = i+1  ; j <= Math.min(s.length(), i+k) ; j++) {
                set.add(s.substring(i, j));
            }
        }
        List<String> uniqueList = new ArrayList<>(set);
        Collections.sort(uniqueList);

        out.println(uniqueList.get(k-1));
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 24472
#include<stdio.h>
int main()
{
    int A,B,N;
    scanf("%d %d",&A,&B);


    if(A > 0 && A < 10 && B >0 && B < 10)
    {




        N = A*B;
        printf("%d\n",N);
    }


    else
        printf("-1\n");


return 0;


}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int M,N,D,s[150][150]={0},co=0,co2=0,c,c2;
  cin >> N >> M >> D;
  char p[150][150] = {};
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >> p[i][j];
      if(p[i][j]=='#'){ 
        s[i][j]= 1; 
      }else if(p[i][j] == '.'){ 
        s[i][j] = 0; 
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<M+1-D;j++){
        c=0;
      for(int k=0;k<D;k++){
        if(s[i][j+k]==0){
          c++;
        }
      }
      if(c==D){
        co++;
      }
    }
  }
  for(int i=0;i<N+1-D;i++){
    for(int j=0;j<M;j++){
      c2=0;
      for(int l=0;l<D;l++){
        if(s[i+l][j]==0){
          c2++;
        }
      }
      if(c2==D){
        co2++;
      }
    }
  }
  cout << co+co2 << endl;
  return 0;
}




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

string Shuffle(string alp, int h){
    string top = alp.substr(0, h);
    string bottom = alp.substr(h, alp.size());
    return bottom + top;
}

int main(){
    string cards;
    int m, h;

    while(1){
        cin >> cards;
        if(cards == "-") break;

        cin >> m;
        for (int i = 0; i < m; i++){
            cin >> h;
            cards = Shuffle(cards, h);
        }
        cout << cards << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll longlongint
using namespace std;
int main(){
     SPEED;
     int n,y;
     cin>>n>>y;
     int ans10=-1;
     int ans5=-1;
     int ans1=-1;
     rep(i,n+1){
         rep(j,n-i+1){
             int k=n-i-j;
             int sum=10000*i+5000*j+1000*k;
             if(sum==y){
                 ans10=i;
                 ans5=j;
                 ans1=k;
             }
         }
     }
     cout<<ans10<<" "<<ans5<<" "<<ans1;
     ed;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    
    int N;
    cin >> N;
    ve<string> s(N);
    in(N,s);
    
    map<char,int> A;
    rep(i,int(s[0].length())) A[s[0][i]]++;
    
    rep(i,N){
        map<char,int> B,C;
        rep(j,int(s[i].length())) B[s[i][j]]++;
        
        C = A;
        for (auto p : A) {
            if(B.count(p.fi)) C[p.fi] = min(A[p.fi],B[p.fi]);
            else C.erase(p.fi);
        }
        A = C;
        

    }
    
    string ans = "";
    for (auto p : A) ans += string(p.se,p.fi);
    
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>

using namespace std;

int main(){
    int m,n,o;
    cin>>m>>n>>o;

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

    int minx=0,maxx=m,miny=0,maxy=n;
    for(int i=0;i<o;++i){
        switch(c[i]){
            case 1:
                if((a[i]-minx)>0)
                minx += (a[i]-minx);break;
            case 2:
                if((maxx-a[i])>0)
                maxx -= (maxx-a[i]);break;
            case 3:
                if((b[i]-miny)>0)
                miny += (b[i]-miny);break;
            case 4:
                if((maxy-b[i])>0)
                maxy -= (maxy-b[i]);break;
        }
    }
    //cout<<minx<<" "<<maxx<<" "<<miny<<" "<<maxy<<" "<<endl;
    int ans = (maxx-minx)*(maxy-miny);
    if((maxx-minx)<0 || (maxy-miny)<0)ans = 0;
    cout<<ans;
}

Measured memory_bytes: 256