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

using namespace std;

typedef long long int lli;

lli i,j,k,l,m,n,t,a,b,c,d,x,y,p,q,sum=0,total=0;

#define read(in) freopen("Input.txt","r",stdin)

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

    //read(in);

    cin>>a>>b>>c;
  	cout<<c<<" "<<a<<" "<<b<<"\n";

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <iomanip>
#include <queue>
#include <deque>
#include <sstream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <map>
#include <utility>
using namespace std;

#define s(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",&n)
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795


int main() {
	int r,g,b;
	cin >> r >> g >> b;
	cout << ((10*g+b)%4 == 0 ? "YES" : "NO");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

const int SIZE = 5;
int main() {
	llong int N;
	vector<llong int> a(SIZE);
	cin >> N;
	for (int i = 0; i < SIZE; i++) {
		cin >> a[i];
	}
	llong int min = *min_element(a.begin(), a.end());
	cout << ((N - 1) / min) + 5 << endl;
}


Measured memory_bytes: 256
s = gets.strip
s = s.reverse

while s.size > 0
  t = s
  s.gsub!(/resare/, '')
  s.gsub!(/esare/, '')
  s.gsub!(/remaerd/, '')
  s.gsub!(/maerd/, '')
  break if t == s
end

if s.size == 0
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 2172
program tenquestionnine
 implicit none
 character(10**5) :: S
 character(7) :: T(4) = (/"dream  ","dreamer","erase  ","eraser "/)
 integer :: L(4) = (/5,7,5,6/)
 integer i, len
 read(*,*) S
 len=len_trim(S)
 a: do while (len.gt.0)
  do i=1,4
   if((trim(T(i))).eq.(S((len-L(i)+1):len))) then
   len = len - L(i)
   cycle a
   end if
  end do
  write(*,*) "NO"
  return
  end do a
  write(*,*) "YES"
end program


Measured memory_bytes: 700
#include<stdio.h>
int main(void){
	int r, d, x, ans;
  
  scanf("%d %d %d", &r, &d, &x);
  
  for(int i = 0; i < 10; i++){
  	ans = r * x - d;
    printf("%d\n", ans);
    x = ans;
  }
}


Measured memory_bytes: 128
from collections import deque

n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(m)]
d = {i: [] for i in range(1, n+1)}
for a, b in L:
    d[a].append(b)
    d[b].append(a)
cnt = 0
for a, b in L:
    d[a].remove(b)
    d[b].remove(a)
    ds = {i: -1 for i in range(1, n+1)}
    ds[1] = 0
    q = deque([1])
    while q:
        t = q.popleft()
        for v in d[t]:
            if ds[v] < 0:
                ds[v] += 1
                q.append(v)
    if -1 in ds.values():
        cnt += 1
    d[a].append(b)
    d[b].append(a)
print(cnt)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N;
  cin>>N;
  string s= to_string(N);
  cerr << s << endl;
  int sum(0);
  for (int i(0);i<s.size();i++){
    sum+=s[i]-'0';
  }
  cerr << N <<" "<< sum << endl;
  cout << (N%sum==0? "Yes" : "No") << endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		HashSet<Integer> list = new HashSet<>();
		for(int i=0;i<N;i++){
			int ins = Integer.parseInt(sc.next());
			if(list.contains(ins)){
				list.remove(ins);
			}
			else{
				list.add(ins);
			}
		}


		out.println(list.size());
		
		sc.close();
		out.flush();
	}

	public static long gcd(long a, long b){
		long r = a % b;
		if(r==0){
			return b;
		}
		else{
			return gcd(b,r);
		}
	}
}

Measured memory_bytes: 47316
import java.util.Scanner;

