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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n,m;cin>>n>>m;
    multiset<ii,greater<ii> > a;

    FOR(i,n){
        int x;cin>>x;
        a.emplace(x,0);
    }
    while(m && !a.empty()){
        ii y=*a.begin();
        a.erase(a.begin());
        y.first <<= y.second;
        ++y.second;
        y.first >>= y.second;
        if (y.first) a.insert(y);
        --m;
    }
    ll ret=0;
    for(ii j:a) ret += j.first;
    cout << ret;
    return 0;
}



Measured memory_bytes: 4992
#include <stdio.h>

int main()
{
  int n, itg, q;
  int A[2001] = {};
  int i, j;

  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    scanf("%d", &itg);
    A[0] = 1;
    for (j = 2000; j >= 0; j--)
    {
      if (A[j] && j + itg < 2001)
        A[j + itg] = 1;
    }
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++)
  {
    scanf("%d", &itg);
    if (A[itg])
      printf("yes\n");
    else
      printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2004
n = gets.to_i
an = gets.strip.split.map(&:to_i)

mod = 10 ** 9 + 7
ans = 0
keta = 1
(0..60).each do |d|
  count = an.count {|a| (a / keta) % 2 == 1}
  ans += count * (n - count) * keta
  ans %= mod
  keta *= 2
end

puts ans


Measured memory_bytes: 40324
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
struct t{
	string s;
	int ind,val;
};
bool comp(t a,t b)
{
	if(a.s<b.s)
		return true;
	if(a.s==b.s&&a.val>b.val)
		return true;
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	t p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i].s>>p[i].val;
		p[i].ind=i+1;
	}
	sort(p,p+n,comp);
	for(int i=0;i<n;i++)
		cout<<p[i].ind<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;


main(){
    string s;cin>>s;
    int n=s.size();
    ll ans=0;
    rep(i,s.size()){
        rep(j,n-i){
            ans+=pow(10,j)*pow(2,n-1-j-1+(j==n-i-1?1:0))*(s[i]-'0');
        }
    }
    cout<<ans;
}

Measured memory_bytes: 512
import sys
from fractions import gcd
from functools import reduce

MOD = 1000000007
lcm = lambda x, y: (x*y)//gcd(x,y)
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
l = reduce(lcm, a)
ans = 0
for x in a:
    ans += l//x
print(ans%MOD)




Measured memory_bytes: 6140
use v5.18;
use warnings;
use List::Util qw( reduce max );
 
<>;
my @nums = glob <>;
say max map { gcb(right($_ - 1), left($_ + 1)) } 0 .. $#nums;

sub right {
  my $n = shift;
  return 0 if $n < 0;
  state @dp;
  return $dp[$n] if defined $dp[$n];
  if ($n > 0) {
    $dp[$n] = gcb($nums[$n], right($n - 1));
  } else {
    $nums[$n];
  }
}

sub left {
  my $n = shift;
  return 0 if $n > $#nums;
  state @dp;
  return $dp[$n] if defined $dp[$n];
  if ($n < $#nums) {
    $dp[$n] = gcb($nums[$n], left($n + 1));
  } else {
    $nums[$n];
  }
}
 
sub gcb {
  my ($x, $y) = @_;
  return $x if $y == 0;
  my $mod = $x % $y;
  $mod == 0 ? $y : gcb($y, $mod);
}

Measured memory_bytes: 100852
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool x = true;
    rep(i, s.size()) {
        if(i and s[i] != '0') {
            x = false;
        } 
        if(!i and s[i] != '1') x = false;
    }
    int ans = 0;
    rep(i, s.size()) {
        ans += s[i]-'0';
    }
    if(!x) {
        cout << ans << endl;
    } else {
        cout << ans+9 << endl;
    }
}

Measured memory_bytes: 3668
#pragma region Macros
// ===========
// include
// ===========
#include <iostream>
#include <vector>
#include <cstdint>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

// ===========
// conversion
// ===========
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

// ===========
// math
// ===========
template<class T> inline T sqr( T x ){ return x * x; }

// ===========
// typedef
// ===========
typedef int64_t int64;
typedef vector<int64> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

// ===========
// repetition
// ===========
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), __length = int(b); i < __length; ++i)

