akhauriyash/Code-Regression huggingface dataset:
#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 N; cin>>N;
  int t,a;
  ll r = 0;
  ll rt = 0;
  ll ra = 0;
  REP(i,N){
    cin >> t >> a;
    ll k = 1;
    ll kt,ka;
    while(1){
      kt = k*t;
      ka = k*a;
      if(kt>=rt && ka>=ra && kt+ka>=r){
        rt = kt;
        ra = ka;
        r = kt+ka;
        break;
      }else{
        k += max( max((rt-kt)/t, (ra-ka)/a),(ll)1 );
      }
    }
  }
  cout << r;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    str S;
    cin >> S;
    ll cnta = 0, cntb = 0, cntc = 0;
    rep(i, S.size()) {
        if (S[i] == 'a') {
            cnta ++;
        }
        else if (S[i] == 'b') {
            cntb++;
        }
        else {
            cntc++;
        }
    }
    ll ab = cnta - cntb, bc = cntb - cntc, ca = cntc - cnta;
    if ((-1 <= ab && ab <= 1) && (-1 <= bc && bc <= 1) && (-1 <= ca && ca <= 1)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll r, D, x; cin >> r >> D >> x;
    ll p = x;
    for(int i=1; i<11; i++){
        cout << r*x - D << endl;
        x = r*x - D;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<LL>>;

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}



int main() {
  LL n,m,x,k=0,sum=0,a=0,b=0,c=0,d=0,ans=10000000;
  LL MOD = 1000000007;
  LL INF = 1LL << 60;
  LL C[100001],A[13][13],R[100001]={0},O[100001];
  string S="",T="",U="";
  cin >> n >> m >> x;
  for (LL i=0;i<n;i++){
    cin >> C[i];
    for (LL j=0;j<m;j++){
      cin >> A[i][j];
      R[j] += A[i][j];
    }
  }
  for (int i=0;i<m;i++){
    if(R[i]<x) ans=-1;
  }

  if(ans != -1){
    for (int bit = 0; bit < (1 << n); ++bit) {
          b=0;
          a=0;
          for(int i=0;i<m;i++){
            O[i]=0;
          }
          for (int i = 0; i < n; ++i) {
              if (bit & (1 << i)){
                b += C[i];
                for (int j=0;j<m;j++){
                  O[j] += A[i][j];
                }
              }
          }
          for(int j=0;j<m;j++){
            if(O[j]<x){
              a=1;
            }
          }
          if(a==0){
            ans = min(ans,b);
          }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4424
N = int(input())
A = list(map(int,input().split()))
tot = sum(A)
D = {}
for i in range(N):
    a = A[i]
    if a not in D:
        D[a] = 0
    D[a] += 1
Q = int(input())
for _ in range(Q):
    b,c = map(int,input().split())
    if b not in D:
        print(tot)
    else:
        d = c-b
        if c in D:
            n = D[b]
            D[c] += D[b]
            del D[b]
        else:
            n = D[b]
            D[c] = D[b]
            del D[b]
        tot += n*d
        print(tot)

Measured memory_bytes: 93728
from collections import defaultdict
import math
import numpy as np
N, X, Y = map(int, input().split(' '))
d = defaultdict(int)
for i in range(1, N):
    for k in range(i+1, N+1):
        if(k < X):
            ans = k-i
            d[ans] += 1
        else:
            ans = min(k-i, abs(Y-k)+1+abs(i-X))
            d[ans] += 1

for i in range(1, N):
    print(d[i])


Measured memory_bytes: 14528
#include <bits/stdc++.h>
#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 srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;cin >> n;
    int b[n];
    int max_b = 0;
    rep(i,n){
        cin >> b[i];
        max_b = max(max_b,b[i]);
    }
    int ans[n] = {};

    drep(i,max_b+1){
        rep(j,n){
            if(b[j] == i){
                int count = b[j]-1;
                int count2 = 0;
                rep(k,n){
                    if(k<=j){
                        if(b[k]<b[j])count2++;
                    }else{
                        if(b[k]<=b[j])count++;
                    }
                }
                if(count2<b[j]-1){
                    cout << "-1" << endl;
                    return 0;
                }
                rep(k,n){
                    if(count==0){
                        if(ans[k]==0){
                            ans[k] = b[j];
                            break;
                        }
                    }else{
                        if(ans[k]==0)count--;
                    }
                }
            }
        }
    }

    rep(i,n){
        cout << ans[i] << endl;
    }

    return 0;
}
 
 


Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = input()
 
def step(x,y):
    N_last = S[x:y-1]
    return N_last.find('##') == -1

Ans = step(A,C) and step(B,D)
 
if C > D:
    pass_path = False
    for b in range(B-1,D):
        if S[b] == '#':
            continue
        if S[b-1] == '.' and S[b+1] == '.':
            pass_path = True
            break
    Ans = step(A,C) and step(B,D) and  pass_path


if Ans == True:
    print('Yes')
else:
    print('No')

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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    clock_t start_clock = clock();
    std::mt19937 engine(20000000);
    std::uniform_int_distribution<> type_random(1, type_num);
    std::uniform_int_distribution<> day_random(1, Day_num);
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }

    Scoring scoring(D, costs, incentives);

    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        types[day-1] = type_random(engine);
    }

    while (static_cast<double>(clock() - start_clock)/CLOCKS_PER_SEC*1000.0 < 2000.0-20.0) {
        const auto old_types = types;
        types[day_random(engine)-1] = type_random(engine);
        if (scoring.score(old_types).back() > scoring.score(types).back()) {
            types = old_types;
        }
    }

    for (long day = 1; day <= D; ++day) {
        std::cout << types[day-1] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    string dr="dream";
    string er="erase";
    string s;
    cin>>s;
    int len=s.size();
    bool flag=true;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='d')
        {
            int j;
            for(j=i;j<=i+4;j++)
            {
                if(j>=len||s[j]!=dr[j-i])
                {
                    flag=false;
                    break;
                }
            }
            if(j==i+5)
            {
                if(s[j]=='e'&&s[j+1]=='r'&&s[j+2]!='a')
                {
                    i=j+1;
                }else
                i=j-1;

            }
        }else
        if(s[i]=='e')
        {
            int j;
            for(j=i;j<=i+4;j++)
            {
                if(j>=len||s[j]!=er[j-i])
                {
                    flag=false;
                    break;
                }
            }
            if(j==i+5)
            {
                if(s[j]=='r')
                {
                    i=j;
                }else
                i=j-1;
            }
        }else
        {
            flag=false;
        }
        if(flag==false)
        {
            break;
        }
    }
    if(flag==true)
    {
        cout<<"YES"<<endl;
    }else
        cout<<"NO"<<endl;
        return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

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

  int size = pow(2, s.length()-1);
  
  long ans=0;
  for(int i=0; i<size; i++){
    string sig = bitset<10>(i).to_string();

    string val="";
    for(int j=0; j<s.length(); j++){
      val += s.at(j);
      int k = 10-s.length()+1+j;
      if(k<10 && sig.at(k)=='1') {
        ans+=stol(val);
        val="";
      }else if(k==10){
        ans+=stol(val);
      }
    }

  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>


int main()
{
    std::string s;
    size_t w;
    std::cin >> s;
    std::cin >> w;

    for (size_t i = 0; i < s.size(); i+=w) {
        std::cout << s[i];
    }
    std::cout << std::endl;

    return 0;
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define mod 1000000007;

main(){
  int n, l; cin >> n >> l;
  vs s(n); rep(i,n) cin >> s[i];
  sort(all(s));
  string ans;
  rep(i,n) ans += s[i];
  cout << ans << endl;
}


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

int main(void){
    int n;
    cin >> n;
    ll tmp;
    vector<ll> a;
    for (int i=0; i<n; i++){
        cin >> tmp;
        auto it = find(a.begin(), a.end(), tmp);
        if (it == a.end()){
            a.emplace_back(tmp);
        } else{
            a.erase(a.begin()+distance(a.begin(), it));
        }
    }
    cout << a.size() << endl;
    return 0;
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,v,p,a[100001],ans,a1;
bool cmp(int i,int j){return i>j;}
signed main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	ans=p;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i=p+1;i<=n;i++)
	{
		if(a[i]+m<a[p])break;
		if(v<=p+n-i)++ans;
		else if(((v-p-n+i)*m-a1-1)/(i-p)+1+a[p]<=a[i]+m)++ans;
		a1+=a[p]-a[i];
	}
	printf("%lld",ans);
	return 0;
 } 


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

using namespace std;

int main()
{
	string a;
	cin >> a;
	a.erase(a.begin() + 5);
	a.erase(a.begin() + 12);
	a.insert(a.begin() + 5, ' ');
	a.insert(a.begin() + 13, ' ');
	cout << a << endl;
}

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


//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n)        for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define PB push_back
#define vvi vector<vi>
#define vvll vector<vll>
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>

#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define GC getchar
#define PC putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()

//policy based data structure
 /*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

*/
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=111111;


//Main function

int main(){
IOS;
TIE;     
#ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 
  
#endif   
int n;
cin>>n;
vi a(n);
for(auto &x : a) cin>>x;
int cnt=0;
for(int i=0;i<n;i++)
{
    for(int j=i;j<n;j++)
    {
        if(a[i]!=a[j])
        {
            for(int k=j;k<n;k++)
            {
                if(a[j]!=a[k] && a[k]!=a[i])
                {
                    if(a[i]+a[j]<=a[k] || a[j]+a[k]<=a[i] || a[k]+a[i]<=a[j])
                    continue;
                    cnt++;
                }
            }
        }
    }
}
cout<<cnt<<endl;
}
   


Measured memory_bytes: 3656
N=int(input())
*A,=map(int, input().split())

s=0
ans=1
for i in range(1,N):
    #print(i,s,ans)
    if s==0:
        if A[i] < A[i-1]:
            s=-1
        elif A[i] == A[i-1]:
            s=0
        elif A[i] > A[i-1]:
            s=1
    elif s==-1:
        if A[i] < A[i-1]:
            s=-1
        elif A[i] == A[i-1]:
            s=-1
        elif A[i] > A[i-1]:
            s=0
            ans+=1
    elif s==1:
        if A[i] < A[i-1]:
            s=0
            ans+=1
        elif A[i] == A[i-1]:
            s=1
        elif A[i] > A[i-1]:
            s=1
print(ans)


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

int main(){
  int N,X,Y,i,j,ans,dist,list[2001]={0};
  
  //stdinから入力受付
  cin>>N>>X>>Y;
  X--;Y--;//0からの値に変換
  
  //メイン処理
  for(i=0;i<N-1;i++){//始点
    for(j=i+1;j<N;j++){//目的地
      //道を必ず通る場合
      if(abs(i-X)<abs(i-Y)) dist=abs(i-X)+1+abs(j-Y);
      else dist=abs(i-Y)+1+abs(j-X);
      //直接行く場合と比較、短いほうをdistに入れる
      if(j-i<dist) dist=j-i;
      //list配列のdist番目を1増やす
      list[dist]++;
    }
  }
    
  //答えをstdoutに出力
  for(i=1;i<N;i++) cout<<list[i]<<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
ls = [0 for p in range(k)]
new = [0 for q in range(k)]
for i in range(k):
    ls[i] = int(input())
    new[i] = list(map(int,input().split()))
for l in range(1,k):
    new[0] = new[0] + new[l]
c = len(set(new[0]))
print(n-c)

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

void Main(){
    ll n, x, m; cin >> n >> x >> m;
    
    set<pair<ll, int>> st;
    vll data(m+5), sum(m+5);
    
    ll now = x;
    st.insert({now, 0});
    data[0] = now;
    sum[0] = 0;
    sum[1] = now;
    
    int s = -1, t = -1;
    rep3(i, 1, m+1){
        now *= now;
        now %= m;
        data[i] = now;
        sum[i+1] = sum[i] + now;
        Pll LB = *st.lower_bound({now, -1});
        if(LB.fi == now){
            s = LB.se;
            t = i;
            break;
        }
        st.insert({now, i});
    }
    
    if(s == -1){
        cout << sum[n] << endl;
        return;
    }
    
    int k = t - s;
    // cout << s << " " << t << " " << k << endl;
    /*
    for(auto [a, b] : st){
        cout << a << " " << b << endl;
    }
    //*/
    ll q = (n-s)/k;
    ll r = (n-s)%k;
    // cout << q << " " << r << endl;    
    
    ll tot = sum[s];
    // cout << tot << endl;
    tot += (sum[t] - sum[s]) * q;    
    // cout << tot << endl;
    tot += sum[s+r] - sum[s];
    cout << tot << endl;
    return;
}

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

Measured memory_bytes: 7848
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  cout << a.back() - a.front() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<iostream>
using namespace std;
char a[17];
int main()
{
    cin>>a;
    if(a[0]!='A'){cout<<"WA";return 0;}
    int len=strlen(a);
    if(a[1]=='C'||a[len-1]=='C'){cout<<"WA";return 0;}
    for(int i=1;i<len;++i)
    if(a[i]>='A'&&a[i]<='Z'&&a[i]!='C'){cout<<"WA";return 0;}
    int cnt=0;
    for(int i=2;i<=len-2;++i)
    if(a[i]=='C')cnt++;
    if(cnt!=1){cout<<"WA";return 0;}
    cout<<"AC";
    return 0;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,x,d;
int g(int y){
  int l1=((n-y)+(n-1))*y/2,
      l2=y*(y-1)/2,
      r1=((n-y-d)+(n-1))*(y+d)/2+x,
      r2=(y+d)*(y+d-1)/2+x;
  return max(min(l1,r1)-max(l2,r2)+1,0LL);
}
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  cin>>n>>x>>d;
  if(!d&&!x)fin(1);
  if(!d)fin(n+1);
  if(!x)fin(n*(n-1)/2+1);
  if(x<0)x*=-1,d*=-1;
  int gcd=__gcd(x,abs(d));x/=gcd;d/=gcd;
  int ans=n*n*(n+1)/2-n*(n+1)*(2*n+1)/6+n+1;
  for(int i=0;i<=n;i++)ans-=g(i);
  fin(ans);
}


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

#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;

struct node{
  int u, v;
};

bool cmp(node a, node b){
  return a.u + a.v > b.u + b.v;
}

void solve(){
  int n;
  cin >> n;
  vector <node> coins(n);
  for (int i = 0; i < n; i++){
     cin >> coins[i].u >> coins[i].v;
  }
  sort(coins.begin(), coins.end(), cmp);
  int ret = 0;
  for (int i = 0; i < n; i++){
    if (i % 2  == 0) 
      ret += coins[i].u;
    else 
      ret -= coins[i].v;
  }
  cout << ret << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}

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

using namespace std;

#define ll long long

bool is_square(int k) {
    int sq = sqrt(k);
    return sq*sq == k;
}

bool func(vector <int>& v1, vector <int>& v2) {
    int sum=0, sz = v1.size();
    for (int i=0; i<sz; ++i)
        sum += (v1[i] - v2[i]) * (v1[i] - v2[i]);

    return is_square(sum);
}

int main()
{
    int n, d, ans = 0;
    cin >> n >> d;
    vector <vector <int>> a(n, vector <int> (d));
    for (int i=0; i<n; ++i)
        for (int j=0; j<d; ++j)
            cin >> a[i][j];

    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            vector <int> v1 = a[i];
            vector <int> v2 = a[j];
            ans += func(v1, v2);
        }
    }

    cout << ans;

}