//Lost in Space
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		double RATIO = 1e-4;
		while(t--!=0){
			double qr = sc.nextDouble(), rp = sc.nextDouble(), pq = sc.nextDouble();
			double r1 = qr/rp, r2 = rp/pq, r3 = pq/qr;
			int n = sc.nextInt();
			double[] x = new double[n+1], y = new double[n+1], z = new double[n+1];
			for(int i=1;i<=n;i++){
				x[i] = sc.nextDouble(); y[i] = sc.nextDouble(); z[i] = sc.nextDouble();
			}
			for(int p=1;p<=n;p++)for(int q=1;q<=n;q++)for(int r=1;r<=n;r++){
				if(p==q||q==r||r==p)continue;
				double QR = Math.sqrt(Math.pow(x[q]-x[r], 2)+Math.pow(y[q]-y[r], 2)+Math.pow(z[q]-z[r], 2));
				double RP = Math.sqrt(Math.pow(x[p]-x[r], 2)+Math.pow(y[p]-y[r], 2)+Math.pow(z[p]-z[r], 2));
				double PQ = Math.sqrt(Math.pow(x[q]-x[p], 2)+Math.pow(y[q]-y[p], 2)+Math.pow(z[q]-z[p], 2));
				double R1 = QR/RP, R2 = RP/PQ, R3 = PQ/QR;
				double d1 = Math.abs(r1-R1), d2 = Math.abs(r2-R2), d3 = Math.abs(r3-R3);
				if(d1<RATIO && d2<RATIO && d3<RATIO){
					System.out.println(p+" "+q+" "+r);break;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
bool a[105][105];
int main()
{
// 	freopen("mine.in","r",stdin);
// 	freopen("mine.out","w",stdout);
    memset(a,0,sizeof(a)); 
    int n,m;
    char tmp;
    cin>>n>>m; 
    for(int i=1;i<=n;i++)
	{
        for(int j=1;j<=m;j++) 
        {
            cin>>tmp; 
            if(tmp=='#') a[i][j]=1; 
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]==1) printf("#");
            else
            {
                printf("%d",a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1]);
              
            }
        }
        printf("\n");
    }
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

bool cmp(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.first<b.first;
}

int main()
{
  long long N,K,a,b;
  cin>>N>>K;
  vector <pair<long long, long long> > p(N);
  for(int i=0;i<N;i++){
    cin>>a>>b;
    p[i]=make_pair(a,b);
  }
  sort(p.begin(),p.end(),cmp);
  long long cnt=0;
  for(int i=0;i<N;i++){
    cnt+=p[i].second;

    if(cnt>=K){
      cout<<p[i].first<<endl;
      break;
    }
  }
}

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

typedef long double ld;
#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);         
#endif
}

const int mod = 1e9+7;
const int maxn = 1e6+5;

void solve(){  
	int n; cin>>n;
	string s=""; 
	while(n){
		n--;
		int z = n%26; 
		s += 'a'+z; 
		n/=26;
	}
	reverse(all(s));
	cout<<s;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// io();
    //cout<<setprecision(100);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif

    return 0;
}


Measured memory_bytes: 3640
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる

from math import ceil


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] <= x:
            continue
        a = ceil(A[i] - x / F[i])  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return K > -1


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**12 + 1))


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