void input(vector<int64> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }

#pragma endregion //Macros

int main()
{
    int N;
    cin >> N;
    int ans = (1000 - (N % 1000)) % 1000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
a, b = gets.split.map(&:to_i)

sum = 0
(a..b).to_a.each do |i|
    hoge = i.to_s.split("")
    fuga = hoge.length / 2
    flag = 0
    fuga.times do |j|
        if hoge[j] != hoge[(j+1)*(-1)]
            flag = 1 
            break
        end
    end
    sum += 1 if flag == 0
end
puts sum

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;

    ll res = ( ( mod_pow(10LL, n, MOD) - ( 2 * mod_pow(9LL, n, MOD))%MOD )%MOD + mod_pow(8LL, n, MOD) ) % MOD ;
    if (res < 0) res += MOD;
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, x;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            if (a * n < b)
            { x = a * n; }
            else
            { x = b; }
            Console.WriteLine(x);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;



int main(){
  int n,m;
  cin >> n>>m;
  cout << ((n==m)?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int mod = 1e5;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    bool ok = false;
    for (int i = 0; i <= 100; i += 4) {
        for (int j = 0; j <= 100; j += 7) {
            if (i + j == n) ok = true;
        }
    }
    printf(ok?"Yes\n":"No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <string>
#include <queue>
using namespace std;

int parent(int i){
	return i/2;
}

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i +1;
}

int maxheapify(vector <int> &X, int i){
	int l, r;
	l = left(i);
	r = right(i);

	if (r <=X[0] && X[r] > X[i] && X[l] < X[r]){
		swap(X[r], X[i]);
		maxheapify(X, r);
	}
	else if (l <= X[0] && X[l] > X[i]){
		swap(X[l], X[i]);
		maxheapify(X, l);
	}
	return 0;
}

int buildmaxheap(vector <int> &X){
	for (int i= X[0]/2; i>0; i--){
		maxheapify(X, i);
	}
	return 0;
}

int maxheapinsert(vector <int> &X, int key){
	
	if (X[0]<X.size()-1){
		X[0]++;
		X[X[0]] = key;
	}
	else{
		X[0]++;
		X.push_back(key);
	}
	int i = X[0], p = parent(i);
	while (i > 1 && X[p] < X[i]){
		swap(X[i], X[p]);
		i = p;
		p = parent(i);
	}
	return 0;
}

int heapincreasekey(vector <int> &X, int i, int key){
	if (i > X[0] || key < X[i]) return NULL;
	X[i] = key;
	int p=parent(i);
	while (i > 1 && X[p] < X[i]){
		swap(X[i], X[p]);
		i = p;
		p = parent(i);
	}
	return 0;
}

int heapextractmax(vector <int> &X){
	if (X[0] < 1) return NULL;

	int maxheap = X[1];
	X[1] = X[X[0]--];
	maxheapify(X, 1);
	return maxheap;
}
int print(vector <int> &X){
	int *tmp = &X[0];
	for (int i=1; i<=X[0]; i++){
		tmp++;
		cout<<*tmp<<" ";
	}
	cout<<endl;
	return 0;
}

int str2int(string text){
    stringstream buf;
    int n;
 
    buf<<text;
    buf>>n;
    return n;
}

int main(void){
	int n;
	priority_queue <int> X;
	string text;

	while (true){
		cin>>text;
		if (text[2] == 'd'){
			break;
		}
		else if (text[0] == 'i'){
			cin>>n;
			X.push(n);
		}
		else if (text[0] == 'e'){
			cout<<X.top()<<endl;
			X.pop();
		}
	}
	return 0;
} 


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

bool ok(long long attacks, int A, int B, const vector<long long>& hps) {
    long long d = A - B;
    long long a = attacks;

    for (const auto h: hps) {
        if (h - B * attacks > 0) {
            a -= (h - B*attacks + d - 1) / d;
            if (a < 0) return false;
        }
    }
    return a >= 0;
}

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

    vector<long long> hps(N);
    for (int i=0; i<N; i++) {
        cin >> hps[i];
    }

    // ref: http://kujira16.hateblo.jp/entry/2015/09/26/234614
    // (lb, ub]
    // 攻撃回数でにぶたん
    long long lb = 0;
    long long ub = 1e9;
    while (ub - lb > 1) {
        long long mid = (lb + ub) / 2;
        if (ok(mid, A, B, hps)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }

    cout << ub << endl;

    return 0;
}

Measured memory_bytes: 1024
import std.stdio,std.string,std.conv,std.math;
void main(){
	while(1){
		string[] arr;
		int[] arr2;arr2.length=2;
		auto rd = chomp( readln() );
		if(rd){
			arr = split(rd);
			arr2[0] = to!int(arr[0]);
			arr2[1] = to!int(arr[1]);
			auto sum = to!string(arr2[0] + arr2[1]);
			writeln( sum.length );
		}else{
			break;
		}
	}
}

Measured memory_bytes: 1072
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> K(N);
  vector<vector<int>> A(N,vector<int>(100));
  for(int i=0; i<N; i++){
    cin >> K.at(i);
    for(int j=0; j<K.at(i); j++){
      cin >> A.at(i).at(j);
    }
  }
  int count=0;
  int ans=0;
  for(int i=0; i<K.at(0); i++){
    for(int j=1; j<N; j++){
      for(int k=0; k<K.at(j); k++){
        if(A.at(0).at(i)==A.at(j).at(k)){
          count++;
          break;
        }
      }
    }
    if(count==N-1)
      ans++;
    count=0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  _n,_m,x,y = map(int,input().split())
  X = list(map(int,input().split()))
  Y = list(map(int,input().split()))
  X = sorted(X,reverse=True)
  Y = sorted(Y)
  
  for Ex in range(x+1,y+1):
    if X[0] < Ex <= Y[0]:
      print('No War')
      exit()
    else:
      pass
    
  print('War')
  
  
if __name__ == '__main__':
  main()

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    int ans = max(a, b) + max(a, b - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    ll int n,m,mod=(ll int)1e9+7;
    cin>>n>>m;
    vector<vector<char> > a(n,vector<char>(m));
    vector<vector<ll int> > dp(n,vector<ll int>(m,0)),temp(n,vector<ll int>(m,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
            if(a[i][j] == '.')
                temp[i][j]=1;
        }
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i > 0 && j > 0)
            {
                if(a[i][j]=='.')
                    dp[i][j]=dp[i-1][j]+dp[i][j-1],dp[i][j]%=mod;
                else
                    dp[i][j]=0;
            }
            if(i == 0 && j > 0)
            {
                if(a[i][j]=='.')
                    dp[i][j]=dp[i][j-1],dp[i][j]%=mod;
                else
                    dp[i][j]=0;
            }
            if(i > 0 && j == 0)
            {
                if(a[i][j]=='.')
                    dp[i][j]=dp[i-1][j],dp[i][j]%=mod;
                else
                    dp[i][j]=0;
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<dp[n-1][m-1];
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}



Measured memory_bytes: 19776
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> even;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] % 2 == 0) {
      even.push_back(a[i]);
    }
  }
  bool ok = true;
  for (int i = 0; i < even.size(); ++i) {
    if (even[i] % 3 == 0 || even[i] % 5 == 0) {
      ;
    } else {
      ok = false;
    }
  }
  cout << (ok ? "APPROVED" : "DENIED") << endl;
  return 0;
}

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

int main() {
	// your code goes here
   int n;
   cin>>n;
   int ar[n-1];
   for(int i=0;i<n-1;i++)
    cin>>ar[i];
   int fr[n+1];
   for(int i=0;i<=n;i++)
    fr[i]=0;
   for(int i=0;i<n-1;i++)
    fr[ar[i]]++;
   for(int i=1;i<=n;i++) cout<<fr[i]<<endl; 
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void push(int t[],bool marked[], int v) 
{
    if (marked[v]) 
    {
        //t[v*2] = t[v*2+1] = t[v];
        t[v*2]=min(t[v*2],t[v]);
        t[v*2+1]=min(t[v*2+1],t[v]);
        marked[v*2] = marked[v*2+1] = true;
        marked[v] = false;
    }
}

void update(int t[], bool marked[],int v, int tl, int tr, int l, int r, int new_val) 
{
    if (l > r) 
        return;
    if (l == tl && tr == r) 
    {
        t[v] = min(t[v],new_val);
        marked[v] = true;
    } 
    else 
    {
        push(t,marked,v);
        int tm = (tl + tr) / 2;
        update(t,marked,v*2, tl, tm, l, min(r, tm), new_val);
        update(t,marked,v*2+1, tm+1, tr, max(l, tm+1), r, new_val);
    }
}

int get(int t[],bool marked[],int v, int tl, int tr, int pos) 
{
    if (tl == tr) 
    {
        return t[v];
    }
    push(t,marked,v);
    int tm = (tl + tr) / 2;
    if (pos <= tm) 
        return get(t,marked,v*2, tl, tm, pos);
    else
        return get(t,marked,v*2+1, tm+1, tr, pos);
}
int T1[800009],T2[800009];
bool m1[800009],m2[800009];
void solve()
{
	ll n;
	cin>>n;
	ll ans=(n-2)*(n-2);
	for(int i=0;i<=4*n;i++) T1[i]=T2[i]=n;
	int q;
	cin>>q;
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		if(a==1)
		{
			int pos = get(T1,m1,1,1,n,b);
			//cout<<pos<<'\n';
			ans -= pos-2;
			update(T2,m2,1,1,n,2,pos-1,b);
		}
		else
		{
			int pos = get(T2,m2,1,1,n,b);
			//cout<<pos<<'\n';
			ans -= pos-2;
			update(T1,m1,1,1,n,2,pos-1,b);
		}
	}
	cout<<ans<<'\n';
}

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


Measured memory_bytes: 10748
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vl va(a), vb(b), vc(c);
	for (auto& x : va)
		cin >> x;
	for (auto& x : vb)
		cin >> x;
	for (auto& x : vc)
		cin >> x;
	sort(all(va));
	sort(all(vb));
	sort(all(vc));
	reverse(all(vc));
	va.erase(va.begin(), va.begin() + (a - x));
		
	vb.erase(vb.begin(), vb.begin() + (b - y));
	
	ll res = accumulate(all(va), 0LL) + accumulate(all(vb), 0LL);
	va.push_back(INT_MAX);
	vb.push_back(INT_MAX);
	int ca = 0, cb = 0;
	for (int i = 0; i < c; i++)
	{
		if (vc[i] < va[ca] && vc[i] < vb[cb])
			break;
		if (va[ca] < vb[cb])
		{
			res -= va[ca];
			res += vc[i];
			ca++;
		}
		else
		{
			res -= vb[cb];
			res += vc[i];
			cb++;
		}
	}
	cout << res;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  while (S.size() >= 2) {
    vector<int> A(N);
    int c = 0;
    for (int i = 1; i < N; i++) {
      if (i + A[i - c] <= c + A[c] - 1) {
        A[i] = A[i - c];
      } else {
        int j = max(0, c + A[c] - i);
        while (i + j < N && S[j] == S[i + j]) j++;
        A[i] = j;
        c = i;
      }
    }
    A[0] = N;
    for (int i = 1; i < N; i++) {
      ans = max(ans, min(i, A[i]));
    }
    S = S.substr(1);
    N--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

int mod;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int n, p, t = 0, ans = 0;
	string s;
	map<int, int>ma;
	ma[0] = 1;
	cin >> n >> p >> s;
	if (p == 2) {
		rep(i, s.size()) {
			if ((s[i]-'0') % 2 == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	if (p == 5) {
		rep(i, s.size()) {
			if ((s[i]-'0') % 5 == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	mod = p;
	for (int i = n - 1; i >= 0; i--) {
		t += (s[i] - '0') * modpow(10, n - 1 - i);
		t %= mod;
		if (!ma.count(t)) {
			ma[t] = 1;
		}
		else {
			ma[t]++;
		}
	}
	for (auto p : ma) {
		auto k = p.first;
		auto v = p.second;
		ans += v * (v - 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int b[n+1]={};
	for(int i=1;i<=n;i++)cin>>a[i];
	n=1;
	b[n]=1;
	int count=0;
	while(n!=2){n=a[n];if(b[n]){cout<<-1<<endl;return 0;}b[n]=1;count++;}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1024
let rec f maxN others lst =
  match lst with
  | [] -> (maxN, others)
  | x :: xs -> if x > maxN then f x (maxN :: others) xs else f maxN (x :: others) xs
let rec sum lst = match lst with
  | [] -> 0
  | x :: xs -> x + sum xs
let () =
  Scanf.scanf "%d\n"
    (fun n -> Array.init n (fun _ -> Scanf.scanf "%d\n" (fun x -> x)))
  |> Array.to_list |> f 0 []
  |> (fun (maxN, others) -> maxN/2 + sum others) |> print_int

Measured memory_bytes: 384
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#define ll long long
using namespace std;
int main()
{ 
   int n,k;
   int ans=1;
   scanf("%d %d",&n,&k);
   for(int i=0;i<n;i++)
   ans=min(ans*2,ans+k);
   printf("%d\n",ans);
   
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

void relax(long long& a, long long b) {
	a = max(a, b);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	long long ans[3] = { 0,0,0 };
	for (int i = 0; i < n; ++i) {
		long long ans2[3] = { 0,0,0 };
		for (int j = 0; j < 3; ++j) {
			long long x;
			cin >> x;
			for (int q = 0; q < 3; ++q) {
				if (q == j) continue;
				relax(ans2[j], ans[q] + x);
			}
		}
		swap(ans, ans2);
	}
	cout << *max_element(ans, ans + 3) << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
s = list(input())

ans = 0
for i in range(1, n):
    TF = [False] * 26
    x = s[0:i]
    y = s[i:]
    col = collections.Counter(x)
    sub = 0
    for one in y:
        if TF[ord(one) - 97] == False:
            if one in col:
                sub += 1
                TF[ord(one) - 97] = True
    ans = max(ans, sub)

print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 100005
using namespace std;
int n,m,q,v[MN],c[MN],d[MN],col[MN][11],num,head[MN];
struct edge{int to,next;}g[MN<<2];
void ins(int u,int v){g[++num].next=head[u];head[u]=num;g[num].to=v;}
void dfs(int u,int cc,int dd){
	if(col[u][dd])return;col[u][dd]=cc;
	for(int i=head[u];i;i=g[i].next)if(dd-1>=0)dfs(g[i].to,cc,dd-1);	
}
int main(){
	scanf("%d%d",&n,&m);int x,y;
	for(int i=1;i<=m;i++)scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
	for(int i=1;i<=n;i++)ins(i,i);
	scanf("%d",&q);for(int i=1;i<=q;i++)scanf("%d%d%d",&v[i],&d[i],&c[i]);
	for(int i=q;i>=1;i--)dfs(v[i],c[i],d[i]);
	for(int i=1;i<=n;i++)printf("%d\n",col[i][0]);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main() {
    bool ok[10]={0};
    int a[4],i;
    for (i=0;i<4;i++) {
        cin >>a[i];
        ok[a[i]]=1;
    }
    if (ok[1]==1 && ok[9]==1 && ok[7]==1 && ok[4]==1) cout <<"YES";
    else cout <<"NO";
    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b) {
        if (a < c && c < b) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }

    } else {
        if (b < c && c < a) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }

    }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

//////////////////////////

int main(){fastio
    
    ll a,b,c,d;cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;return 0;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3652
a0 = gets.to_i
a1 = a0%10
a0 = a0/10
a2 = a0%10
a0 = a0/10
a3 = a0%10
a0 = a0/10
a4 = a0%10
if a2 == a3
  if a2 == a1
    puts "Yes"
  elsif a2 == a4
     puts "Yes"
  else
     puts "No"
  end
  else
  puts "No"
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i+=2){
		if(a[i]%2==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if ((a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7) && (a + b + c == 17)) {
		
		cout << "YES" << endl;

	}
	else {

		cout << "NO" << endl;

	}

	return 0;

}

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

using namespace std;

deque<int> seq(long long n) {
	if (n == 1) return {};
	if (n % 2 == 0) {
		auto s = seq(n / 2);
		s.push_back(s.size() + 1);
		return s;
	} else {
		auto s = seq(n - 1);
		s.push_front(s.size() + 1);
		return s;
	}
}

int main() {
	long long n;

	cin >> n;

	auto s = seq(n + 1);
	cout << s.size() * 2 << endl;
	for (int x: s) cout << s.size() + 1 - x << ' ';
	for (int i = s.size(); i >= 1; --i) cout << i << ' ';
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := nextLine()
	v := strings.ToUpper(s)
	if s == v {
		fmt.Println("A")
	} else {
		fmt.Println("a")
	}
}


Measured memory_bytes: 1780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class DebtHell
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(System.Console.ReadLine());
            double tmp = 0;
            int zandaka = 100000;

            for (int i = 0; i < n;i++ )
            {
                tmp = 1.0 * zandaka * 1.05;
                if(tmp % 1000 != 0)
                {
                    tmp = (int)(tmp / 1000) * 1000 + 1000;
                }
                zandaka = (int)tmp;
            }
            System.Console.WriteLine(zandaka);
        }
    }
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  string S; cin >> S;
  ll N = S.size();
  ll res = (N * (N - 1)) / 2 + 1;
  vector<int> cnt(26, 0);
  rep(i, 0, N){
    cnt[S[i] - 'a']++;
  }
  rep(i, 0, 26){
    res -= (cnt[i] * (cnt[i] - 1LL)) / 2;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, K;
    cin >> n >> K;
    vector<ll> V(n);
    rep(i, n) cin >> V[i];

    ll res = 0;
    for (int k = 0; k <= K; k++) {
        for (int l = 0; l <= n; l++) {
            for (int r = 0; r <= n - l; r++) {
                int back = k - l - r;
                if (back < 0 || l + r < back || l + r > n) {
                    continue;
                }
                vector<ll> u;
                ll sum = 0;
                rep(i, l) {
                    sum += V[i];
                    u.push_back(V[i]);
                }
                for (int i = n - 1; i >= n - r; i--) {
                    sum += V[i];
                    u.push_back(V[i]);
                }
                sort(all(u));
                rep(i, back) {
                    sum -= u[i];
                }

                res = max(res, sum);
            }
        }
    }
    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3612
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    import queue
    N,Q=MI()
    adj=[[]for _ in range(N)]
    for _ in range(N-1):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
        adj[b].append(a)
        
    ans=[0]*N
    for _ in range(Q):
        p,x=MI()
        p-=1
        ans[p]+=x
        
    q=queue.Queue()
    q.put((0,-1))
    
    while not q.empty():
        v,p=q.get()
        for nv in adj[v]:
            if nv!=p:
                ans[nv]+=ans[v]
                q.put((nv,v))
                
    print(' '.join(map(str, ans)))
        
    

main()


Measured memory_bytes: 137244
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
	int A,B,Q;cin>>A>>B>>Q;
	vector<ll> S(A),T(B),X(Q);
	rep(i,A)cin>>S[i];
	sort(all(S));
	rep(i,B)cin>>T[i];
	sort(all(T));
	rep(i,Q)cin>>X[i];
	rep(i,Q){
		ll q = X[i];
		ll ls = lower_bound(S.begin(), S.end(),q)-S.begin()-1;
		ll rs = lower_bound(S.begin(), S.end(),q)-S.begin();
		ll lt = lower_bound(T.begin(), T.end(),q)-1-T.begin();
		ll rt = lower_bound(T.begin(), T.end(),q)-T.begin();
		ll ans = LINF;
		if(ls>=0&&lt>=0)ans = min(ans,abs(q-min(S[ls],T[lt])));
		if(rs<S.size()&&rt<T.size())ans = min(ans,abs(q-max(S[rs],T[rt])));
		if(rs<S.size()&&lt>=0){
			ans = min(ans,abs(q-S[rs])+abs(q-T[lt])*2);
			ans = min(ans,abs(q-S[rs])*2+abs(q-T[lt]));
		}
		if(ls>=0&&rt<T.size()){
			ans = min(ans,abs(q-T[rt])+abs(q-S[ls])*2);
			ans = min(ans,abs(q-T[rt])*2+abs(q-S[ls]));
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3712
import sys; from collections import deque; readline = sys.stdin.readline;

from heapq import heappush, heappop

N, M = map(int, readline().split())
A = list(map(int, readline().split()))

heap = []

for a in A:
    heappush(heap, -a)

for i in range(M):
    a = heappop(heap)
    heappush(heap, -((-a) // 2))

total = -sum(heap)

print(total)

Measured memory_bytes: 60824
s=input()
ans="AC"
cnt1=0
cnt2=0
cnt3=0
for i in range(len(s)):
    if i==0:
        if s[i]!="A":
            ans="WA"
    if i==1:
        cnt1+=s[i].isupper()*1
    if i>=2:
        if i==len(s)-1:
            if s[i]=="C":
                ans="WA"
            elif s[i].isupper()*1>0:
                ans="WA"
        elif s[i]=="C":
            cnt2+=1
        else:
            cnt3+=s[i].isupper()*1
if cnt1!=0 or cnt2!=1 or cnt3!=0:
    ans="WA"
print(ans)

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a = 0, b = 0;
	string s;
	cin >> s;
	for(int i = 1; i < 4; ++i) if(s[0] == s[i]) ++a;
	if(s[0] != s[1]){
	    for(int i = 2; i < 4; ++i) if(s[1] == s[i]) ++b;
	}
	else for(int i = 3; i < 4; ++i) if(s[2] == s[i]) ++b;
	if(a == 1 and b == 1) cout << "Yes";
	else cout << "No";

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
int h,w;
const int nmax=102;
char c[nmax][nmax];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
int p[4][6]={{1,5,2,3,0,4},{2,1,5,0,4,3},{3,1,0,5,4,2},{4,0,2,3,5,1}};
bool vis[nmax][nmax];
bool bfs(int i,int j,vector<int> a){
    vis[i][j]=true;
    if(i==h-1&&j==w-1){
        return true;
    }
    bool f=false;
    vector<int> r(6);
    for(int l=0;l<4;l++){
        int x=i+dx[l],y=j+dy[l];
        if(x<0||x>h-1||y<0||y>w-1){
            continue;
        }
        if(c[x][y]=='#'||vis[x][y]){
            continue;
        }
        if(c[x][y]-'0'==a[l+1]){
            for(int s=0;s<6;s++){
                r[s]=a[p[l][s]];
            }
            f=f|bfs(x,y,r);
        }
    }
    return f;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c[i][j];
        }
    }
    vector<int> n(6);
    for(int i=0;i<6;i++){
        n[i]=6-i;
    }
    if(bfs(0,0,n)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 4124
#include <iostream>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
	int N, K;
	cin >> N >> K;
	map<int, int> mii;
	rep(i, K) {
		int d, tmp;
		cin >> d;
		rep(j, d) {
			cin >> tmp;
			++mii[tmp-1];
		}
	}
	
	int ans = 0;
	rep(i, N) {
		if (mii[i] == 0) ++ans;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

lli c[55][55];

void make(){
	c[0][0]=1;
	for(lli i=1;i<55;i++){
		for(lli j=0;j<=i;j++){
			if(j==0 || j==i)c[i][j]=1;
			else{
				c[i][j] = c[i-1][j]+c[i-1][j-1];
			}
		}
	}
}

int main(){

	lli n,a,b;
	cin>>n>>a>>b;

	vector<lli> v(n);
	REP(i,n)cin>>v[i];

	sort(v.begin(),v.end(),greater<lli>());
	make();

	if(DEBUG){
		for(lli i=0;i<55;i++){
			for(lli j=0;j<=i;j++){
				cout<<c[i][j]<<" ";
			}
			cout<<endl;
		}
	}

	/*基本的な考え方は大きい順にとっていき、a個まで行った時が最大値*/
	/*a個とるまでぜんぶ同じ数だった場合は*/
	/*C(a,min(その数分,b))の計算となる*/
	/*というよりは*/
	/*1番小さい数については組み合わせ列挙が必要そう*/
	/*つまり数えるのは*/
	/*1.上からa個とったときの合計値*/
	/*2.一番小さい数の個数*/
	/*3.上からa個とったときに一番小さい個数は何個入っているか*/
	/*上からa個とった時に全部同じ数のときは例外判定する*/

	lli sum=0;
	lli small = v[a-1];
	lli smallCnt=0;
	lli smallACnt=0;
	lli flag=1;
	REP(i,n)smallCnt += small==v[i] ? 1:0;
	for(lli i=a-1;i>=0;i--){
		sum += v[i];
		smallACnt += small==v[i] ? 1:0;
		if(small != v[i])flag=0;
	}

	double ansMax = sum/(double)a;

	/*ここから2つ目の回答*/
	/*a個とったとき、全部同じ数だった場合*/
	/*ans = bCa * bCa-1* ・・・ bC1*/
	lli ansSum=0;
	if(flag){
		lli target = min(b,smallCnt);
		if(DEBUG)cout<<"smallCnt="<<smallCnt<<endl;
		if(DEBUG)cout<<"c="<<c[smallCnt][target]<<endl;
		ansSum = c[smallCnt][target];
		for(lli i=target-1;i>=a;i--){
			if(DEBUG)cout<<"c="<<c[smallCnt][i]<<endl;
			ansSum += c[smallCnt][i];
		}
	}
	/*全部同じ数じゃなかった場合*/
	/*ans = c[smallCnt][a個の中にあったsmallCnt];*/
	else{
		if(DEBUG)cout<<"smallCnt="<<smallCnt<<" smallACnt="<<smallACnt<<endl;
		ansSum = c[smallCnt][smallACnt];
	}

	printf("%.10f\n",ansMax);
	cout<<ansSum<<endl;

	return 0;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define MAX 1000000000000000000LL
ll inf=100000000000007;
using namespace std;

int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll to[100005];
    for(int i=1;i<=n; i++){
        cin>>to[i];
    }
    ll ans=0;
    for(int i=2;i<=n; i++){
        ans+=min((to[i]-to[i-1])*a,b);
    }
    cout<<ans<<endl;
    return 0;
}

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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  int l,r,k,z,ans,current,i,j;
  cin>>l>>r;
  vector<int> v;
  k = std::min(r,l+2018);
  for (z=l;z<=k;z++)
  {
  	v.push_back(z%2019);
  }
  k=v.size();
  ans=2019;
  for (i=0;i<k;i++)
  {
  	for (j=i+1;j<k;j++)
  	{
  		current=(v[i]*v[j])%2019;
  		if (current < ans)
  		{
  			ans=current;
  		}
  	}
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n,x,a,b,t;
	ll cnt=0;

	cin >> n>>x>>a;
	
	if (a>x) {
	cnt += a-x;
	a = x;
	}

	for (int i=1;i<n;i++) {
	cin >> b;
	t = a+b-x;

	if (t>0) {
	cnt += t;
	b -= t;
	}
	a=b;
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 2e5 + 10;//;
ll h[N], seg[4*N] ;
ll dp[N] ;

ll Q(int pos,int l,int r,int ql,int qr)
{
    if(l > qr or r < ql)
        return 0;
    if(ql <= l and r <= qr)
        return seg[pos] ;
    int mid = (l + r) / 2;
    return max(Q(pos*2,l,mid,ql,qr), Q(pos*2 + 1,mid+1,r,ql,qr));

}

void update(int pos,int l,int r,int ind, ll val)
{
    if(l == r and r == ind)
    {
        seg[pos] = val; return ;
    }

    if(l > ind or r < ind) return ;
    int mid = (l + r) / 2;

    update(pos*2,l,mid, ind, val);
    update(pos*2+1,mid+1,r, ind, val);
    seg[pos] = max(seg[pos*2], seg[pos*2 + 1]) ;
}
int n;
ll val[N] ;

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

    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> h[i];
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    dp[0] = 0;

    for(int i = 1; i <= n; i++)
    {
        if(h[i] == 1)
        {
            dp[i] = val[i] ;
            update(1,1,n,h[i],val[i]);
            continue;
        }

        ll here = Q(1,1,n,1,h[i]-1 );
        dp[i] = val[i] + here;
        update(1,1,n,h[i],dp[i]);

    }
    cout << *max_element(dp+1,dp+n+1) ;
    return 0;
}




Measured memory_bytes: 11264
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    s = input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)


Measured memory_bytes: 3064