akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int N, K;

  CIN(N >> K);

  int count = 0;
  int h;
  for (int i = 0; i < N; i++) {
    CIN(h);
    if (K <= h)
      count++;
  }

  COUT(count);

  return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string sa, sb ,sc;
    cin >> sa >> sb >> sc;

    queue<char> a;
    queue<char> b;
    queue<char> c;
    for(int ia=0;ia<sa.size();ia++) {
        a.push(sa.at(ia));
    }
    for(int ib=0;ib<sb.size();ib++) {
        b.push(sb.at(ib));
    }
    for(int ic=0;ic<sc.size();ic++) {
        c.push(sc.at(ic));
    }

    char p = 'a', card;
    while(1) {
        // cout << p;
        if(p=='a') {
            if(a.empty()) {
                cout << "A" << endl;
                return 0;
            }
            else {
                card = a.front(); a.pop();
            }
        }
        else if(p=='b') {
            if(b.empty()) {
                cout << "B" << endl; 
                return 0;
            }
            else {
                card = b.front(); b.pop();
            }
        }
        else { 
            if(c.empty()) {
                cout << "C" << endl; 
                return 0;
            }
            card = c.front(); c.pop();
        }
        p = card;
    }
    return 0;
}


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

public class S
{
    private const char BLANK = '.';
    private const char ROCK = '#';
    public static void Main()
    {

        // diverta 2 C
        // 負数を1個作り(正数最小値-正数最大値)、ひたすら正数をそこに減算していく。
        // 負数は1個以外すべて最大値に対して減算する。
        var N = long.Parse(Console.ReadLine());

        var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

        var list = new List<long>();
        foreach(var tgt in input){
            list.Add(tgt);
        }
        list.Sort();
        input = list.ToArray();

        long max = input[N-1];
        long? hoge = null;
        long focusIndex = -1;

        for(long i =0; i < N-1; i++){
            if(input[i] < 0){
                if(input[i + 1] >= 0 && i != N-2){
                    focusIndex = i;
                    hoge = input[i];
                }else{
                    max -= input[i];
                }
            }else{
                if(focusIndex == -1){
                    focusIndex = i;
                    hoge = input[i];
                }else{
                    hoge -= input[i];
                }
            }
        }


        if(hoge != null){
            Console.WriteLine(max - hoge);
        }else{
            Console.WriteLine(max);
        }
        max = input[N-1];
        focusIndex = -1;
        hoge = null;
        for(long i =0; i < N-1; i++){
            if(input[i] < 0){
                if(input[i + 1] >= 0 && i+1 != N-1){
                    focusIndex = i;
                    hoge = input[i];
                }else{
                    Console.WriteLine(max + " " + input[i]);
                    max -= input[i];
                }
            }else{
                if(focusIndex == -1){
                    focusIndex = i;
                    hoge = input[i];
                }else{
                    Console.WriteLine(hoge + " " + input[i]);
                    hoge -= input[i];
                }
            }

            
        }
        if(hoge != null)
            Console.WriteLine(max + " " + hoge);
    }
}

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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w * h / 2;
  cout << " ";
  if (x * 2 == w && y * 2 == h) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
def pr(n):
    ip = [True]*(n+1)
    ip[0] = False
    ip[1] = False
    for i in range(2,int(n**0.5)+1):
        if not ip[i]:
            continue
        for j in range(i*2,n+1,i):
            ip[j] = False
            
    return ip[n]