Measured memory_bytes: 256
N, D = gets.chomp.split.map { |i| i.to_i } # 入力
count = 0

while line = gets
    x, y = line.chomp.split(' ').map(&:to_i)
    
    count += 1 if ( ((x**2 + y**2)**0.5) <= D) 
end

puts count

Measured memory_bytes: 14696
// https://atcoder.jp/contests/abc066/tasks/arc077_a
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    int idx = N - 1;
    vector<int> res;
    while(idx >= 0)
    {
        res.push_back(a[idx]);
        idx -= 2;
    }
    if (idx == -2) idx = 1;
    else if (idx == -1) idx = 0;
    while(idx < N - 1)
    {
        res.push_back(a[idx]);
        idx += 2;
    }
    for (const auto& num : res)
    {
        cout << num << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 5004
#include<stdio.h>
long long a[100000];

long long gcd(long long a, long long b) {
    if(a < b)return gcd(b, a);
    if(a % b == 0) return b;
    return gcd(b, a % b);
}

int main(){
    int n, m, i;
    scanf("%d %d", &n, &m);
    
    long long p = 1;
    for(i = 0; i < n; i++){
        scanf("%lld", &a[i]);
        a[i] /= 2;
        long long d = gcd(a[i], p);
        p = (a[i] / d) * p;
        if (p > m) {
            puts("0");
            return 0;
        }
    }

    for(i = 0; i < n; i++) {
        if ((p / a[i]) % 2 == 0) {
            puts("0");
            return 0;
        }
    }

    printf("%lld\n", (1 + m / p) / 2);
    return 0;
}

Measured memory_bytes: 896
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,m = LI()

    return (n-1)*(m-1)



print(main())



Measured memory_bytes: 7748
def s(n):
	return sum([ord(x)-ord('0') for x in str(n)])

def r(n):
	return n/s(n)

def f(n):
	d = 10
	m = n
	while d <= n*10:
		n //= d
		n *= d
		n += d-1
		d *= 10
		if(r(n) < r(m)):
			m = n
	return m

n = 1
for _ in range(int(input())):
	print(n)
	n = f(n+1)

Measured memory_bytes: 45032
fun gcd(a: Int, b:Int):Int = if (b == 0) {a} else {gcd(b, a % b)}
fun main(args:Array<String>) {
    val (A,B,K) = readLine()!!.split(" ").map(String::toInt)

    val gcdAB = gcd(A,B)

    (1..gcdAB).filter { 
        A % it == 0 && B % it == 0
    }.sortedDescending().take(K).last().run(::println)

}
 

Measured memory_bytes: 37832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
	int N;
	cin >> N;
	vector<int> d(100000,0);
	rep(i,N){
		int a;
		cin >> a;
		d.at(a)++;
	}

	int ans=0;

	for(int i = 1 ; i <= 99998; i++){
		ans = max(ans, d.at(i-1)+d.at(i)+d.at(i+1));
	}

	cout << ans << endl;

}




Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	string s; cin >> s;

	Vi part;
	ll ans = 0;

	auto endPart = [&]() {
		int zeroes = 0;
		each(i, part) {
			if (i) {
				ans += zeroes;
			} else {
				zeroes++;
			}
		}
		part.clear();
	};

	int i = 0;
	while (i < sz(s)) {
		if (s[i] == 'A') {
			part.pb(0);
			i++;
			continue;
		}

		if (i+1 >= sz(s)) break;

		if (s[i] == 'B' && s[i+1] == 'C') {
			part.pb(1);
			i += 2;
		} else {
			endPart();
			i++;
		}
	}

	endPart();
	cout << ans << endl;
}


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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
	}
	std::vector<int> dp(n, std::numeric_limits<int>::max());
	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		if (i + 1 < n)
		{
			dp[i + 1] = std::min(dp[i + 1], abs(a[i] - a[i + 1]) + dp[i]);
		}
		if (i + 2 < n)
		{
			dp[i + 2] = std::min(dp[i + 2], abs(a[i] - a[i + 2]) + dp[i]);
		}
	}
	std::cout << dp[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 4056
str=input()
list=["a","b","c"]
if str[0] in list:
  list.remove(str[0])
  if str[1] in list:
    list.remove(str[1])
    if str[2] in list:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 38256
N =int(input())
lh = list(map(int,input().split()))
dp = [float("inf")] * N
dp[0:2] = [0,abs(lh[1]-lh[0])]
for i in range(2,N):
    dp[i] = min(dp[i],dp[i-1]+abs(lh[i]-lh[i-1]))
    dp[i] = min(dp[i],dp[i-2]+abs(lh[i]-lh[i-2]))
print(dp[-1])

Measured memory_bytes: 52208
#include <cstdio>
#include <cmath>
#include <algorithm>
const int maxn = 2010;

int a[maxn];
int s[maxn][maxn];

int main() {
  static int n, ans;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = n; i; --i) {
    s[i][a[i]]++;
    for (int j = 1; j <= 2000; ++j) s[i][j] += s[i][j - 1];
    for (int j = 1; j <= 2000; ++j) s[i][j] += s[i + 1][j];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      int u = a[i], v = a[j];
      ans += s[j + 1][u + v - 1] - s[j + 1][abs(u - v)];
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 15872
n = int(input())
dams = list(map(int, input().split()))

mountSum = sum(dams)
result = []
otSum = 0
for j in range(0, n // 2):
    otSum += dams[j * 2 + 1] * 2
result.append(mountSum - otSum)
for i in range(1, n-1):
    result.append(dams[i-1] * 2 - result[i-1])
result.append(dams[n-1]*2 - result[0])

print(*result)



Measured memory_bytes: 14092
#include<stdio.h>
#define true 1;
#define false 0;

int solve(int,int);

int A[2000],n;

int main(){
  int q,m,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&m);
      if(solve(0,m))printf("yes\n");
      else printf("no\n");
    }  
  return 0;
}

int solve(int i,int m){
  int res;
  if(m==0)return true;
  if(i>=n)return false;
res =solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 580
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

#pragma endregion 

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

	st s;
	cin >> s;
	reverse(all(s));
	bool f;
	while (!s.empty()) {
		f = false;
		if (s.substr(0, 6) == "resare") {
			s.erase(0, 6);
			f = true;
		}
		if (s.substr(0, 7) == "remaerd") {
			s.erase(0, 7);
			f = true;
		}
		if (s.substr(0, 5) == "esare") {
			s.erase(0, 5);
			f = true;
		}
		if (s.substr(0, 5) == "maerd") {
			s.erase(0, 5);
			f = true;
		}
		if (!f) {
			_N();
			return 0;
		}
	}
	_Y();
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int main(){
  string s;cin>>s;
  int n=(int)s.size();
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0')ans++;
  }
  if(ans>n/2)ans=n-ans;
  cout<<ans*2<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	long long int N, K; 
	cin >> N >> K; 
	long long int ans = 0; 
	for(int b = K+1; b <= N; b++){
		long long int c = N/b; 
		long long int d = c * (b-K) + max(N - b * c - K + 1, (long long) 0); 
		ans += d; 
	}
  if(K > 0){
	cout << ans << endl; 
  }
  else{
    cout << ans - N << endl; 
  }
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::fmt;

fn read_line() -> String {
    let mut ret = String::new();
    io::stdin().read_line(&mut ret).expect("read_line failed");
    ret.trim().to_string()
}

fn read_one<F>() -> F where F: FromStr {
    // FromStr has type Error in its struct.
    // https://doc.rust-lang.org/std/str/trait.FromStr.html
    // String#parse return Result<F, F::Err>,
    // and unwrap is only available in Result<T, Result>
    match read_line().parse::<F>() {
        Ok(v)  => v,
        Err(_) => panic!("failed to parse.")
    }
}

fn read_many<F>() -> Vec<F> where F: FromStr {
    read_line().split(' ').map(
        |s| match s.parse::<F>() {
            Ok(v)  => v,
            Err(_) => panic!("failed to parse.")
        }
    ).collect()
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
fn main() {
    let mut abc = read_many::<u32>();
    abc.sort();

    let kawaisou = (abc[0] == abc[1] && abc[1] != abc[2]) ||
                   (abc[0] != abc[1] && abc[1] == abc[2]);

    println!("{}", if kawaisou { "Yes" } else { "No" });
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Endl endl
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(n, k);
    vi data(n);
    rep(i, n) cin >> data[i];
    sort(all(data));
    reverse(all(data));
    int ans = 0;
    rep(i, k) {
        ans += data[i];
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

void  test_case()
{
int n,temp,cnt=0;
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>temp;
if(i%2&&temp%2)
cnt++;
}
cout<<cnt<<"\n";
}
int main()
{
int tc=1;
//cin>>tc;
while(tc--)
{
test_case();
}
return 0;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

const int MAX = 5e5;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;
  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n = n >> 1;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }
  return ret;
}

int main(){
  int a[3][3];
  rep(i,3) rep(j,3) cin >> a[i][j];
  int n; cin >> n;
  vi b(n);
  rep(i, n) cin >> b[i];
  bool seen[3][3] = {false};
  rep(k,n) {
    rep(i, 3) rep(j, 3){
      if(a[i][j] == b[k]) seen[i][j] = true;
    }
  }

  bool ok = false;
  rep(i,3) {
    bool tmp = true;
    rep(j,3) {
      if(seen[i][j] == false) tmp = false;
    }
    if(tmp) ok = true;
  }
  rep(i,3) {
    bool tmp = true;
    rep(j,3) {
      if(seen[j][i] == false) tmp = false;
    }
    if(tmp) ok = true;
  }
  bool tmp = true;
  rep(i,3) {
    if(seen[i][i] == false) tmp = false;
  }
  if(tmp) ok = true;

  tmp = true;
  rep(i,3) {
    if(seen[i][2-i] == false) tmp = false;
  }
  if(tmp) ok = true;

  cout << (ok ? "Yes" : "No") << endl;
}

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

using namespace std;

template <typename T>
struct BIT
{
	int N, K;
	vector<T> bit;

	BIT(int X)
	{
		bit = vector<T>(X + 1, 0);
		N = X + 1;
		K = pow(2, (int)(log(X) / log(2)));
	}

	void add(int idx, T w)
	{
		for (int x = idx; x <= N; x += x & -x)
		{
			bit[x] += w;
		}
	}

	T sum(int idx)
	{
		T res = 0;
		for (int x = idx; x > 0; x -= x & -x)
			res += bit[x];
		return res;
	}

	int lb(T w)
	{
		int k = K, idx = 0;

		while (k > 0)
		{
			if (idx + k <= N && w > bit[idx + k])
			{
				w -= bit[idx + k];
				idx += k;
			}
			k >>= 1;
		}

		return idx + 1;
	}
};

void solve(void)
{
	int q, x, a, b;
	cin >> q;
	vector<pair<int, pair<int, int>>> qs(q);
	set<int> s;
	for (int i = 0; i < q; i++)
	{
		cin >> x;
		if (x == 1)
		{
			cin >> a >> b;
			qs[i] = {x, {a, b}};
			s.insert(a);
		}
		else
		{
			qs[i] = {x, {0, 0}};
		}
	}
	int cnt = 0;
	map<int, int> mp, rev;
	for (int v : s)
	{
		mp[v] = ++cnt;
		rev[cnt] = v;
	}
	BIT<long> bitcnt(cnt), bitsum(cnt);
	long sumb = 0;
	int now = 0;
	for (auto &q : qs)
	{
		if (q.first == 1)
		{
			sumb += q.second.second;
			long z = q.second.first, v = mp[z];
			bitcnt.add(v, 1);
			bitsum.add(v, z);
			now++;
		}
		else
		{
			int idx = bitcnt.lb((now+1)/2);
			long res = sumb, rv = rev[idx];
			res += bitsum.sum(cnt) - 2*bitsum.sum(idx) + (bitcnt.sum(idx)*2 - now) * rv;
			cout << rv << ' ' << res << endl;
		}
	}

}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 20608
#include<stdio.h>
void quicksort(long int a[],int s,int t){
  if(s<t){
    int i=s,j=t,p=a[(s+t)/2];
    while(1){
      while(a[i]<p)i++;
      while(p<a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  long int n,a[100000],b[100000],c[100000],i,j=0,r=0,x[100000],y[100000],z[100000]={0};
  scanf("%ld",&n);
  for(i=0;i<n;i++)scanf("%ld",&a[i]);
  for(i=0;i<n;i++)scanf("%ld",&b[i]);
  for(i=0;i<n;i++)scanf("%ld",&c[i]);
  quicksort(a,0,n-1);
  quicksort(b,0,n-1);
  quicksort(c,0,n-1);
  for(i=0;i<n;i++){while(j<n&&a[i]>=b[j])j++;x[i]=j;}j=0;
  for(i=0;i<n;i++){while(j<n&&b[i]>=c[j])j++;y[i]=j;}j=n-1;
  for(i=n-1;i>=0;i--){
    if(i<n-1)z[i]=z[i+1];
    while(j>=x[i]){z[i]+=(n-y[j]);j--;}
  }
  for(i=0;i<n;i++)r+=z[i];
  printf("%ld",r);
}


Measured memory_bytes: 6412
#![allow(unused)]

use std::io::{Read, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

pub fn read_bytes<T: FromIterator<char>>(s: &mut StdinLock) -> T {
    s.bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<T>()
}

pub fn reads(s: &mut StdinLock) -> String {
    read_bytes::<String>(s)
}

pub fn read<T: FromStr>(s: &mut StdinLock) -> T {
    reads(s).parse().ok().unwrap()
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut sin = sin.lock();

    let x: i64 = read(&mut sin);

    println!("{}", (x / 500) * 1000 + (x % 500) / 5 * 5);
}

Measured memory_bytes: 4352
$<.map{|e|n,*a,d=e.split.map &:to_i
h={0=>0,1=>d}
f=->x{h[x]||=a.zip([2,3,5]).map{|a,b|[x%b*d+f[x/b]+a,-x%b*d+f[0--x/b]+a,x*d].min}.min}
d&&p(f[n])}

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

int main()
{
 float A,B;
  cin>>A>>B;
 int ans=-1; 
 for(int i=1;i<1001;i++)
 {
  if((floor(i*0.08)==A)&&(floor(i*0.1)==B))
  {
  ans=i;
  break;
  }
 }
 cout<<ans<<endl;
}

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

namespace _ {
	bool rEOF = 1;//为0表示文件结尾
	inline char nc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return p1 == p2 && rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
	}
	template<class _T>
	inline bool read(_T &num) {
		char c = nc(), f = 1; num = 0;
		while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
		while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
		return (bool)(num *= f);
	}
	inline bool need(char &c) { return c >= 'a'&&c <= 'z' || c >= '0'&&c <= '9' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
	inline bool read_str(char *a) {
		while ((*a = nc()) && need(*a) && rEOF)++a;
		*a = '\0'; return rEOF;
	}
}using namespace _;

int a[500];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int sum = 0;
	for (int i = 1; i <= n; i++)
		if (a[i]!=i)sum++;
	if (sum >= 3)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    string S; cin >> S;
    ll N = S.size();

    ll b_c = 0, b_acc = 0;
    rep(i, N) {
        if (S[i] == 'B') {
            b_c++;
            b_acc += i;
        }
    }
    // cout<<FMT4(N,b_c, b_acc, (N - b_c) + N - 1)<<endl;;
    cout <<
        ((N - b_c) + N - 1) * b_c / 2 - b_acc 
    << endl;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<10)
    {
        if(n==3)
        {
            cout<<"bon";
            return 0;
        }
        else if(n==2 || n==4 || n==5 || n==7 || n==9)
        {
            cout<<"hon";
            return 0;
        }
        else
        {
            cout<<"pon";
            return 0;
        }
    }
    else
    {
        n=n%10;
        if(n==3)
        {
            cout<<"bon";
            return 0;
        }
        else if(n==2 || n==4 || n==5 || n==7 || n==9)
        {
            cout<<"hon";
            return 0;
        }
        else
        {
            cout<<"pon";
            return 0;
        }
    }
}


Measured memory_bytes: 3580