akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);} while(0)
  #define trcc(v) do { cerr << "name : " << #v << "\n"; int cnt = 0; each(x , v){cerr << (cnt++) << " : "; trc(x); } } while(0)
#else
  #define trc(...)
  #define trca(...)
  #define trcc(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(s,t)   rep(i,sz(s)){in(s[i] , t[i]);}
#define in3(s,t,u) rep(i,sz(s)){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N);
  vi a(N); in(a);
  vi cnt(100100);
  each(x , a) cnt[x]++;
  int nya = 0;
  each(x , cnt) nya += !!x;
  out(nya % 2 ? nya : nya - 1);
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int x[MAXN], d[MAXN], f[MAXN], ans[MAXN];

pii pp[MAXN];

int n, l, t;

void solve(){
	scanf("%d%d%d", &n, &l, &t);
	REP(i, 0, n){
		scanf("%d%d", &x[i], &d[i]);
		if (d[i] == 2){
			d[i] = -1;
		}
		f[i] = (x[i] + d[i] * t) % l;
		if (f[i] < 0){
			f[i] += l;
		}
		pp[i] = mp(f[i], i);
	}
	sort(pp, pp + n);
	int ind_0 = 0;
	REP(i, 0, n){
		if (pp[i]._2 == 0){
			ind_0 = i;
		}
	}
	rotate(pp, pp + ind_0, pp + n);
	if (d[0] == 1){
		ll cnt = 0ll;
		int fl = 0;
		REP(i, 1, n){
			if (d[i] == -d[0]){
				int dis = x[i] - x[0];
				if (dis <= t * 2){	// dis / 2 <= t
					cnt++;
					cnt += (2 * t - dis) / l;
					if ((2 * t - dis) % l == 0){
						fl = 1;
					}
				}
			}
		}
		cnt -= fl;
		cnt %= n;
		int ind;
		for(ind = 0; ind < n; cnt = (cnt + 1) % n, ind++){
			ans[cnt] = pp[ind]._1;
		}
	} else if (d[0] == -1){
		ll cnt = 0ll;
		int fl = 0;
		REP(i, 1, n){
			if (d[i] == -d[0]){
				int dis = l - (x[i] - x[0]);
				if (dis <= t * 2){	// dis / 2 < t
					cnt++;
					cnt += (2 * t - dis) / l;
					if ((2 * t - dis) % l == 0){
						fl = 1;
					}
				}
			}
		}
		//cnt -= fl;
		cnt %= n;
		cnt = (n - cnt) % n;
		int ind;
		for(ind = 0; ind < n; cnt = (cnt + 1) % n, ind++){
			ans[cnt] = pp[ind]._1;
		}
	}
	REP(i, 0, n){
		printf("%d\n", ans[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3584
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
//インクルード(アルファベット順)
#include<bits/stdc++.h>
using namespace std;
typedef int ll;

#define REP(i,n) for(ll i=0;i<n;i++)
//xにはvectorなどのコンテナ
#define SIZE(x) ll(x.size())
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n-1));
    REP(i,n){
        REP(j,n-1){
            ll c;cin>>c;
            if(c-1<i)a[i][j]=c-1+n*i;
            else a[i][j]=i+n*(c-1);
        }
    }
    Umap<ll,ll> d;
    REP(i,n)d[a[i][0]]++;
    vector<ll> b(n,0);
    ll ans=0;
    deque<ll> nextd;
    deque<ll> cleard;
    while(!d.empty()){
        ans++;
        bool g=true;
        for(const auto& i : d){
            if(i.S==2){
                g=false;
                ll e=(i.F)/n;ll f=(i.F)%n;
                cleard.insert(cleard.begin(),i.F);
                b[e]++;b[f]++;
                if(b[e]<n-1)nextd.insert(nextd.begin(),a[e][b[e]]);
                if(b[f]<n-1)nextd.insert(nextd.begin(),a[f][b[f]]);
            }
        }
        if(g){
            cout<<-1<<endl;
            return 0;
        }
        ll ln,lc;ln=SIZE(nextd);lc=SIZE(cleard);
        REP(i,ln){
            d[*--nextd.end()]++;
            nextd.pop_back();
        }
        REP(i,lc){
            d.erase(*--cleard.end());
            cleard.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7436
#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <climits>
#include <bitset>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
#include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef pair<int,long long> pil;
typedef pair<long long,int> pli;
typedef vector<vector<long long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef priority_queue<int, vector<int>, greater<int> > minq;
typedef priority_queue<int> maxq;
// to initialize PQs with a vector, do 
// minq(v.begin(),v.end()) or maxq(v.begin(),v.end())
// or minq(a,a+10) for arrays

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

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

    bool good=false;
    for (int x=a; x<=b; ++x) {
        if (x%k ==0) good=true;
    }

    if (good) {
        cout<<"OK";
    } else {
        cout<<"NG";
    }

    cout<<el;



}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(){
   int l, r, d;
   cin >> l >> r >> d;
   int res = 0;
   for(l = l; l <= r; l++){
     if((l % d) == 0){
        res++;
     }
   }
  cout << res << "\n";
   return 0; 
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;

int main(){
	int s,w;
	cin >> s >> w;
	if(w >= s) cout << "unsafe\n";
	else cout << "safe\n";
    return 0;
}

Measured memory_bytes: 3632
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    set<int> d;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        d.insert(x);
    }
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long K, K_, A, B;
long num = 1;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> K >> A >> B;
    K_ = K;
    if(A >= B || A >= K)num += K;
    else{
        K -= (A + 1);
        num = B;
        if(K > 0){
            if(B - A == 1)num += K;
            else if(K % 2 == 0){
                num += (B - A) * (K / 2);
            }
            else{
                num += (B - A) * ((K - 1) / 2) + 1;
            }
        }
    }
    if(num < K_ + 1)num = K_ + 1;
    cout << num << "\n";
    return 0;
}

Measured memory_bytes: 256
//Solution by Tima
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
 
using namespace std;    
const int N = int(3e5) + 12, mod = int(1e9)  + 7; 

int n, a[N], b[N], T,qn,pn;
ll dp[N][40], mn[40];
int q[N];

pair <int,int> p[N];

bool cmp(pair<int,int> a, pair<int,int> b){
	return 1ll * a.f * (b.f + b.s) + a.s > 1ll * b.f * (a.f + a.s) + b.s;
} 

int main () {
	scanf("%d%d", &n, &T);
	for(int i = 1,x,y; i <= n; i++){
		scanf("%d%d", &x, &y);
		x++;
		y++;
		if(x > 1) p[++pn] = mp(x,y);
		else q[++qn] = y; 
	}
	T++;
	sort(p + 1, p + pn + 1, cmp);
	sort(q + 1, q + qn + 1);
	mn[0] = 1;
	for(int i = 1; i < 40; i++) mn[i] = mod;
	int ans = 0;
	ll tx = 0;
	for(int i = 1; i <= pn; i++){
		a[i] = p[i].f, b[i] = p[i].s;
		dp[i][0] = a[i] + b[i];
		for(int j = 1; j < 40; j++){
			dp[i][j] = mn[j - 1] * a[i] + b[i];
		}
		for(int j = 0; j < 40; j++){
			mn[j] = min(mn[j], dp[i][j]);
		}
	}

	for(int j = 0; j < 40; j++){
		if(mn[j] > T) continue;
		int res = j;
		ll t = mn[j];
		for(int k = 1; k <= qn; k++){
		    if(t + q[k] <= T){
		    	res++;
		    	t += q[k];
		    }
		    else break;
		}
		if(ans < res){
			ans = res;
			tx = t;
		}
		else if(ans == res) tx = min(tx, t);
	}

	printf("%d", ans);

return 0;
}

Measured memory_bytes: 70144
#coding: utf-8
N = int(input())
ans = 0
l_B = 0
r_A = 0
lbra = 0
for _ in range(N):
	tmp = input()
	ans += tmp.count("AB")
	if tmp[0] == "B":
		if tmp[-1] == "A":
			lbra += 1
		else:
			l_B += 1
	elif tmp[-1] == "A":
		r_A += 1
        
if lbra == 0:
    ans += min(l_B, r_A)
else:
    if l_B + r_A > 0:
        ans += lbra + min(l_B, r_A)
    else:
        ans += lbra - 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
int main()
{
	int n=io::F();
	int T=io::F(),a=io::F();
	int id=0;
	double min=1e233;
	for(register int i=1;i<=n;++i)
	{
		double x=T-io::F()*0.006;
		if(cmin(min,fabs(x-a)))id=i;
	}
	printf("%d\n",id);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
   int N, M, X, Y;
   cin >> N >> M >>X >>Y;
   vector<int> x, y;
   for(int i=0; i < N; i++){
      int x_tmp;
      cin >> x_tmp;
      x.push_back(x_tmp);
   }
   x.push_back(X);
   for(int i=0; i < M; i++){
      int y_tmp;
      cin >> y_tmp;
      y.push_back(y_tmp);
   }
   y.push_back(Y);
   sort(x.begin(), x.end());
   sort(y.begin(), y.end());
   int x_max = x.back();
   int y_min = y[0];

   // abs(x_max - y_min) == 0で判定すると,
   // 既にx, yが交わっている条件を逃してしまうので,
   // 以下のようにする.
   if(not(x_max < y_min)){
      cout << "War" << endl;
      return 0;
   }
      cout << "No War" << endl;

   return 0;
}

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

int main(void){
	int N,K,X,Y;
	cin >> N >> K >> X >> Y;
	int ans = 0;
	if(N>=K){
		ans = K*X;
		ans += (N-K)*Y;
	}else{
		ans = N * X;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
cnt = 0
for i in range(n):
    if a[i] % 2 == 0:
        while(a[i] % 2 == 0):
            a[i] = a[i]//2
            cnt += 1
print(cnt)


Measured memory_bytes: 40944
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int N, W; cin >> N >> W;
	vector<int>v, w; v.push_back(0), w.push_back(0);
	rep(i, 0, N) {
		int a, b, m; cin >> a >> b >> m;

		for (int x = 1; x <= m; x++) {
			v.push_back(x*a);
			w.push_back(x*b);
			m -= x;
		}
		if (m > 0) v.push_back(m*a), w.push_back(m*b);

	}
	
	vector<int>dp(W + 1, 0);
	rep(i, 1, v.size())rrep(j, w[i], W + 1) {
		dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
	}
	cout << dp[W] << endl;

	return 0;
}

Measured memory_bytes: 3268
#include<iostream>
using namespace std;
enum POSITION{ONLINE_BACK = -2, CLOCKWISE = -1, ON_SEGMENT = 0,
              COUNTER_CLOCKWISE = 1, ONLINE_FRONT = 2};
struct Point{
    double x;
    double y;
    Point(double x, double y) : x(x), y(y){}
    Point operator-(Point p){
        return Point(x - p.x, y - p.y);
    }
};
typedef Point Vector;
double get_cross(Vector v1, Vector v2){
    return v1.x * v2.y - v1.y * v2.x;
}
double get_dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}
struct Segment{
    Point p1;
    Point p2;
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
POSITION get_position(Point p, Segment s){
    Vector base = s.p2 - s.p1;
    Vector obj  = p    - s.p1;
    double cross = get_cross(base, obj);
    if (cross >  1e-10) return CLOCKWISE;
    if (cross < -1e-10) return COUNTER_CLOCKWISE;
    // if (get_dot(base, obj) < 0) return ONLINE_BACK;
    // if (get_dot(base, base) < get_dot(obj, obj)) return ONLINE_FRONT;
    if (get_dot(base, obj) < 0) return CLOCKWISE;
    if (get_dot(base, base) < get_dot(obj, obj)) return COUNTER_CLOCKWISE;
    return ON_SEGMENT;
}
bool is_intersection(Segment s1, Segment s2){
    if (get_position(s2.p1, s1) * get_position(s2.p2, s1) <= 0 &&
        get_position(s1.p1, s2) * get_position(s1.p2, s2) <= 0) {
        return true;
    }
    return false;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3;
        cin >> x_p0 >> y_p0 >> x_p1 >> y_p1;
        cin >> x_p2 >> y_p2 >> x_p3 >> y_p3;
        Point p0(x_p0, y_p0);
        Point p1(x_p1, y_p1);
        Point p2(x_p2, y_p2);
        Point p3(x_p3, y_p3);
        Segment s1(p0, p1);
        Segment s2(p2, p3);
        int ans = 0;
        if (is_intersection(s1, s2)) ans = 1;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int h,w; cin >> h >> w;
  char s[h][w];
  REP(i,h)REP(j,w){
    cin >> s[i][j];
  }
  vector<int> horizontal[h];
  vector<int> vertical[w];
  REP(i,h){
    horizontal[i].push_back(-1);
    REP(j,w){
      if(s[i][j]=='#') horizontal[i].push_back(j);
    }
    horizontal[i].push_back(w);
  }
  REP(j,w){
    vertical[j].push_back(-1);
    REP(i,h){
      if(s[i][j]=='#') vertical[j].push_back(i);
    }
    vertical[j].push_back(h);
  }
  ll ans = 0;
  REP(i,h) REP(j,w){
    if(s[i][j]=='#') continue;
      auto it_r = lower_bound(horizontal[i].begin(),horizontal[i].end(),j);
      ll r = *it_r;
      it_r--;
      ll l = *it_r;
      auto it_d = lower_bound(vertical[j].begin(),vertical[j].end(),i);
      ll d = *it_d;
      it_d--;
      ll u = *it_d;
      ans = max(ans, r-l-1+d-u-1-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 36352
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  vi a(n);
  REP(i,n){
    cin>>a[i];
    a[i]--;
  }



  vvi b(64, vi(n));
  REP(i,n) b[0][i]=a[i];

  for(ll i=1;i<64;i++){
    for(ll j=0;j<n;j++){
      b[i][j]=b[i-1][b[i-1][j]];
    }
  }


  ans=0;
  for(ll i=0;i<64;i++){
    if (k%2==1){
      ans=b[i][ans];
    }
    k/=2;
    
  }


  cout<<(ans+1)<<endl;
  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

bool dp[100001];

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (Int i = 0; i <= k; i++) {
        bool check = true;
        for (Int j = 0; j < n; j++) {
            if (0 <= i - a[j]) {
                if (dp[i - a[j]]) {
                    check = false;
                } 
            }
        }
        dp[i] = check;
    }
    dump(not dp[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    //IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>a>>b>>c>>d;
        ll p,q,r,s,pp,qq;
        p=a*c;
        q=b*d;
        r=a*c;
        s=b*d;
        pp=a*d;
        qq=b*c;
        cout<<max({p,q,r,s,pp,qq})<<endl;



    }
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node* right, *left, *parent;
};

Node *root, *NIL;

void insertKey(int k) {
    //y: empty node
    Node* y = NIL;
    //xroot: temp argument which saves root datas temporarily
    Node* xroot = root;
    Node* keyNode;

    //node what we want to insert where its place will be found
    keyNode = (Node*)malloc(sizeof(Node));
    keyNode -> key = k;
    keyNode -> left = NIL;
    keyNode -> right = NIL;

    //program is going until node is empty
    //y: parent node of last empty node
    // keynode become left or right childe of y
    while (xroot != NIL) {
        y = xroot;
        if (keyNode -> key < xroot -> key) {
            xroot = xroot -> left;
        } else {
            xroot = xroot -> right;
        }
    }

    keyNode -> parent = y;
    if (y == NIL) {
        root = keyNode;
    } else {
        if (keyNode -> key < y -> key) y -> left = keyNode;
        else y -> right = keyNode;
    }
}

void inOrder(Node *root) {
    if (root == NIL) return;
    inOrder(root -> left);
    printf(" %d", root -> key);
    inOrder(root -> right);
}

void preOrder(Node *root) {
    if (root == NIL) return;
    printf(" %d", root -> key);
    preOrder(root -> left);
    preOrder(root -> right);
}

Node* findKey(Node* xroot, int key) {
    while (xroot != NIL && key != xroot -> key) {
        if (key < xroot -> key) xroot = xroot -> left;
        else xroot = xroot -> right;
    }
    return xroot;
}

int main()
{
    int n, i, x;
    string com;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "find") {
            scanf("%d", &x);
            Node* t = findKey(root, x);
            if (t != NIL) printf("yes\n");
            else printf("no\n");
        }
        else if (com == "insert") {
            scanf("%d", &x);
            insertKey(x);
        }
        else if (com == "print") {
            inOrder(root);
            printf("\n");
            preOrder(root);
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 22040
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, K = Is()

tmp = N % K
ans = min(tmp, abs(tmp-K))
print(ans)

Measured memory_bytes: 63340
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

string s;
int k;



int main() {

	cin >> s >> k;
	int len = s.length();
	ll ans = 0;
	if (len - 1 >= k) {
		ans = 1;
		for (int i = 0;i < k;i++) {
			ans *= (len - 1 - i)*9;
		}
		for (int i = k; i > 0;i--) {
			ans /= i;
		}
	}
	else {
		ans = 0;
	}
	
	
	
	int cnt = 0;
	
	for (int i = 0; i <len ;i++) {
		int num = s[i] - '0';
		if (num > 0) {
			int tmp;
			if (cnt > 0) {
				tmp = 1;

				for (int l = 0;l < k - cnt;l++) {
					tmp *= (len - 1 - i - l) * 9;
				}
				for (int l = k - cnt; l > 0;l--) {
					tmp /= l;
				}

				ans += tmp;

			}
			cnt++;
			if (cnt == k) {
				ans += num;
				break;
			}
			tmp = num-1;

			for (int l = 0;l < k - cnt;l++) {
				tmp *= (len - 1 - i - l) * 9;
			}
			for (int l = k - cnt; l > 0;l--) {
				tmp /= l;
			}

			ans += tmp;



		}
		
	}


	cout << ans << endl;
}





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

using namespace std;

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

    bool ac = (s[0] == 'A');

    if (ac) {
        for (int i = 2, cnt_c = 0; i < static_cast<int>(s.size()) - 1; i++) {
            if (s[i] == 'C') {
                cnt_c++;
            }

            ac = (cnt_c == 1);
        }
    }

    if (ac) {
        ac = ('a' <= s[1] && s[1] <= 'z');
        for (int i = 2; i < static_cast<int>(s.size()); i++) {
            ac = (ac && (s[i] == 'C' || ('a' <= s[i] && s[i] <= 'z')));
        }
    }

    cout << (ac ? "AC" : "WA") << endl;
}


Measured memory_bytes: 256
/*
May the God who gives endurance and encouragement give you the same attitude of mind toward each other that Christ Jesus had,
so that with one mind and one voice you may glorify the God and Father of our Lord Jesus Christ.
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const int N = (int)5e3+5;
const ll oo = (ll)1e18+7;
int n, m, L[N][205], R[N][205];
ll a[N], b[N][205], dp[N][N];
vector<int> st[205];

void init() {
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			while (SZ(st[j]) && b[i][j] > b[st[j].back()][j]) st[j].pop_back();
			L[i][j] = (SZ(st[j]) ? st[j].back() + 1 : 1), st[j].push_back(i);
		}
	}
	for (int j = 1; j <= m; ++j) st[j].clear();
	for (int i = n; i >= 1; --i) {
		for (int j = 1; j <= m; ++j) {
			while (SZ(st[j]) && b[i][j] >= b[st[j].back()][j]) st[j].pop_back();
			R[i][j] = (SZ(st[j]) ? st[j].back() - 1 : n), st[j].push_back(i);
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			int u = L[i][j], x = i, v = i, y = R[i][j];
			dp[u][v] += b[i][j], dp[u][y + 1] -= b[i][j];
			dp[x + 1][v] -= b[i][j], dp[x + 1][y + 1] += b[i][j];
		}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 2; i <= n; ++i) scanf("%lld", &a[i]), a[i] += a[i - 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			scanf("%lld", &b[i][j]);
	init();
	ll res = -oo;
	for (int i = 1; i <= n; ++i)
		for (int j = i; j <= n; ++j)
			res = max(res, dp[i][j] - a[j] + a[i]);
	printf("%lld", res);
	return 0;
}


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

int main(){
  int a, b, c; cin >> a >> b >> c;
  int k; cin >> k;
  
  if (max({a, b, c}) == a){
    cout << a * (1<< k)  + b + c << endl;   
  } else if (max({a, b, c}) == b){
    cout << b * (1<< k)  + c + a << endl;   
  } else {
    cout << c * (1<< k)  + a + b << endl;   
  }

	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
n, *l = map(int, open(0).read().split())
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ng = n - bisect_left(l, l[i] + l[j]) + 1
        ans += (n - j) - ng
print(ans)


Measured memory_bytes: 9240
#include<iostream>
using namespace std;
bool ispal(string s)
{
	int l=0 , r = s.size()-1;
	while(l<r)
	{
		if(s[l]!=s[r])
		return false;
		l++;
		r--;
	}
	return true;
}
main()
{
 string s, s1 , s2;
 cin >> s;	
  int i,n = (s.size()-1)/2;
  for(i=0;i<n;i++)
  s1+=s[i];
  n = (s.size()+3)/2;
  n--;
  for(i=n;i<s.size();i++)
  s2+=s[i];
  //cout << s << " " << s1 << " " << s2 << endl;
  if(ispal(s) && ispal(s2) && ispal(s1))
	cout << "Yes";
	else
	cout << "No";
	return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 3; i++)
    {
        if((a * b * i) % 2 == 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define ll long long int
#define vi vector<int>
#define pr pair<ll, ll>
#define vll vector<pr>
#define vl vector<ll>
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(a, b))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x%mod);
    return v;}
void out(vl v){fl(i,v)cout<<i;}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;}

ll kill(ll n)
{
    if(n == 1)
    return 1;
    
    return 1+(2*kill(n/2));
    
}

void solve(){
    ll n;
    cin>>n;
    cout<<kill(n);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin >> n >> s;
	ll ans = 0;
	ll x = 0;
	REP(i, n){ 
		if (s[i]=='I'){ x++; }
		else if (s[i]=='D'){ x--; }
		ans = max(ans, x);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
// Crt. 2019-12-17  10:14:31
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 300005
#define PII pair<int, int>
using namespace std;

int n, m, sum[N];
PII s[N];

inline void add(int p, int w) {
    while (p <= m) sum[p] += w, p += p & (-p);
}

inline int ask(int p) {
    int res = 0;
    while (p) res += sum[p], p -= p & (-p);
    return res;
}

bool cmp(PII a, PII b) { return a.second + b.first < b.second + a.first; }

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &s[i].first, &s[i].second);

    sort(s + 1, s + n + 1, cmp);

    for (int i = 1, pos = 0; i <= m; ++i) {
        while (pos < n && s[pos + 1].second - s[pos + 1].first + 1 <= i)
            ++pos, add(s[pos].first, 1), add(s[pos].second + 1, -1);
        long long ans = n - pos;
        for (int j = i; j <= m; j += i)
            ans += ask(j);
        printf("%lld\n", ans);
    }


    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using ll = long long;

int main() {
    int N;
    ll W;
    std::cin >> N >> W;

    std::vector<ll> v(N), w(N);
    for (int i = 0; i < N; ++i) std::cin >> v[i] >> w[i];

    std::vector<std::pair<ll, ll>> vp;
    int M = N / 2;
    for (int b = 0; b < (1 << M); ++b) {
        ll wsum = 0, vsum = 0;
        for (int i = 0; i < M; ++i) {
            if ((b >> i) & 1) {
                wsum += w[i];
                vsum += v[i];
            }
        }
        vp.emplace_back(wsum, vsum);
    }

    // 重さについて価値が昇順になるよう記録
    std::sort(vp.begin(), vp.end());
    std::map<ll, ll> fore;
    ll vmax = -1;
    for (auto& p : vp) {
        if (p.second <= vmax) continue;
        fore[p.first] = p.second;
        vmax = p.second;
    }

    ll ans = 0;
    for (int b = 0; b < (1 << (N - M)); ++b) {
        ll wsum = 0, vsum = 0;
        for (int i = 0; i < N - M; ++i) {
            if ((b >> i) & 1) {
                wsum += w[i + M];
                vsum += v[i + M];
            }
        }
        if (wsum > W) continue;
        auto itr = fore.upper_bound(W - wsum);
        ans = std::max(ans, vsum + (--itr)->second);
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 19444
#include<iostream>
#include<string>
#include<stack>
using namespace std;

int main()
{
	stack <int>s;
	string a;
	getline(cin,a);
	int i=0,j,num=0;
	while(a[i])
	{
		if(a[i]>='0'&&a[i]<='9')
		{
			if(!(a[i]>='0'&&a[i]<='9'))
			{
				s.push(a[i]-'0');
				i++;
			}
			
			else
			{
				j=i;
				num=a[i]-'0'; 
				j++;
				while(a[j]>='0'&&a[j]<='9')
				{
					num=num*10+(a[j]-'0');
					j++;
				}
				s.push(num);
				i=j;
			}
			
		}
		if(a[i]=='+')
		{
			int b=s.top();
			s.pop();
			int c=s.top();
			s.pop();
			s.push(b+c);
			i++;
		}
		if(a[i]=='-')
		{
			int b=s.top();
			s.pop();
			int c=s.top();
			s.pop();
			s.push(c-b);
			i++;
		}
		if(a[i]=='*')
		{
			int b=s.top();
			s.pop();
			int c=s.top();
			s.pop();
			s.push(b*c);
			i++;
		}
		else
		i++;
	}
	cout<<s.top()<<endl;
	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)

const int N=2005,K=2005,S=N*K,MOD=1e9+7;
int n,k;
int fac[S],inv[S];
int dp[N][K];

inline int qsm(int a,int b) {int ans=1; while(b) {if(b&1) ans=1ll*ans*a%MOD; a=1ll*a*a%MOD; b>>=1;} return ans;}
inline int C(int a,int b) {return b<0||a<b?0:1ll*fac[a]*inv[b]%MOD*inv[a-b]%MOD;}
inline void inc(int &a,int b) {(a+=b)>=MOD?a-=MOD:a;}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	#endif

	cin>>n>>k;
	if(k==1) return puts("1"),0;
	fac[0]=1l; lor(i,1,n*k) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[n*k]=qsm(fac[n*k],MOD-2); ror(i,0,n*k-1) inv[i]=1ll*inv[i+1]*(i+1)%MOD;
	dp[0][0]=1;
	lor(i,0,n) lor(j,0,i){
		if(i) inc(dp[i][j],dp[i-1][j]);
		if(j) inc(dp[i][j],1ll*dp[i][j-1]*C(n*k-i-(j-1)*(k-1)-1,k-2)%MOD*(n-j+1)%MOD);
	}
	printf("%d\n",dp[n][n]);

	return 0;
}

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

#define ld			long double
#define int         long long
#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 sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl
# define M_PI           3.14159265358979323846 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

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

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

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

void solve()
{
	int n, m;
	cin >> n >> m;
	int sum = 0;

	rep(i, 0, m){
		cin >> arr[i];
		sum += arr[i];
	}

	if(sum > n){
		cout << -1 << endl;
	}
	else{
		cout << n-sum << endl;
	}

}			 	

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




Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    constexpr ll mod = 1e9+7;
    rep(i, K, N+2){
        ll s = i * (i-1) / 2;
        ll l = N * (N + 1) / 2 - (N - i) * (N - i + 1) / 2;
        ans += l - s +  1;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>

int main(){
    int i, j, k;
    int N;
    long long sum[5];
    int a[10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
    int b[10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
    int c[10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
    long long ans=0;
    char s[20];
    char t[6]="MARCH";

    scanf("%d", &N);
    for(i=0; i<5; i++){
        sum[i]=0;
    }
    for(i=0; i<N; i++){
        scanf("%s", &s);
        for(j=0; j<5; j++){
            if(s[0]==t[j]){
                sum[j]++;
            }
        }
    }

    for(i=0; i<10; i++){
        ans += sum[a[i]]*sum[b[i]]*sum[c[i]];
    }

    printf("%lld", ans);

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000010
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;

int n;
vector<PP> v;

void solve(){
	v.clear();
	rep(i,n){
		char x; cin >> x;
		if(x == 'D'){
			int l; cin >> l;
			rep(j,v.size()) if(v[j].second == l){
				v[j].first.first = INF;
			}
			sort(v.begin(),v.end());
			while(true){
				if(v.size() == 0) break;
				if(v[v.size()-1].first.first != INF) break;
				v.pop_back();
			}
		} else if(x == 'R'){
			int p; cin >> p;
			bool ok = false;
			rep(j,v.size()){
				if(v[j].first.first <= p && p <= v[j].first.second){
					cout << v[j].second << endl;
					ok = true;
					break;
				}
			}
			if(!ok) puts("-1");
		} else{
			int l, s; cin >> s >> l;
			int st = 0;
			int V = v.size();
			rep(j,V){
				if(v[j].first.first > st){
					if(l <= v[j].first.first-st){
						v.push_back(PP(P(st,st+l-1),s));
						l = 0;
						break;
					} else{
						v.push_back(PP(P(st,v[j].first.first-1),s));
						l -= v[j].first.first-st;
					}
				}
				st = v[j].first.second+1;
				if(st > INF){
					l = 0;
					break;
				}
			}
			if(l > 0) v.push_back(PP(P(st,st+l-1),s));
			sort(v.begin(),v.end());
		}
	}
	cout << endl;
}

int main(){
	while(true){
		cin >> n;
		if(n == 0) break;
		solve();
	}
}

Measured memory_bytes: 1288
#include<stdio.h>
int main(){
  int x[10000], t, s = 0;
  while(1){
    scanf("%d\n", &t);
    if(t == 0) break;
    else { x[s]=t; s++;}
  }
  for(t=0;t<s;t++)printf("Case %d: %d\n", t+1, x[t]);
  return 0;
}


Measured memory_bytes: 2784
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)


import sys
import numpy as np

def main():
    N, K = map(int, sys.stdin.buffer.readline().split())
    XYC = sys.stdin.buffer.read().split()
    X, Y, C = np.array(XYC[::3], dtype=np.int64), np.array(XYC[1::3], dtype=np.int64), np.array(XYC[2::3])==b"B"
    solve(N, K, X, Y, C)

def solve(N, K, X, Y, C):
    M = np.zeros((K*2+1, K*4), dtype=np.int64)
    for x, y, c in zip(X, Y, C):
        if c:
            x += K
        x %= 2*K
        y %= 2*K
        if x >= K and y >= K:
            x -= K
            y -= K
        elif y >= K:
            y -= K
            x += K
        M[y, x] += 1
        M[y, (x+2*K)%(4*K)] += 1
        M[y+K, x+K] += 1
        M[y+K, (x+3*K)%(4*K)] += 1
        if y == 0:
            M[2*K, x] += 1
            M[2*K, (x+2*K)%(4*K)] += 1
    for y in range(2*K):
        for x in range(4*K):
            M[y+1, x] += M[y, x]
    for y in range(2*K+1):
        for x in range(4*K-1):
            M[y, x+1] += M[y, x]
    ans = max([M[y+K, x+K]+M[y, x]-M[y+K, x]-M[y, x+K] for y in range(K+1) for x in range(2*K+1)])
    print(ans)

numba_compile([
    [solve, "void(i8,i8,i8[:],i8[:],b1[:])"],
])

main()


Measured memory_bytes: 125512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  int hcf,hcf1=0;
  for(int i=1;i<=k;i++)
  {
  for(int j=1;j<=k;j++)
      {
        for(int l=1;l<=k;l++)
        {
           hcf=__gcd(__gcd(i,j),l);
           //cout<<i<<" "<<j<<" "<<l<<endl;
           hcf1=hcf1+hcf;
           //cout<<hcf<<" "<<hcf1<<endl;
        }
      }
  }
      cout<<hcf1;

}


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

using namespace std;
using ll = long long;

int main() {
    ll N, Y;
    cin >> N >> Y;

    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N - i; j++) {
            if (10000*i + 5000*j + 1000*(N - i - j) == Y) {
                cout << i << ' ' << j << ' ' << N - i - j << endl;
                return 0;
            }
        }
    }

    cout << -1 << ' ' << -1 << ' ' << -1 << endl;

    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 2007;

int n, k, ans = maxn, qu[maxn], fr, rr, dist[maxn];
vector<int> G[maxn];

void proc(int u, int v)
{
	fr = rr = 0;
	for (int i = 1; i <= n; ++i) dist[i] = maxn;
	if (u) dist[qu[++rr] = u] = 0;
	if (v) dist[qu[++rr] = v] = 0;
	int cur = n;
    while (fr < rr) {
        u = qu[++fr];
        if (dist[u] <= k) --cur;
        else break;

        for (int v : G[u]) if (dist[u] + 1 < dist[v]) {
            dist[qu[++rr] = v] = dist[u] + 1;
        }
    }
    ans = min(ans, cur);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n-1; ++i) {
    	int u, v; cin >> u >> v;
    	G[u].push_back(v);
    	G[v].push_back(u);
    }

    if (k & 1) {
        k >>= 1;
        for (int u = 1; u <= n; ++u) for (int v : G[u]) if (u < v) {
            proc(u, v);
        }
    } else {
    	k >>= 1;
        for (int u = 1; u <= n; ++u) proc(u, 0);
    }

    cout << ans;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

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

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int running_sum=0;
    vector<int> summ(n);
    for(int i=n-1;i>=0;i--)
    {
        summ[i]=running_sum;
        running_sum+=a[i];
    }
    int total=0;
    for(int i=0;i<n;i++)
    {
        total+=a[i]*summ[i];
    }
    cout<<total;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int M,D; cin>>M>>D;
  int count = 0;
  for(int m=4;m<=min(M,81);++m){
    for(int d=22; d<=D; ++d){
      int d1 = d%10;
      int d10 = d/10;
      if(d1>1 && d10>1 && d1*d10==m){
        ++count;
      }
    }
  }
  cout << count <<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

#include <cstdio>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    double ans = 0.0;

    for (int i = 1; i <= N; ++i) {
        if (i >= K) {
            ans += (1.0/N);
        } else {
            int num_heads = ceil(log2((double)K / i));
            ans += (1.0/N) * pow(0.5, num_heads);
        }
    }

    printf("%.12f\n", ans);

    return 0;
}


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

int main() {
  int N,count=0,ans=0;
  string S;
  string T="ABC";
  cin >> N >> S;
  
  for(int i=0;i<N-2;i++){
    for(int j=0;j<3;j++){
      if(S.at(i+j) == T.at(j)) count++;
      else{
        count = 0;
        break;
      }
    }
    if(count==3) ans++;
  }
  
  cout << ans << endl;
  return 0;
}


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


int main(){
  int n,m;
  cin >> n >> m;
  for (int i=0; i<m; i++){
    int a;
    cin >> a;
    n -=a;
  }
  if(n<0) n=-1;
  cout << n << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<str,int> p;

const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    vector<pair<str, pair<int, int> > > s;
    for(int i=0; i<N;i++){
      str ss; int pp;
      cin>>ss>>pp;
      s.push_back(make_pair(ss, make_pair(-pp, i+1)));
    }
    sort(s.begin(), s.end());
    for(int i=0; i<N;i++){
      cout<<s[i].second.second<<endl;
    }
    return 0;
}


Measured memory_bytes: 256