n = int(input())
while True:
    if pr(n) == True:
        print(n)
        exit()
    n += 1

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, q;
  cin >> n >> q;
  vector<tuple<int, int, int> > v;
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    v.eb(s - x, -1, x);
    v.eb(t - x, 0, x);
  }
  rep(i, q) {
    int d;
    cin >> d;
    v.eb(d, 1, i);
  }
  sort(all(v));

  multiset<int> s;
  vector<int> ans(q);

  for (auto p : v) {
    int a, b, c;
    tie(a, b, c) = p;
    // cout << "a b c " << a << " " << b << " " << c << endl;
    if (b == -1) s.insert(c);
    else if (b == 0) s.erase(s.lower_bound(c));
    // 工事中のとこにぶつかる
    else ans[c] = (s.empty() ? -1 : *(s.begin()));
  }
  for (auto v : ans) cout << v << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 100007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q, t, indx, l, r;
    char ch;
    string s;
    cin >> n >> s >> q;
    map<char, set<int> > cache;
    for (int i = 0; i < n; i++) {
        cache[s[i]].insert(i);
    }
    while (q--) {
        cin >> t;
        if (t == 1) {
            cin >> indx >> ch;
            indx--;
            if (s[indx] == ch) continue;
            cache[s[indx]].erase(indx);
            s[indx] = ch;
            cache[ch].insert(indx);
        } else {
            cin >> l >> r;
            l--, r--;
            int res = 0;
            tr(cache, it) {
                auto iter = it->second.upper_bound(l - 1);
                if (iter == it->second.end()) continue;
                if (*iter <= r) res++;
            }
            cout << res << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 24220
// https://atcoder.jp/contests/abc155/tasks/abc155_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll A, B, C;
  cin >> A >> B >> C;

  bool yes = (A == B && B != C) || (B == C && C != A) || (C == A && A != B);
  string res = yes ? "Yes" : "No";
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int CONTEST_NUM=26;

int score_function(const vector<int> &t,const vector<vector<int>> &s,const vector<int> &c,const int &d){
    vector<int> last(27);
    int manzoku=0;
    for(int i=1;i<=d;i++){
        manzoku+=s[i][t[i]];
        last[t[i]]=i;
        int sum=0;
        for(int j=1;j<=CONTEST_NUM;j++){
            sum+=c[j]*(i-last[j]);
        }
        manzoku-=sum;
    }
    return manzoku;
}

void set_ans(const vector<int> &t,vector<int> &ans,const int &d){
    for(int i=1;i<=d;i++){
        ans[i]=t[i];
    }
}

int main() {
    int d;cin>>d;
    vector<int> c(27);
    for(int i=1;i<=CONTEST_NUM;i++){
        cin>>c[i];
    }
    vector<vector<int>> s(d+1,vector<int>(27));
    for(int i=1;i<=d;i++){
        for(int j=1;j<=CONTEST_NUM;j++){
            cin>>s[i][j];
        }
    }
    vector<int> t(d+1);
    vector<int> ans(d+1);
    int old_ans=-1000000000;
    std::random_device rnd;
    std::mt19937 mt(rnd());
    std::uniform_int_distribution<> rand26(1,26);
    std::uniform_int_distribution<> randd(1,d);

    for(int i=1;i<=d;i++){
        int max_contest=-1;
        for(int j=1;j<=CONTEST_NUM;j++){
            if(max_contest<s[i][j]){
                max_contest=s[i][j];
                t[i]=j;
            }
        }
    }
    int k=0;
    while(k<320000){
        int che=randd(mt);
        int old_f=t[che];
        t[che]=rand26(mt);
        int tmp=score_function(t,s,c,d);
        if(tmp>old_ans){
            old_ans=tmp;
        }
        else{
            t[che]=old_f;
        }
        k++;
    }
    //cout<<old_ans<<endl;
    for(int i=1;i<=d;i++){
        cout<<t[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  double n;
  std::cin >> n;
  vt<double> x(n), y(n);
  rep(i,n)
    std::cin >> x[i] >> y[i];

  long double ans = 0.0;
  rep(i,n)
    rep(j,n)
      ans += sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));

  std::cout << std::fixed << std::setprecision(10);
  std::cout << ans/n << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 5000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int x[N], y[N];
    int area = INF2;
    rep(i, N) {
        cin >> x[i] >> y[i];
    }
    rep(a, N) {
        rep(b, N) {
            rep(c, N) {
                rep(d, N) {
                    if(x[a] > x[b] || y[c] > y[d]) continue;
                    int countK = 0;
                    rep(i, N) {
                        if (x[a] <= x[i] && x[i] <= x[b] && y[c] <= y[i] && y[i] <= y[d]) {
                            countK++;
                        }
                    }
                    //dump(countK);
                    if (countK >= K) {
                        area = min(area, (x[b] - x[a]) * (y[d] - y[c]));
                    }
                }
            }
        }
    }
    cout << area << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int A, B, C; cin >> A >> B >> C;
    cout << max(0LL, C-(A-B)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,a,b,count=0;
    cin>>n;
    vector<int>v(n),p(n),q(n);
    for(int i=0;i<n;i++)v[i]=i+1;
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
    do{
        if(p==v)a=count;
        if(q==v)b=count;
        count++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(a-b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch OneQuadrillionAndOneDalmatians | diff OneQuadrillionAndOneDalmatians.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address OneQuadrillionAndOneDalmatians.cpp && ./a.out

/*

 6/21/2020

 5:04-

 */

LL N;

void solve() {
  string res;
  while(N>0) {
    N-=1;
    //dump(N,N%26);
    res.push_back('a'+N%26);
    N/=26;
  }
  reverse(ALL(res));
  cout<<res<<endl;
}

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

  cin>>N;
  solve();

  return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fup(i,a,b) for(int i=a;i<=b;++i)

int x[200004],y[200004];
void Main()
{
    int n,nn;
    scanf("%d",&n);
    nn=n/2;
    fup(i,1,n)scanf("%d",&x[i]),y[i]=x[i];
    sort(y,y+1+n);
    int t=y[nn],tz=y[nn-1],ty=y[nn+1],sz=0,sy=0;
    {
        int i=nn,j=nn;
        while(y[--i]==t)++sz;
        while(y[++j]==t)++sy;
    }
    if(sz&&sy)fup(i,1,n)printf("%d\n",t);
    else if(!sz&&sy)fup(i,1,n)printf("%d\n",t);
    else if(sz&&!sy)fup(i,1,n){
        if(x[i]<=t)printf("%d\n",ty);
        else printf("%d\n",t);
    }
    else fup(i,1,n){
        if(x[i]<=t)printf("%d\n",ty);
        else printf("%d\n",t);
    }
}
int main()
{
Main();
return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;



int main() {
  int N, a;
  cin >> N;

  //
  vector<int> colors(8, 0);
  int free = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    if(a >= 3200){
      free++;
    }else{
      a/=400;
      colors[a]++;
    }
  }

  //
  int num_color = 0;
  for(int c: colors){
    if(c > 0) num_color++;
  }

  int min_color, max_color;
  if(num_color == 0){
    min_color = 1;
  }else{
    min_color = num_color;
  }
  max_color = num_color + free;

  cout << min_color << " " << max_color << endl;

  return 0;
}



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

int main(){
  string S;cin>>S;
  vll ans(S.size(),0);
  ll left=0,right=0;
  rep(i,S.size()){
    if(S[i]=='L') left++;
    else break;
  }
  rep(i,S.size()){
    if(S[S.size()-1-i]=='R') right++;
    else break;
  }
  ans[0]=left; ans[S.size()-1]=right;
  //切り替わり点と区間
  vector<pair<ll,pair<ll,ll>>> p;
  int r_left=left,tmp=0;
  while(r_left+tmp<S.size()-right){
    while(S[r_left+tmp]=='R'){
      tmp++;
    }
    int r_right=r_left+tmp-1;
    tmp++;
    while(S[r_left+tmp]=='L'){
      tmp++;
    }
    int l_right=r_left+tmp-1;
    p.push_back(make_pair(r_right,make_pair(r_left,l_right)));
    r_left = l_right+1;
    tmp=0;
  }
  //rep(i,p.size()) cout << p[i].first << p[i].second.first << p[i].second.second << endl;
  rep(i,p.size()){
    int rl = p[i].first;
    int l=p[i].second.first,r=p[i].second.second;
    ans[rl]=(r-l+1)/2 + ((r-l+1)%2==1 && (rl-r)%2==0 ? 1 : 0 );
    ans[rl+1]=(r-l+1)-ans[rl];
  }
  rep(i,S.size()) cout<<ans[i]<<" ";
  cout<<endl;
}

Measured memory_bytes: 2872
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


vector<list<pair<int, int>>> edge;
vector<ll> cost;

void dfs(int x, int par)
{
	for (auto & y : edge[x])
	{
		if (y.first == par) { continue; }
		cost[y.first] = y.second + cost[x];
		dfs(y.first, x);
	}
}


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

	edge = vector<list<pair<int, int>>>(N);
	cost = vector<ll>(N,0);

	for (int i = 0; i < N - 1; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;

		edge[a].emplace_back(b, c);
		edge[b].emplace_back(a, c);
	}

	int Q, K;
	cin >> Q >> K;
	--K;
	dfs(K, K);

	for (int i = 0; i < Q; ++i)
	{
		int x, y; cin >> x >> y; --x; --y;
		cout << cost[x] + cost[y] << endl;
	}

	return 0;
}

Measured memory_bytes: 15104
#include <cstdio>
#include <cstdint>

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

  intmax_t res=0;
  int prev=0;
  for (int i=0; i<N; ++i) {
    int a;
    scanf("%d", &a);

    if (a+prev > x) {
      res += a+prev-x;
      a = x-prev;
    }
    prev = a;
  }

  printf("%jd\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

//vector<unordered_map<int,int> > kp;
// int knapsack(int val[],int wt[],int n,int w){
//     if(n<=0)
//         return 0;
//     if(w<=0) 
//         return 0;
//     if(kp[n].find(w) != kp[n].end())
//         return kp[n][w];
//     if(wt[n-1]<=w)
//         kp[n][w] = max(knapsack(val,wt,n-1,w),val[n-1]+knapsack(val,wt,n-1,w-wt[n-1]));
//     else
//         kp[n][w] = knapsack(val,wt,n-1,w);           

//     return kp[n][w];
// }


int main(){

    int N,W;
    cin>>N>>W;
    long long val[N];
    long long wt[N];
     int maxVal = 0;
    for(int i=0;i<N;i++){
        int w,v;
        cin>>w>>v;
        wt[i]= w;
        val[i] = v;
        maxVal +=v;
    }
    long long kp[N+1][maxVal+1];
   

    for(int n=0;n<=N;n++){
    for(int i=0;i<=maxVal;i++){
        if(n==0 && i == 0)
            kp[n][i] = 0;
        else if(n == 0)
            kp[n][i] = 1e18L;         
        else if(val[n-1]<=i)
            kp[n][i] =min(kp[n-1][i], kp[n-1][i-val[n-1]] + wt[n-1]);
        else 
            kp[n][i] = kp[n-1][i];   
        // if(kp[n][i] == 0){
        //     maxVal = i;
        //     break;
        // }

    }
    }
    int ans=0;
    for(int n=0;n<=N;n++){
    for(int i=0;i<=maxVal;i++){
        if(kp[n][i]<=W)
        ans = max(ans,i);
    }
    }
    cout<<ans<<endl;
    //kp.resize(N+1);
   // cout<<knapsack(val,wt,N,W);
    return 0;
}

Measured memory_bytes: 82460
#include<stdio.h>

int A[1000000], n;

int binary(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(){

int i, q, k, sum = 0;
scanf("%d", &n);
for(i = 0; i < n; i++){
  scanf("%d", &A[i]);
}
scanf("%d", &q);
for(i = 0; i < q; i++){
  scanf("%d", &k);
  if(binary(k)) sum++;
  } 
printf("%d\n", sum);
return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (i) a[i] += a[i - 1];
	}
	vector<long long> cand;
	for (int l = 0; l < n; ++l) {
		for (int r = l; r < n; ++r) {
			cand.push_back(a[r] - (l ? a[l - 1] : 0));
		}
	} 
	long long ans = 0;
	for (int i = 40; i >= 0; --i) {
		int cnt = 0;
		for (auto v : cand) if (v & (1LL << i)) {
			cnt++;
		}
		if (cnt >= k) {
			ans |= (1LL << i);
			vector<long long> ncand;
			for (auto v : cand) if (v & (1LL << i)) {
				ncand.push_back(v);
			}
			cand.swap(ncand);
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 6384
#include <iostream>
#include <string>

using namespace std;

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

    bool ans = true;
    for (int i = 0; i < A; i++) {
        if (S[i] < '0' || '9' < S[i]) ans = false;
    }
    if (S[A] != '-') ans = false;
    for (int i = 0; i < B; i++) {
        if (S[A + 1 + i] < '0' || '9' < S[A + 1 + i]) ans = false;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;
int main(){
  int N, K;
  while(cin>>N>>K && N){
    int c[2000], g[2000];
    vector<int> cash[10];
    REP(i, N){
      cin>>c[i]>>g[i]; g[i]--;
      cash[g[i]].push_back(c[i]);
    }
    vector<int> total[10];
    REP(i, 10){
      sort(cash[i].begin(), cash[i].end());
      reverse(cash[i].begin(), cash[i].end());
      total[i] = vector<int>(cash[i].size() + 1);
      REP(j, cash[i].size()) total[i][j+1] = total[i][j] + cash[i][j];
    }
    int dp[2][2000] = {};
    for(int i = 0; i < 10; i++){
      for(int j = 0; j <= K; j++){
        for(int k = 0; k <= min(j, (int)cash[i].size()); k++){
          dp[(i+1)%2][j] = max(dp[(i+1)%2][j], dp[i%2][j-k] + total[i][k] + k * (k-1));
        }
      }
    }
    cout<<dp[10%2][K]<<endl;
  }
  return 0;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

set<int> s;

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

  int a, b, k; cin >> a >> b >> k;

  FOR(i, a, a + k) s.insert(i);
  FOR(i, b - k + 1, b + 1) s.insert(i);

  for(auto x: s) {
    if(x >= a && x <= b) cout << x << " ";
  }
}


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

int N,A,B;

vector<int> unit(int bit, int A, int B)
{
    vector<int> ret;
    int cnt = 0, dif = -1;
    for(int i = 0; i < N; i++)
    {
        if(bit & (1 << i))cnt++;
        if(((A ^ B) & bit) & (1 << i))dif = i;
    }

    if(cnt == 1)
    {
        ret.push_back(dif);
        return ret;
    }

    int next;
    for(int i = 0; i < N; i++)if(i != dif && bit & (1 << i))next = i;

    vector<int> ret1 = unit(bit ^ (1 << dif), A, A ^ (1 << next));
    ret.insert(ret.end(), ret1.begin(), ret1.end());

    ret.push_back(dif);

    vector<int> ret2 = unit(bit ^ (1 << dif), A ^ (1 << next) ^ (1 << dif), B);
    ret.insert(ret.end(), ret2.begin(), ret2.end());

    return ret;
}

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

    int flag = 1;
    for(int i = 0; i < N; i++)if((A & (1 << i)) != (B & (1 << i)))flag ^= 1;

    if(flag)
    {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

    vector<int> act = unit((1 << N) - 1, A, B);

    int ans = A;
    for(int i = 0; i < act.size(); i++)
    {
        cout << ans << " ";
        ans ^= (1 << act[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1872
N=int(input())
buttun=[0]
for i in range(N):
    buttun.append(int(input()))

light=1
ans=0
while True:
    if light==2:
        break
    elif light==buttun[light]:
        ans=-1
        break
    else:
        tmp=light
        light=buttun[light]
        ans+=1
        buttun[tmp]=1
    if light==1:
        ans=-1
        break
print(ans)

Measured memory_bytes: 7080
#include <iostream> 

int main() {
  int k;
  std::cin >> k;
  int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  std::cout << arr[k-1] << std::endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main{
	static Scanner scan = new Scanner(System.in);
	static void programmingEducation(){
		int age = scan.nextInt();
		if(age == 1){
			System.out.println("Hello World");
		}
		else{
			int a = scan.nextInt(), b = scan.nextInt();
			System.out.println(a+b);
		}
		
	}
	public static void main(String[] argv){
		programmingEducation();
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

int max(int a, int b) {
  return a > b ? a : b;
}

int main() {
  std::vector<std::pair<int, int> > turara;

  int N, L;
  std::cin >> N >> L;

  for (int i = 0; i < N; i++) {
    int length;
    std::cin >> length;
    turara.push_back(std::make_pair(length, i));
  }

  std::sort(turara.begin(), turara.end(), std::greater<std::pair<int, int> >());
  
  std::vector<int> dp(N);

  for(int i = 0; i < N; i++) {
    int j = turara[i].second;
    int now = turara[i].first;
    dp[j] += L - now;
    if (j - 1 >= 0) {
      dp[j - 1] = max(dp[j - 1], dp[j]);
    }
    if (j + 1 < N) {
      dp[j + 1] = max(dp[j + 1], dp[j]);
    }
  }

  int ans = 0;
  for(int i = 0; i < N; i++) {
    ans = max(ans, dp[i]);
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 2304
def main():
    input()
    array = sorted(int(x) for x in input().split())
    maximum = array[-1] + 1
    counter = [0] * maximum

    for x in array:
        if counter[x] != 0:
            counter[x] = 2
            continue
        else:
            for multiple in range(x, maximum, x):
                counter[multiple] += 1
    ans = sum(counter[x] == 1 for x in array)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    int D = A-B;
    if(C-D<0){
        cout << 0  << endl;
    }else{
    cout << C - D << endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int minNum= 1000000000;
  rep(i,n){
    int x;
    cin >> x;
    minNum = min(minNum,x);
    if(minNum == x) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3592
x, y = map(int, input().split())
mod = 10 ** 9 + 7

cnt1 = cnt2 = 0
for i in range(x + 1):
    x_left = x - i
    y_left = y - 2 * i
    if x_left == y_left * 2:
        cnt1 = i
        cnt2 = y_left

if cnt1 == cnt2 == 0:
    ans = 0
else:
    ans = 1
    for i in range(1, cnt1 + 1):
        ans *= (cnt1 + cnt2 - i + 1)
        ans %= mod
        ans *= pow(i, mod - 2, mod)
        ans %= mod

print(ans)


Measured memory_bytes: 40300
function rot(n,str) {
  // //console.log(str.split('').map(function(c) {
  //   return parseInt(c.charCodeAt(0) - 'A'.charCodeAt(0),10) + n;
  // }));
  return str.split('').map(function(c){
    return String.fromCharCode(((c.charCodeAt(0) - 'A'.charCodeAt(0)) + n ) % 26 + 'A'.charCodeAt(0)); 
  }).join('');  
  
}

function Main(inp) {
  var input = inp.split("\n");
  var n = parseInt(input[0],10);
  var str = input[1];

  console.log(rot(n,str));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21828
#include<bits/stdc++.h>
 
using namespace std;
const int maxn=2e5+10;
typedef long long ll;
struct Edge
{
    ll v,cost,nxt;
};
Edge edge[maxn];
ll head[maxn];
ll dis[maxn];
int flag[maxn];
int ok[maxn];
ll cnt;
ll tp[maxn];
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
    memset(flag,0,sizeof(flag));
    memset(edge,0,sizeof(edge));
    for(ll i=2;i<maxn;i++)
    {
        dis[i]=-1000000000000000;
    }
    dis[1]=0;
}
void add(ll u,ll v,ll w)
{
    edge[cnt].v=v;
    edge[cnt].cost=w;
    edge[cnt].nxt=head[u];
    head[u]=cnt;
    cnt++;
}
int flag2[maxn],flag1[maxn];
vector<int> vec[maxn];
void dfs1(ll x)
{
	flag1[x]=1;
	for(int i=0;i<vec[x].size();i++)
	{
		if(!flag1[vec[x][i]])
		dfs1(vec[x][i]);
	}
}
 
void dfs2(ll x)
{
    flag2[x]=1;
    for(ll i=head[x];i!=-1;i=edge[i].nxt)
    {
        if(!flag2[edge[i].v])
            dfs2(edge[i].v);
    }
}
int main()
{
    ll n,m,p,u,v,w;
    init();
    scanf("%lld%lld%lld",&n,&m,&p);
    for(int i=0;i<m;i++)
    {
        scanf("%lld%lld%lld",&u,&v,&w);
        add(u,v,w-p);
        vec[v].push_back(u);
    }
    memset(flag1,0,sizeof(flag1));
    memset(flag2,0,sizeof(flag2));
    dfs2(1);dfs1(n);
    for(ll i=1;i<=n;i++)
    {
        for(ll k=1;k<=n;k++)
        {
            if(flag1[k]&&flag2[k])
                for(ll j=head[k];j!=-1;j=edge[j].nxt)
                {
                    if(dis[edge[j].v]<dis[k]+edge[j].cost)
                    {
                        dis[edge[j].v]=dis[k]+edge[j].cost;
                    }
                }
        }
    }
    for(int i=1;i<=n;i++){tp[i]=dis[i];}
    for(ll i=1;i<=n;i++)
    {
        for(ll k=1;k<=n;k++)
        {
            if(flag1[k]&&flag2[k])
                for(ll j=head[k];j!=-1;j=edge[j].nxt)
                {
                    if(dis[edge[j].v]<dis[k]+edge[j].cost)
                    {
                        dis[edge[j].v]=dis[k]+edge[j].cost;
                    }
                }
        }
    }
    //如果不相等，表示跑完最长路之后还可以松弛 
    for(int i=1;i<=n;i++)if(flag1[i]&&flag2[i]&&tp[i]!=dis[i]){printf("-1");return 0;}
    if(dis[n]>0){printf("%lld\n",dis[n]);}else{printf("0\n");}
    return 0;
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll X,T;
	ll result=0;
	cin>>X>>T;
	if(X<=T) result=0;
	else result=X-T;
	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1000000007
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h, h + n);
    int res = INF;
    for (int i = k - 1; i < n; i++) {
        res = min(h[i] - h[i - k + 1], res);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val T = A.reduce { acc, a ->  acc + a }
    val S = LongArray(N + 1)
    for (n in 0 until N) S[n + 1] = A[n] + S[n]
    var ans = Long.MAX_VALUE
    for (n in 1 .. N - 1) ans = Math.min(ans, Math.abs(S[n] - (T - S[n])))
    println(ans)
//System.err.println(S.joinToString(" "))
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong() = listOfString().map(String::toLong)



Measured memory_bytes: 82884
#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

int dp[100010];

int main(void)
{
    int platform_counts;
    vector<int> heights;

    cin >> platform_counts;

    for(int i = 0; i < platform_counts; i++){
        int h;
        cin >> h;
        heights.push_back(h);
    }

    dp[0] = 0;
    dp[1] = abs(heights[0] - heights[1]);
    dp[2] = abs(heights[0] - heights[2]);

    for(int i = 3; i < platform_counts; i++){
        const int cost_one = abs(heights[i - 1] - heights[i]);
        const int cost_two = abs(heights[i - 2] - heights[i]);
        dp[i] = min(dp[i - 1] + cost_one, dp[i - 2] + cost_two);
    }

    cout << dp[platform_counts - 1] << endl;

    return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n, q;
    cin>>n>>q;
    queue<pair<string, int>> table;
    pair<string, int> t;
    rep(i, n) {
        cin>>t.first>>t.second;
        table.push(t);
    }

    int time = 0;
    vector<pair<string, int>> finished;
    while (!table.empty()) {
        t = table.front(); table.pop();
        if (t.second <= q) {
            time += t.second;
            finished.push_back(pair<string, int>(t.first, time));
            continue;
        }

        time += q;
        t.second -= q;
        table.push(t);
    }

    rep(i, n) cout<<finished[i].first<<" "<<finished[i].second<<endl;
}


Measured memory_bytes: 7032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public struct Edge
{
	public int I;
	public int To;

	public Edge(int i, int t)
	{
		I = i;
		To = t;
	}
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[] a = new int[N - 1];
		int[] b = new int[N - 1];
		int[] deg = new int[N];
		var adj = Enumerable.Range(0, N).Select(_ => new List<Edge>()).ToArray();
		for(int i = 0; i < N - 1; i++)
		{
			a[i] = GetInt() - 1;
			b[i] = GetInt() - 1;
			adj[a[i]].Add(new Edge(i, b[i]));
			adj[b[i]].Add(new Edge(i, a[i]));
			deg[a[i]]++;
			deg[b[i]]++;
		}

		int K = deg.Max();
		int[] color = new int[N - 1];
		int r = Array.FindIndex(deg, x => (x == K));
		int c = 1;
		foreach(var edge in adj[r])
		{
			color[edge.I] = c;
			dfs(adj, edge.To, K, c, color);
			c++;
		}

		WriteLine(K);
		WriteLine(string.Join("\n", color));
	}

	private void dfs(List<Edge>[] adj, int v, int K, int x, int[] color)
	{
		int c = 1;
		foreach(var edge in adj[v])
		{
			if(color[edge.I] != 0)
				continue;

			if(c == x)
				c++;

			color[edge.I] = c;
			dfs(adj, edge.To, K, c, color);		
			c++;
		}
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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

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

const int D = 60 ;
const int MAX_N = 200005 ;
int to[D][MAX_N] ; 

int main() {
  int n ;
  ll k ;
  cin >> n >> k ;
  rep(j,n){
    cin >> to[0][j] ; 
    to[0][j] -- ;
  }
  
  rep(i,D-1){
    rep(j,n){
      to[i+1][j] = to[i][to[i][j]] ;
    }
  }
  
  int now = 0 ;
  for(int i=D-1;i >=0 ;i--){
    ll l = 1ll<<i ;
    if(l<=k){
      now = to[i][now] ;
      k -= l ;
    }
  }
  
  cout << now + 1 <<endl ;


}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

struct BIT {
  vector<int> bit;

  BIT() {}

  int n;

  BIT(int n) {
    this->n = n;
    bit.resize(n + 1);
  }

  void update(int idx, int val) {
    for (int i = idx; i <= n; i += i & -i) {
      bit[i] += val;
    }
  }

  int prefix_query(int idx) {
    int ans = 0;
    for (int i = idx; i > 0; i -= i & -i) {
      ans += bit[i];
    }
    return ans;
  }

  int query(int l, int r) { return prefix_query(r) - prefix_query(l - 1); }

  // int bit 0-1 it finds the index of k-th element active
  int kth(int k) {
    int cur = 0;
    int acc = 0;
    for (int i = 19; i >= 0; i--) {
      if (cur + (1 << i) > n) continue;
      if (acc + bit[cur + (1 << i)] < k) {
        cur += (1 << i);
        acc += bit[cur];
      }
    }
    return ++cur;
  }
};

//#define MULTIPLE_TEST_CASE
void solution() {
  int n, q;
  cin >> n >> q;
  int v[n + 1];
  vector<int> lst(n + 1, -1);
  BIT bit = BIT(n + 1);
  for (int i = 1; i <= n; i++) cin >> v[i];
  vector<vector<tuple<int, int, int>>> queries(n + 1);
  int ans[q];
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    queries[r].pb(mt(l, r, i));
  }
  for (int i = 1; i <= n; i++) {
    if (lst[v[i]] != -1) {
      bit.update(lst[v[i]], -1);
    }
    bit.update(i, 1);
    lst[v[i]] = i;
    // cout << "updated" << endl;
    for (auto tp : queries[i]) {
      int l, r, i;
      tie(l, r, i) = tp;
      ans[i] = bit.query(l, r);
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 47356
import java.io.{PrintWriter, _}
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val a = in.next
      val b = in.next
      if (a == "H"){
        println(b)
      }else{
        if (b == "H"){
          println("D")
        }else {
          println("H")
        }
      }
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


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

class Problem_C
{
  public static void Main(string[] args)
  {
    var n = int.Parse(Console.ReadLine());
    long mNum = 0, aNum = 0, rNum = 0, cNum = 0, hNum = 0;

    for (var i = 0; i < n; i++)
    {
      var name = Console.ReadLine();
      if (name.First() == 'M')
      {
        mNum++;
      }
      else if (name.First() == 'A')
      {
        aNum++;
      }
      else if (name.First() == 'R')
      {
        rNum++;
      }
      else if (name.First() == 'C')
      {
        cNum++;
      }
      else if (name.First() == 'H')
      {
        hNum++;
      }
    }
    long ans = (mNum * aNum * rNum) + (mNum * aNum * cNum) + (mNum * aNum * hNum)
      + (mNum * rNum * cNum) + (mNum * rNum * hNum) + (mNum * cNum * hNum)
      + (aNum * rNum * cNum) + (aNum * rNum * hNum) + (aNum * cNum * hNum)
      + (rNum * cNum * hNum);
    Console.WriteLine($"{ans}");
  }
}


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

int main() {
  int N, K, B=0;
  string S;
  cin >> N >> K;
  cin >> S;
  for (int i=0; i<N-1; i++){
    if(S.at(i)!=S.at(i+1)) B++;
  }
  if (B-2*K>=0) cout << N-(B-2*K)-1 << endl;
  else cout << N-1 << endl;
}

Measured memory_bytes: 512