int main() {
  int n, x = 2;
  ll o = 1;
  cin >> n;
  vector<int> prime(n + 1, 1);
  vector<pair<int, int>> p;
  while(x * x <= n) {
    for(int i = x * 2; i <= n; i += x)
      prime[i] = 0;
    do
      x++;
    while(prime[x]);
  }
  for(int i = 2; i <= n; i++)
    if(prime[i])
      p.push_back({i, 0});
  for(int i = 2; i <= n; i++) {
    auto t = i;
    for(int j = 0; j < p.size(); j++) {
      while(t % p.at(j).first == 0) {
        t /= p.at(j).first;
        p.at(j).second++;
      }
    }
  }
  for(auto x : p)
    o = o * (x.second + 1) % MOD;
  cout << o << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	int N,K,Q;
	cin>>N>>K>>Q;
	
	vector<int> X(N,0);
	
	for(int i=0;i<Q;i++){
		int a;
		cin>>a;
		a--;
		X[a]++;
	}
	
	for(int i=0;i<N;i++){
		int a = K-(Q-X[i]);
		if(a<=0){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
line = gets
data = line.split(" ")
odd = Array.new
even = Array.new
n.times do |i|
  if i % 2 == 0
    odd << data[i]
  else
    even << data[i]
  end
end
if n == 1
  puts data[0]
elsif n % 2 == 1
  odd.reverse_each do |item|
    print "#{item} "
  end
  even.each do |item|
    if item == even[even.length-1]
      print "#{item}\n"
    else
      print "#{item} "
    end
  end
else
  even.reverse_each do |item|
    print "#{item} "
  end
  odd.each do |item|
    if item == odd[odd.length-1]
      print "#{item}\n"
    else
      print "#{item} "
    end
  end
end

Measured memory_bytes: 21872
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;
vector<pair<ll,ll>>prime_factorize(ll n){
  vector<pair<ll,ll>>res;
  for(ll p=2;p*p<=n;p++){
    if(n%p!=0)continue;
    ll num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    res.push_back(make_pair(p,num));
  }
  if(n!=1)res.push_back(make_pair(n,1));
  return res;
}
int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  map<ll,ll>mp;
  rep(i,n){
    cin >> a[i];
    auto pf=prime_factorize(a[i]);
    for(auto p:pf){
      mp[p.first]=max(mp[p.first],p.second);
    }
  }
  mint lcm=1;
  for(auto p:mp){
    lcm*=modpow(mint(p.first),p.second);
  }
  mint ans=0;
  rep(i,n){
    ans+=lcm/a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
n=int(input())
x,y=(1,1)
m=10**12+1
for i in range(1, int(n**0.5)+1):
    x+=1
    if n%x==0: y=n//x
    if n==x*y and m>x+y-2:
        m=x+y-2

if m==10**12+1:
    m=n-1
print(m)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, m; std::cin >> n >> m;
  vector<bool> isAC(n);
  vi wa_cnt(n);
  rep(i, m) {
    int p; std::cin >> p;
    string s; std::cin >> s;
    if (s == "AC") isAC[p-1] = true;
    else if (!isAC[p-1]) wa_cnt[p-1]++;
  }
  int ac = 0, wa = 0;
  rep(i, n) {
    if (isAC[i]) ac++, wa += wa_cnt[i];
  }
  std::cout << ac << ' ' << wa << "\n";
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(c > a + b){
        cout << min(a + b + 1, c) + b << endl;
    }
    else{
        cout << c + b << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int n,m;
Q stu(50),che(50);

ll check(ll a,ll b){
  ll ans=inf,point=0;
  rep(i,m){
    ll det=abs(a-che[i].first)+abs(b-che[i].second);
    if(det<ans) ans=det,point=i;
  }

  return point+1;
}


int main(){
  cin>>n>>m;
  rep(i,n) cin>>stu[i].first>>stu[i].second;
  rep(i,m) cin>>che[i].first>>che[i].second;

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int K, X, i ;
	scanf("%d", &K);
	scanf("%d", &X);
	for (i = 1; i < K; i++)
		printf("%d\n", X - K+i);
	i = 1;
	do {
		printf("%d\n", X +i-1);
		i++;
	} while (i < K + 1);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

ll fun(ll n, ll b)
{
	ll ans = 0;
	while (n)
	{
		ans += n % b;
		n /= b;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, s;
	cin >> n >> s;
	if (n == s)
	{
		cout << n + 1 << endl;
		return 0;
	}
	for (ll b = 2; b * b <= n; b++)
	{
		if (fun(n, b) == s)
		{
			cout << b << endl;
			return 0;
		}
	}
	if (s > n)
	{
		cout << -1 << endl;
		return 0;
	}
	for (ll a1 = 1000000; a1 >= 1; a1--)
	{
		ll a2 = s - a1;
		if (a2 < 0 || n - a2 < 0 || (n - a2) % a1 != 0)
		{
			continue;
		}
		ll b = 1 + (n - s) / a1;
		if (b <= a1 || b <= a2 || b <= 1)
		{
			continue;
		}
		cout << b << endl;
		return 0;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int N,L,T;
int X[MAXN];
int W[MAXN],d[MAXN],ans[MAXN];
map<int,int> mp;
vector<int> dest;
int main()
{
    scanf("%d%d%d",&N,&L,&T);
    for(int i=1;i<=N;i++) 
    {
        scanf("%d%d",&X[i],&W[i]);
        if(W[i]==1)
        {
            d[i]=(X[i]+T)%L;
            dest.push_back(d[i]);
        }
        else
        {
            d[i]=((X[i]-T)%L+L)%L;
            dest.push_back(d[i]);
        }
    }  
    sort(dest.begin(),dest.end());
    int lab=1;
    if(W[1]==1)
    {
        int cnt=0;
        for(int i=2;i<=N;i++)
        {
            if(W[i]==2)
            {
                int dist=X[i]-X[1];
                if(dist<0) dist+=L;
                if(2*T>=dist) cnt+=(2*T-dist-1)/L+1;
            }
        }
        lab=1+cnt%N;
    }
    else
    {
        int cnt=0;
        for(int i=2;i<=N;i++)
        {
            if(W[i]==1)
            {
                int dist=X[1]-X[i];
                if(dist<0) dist+=L;
                if(2*T>=dist) cnt+=(2*T-dist)/L+1;
            }
        }
        lab=((1-cnt%N)+N)%N;
        if(lab==0) lab=N;
    }
    int p=lower_bound(dest.begin(),dest.end(),d[1])-dest.begin();
    for(int i=1;i<=N;i++)
    {
        ans[lab]=dest[p];
        lab++; if(lab>N) lab-=N;
        p++; if(p>=N) p-=N;
    }
    for(int i=1;i<=N;i++) printf("%d\n",ans[i]);
    return 0;
}



Measured memory_bytes: 3320
#include<iostream>
using namespace std;

int main()
{
  long long int x;
  cin>>x;
  if((x>=400)&&(x<=599))
    cout<<8;
  else if((x>=600)&&(x<=799))
    cout<<7;
  else if((x>=800)&&(x<=999))
    cout<<6;
  else if((x>=1000&&(x<=1199)))
     cout<<5;
  else if((x>=1200)&&(x<=1399))
    cout<<4;
  else if((x>=1400)&&(x<=1599))
    cout<<3;
  else if((x>=1600)&&(x<=1799))
    cout<<2;
  else if((x>=1800)&&(x<=1999))
   cout<<1;
      return 0;
          }
  

Measured memory_bytes: 3620
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
s=[None]+list(input())+[None]
L=[tuple(input().split()) for _ in range(q)]

def judge(k):
    now=k
    if now==0:
        return 1
    if now==n+1:
        return 2
    for t,d in L:
        if s[now]==t:
            if d=='R':
                now+=1
            else:
                now-=1
        if now==0:
            return 1
        elif now==n+1:
            return 2
    else:
        return 0

left,right=0,n+1
while right-left>1:
    mid=(left+right)//2
    if judge(mid)==1:
        left=mid
    else:
        right=mid
out=left
left,right=0,n+1
while right-left>1:
    mid=(left+right)//2
    if judge(mid)==2:
        right=mid
    else:
        left=mid
out+=(n+1-right)
print(n-out)

Measured memory_bytes: 106072
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 2000100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  ll ans = 0;
  for(ll i=1;i<n;i++){
    if(n < i*3)break;
    ll ama = n-i*3;
    ans += combination(i+ama-1,ama);
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 18660
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    x, y, a, b, c = LI()
    p = LI()
    A = []
    for pi in p:
        if len(A) < x:
            heappush(A, pi)
        else:
            aa = heappop(A)
            if aa > pi: pi = aa
            heappush(A, pi)
    q = LI()
    B = []
    for qi in q:
        if len(B) < y:
            heappush(B, qi)
        else:
            aa = heappop(B)
            if aa > qi: qi = aa
            heappush(B, qi)
    r = LI()
    r.sort()
    for ri in r:
        pi = heappop(A)
        qi = heappop(B)
        if pi > qi:
            if ri > qi:
                qi = ri
        else:
            if ri > pi:
                pi = ri
        heappush(A, pi)
        heappush(B, qi)
    print(sum(A) + sum(B))
    

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 103916
n,k = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map{|i| i.to_i - 1}
now = 0
went = Array.new(n,false)
went[0] = true
path = [0]
ans = 0
k.times do |i|
    now = a[now]
    if went[now]
        init = path.index(now)
        loop_length = i+1-init
        remainder = (k-i-1)%loop_length
        ans = path[init + remainder]
        break
    else
        went[now] = true
        ans = now
        path << now
    end
end

puts ans+1

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

using namespace std;

#define ll long long

//#define TEST

signed main() {
	// 入力の受け取り
	int n; ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	//  c[i] := aのうち下からiビット目が1であるものの個数
	// を計算する.
	vector<int> c(40, 0);
	for (int i = 0; i < 40; ++i)
		for (int j = 0; j < n; ++j)
			if (a[j] & ((ll)1 << i))
				++c[i];

	//   d[i] := c[i] < (n - c[i]) ? 1 : 0
	// とする.
	// kを超えないようにxを調整し、最大値を更新していく.
	ll ans = accumulate(a.begin(), a.end(), (ll)0);
	ll x = 0;
	vector<int> d(40);
	for (int i = 0; i < 40; ++i) // dを計算
		d[i] = c[i] < (n - c[i]) ? 1 : 0;
	for (int j = 39; j >= 0; --j) {
		ll x_ = x ^ ((ll)d[j] << j);
		if (k < x_) continue;
		x = x_;
		ll fx = 0;
		for (auto ai : a)
			fx += ai ^ x;
		ans = max(ans, fx);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<map>

int main(){
    std::string w;
    std::cin >> w;
    std::map<char, int> mp;
    for(int i = 0; i < w.size(); i++){
        mp[w[i]]++;
    }

    for(auto p : mp){
        if(p.second % 2 != 0){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	for (int i = 0; i < N; i++)cin >> a.at(i);
	for (int i = 0; i < N; i++) {
		b.at(a.at(i)-1) = i+1;
	}
	for (int i = 0; i < N; i++) {
		if (i != N - 1) {
			cout << b.at(i) << " ";
		}
		else cout << b.at(N - 1) << endl;
	}
	
		return 0;
}


Measured memory_bytes: 4056
import itertools
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
seq = (a,b,c,d,e)
data = list(itertools.combinations(seq,2))
result = 0
for i in range(len(data)):
    if data[i][0] < data[i][1]:
        if data[i][1] - data[i][0] <= k:
            result +=1
    else:
        if data[i][0] - data[i][1] <= k:
            result +=1
if result == len(data):
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
 
int compare(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}
 
 
int main(){
	
	int N,C,K,T[100010],i,ans=0,j=0;
	
	scanf("%d",&N);
	scanf("%d",&C);
	scanf("%d",&K);
	
	for(i=0;i<N;i++){
		scanf("%d",&T[i]);
	}
	
	qsort(T,N,sizeof(int),compare);
	
	while(j<N){
		
		i=j;
		while(j<i+C&&j<N&&T[j]<=T[i]+K){
			j++;
		}
		ans++;
		
	}
	
	printf("\n%d\n\n",ans);
	
	return 0;
}


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

string str1;
string str2;
int solve(){
    int count=0;
    int m=0;
    int limit1;
    int limit2;
    int limit;
    int i, j;
    limit1 = str1.size();
    limit2 = str2.size();
    for(i=0;i<limit1-1;i++){
        for(j=0;j<i+1;j++){
            if(str1[limit1-1-i+j] == str2[j]){
                count++;
            }else{
                m = max(m, count);
                count = 0;
            }
        }
        m = max(m, count);
        count = 0;
    }
    count = 0;
    for(i=0;i<limit2;i++){
        limit = limit1+i<limit2 ? limit1 : limit2-i;
        for(j=0;j<limit;j++){
            if(str1[j] == str2[j+i]){
                count++;
            }else{
                m = max(m, count);
                count = 0;
            }
        }
        m = max(m, count);
        count = 0;
    }
    return m;
}
int main(){
    string temp;
    while(cin >> str1 >> str2){
        if(str1.size() > str2.size()){
            swap(str1, str2);
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    int N,M; cin >> N >> M;
    int ans=(N*2+M)/4;
    cout << min(ans,M/2) << endl;
}

Measured memory_bytes: 256
M, D = [int(i) for i in input().split()]
if D<10:
    print(0)
    exit()
res = 0

for m in range(M+1):
    for d in range(10,D+1):
        d_10 = d//10
        d_1 = d%10
        if m==(d_10 * d_1) and d_1 >= 2 and d_10 >= 2:
            res += 1

print(res)


Measured memory_bytes: 40176
def nibu(a,A): #a in A(sorted)
    mi = 0
    ma = len(A)-1
    while ma-mi>1:
        mid = (ma+mi)//2
        if a < A[mid]:
            ma = mid
        else:
            mi = mid
    if A[ma]==a:
        return True
    elif A[mi]==a:
        return True
    else:
        return False #a not in A
    
n = int(input())
S = list(map(int,input().split())) #sorted
q = int(input())
T = list(map(int,input().split()))


ans = 0
for i in range(q):
    if nibu(T[i],S):
        ans +=1
print(ans)


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

int main(){
    char S[3];
    cin>>S;
    

    if (S[0]==S[1]&&S[1]==S[2]&&S[2]==S[0])
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
    
    return 0;
}

Measured memory_bytes: 256
x = input().split()
n, m = int(x[0]), int(x[1])
vis = [False]*n
c_n = [-1]*n
flag = True
for i in range(m):
    y = input().split()
    s, c = int(y[0]), int(y[1])
    s -= 1
    if vis[s]:
        if c_n[s] != c:
            flag = False
    else:
        vis[s] = True
        c_n[s] = c
#print(flag)
if not flag:
    print(-1)
else:
    start = 10**(n-1)
    if start==1:
        start=0
    end = 10**n
    for i in range(start, end):
        num = str(i)
        #print(num)
        #print(c_n)
        flag2 = True
        for j in range(n):
            if c_n[j] != -1:
                if num[j] != str(c_n[j]):
         #           print("--> Not matched")
                    flag2 = False
                    break
        if flag2:
          #  print("--> Matched")
            print(num)
            break
    if not flag2:
        print(-1)
                

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>

using namespace std;

//DP(®Ivæ@)
int main() {

  while(1) {

    int m; //J[hÌíÞ
    int a[10],b[10]; //J[hÌÆ»Ì
    int g; //Q[ñ
    int n; //aÉµ½¢
 
    int dp[8][1001]; //DPe[u

    cin >> m;

    if(m==0) break;

    for(int i=0;i<m;i++) cin >> a[i] >> b[i];

    cin >> g;


    //DPe[uð0Åú»
    memset(dp,0,sizeof(dp));

    //0ÔÚÜÅÌJ[hðgÁÄ0ðìéû@Í1Êè
    dp[0][0]=1;

    //·×ÄÌíÞÌJ[hÉÂ¢Ä
    for(int i=0;i<m;i++) {

      //0`1000ÜÅÌ·×ÄÌ®ðìéû@ðDPe[uÉLq
      for(int j=0;j<=1000;j++) {

	//i+1ÔÚÜÅÌJ[hðgÁÄjðìé½ßÉÍAiÔÚÜÅÌJ[hðgÁÄj-k*a[i](½¾µ0<=k<=b[i],0<=k*a[i]<=jð½·)ðìé±ÆªoÈ¯êÎÈçÈ¢
	for(int k=0;k<=b[i] && k*a[i]<=j;k++) {

	  //±êð«µÄ¢­±ÆÅAi+1ÔÚÜÅÌJ[hðgÁÄjðìéû@ÌêÌªßçêé
	  dp[i+1][j]+=dp[i][j-k*a[i]];

	}

      }

    }

    for(int i=0;i<g;i++) {

      cin >> n;

      //æÉe[uðìÁÄ¢éÌÅA·ÅÉdp[m][n]ÉÍAmÔÚÜÅÌJ[hðgÁÄnðìéû@ÌêÌA·Èí¿¡ñÌ¦ªL³êÄ¢é
      cout << dp[m][n] << endl;
	
    }

  }

  return 0;

}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int inf=2333;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
ll n;
int g[233];
void init(){
	g[1]=0;
	for(int i=2;i<=100;++i){
		for(int k=1;;++k){
			if((1LL<<k)-i>=g[k]){
				g[i]=k;
				break;
			}
		}
	}
}
const int table[6][20] = {{},
{1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,4,6,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,36,108,220,334,384,0,0,0,0,0,0,0,0},
{0,0,0,0,0,976,inf,inf,inf,inf,inf,inf,inf,inf,inf,inf,inf}
};
int Get_g(ll n){
	if(n<=100)return g[n];
	for(int k=1;;++k){
		if((1LL<<k)-n>=g[k])return k;
	}
	return 2333333;
}
int Solve(ll n,ll k){
	if(n<k)swap(n,k);
	if(k<63&&(1LL<<k)-n<n){
		return Solve((1LL<<k)-n,k);
	}
	if(!k)return 1;
	if(k<=5)return table[k][n];
	return inf;
}
int main(){
	init();
	n=read();
	int ans=Solve(n,Get_g(n))+(n==4)+(n==7)*2;
	printf("%d\n",ans>1000?-1:ans);
	return 0;
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	FOR(k,2,1e5) if (k*(k-1)/2 == n) {
		cout << "Yes" << endl;
		cout << k << endl;
		
		vvl res(k);
		FOR(i,0,k) FOR(j,i+1,k) {
			res[i].pb(n);
			res[j].pb(n);
			n--;
		}
		
		for (vl v: res) {
			cout << sz(v);
			for (ll x: v) cout << " " << x;
			cout << endl;
		}

		return 0;
	}
	cout << "No" << endl;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#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--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int H, W, K; cin >> H >> W >> K;
    vector<string> S(H);
    vector<vector<int> > color(H, vector<int>(W, 0));
    rep(i, 0, H) cin >> S[i]; 
    int cnt = 1;
    int pre = 0;
    rep(i, 0, H){
        if(cnt == K + 1){
            rep(j, 0, W){
                color[i][j] = color[i-1][j];
            }
        }else{
        queue<int> q;
        rep(j, 0, W){
            if(S[i][j] == '#') q.push(j);
        }
        if(q.empty()){
            continue;
        }
        int flag = 1;
        while(!q.empty()){
            int u = q.front(); q.pop();
            if(flag) u = 0;
            flag = 0;
            if(q.empty()){
                
                rep(k, pre, i + 1)rep(j, u, W){
                    color[k][j] = cnt;
                }
            }else{
                int ne = q.front();
                rep(k, pre, i + 1) rep(j, u, ne){
                    color[k][j] = cnt;
                }
            }
            cnt++;
        }
        pre = i + 1;
        }
    }
    rep(i, 0, H){
        rep(j, 0, W){
            if(j != 0) cout << " ";
            cout << color[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {    
    
   public static void main(String[] args){
       
       Scanner sc = new Scanner(System.in);
    
       int A = sc.nextInt();
       int B = sc.nextInt();
       
       if(A == B){
           System.out.println("Draw");
       }else if(A == 1){
           System.out.println("Alice");
       }else if(B == 1){
           System.out.println("Bob");
       }else{
           System.out.println( A > B ? "Alice":"Bob");
       }       
       
   }   
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    while(true){
        cin >>a >>op >>b;
        if (op =='?'){break;}
        if (op =='+'){cout << (a+b) << endl;}
        if (op =='-'){cout << (a-b) << endl;}
        if (op =='*'){cout << (a*b) << endl;}
        if (op =='/'){cout << (a/b) << endl;}
    }
    
}


Measured memory_bytes: 3080
#include <iostream>
     
using namespace std;
typedef long long ll;
const int nmax=10000; 
char S[nmax];

int N;

int main() {
    ll ans=0;
    ll nr=0, ng=0, nb=0; 
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    cin >> S;
    // cout << S << endl;
    if (N<=3){
        cout << 0 << endl;
        exit(0);
    }
    for(int i=1; i<= N; i++){
        if (S[i-1] == 'R') {
            nr ++;
        } else if(S[i-1] == 'G'){
            ng ++;
        } else {
            nb ++;
        }
    }
    //cout << nr << " " << ng << " " << nb << endl;
    ans = nr * nb * ng; 
    for(int i = 1; i<=N-2;i++){
        for(int j=i+2; j<=N; j+=2){
            int k;
            k = (i+j)/2;
            if (S[i-1] != S[j-1] && S[i-1] != S[k-1] && S[j-1] != S[k-1]){
                ans --;
            }
        }
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
    
    def make(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n,q = map(int,input().split())
a = list(map(int,input().split()))
bit = BIT(n)
bit.make(a)
for i in range(q):
    t,l,r = map(int,input().split())
    if t == 0:
        bit.add(l,r)
    else:
        print(bit.sum(r)-bit.sum(l))


Measured memory_bytes: 130380
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint segdata[(1<<20)-1];
lint lazy[(1<<20)-1];

lint neutral(){
    return 0; //単位元
}
lint calc(lint a,lint b){
    return a+b; //演算
}
void seginit(){
    rep(i,(1<<20)-1) segdata[i]=neutral();
}
void update(lint i,lint x){ // i番目の値をxに更新 rangeadd()の後に使ったらだめ 単位元が0以外の時だけ使う
    i+=(1<<19)-1;
    segdata[i]=x;
    while(i>0){
        i=(i-1)/2;
        segdata[i]=calc(segdata[i*2+1],segdata[i*2+2]);
    }
}
void eval(lint k,lint l,lint r){
    if(lazy[k]){
        segdata[k]+=lazy[k];
        if(r-l>1) lazy[2*k+1]+=lazy[k]/2,lazy[2*k+2]+=lazy[k]/2;
        lazy[k]=0;
    }
}
void add(lint a,lint b,lint x,lint k,lint l,lint r){
    eval(k,l,r);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        lazy[k]+=(r-l)*x;
        eval(k,l,r);
    }
    else{
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
        segdata[k]=calc(segdata[2*k+1],segdata[2*k+2]);
    }
}
lint seg(lint a,lint b,lint k,lint l,lint r){
    eval(k,l,r);
    if(r<=a || b<=l) return neutral();
    if(a<=l && r<=b) return segdata[k];
    else{
        lint left=seg(a,b,k*2+1,l,(l+r)/2);
        lint right=seg(a,b,k*2+2,(l+r)/2,r);
        return calc(left,right);
    }
}
lint query(lint a,lint b){
    return seg(a,b+1,0,0,1<<19); //a~b(閉区間）の範囲での演算
}
void rangeadd(lint a,lint b,lint x){ //a~b(閉区間)にxを加算
    add(a,b+1,x,0,0,1<<19); 
    return;
}

int main(void){
    seginit();
    lint N,Q;
    cin >> N >> Q;
    lint black=(N-2)*(N-2);
    rangeadd(1,N-1,N-2);
    rangeadd(N+1,2*N-1,N-2);
    lint tate=N,yoko=N;
    rep(i,Q){
        lint q,x;
        cin >> q >> x;
        if(q==1){
            lint minus=query(x,x);
            black-=minus;
            if(yoko>x) rangeadd(N+1,N+tate-1,min(0LL,-(yoko-1-(x-1))));
            yoko=min(yoko,x);
        }
        else{
            lint minus=query(N+x,N+x);
            black-=minus;
            if(tate>x) rangeadd(1,yoko-1,min(0LL,-(tate-1-(x-1))));
            tate=min(tate,x);
        }
    }
    cout << black << endl;
}

Measured memory_bytes: 18076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int count=0,biggest=1000000;
  rep(i,n){
    if(a[i]<=biggest){
      count++;
    }
    biggest=min(biggest,a[i]);
  }
  cout<<count<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

vector<char> a;
vector<int> v;
vector<int> f;


int ans(int k, int val, int used , int s){
  int cnt = 0;
  if(k == val){
    if(s == 0) return 1;
    else return 0;
  }
  else{
    int tmp = v[k];
    int flag = f[k];
    for(int i = 0; i < 10; i++){
      if(i == 0 && flag) continue;
      if(used & 1 << i) continue;
      int num = i;
      cnt += ans(k+1, val, used+(1 << i), s + tmp * num);
    }
  }
  return cnt;
}

int main(){
  int n;
  while(cin >> n && n != 0){
    a.clear();
    v.clear();
    f.clear();
    std::vector<char>::iterator itr;
    for(int i = 0; i < n - 1 ; i++){
      string s; cin >> s;
      for(int j = 0; j < s.length(); j++){
        itr = find(a.begin(), a.end(), s[j]);
        if(itr == a.end()){
          a.push_back(s[j]);
          v.push_back(pow(10, s.length()-j-1));
          f.push_back(0);
          itr = a.end() - 1;
        }
        else{
          v[itr-a.begin()] += pow(10, s.length()-j-1);
        }
        if(j == 0 && s.length() != 1) f[itr-a.begin()] = 1;
      }
    }
    string y; cin >> y;
    for(int j = 0; j < y.length(); j++){
       itr = find(a.begin(), a.end(), y[j]);
      if(itr == a.end()){
        a.push_back(y[j]);
        v.push_back(-1 * pow(10, y.length()-j-1));
        f.push_back(0);
        itr = a.end() - 1;
      }
      else{
        v[itr-a.begin()] -= pow(10, y.length()-j-1);
      }
      if(j == 0 && y.length() != 1) f[itr-a.begin()] = 1;
    }
    vector<int> rem;
    for(int i = 0; i < 10; i++) rem.push_back(i);
    int val = v.size();
    cout << ans(0, val, 0, 0) << endl;
  }
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& oj);
};

ostream& operator<<(ostream& os, const mint& oj){
    os << oj.x;
    return os;
}

mint factorial(int n){
    mint res = 1;
for(int i=1;i<=n;++i){
        res *= i;
    }
    return res;
}

mint nCr(int n,int r){
    mint numerator = 1;
    if(r > n - r) r = n - r;
    for(int i=n;i>n-r;--i){
        numerator *= i;
    }
    mint denominator = 1;
    for(int i=1;i<=r;++i){
        denominator *= i;
    }
    return numerator/denominator;
}

int main(){
    int n,k;cin >> n >> k;
    mint ans = 0;
    mint num = (ll)(n+1)*n/2;
    for(ll i=k;i<=n+1;++i){
        mint mx = num - (mint)(n+1-i)*(n-i)/2;
        mint mn = (mint)(i-1)*i/2 - 1;
        //cerr << mx << " " << mn << endl;
        ans += mx - mn;
        //cerr << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int main() {
    int X, Y;
    scanf("%d %d", &X, &Y);
    printf("%d\n", X + Y / 2);
    return 0;
}

Measured memory_bytes: 128