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

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();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }
long long gcd(long long x, long long y){return x % y == 0 ? y : gcd(y, x%y);}
int main(void){
    int N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    ll ans = A[0];
    
    REP(i,N-1) ans = gcd(ans, A[i+1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mx 1000007
#define ll long long int
#define ff first
#define ss second
#define pii pair<ll,ll>
#define faster ios_base::sync_with_stdio(false);
#define m 998244353

bool vis[mx];

ll cnt[mx];
ll a[mx];

ll sum[mx];
ll multiply(ll a, ll b){
    ll res = 0; a %= m; b %= m;
    while(b){
        if(b & 0x1)
            res = (res + a)%m;
        b >>= 1;
        if(a < m-a) a<<=1;
        else a -= (m-a);
    }
    return res;
}
ll power(ll x,ll y,ll p)
{
    ll res=1;
    while(y>0) {
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}

int main()
{


    ll tt=1;
    //cin>>tt;
    ll c=0;
    while(tt--){
        ll n;
        cin>>n;


        for(ll i=1;i<=n;i++){
            cin>>a[i];
            cnt[a[i]]++;
        }
        ll inv=power(2,m-2,m);
        ll pre=0;
        for(ll g=1;g<=mx;g++){
            pre=0;
            for(ll i=g;i<=mx;i+=g){

                sum[g]+=(((((pre%m)*(cnt[i]%m))%m)*i)%m);
                sum[g]%=m;
                ll x=((((cnt[i]*(cnt[i]-1))%m)*((i*i)%m))%m);
                x%=m;
                sum[g]+=((x*inv)%m);
                sum[g]%=m;
                pre+=(cnt[i]*i)%m;
                pre%=m;

            }

        }
        ll ans=0;
        for(ll g=mx;g>=1;g--){
            for(ll i=g+g;i<=mx;i+=g){

                sum[g]-=sum[i];
                if(sum[g]<0) sum[g]=((sum[g]+m)%m);
                //sum[g]=(sum[g]+m+m)%m;
            }

            ll x=power(g,m-2,m);
            ans+=((sum[g]*x)%m);
            ans%=m;


        }
        cout<<ans%m<<endl;
    }
}


Measured memory_bytes: 20836
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b){
    if(((a+b)%3 == 0 && a+b > 0)||(a%3 == 0 && a > 0)||(b % 3 == 0 && b >0)) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

vector<int> v;
int n,ans;

int fix(int a){
  if(a >= 10) a -= 10;
  if(a < 0) a += 10;
  return a;
}

void dfs(vector<int> v2, int pos, int res){
  if(ans <= res) return;

  for(int i=pos;i<n;i++){
    if(v2[i] == 0) pos++;
    else break;
  }

  if(pos >= n){
    ans = min(ans,res);
    return;
  }

  int cnt = v2[pos];
  for(int i=pos;i<n;i++){
    v2[i] = fix(v2[i] - cnt);
    dfs(v2, pos+1, res+1);
  }
}

int main(){
  while(cin >> n && n){
    string str,str2;
    v.clear();
    cin >> str >> str2;
    for(int i=0;i<n;i++) v.push_back(fix(str[i]-'0'-(str2[i]-'0')));
    ans = n;
    dfs(v, 0, 0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1228
S = input()
ans_l = [0 for _ in range(len(S))]

"""
for i in range(len(S)):
    if(S[i]=="R"):
        j = 0
        while(S[i+j]=="R"):
            j += 1
        if(j%2==1):
            ans_l[i+j-1]+=1
        else:
            ans_l[i+j]+=1

    if(S[i]=="L"):
        j = 0
        while(S[i-j]=="L"):
            j += 1
        if(j%2==1):
            ans_l[i-j+1]+=1
        else:
            ans_l[i-j]+=1
"""
i =0
while(i<len(S)):
    j=0
    while(S[i+j]=="R"):
        j += 1
    k=0
    while(S[i+j+k]=="L"):
        k += 1
        if(i+j+k>=len(S)):
            break
    ans_l[i+j-1] += j//2+ k//2 + j%2
    ans_l[i+j] += j//2 + k//2 + k%2
    i += j+k


print(" ".join(map(str,ans_l)))



Measured memory_bytes: 10484
#include <iostream>
  
 
int main(){
    using namespace std;
  
    int a, b, c;
    cin >> a >> b >> c;
 
    int count = 0;
    for( int factor = a; factor <= b; ++factor ){
        if( (c % factor) == 0 ){
            ++count;
        }
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n, arr[100010], ans;
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    for (int i = 1; i <= n;)
    {
        int tmp2 = i;
        ++i;
        while (arr[i] == arr[tmp2] && i <= n)
        {
            ++i;
        }
        if (i - tmp2 >= arr[tmp2])
            ans += (i - tmp2 - arr[tmp2]);
        else
            ans += (i - tmp2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

char nextchar(char s){
	if(s=='z')return 'a';
	return s + 1;
}
int main(void){
	string s;
	cin >> s;
	int K;
	cin >> K;
	for(int i=0;i<s.size();i++){
		//s[i]がaになれるならaにする
		if(s[i]!='a'&&'z'-s[i]+1<=K){
			K -= 'z'-s[i]+1;
			s[i] = 'a';
		}
	}
	if(K){
		for(int i=0;i<K%26;i++){
			s[s.size()-1]=nextchar(s[s.size()-1]);
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import heapq
def main():
  N, M = list(map(int, input().split()))
  jobs = [[] for _ in range(M)]
  for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
      jobs[d-1].append(-r)

  m = 0
  heap = []
  for i in range(M):
    for a in jobs[i]:
      heapq.heappush(heap, a)
    if len(heap) > 0:
      b = heapq.heappop(heap)
      m += -b
  print(m)
if __name__ == '__main__':
  main()


Measured memory_bytes: 23752
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    ll H,W;
    cin >>H>>W;
    ll m = min(H,W);
    ll M =max(H,W);
    if(m%3==0||M%3==0){
        cout<<0<<endl;
        return 0;
    }
    ll div = ceil(M/3.0);
    ll S1,S2,S3;
    ll ans1,ans2,ans3,ans4;
    S1 = m*div;
    S2 = (M-div)*floor(m/2.0);
    S3 = (M-div)*ceil(m/2.0);
    ans1 =  max(S1,S3)-min(S1,S2);
    if(M-div>1){
        S2 = m*floor((M-div)/2.0);
        S3 = m*ceil((M-div)/2.0);
        ans2 =  max(S1,S3)-min(S1,S2);
    }
    else ans2 = ans1;
    if(div>1){
        div--;
        S1 = m*div;
        S2 = (M-div)*floor(m/2.0);
        S3 = (M-div)*ceil(m/2.0);
        ans3 =  max(S1,S3)-min(S1,S2);
        if(M-div>1){
            S2 = m*floor((M-div)/2.0);
            S3 = m*ceil((M-div)/2.0);
            ans4 =  max(S1,S3)-min(S1,S2);
        }
        else ans4 =ans3;        
    }
    else {
        ans3 =ans1;
        ans4 =ans1; 
    }
    ll ans=min(min(ans1,ans2),min(ans3,ans4));
    swap(m,M);
    div = ceil(M/3.0);
    S1 = m*div;
    S2 = (M-div)*floor(m/2.0);
    S3 = (M-div)*ceil(m/2.0);
    ans1 =  max(S1,S3)-min(S1,S2);
    if(M-div>1){
        S2 = m*floor((M-div)/2.0);
        S3 = m*ceil((M-div)/2.0);
        ans2 =  max(S1,S3)-min(S1,S2);
    }
    else ans2 =ans1;
    if(div>1){
        div--;
        S1 = m*div;
        S2 = (M-div)*floor(m/2.0);
        S3 = (M-div)*ceil(m/2.0);
        ans3 =  max(S1,S3)-min(S1,S2);
        if(M-div>1){
            S2 = m*floor((M-div)/2.0);
            S3 = m*ceil((M-div)/2.0);
            ans4 =  max(S1,S3)-min(S1,S2);
        }
        else ans4 =ans3;
    }
    else{
        ans3 = ans1;
        ans4 = ans1;
    }
    ll Ans = min(min(ans1,ans2),min(ans3,ans4));
    cout <<min(ans,Ans)<<endl;
}

Measured memory_bytes: 256
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = na()
print(max(a*b, c*d))






Measured memory_bytes: 3900
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String[] substr = str.split(" ", 0);

		int n = Integer.parseInt(substr[0]);
		int r = Integer.parseInt(substr[1]);
		int ans = r;

		if (n <10) {
			ans += 100*(10-n);
		}

		scan.close();
		System.out.println(ans);
	}
}

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

using ll = long long;

#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> K(Q); cin >> K;

    vector<int> sumd(N), summ(N), ic;
    vector<ll> sumdm(N);
    sumd[0] = S[0] == 'D';
    summ[0] = S[0] == 'M';
    sumdm[0] = 0;
    for (int i = 1; i < N; i++) {
        char ch = S[i];
        sumd[i] = sumd[i-1] + (ch == 'D');
        summ[i] = summ[i-1] + (ch == 'M');
        sumdm[i] = sumdm[i-1] + (ch == 'M' ? sumd[i] : 0);
        if (ch == 'C') ic.push_back(i);
    }

    for (const int& k : K) {
        ll ans = 0;
        for (const int& i : ic) {
            ll dm = sumdm[i-1];
            if (i - k >= 0) {
                dm -= sumdm[i-k];
                dm -= (ll)sumd[i-k] * (summ[i-1] - summ[i-k]);
            }
            ans += dm;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 22808
#include <stdio.h>
int main(void)
{
    int A, B;
    int c=0;
    scanf("%d%d", &A, &B);
    for(int i=A;i<=B;i++){
        int n=i;
        int ind=0;
        int x[5]={};
        while(n>0){
            x[ind]=n%10;
            n/=10;
            ind++;
        }
        int res=1;
        for(int j=0;j<(ind-1)/2;j++){
            if(x[j]!=x[ind-1-j]) res=0;
        }
        if(res) c++;
    }
    printf("%d\n",c);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    ans += x-1;
  }
  
  cout << ans << endl;
}

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

int main(){
  long long n, k, ans;
  ans = 0;
  cin >> n >> k;
  vector<long long> vec(n);
  
  for(long long i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(long long i = k; i < n; i++) {
    ans += vec.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a, b, x;

int main()
{
	scanf("%lld %lld", &a, &b);
	scanf("%lld", &x);
	LL cnt = 0LL;
	if(a == 0LL) printf("%lld\n", b / x + 1);
	else printf("%lld\n", b / x - (a - 1) / x);
	return 0;
}


Measured memory_bytes: 256
// ARC098C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2020;

typedef pair<int, int> pii;

int n, k, q, ai[MAX_N], ans = 1e9;

int check(int minimum_val)
{
    vector<int> block, pool;
    for (int i = 1; i <= n + 1; i++)
        if (ai[i] >= minimum_val)
            block.push_back(ai[i]);
        else
        {
            if (block.size() >= k)
            {
                sort(block.begin(), block.end());
                int len = block.size();
                for (int i = 0; i <= len - k; i++)
                    pool.push_back(block[i]);
            }
            block.clear();
        }
    sort(pool.begin(), pool.end());
    if (pool.size() < q)
        return 1e9;
    return pool[q - 1] - minimum_val;
}

int main()
{
    scanf("%d%d%d", &n, &k, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    for (int i = 1; i <= n; i++)
        ans = min(ans, check(ai[i]));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u32,
        d: [u32; n],
    };
    let mut d = d;

    d.sort();
    d.dedup();

    println!("{}", d.len());
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    LL A, B, N;
    cin >> A >> B >> N;

    LL x = min(B - 1, N);
    cout << (A * x) / B - A * (x / B);
}


Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
   ll n; cin >>n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n) cin >>a[i];
  rep(i,n) b[i]=a[i];
  sort(all(b));
  ll ans=a[0];
  rep(i,n) ans=max(ans,a[i]);
  rep(i,n){
    if(ans==a[i]){
      cout <<b[n-2]<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
}
  

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

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

	long long int a,b;
	cin>>a>>b;
	cout<<(a>b?"safe":"unsafe");
	
	return 0;
}

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

// output
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define IN(a, x, b) (a <= x && x < b)
#define OUT(a, x, b) (x < a || b <= x)
template <class T> inline T chmax(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T chmin(T &a, const T b) {
  return a = (a > b) ? b : a;
}

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  int le = 0;
  int ri = 1e12;
  while(ri-le > 1){
    int mid = (ri+le)/2;
    int cnt = 0;

    REP(i, N){
      cnt += A.end()-lower_bound(ALL(A), mid-A[i]);
    }
    if(cnt <= M) ri = mid;
    else le = mid;
  }

  vector<int> sum(N+1, 0);
  REP(i, N){
    sum[i+1] = sum[i]+A[N-1-i];
  }

  int ans = 0;
  int cnt = 0;
  REP(i, N){
    int t = A.end()-lower_bound(ALL(A), le-A[i]);
    ans += t*A[i]+sum[t];
    cnt += t;
  }

  cout << ans-(cnt-M)*le << endl;

  return 0;
}

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

bool prime (long long x){
    if(x <= 1)
       {return false;}
    for(long long i = 2; i*i <= x; i++){
        if(x % i == 0)
           {return false;}
    }
    return true;
}
int main(){
    long long x;
    cin >> x;
    while(true){
        if(prime (x)){
            cout << x <<endl;
            return 0;}
        x++;}}


Measured memory_bytes: 3644
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int count=0;
        
        if(A > B){
            count +=A;
            A--;
        }else{
            count +=B;
            B--;
        }
        if(A > B){
            count +=A;
            A--;
        }else{
            count +=B;
            B--;
        }
        System.out.print(count);
        
    }
    
}


Measured memory_bytes: 23124
#include<stdio.h>

int main(){
    int k,s;
    int cnt=0;
    int x,y,z;
    scanf("%d %d",&k,&s);
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z = s - x - y;
            if(z>=0&&z<=k)
                cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1704
from heapq import *
N,M=map(int,input().split())
P=0
X=[[] for i in range(10**5+1)]
A,B=0,0
for i in range(N):
  A,B=map(int,input().split())
  if A>M:
    continue
  X[M-A].append(B)
Q=[]
heapify(Q)
for i in range(M-1,-1,-1):
  for j in range(len(X[i])):
    heappush(Q,-X[i][j])
  if len(Q):
    P-=heappop(Q)
print(P)

Measured memory_bytes: 88768
#include <stdio.h>

int main(void){
	int n = 0;
  	long int d = 0;
  	long int a = 0;
  	long int b = 0;
  	int count = 0;
  
  	scanf("%d %ld",&n,&d);
  	d *= d; 
  	
  	while(n--){
    	scanf("%ld %ld",&a,&b);
      	if(d >= (a*a+b*b))count++;
    }
  
  	printf("%d\n",count);
  	return 0;
}

Measured memory_bytes: 1736
// #include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 300002;
#define endl '\n'
#define ld long double
#define int ll
#define all(x)  (x).begin(),(x).end()
int t[4*maxn];

 
void update(int id,int l,int r,int pos,int val){
	if(pos>r||pos<l||l>r)return;
	if(l==r&&l==pos){
		t[id]=val;
		return;
	}
	int mid=(l+r)>>1;
	update(id*2,l,mid,pos,val);
	update(id*2+1,mid+1,r,pos,val);
	t[id]=max(t[id*2],t[id*2+1]);
}

int query(int id,int l,int r,int lq,int rq){
	if(l>r||l>rq||lq>r||lq>rq)return 0;
	if(lq<=l&&r<=rq){
		return t[id];
	}
	int mid=(l+r)>>1;
	return max(query(id*2,l,mid,lq,rq),query(id*2+1,mid+1,r,lq,rq));
}
int32_t main(){

  IOS

  int n, k;
  cin >> n >> k;
  int a[n];
  for(int i = 0;i<n;i++) cin >> a[i];
  int ans = 0;
  for(int i = 0;i<n;i++){
    int l = max(0ll, a[i] - k);
    int r = min(300000ll, a[i]+k);
    int dp = query(1,0,300000ll,l,r) + 1;
    ans = max(ans, dp);
    update(1,0,300000ll, a[i],dp);
  }
  cout << ans << endl;


  

  
    
}



Measured memory_bytes: 14188
n = int(input())
h_list = list(map(int, input().split(' ')))

for i, h in enumerate(reversed(h_list)):
    index = len(h_list) - 1 - i
    if index == 0:
        print('Yes')
        break
    prev_h = h_list[index-1]
    # print(prev_h, h)
    if prev_h-1 > h:
        print('No')
        break
    elif prev_h-1 == h:
        h_list[index-1] -= 1


Measured memory_bytes: 14396
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  li n;
  cin>>n;

  vli v(n);
  li sum = 0;
  map<li,li> m;
  rep(i,0,n)
  {
    cin>>v[i];
    sum+=v[i];
    m[v[i]]++;
  }

  li q;
  cin>>q;

  while(q--)
  {
    li b,c;
    cin>>b>>c;
    // cout<<m[b]<<' '<<m[c]<<endl;
    sum-=m[b]*b;
    sum+=m[b]*c;
    m[c]+=m[b];
    m[b] = 0;
    cout<<sum<<endl;
  }
} 

int main()
{
    IOS;

    solve();
    return 0;
}

Measured memory_bytes: 9960
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> v(n-1, vector<int>{0, 0, 0});
    rep(i,n-1){
        cin >> v[i][0] >> v[i][1]>> v[i][2];
    }
    ddump(v)
    vector<ll> ans(n, 0);

    for(int i=0; i<n-1; i++){
        int pos = i;
        int t=v[i][1];
        dd(pos, t)
            t += v[pos++][0];
        while(pos<=n-2){
            dd(pos,t)
            if (t <= v[pos][1])
            {
                t += v[pos][1] - t;
            }
            else
            {
                d((t % v[pos][2]))
                int a = (t % v[pos][2]);
                if(a!=0){
                    t += v[pos][2] - (t % v[pos][2]);
                }
            }
            t += v[pos++][0];
            dd(pos,t)
        }

        ans[i] = t;
    }
    // dump(ans)
    rep(i,n){
        cout << ans[i]<<endl;
    }
    return 0;
}

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

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int>G[MAX];
int color[MAX];

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while(!S.empty()){
        int u = S.top();S.pop();
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            if(color[v] == NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor(){
    int id = 1;
    for(int i=0;i<n;i++)color[i] = NIL;
    for(int u=0;u<n;u++){
        if(color[u] == NIL)dfs(u,id++);
    }
}

int main(){
    int s,t,m,q;

    cin >> n >> m; // n = ノードの数 m = 辺の数 

    for(int i=0;i<m;i++){
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    assignColor();
    
    cin >> q;

    for(int i=0;i<q;i++){
        cin >> s >> t;
        if(color[s] == color[t]){
            cout << "yes" << endl;
        }else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 8920
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vP p(M);
    vl match={0,2,5,5,4,5,6,3,7,6};
    rep(i,M){
        cin >> p[i].first;
        p[i].second=match[p[i].first];
    }
    sort(p.begin(),p.end());
    vl dp(N+1,-INF);
    dp[0]=0;
    FOR(i,1,N+1){
        rep(j,M){
            if(i>=p[j].second){
                chmax(dp[i],dp[i-p[j].second]+1);
            }
        }
    }
    string ans="";
    int res=N;
    while(res){
        rrep(i,M){
            if(res>=p[i].second&&dp[res]==dp[res-p[i].second]+1){
                ans+=(p[i].first+'0');
                res-=p[i].second;
                break;
            }
        }
    }
    sort(ans.begin(),ans.end());reverse(ans.begin(),ans.end());
    cout << ans << '\n';
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
const int N=100005;
int n,tot,s,a[N];
set<int> st;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        st.insert(a[i]);
    }
    sort(a+1,a+n+1);
    if(st.size()>2||a[n]-a[1]>1){
        puts("No");
        return 0;
    }else if(a[n]-a[1]==0){
        if(a[n]==n-1){
            puts("Yes");
        }else if(a[n]>n-1){
            puts("No");
        }else if(a[n]*2<=n){
            puts("Yes");
        }else{
            puts("No");
        }
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(a[i]==a[1]){
            tot++;
        }
    }
    s=a[1]-tot+1;
    if(s<1){
        puts("No");
    }else if(s*2<=n-tot){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using P = pair<int, int>;

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

P next(P p, int w, int h){
  if(p.second == h - 1){
    --p.first;
  }
  else if(p.first == w - 1){
    ++p.second;
  }
  else{
    ++p.first;
  }
  return p;
}

bool adjacent(P p, P q){
  rep(i, 4){
    if(p.first + dx[i] == q.first && p.second + dy[i] == q.second){
      return true;
    }
  }
  return false;
}

int w, h, n;

int main(){
  cin >> w >> h >> n;
  
  P p(0, 0), q(0, 0);
  int ans = 0;
  rep(i, n){
    int t;
    cin >> t;
    if(!t){
      p = next(p, w, h);
    }
    else{
      q = next(q, w - 1, h - 2);
    }
    if(adjacent(p, P(q.first, q.second + 1))){
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  long long int n, l = 0, count = 1; cin >> n;
  long long int a[n]; 
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (l == 0 && a[i] < a[i-1]) 
        l = 2;
    else if (l == 1 && a[i] < a[i-1]) 
        l = 0, count++;
    else if (l == 0 && a[i] > a[i-1]) 
        l = 1;
    else if (l == 2 && a[i] > a[i-1]) 
        l = 0, count++;
  }
  cout << count << endl;
  return 0;
}
    
  
  

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

using namespace std;

int main(){
  long long N,cnt=0,ans=0; cin>>N;
  vector<long long> A(N,0); 
  for(long long i=0;i<N;i++){
    long long temp; cin>>temp;
    if(temp<0) cnt++;
    A[i]=abs(temp);
  }

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  for(long long i=0;i<N-1;i++) ans+=A[i];
  if(cnt%2==0)ans+=A[N-1];
  else ans-=A[N-1];

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int getDigt(int number) {
	int digt = 0;
	while(number > 0) {
		digt++;
		number /= 10;
	}
	return digt;
}

int main () {
	int a , b;
	while(scanf("%d %d" , &a , &b) > 0) {
		printf("%d\n" , getDigt(a + b));
	}
	return 0;
}

Measured memory_bytes: 600
/*
      author  : nishi5451
      created : 15.08.2020 13:02:12
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
n=int(input())
A=list(map(int,input().split()))

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num

from fractions import gcd

def segfunc(x,y):
    return gcd(x,y) 

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

init(A)
ans=-1
for i in range(n):
    ans=max(ans, gcd(query(0,i),query(i+1,n)))
print(ans)

Measured memory_bytes: 14672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const int siz = 1e5 + 7;
vector<int>par;
int getparent(int x) {
	if (par[x] == x)return x;
	return par[x] = getparent(par[x]);
}
void dsu(int a, int b) {
	a = getparent(a);
	b = getparent(b);
	if (a != b) {
		par[b] = a;
	}
}
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	par.resize(n + 1);
	for (int i = 0; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 0; i < m; i++) {
		int u, v, z;
		cin >> u >> v >> z;
		dsu(u, v);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (par[i] == i)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll prvi = 0,drugi = 0,treci = 0;
    for(long i = 1; i <= n; i++){
        ll x;
        cin >> x;
        prvi += (x <= a);
        drugi += (a < x && x <= b);
        treci += (b < x);
    }
    //cout << prvi << " " << drugi << " " << treci << endl;
    cout << min({prvi,drugi,treci}) << endl;
}


Measured memory_bytes: 256
X=input().strip()
N=len(X)
sl=0
tl=0
sp=0
for i in range(N-1,-1,-1):
    if X[i]=='S':
        if tl==0:
            sl+=1
        else:
            tl-=1
    else:
        tl+=1
print(sl+tl)

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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 100000;
int n;
int a[MAX_N];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  n = unique(a, a+n) - a;

  int c = 0; bool in = true;
  for (int i = 1; i < n-1; i++)
    if (in && ((a[i-1] < a[i] && a[i] > a[i+1]) || (a[i-1] > a[i] && a[i] < a[i+1]))) {
        c++;
        in = false;
    } else {
      in = true;
    }

  cout << c + 1 << endl;

  return 0;
}


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

void revStr(char* str){
  int size = strlen(str);
  int i,j;
  char tmp = {0};
	
  for(i = 0, j = size - 1; i < size / 2; i++, j--){
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
  }
	
  return;	
}

int main()
{
  char s[300000], sento[300000], matsu[300000];
  int q, rev = 0, i;

  scanf("%s", s);
  scanf("%d", &q);

  for (; q > 0; q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {	// 文字列反転
      rev++;
    } else if (t == 2) {
      int f;
      char c[2];
      scanf("%d %s", &f, c);
      if (f == 1) {
	if (rev % 2 == 0) {	// 反転してない
	  // 先頭に追加
	  strcat(sento, c);
	} else {		// 反転している
	  // 末尾に追加
	  strcat(matsu, c);
	}
      } else if (f == 2) {
	if (rev %2 == 0) {	// 反転してない
	  // 末尾に追加
	  strcat(matsu, c);
	} else {
	  // 先頭に追加
	  strcat(sento, c);
	}
      }
    }
  }
  // 最後に結合
  if (rev % 2 == 0) {
    revStr(sento);
    strcat(sento, s);
    strcat(sento, matsu);
    printf("%s\n", sento);
  } else {
    revStr(matsu);
    revStr(s);
    strcat(matsu, s);
    strcat(matsu, sento);
    printf("%s\n", matsu);
  }
  return 0;
}


Measured memory_bytes: 896
program Lucky7;
var
	n : integer;
	contain : boolean;
begin
	readln(n);
	if ( n div 100 = 7 )
		then contain := true
		else if ( ((n div 10) mod 10) = 7 )
				then contain := true 
				else if ( (n mod 10) = 7 )
						then contain := true 
						else contain := false;
	if contain
		then writeln('Yes')
		else writeln('No');
end.

Measured memory_bytes: 1388
#include <stdio.h>

 #define N 8
 #define FREE 0
 #define NOT_FREE 1

 void putQueen(int);
 void PrintBoard(void);

 int Queen[N][N];
 int dpos[2*N-1];
 int dneg[2*N-1];
 int row[N];
 int col[N];

 int main(){

 int i;
 int n;
 int q_row;
 int q_col;

 scanf("%d",&n);

 for(i=0;i<n;i++){
 scanf("%d%d",&q_row,&q_col);
 Queen[q_row][q_col] = NOT_FREE;
 }

 putQueen(0);

   return 0;
}
void putQueen(int i){

 int j;

 if(i==N){
 PrintBoard();
 return;
 }

 for(j=0;j<N;j++){
 if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;

 row[i] = j;
 col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
 putQueen(i+1);
 
 col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
 }

}
void PrintBoard(void){

 int i;
 int j;

 for(i=0;i<N;i++){
  for(j=0;j<N;j++){
    
 if(Queen[i][j]==NOT_FREE){
    if(row[i]!=j) return;
    }
 
   }
  }

 for(i=0;i<N;i++){
  for(j=0;j<N;j++){
    
 if(row[i]==j){
  printf("Q");
   }
 
 else{
  printf(".");
   }
 
   }
  printf("\n");
   }
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
int n,m;
char str[MaxN],s[MaxN];
int ans;

int main() {
    scanf("%s",str+1);
    n=strlen(str+1);
    m=0;
    for (int i=1;i<=n;++i) if (str[i]!='x') s[++m]=str[i];
    for (int i=1;i<=m/2;++i) if (s[i]!=s[m-i+1]) return puts("-1"),0;
    int l=0,r=0;
    for (int i=1,cnt=0;i<=n;++i) {
        if (str[i]=='x') continue;
        cnt++;
        if (cnt==(m+1)/2) l=i;
        if (cnt==(m+2)/2) r=i;
    }
    ans=0;
    for (int I=1;I<=(m+1)/2;++I) {
        int nxtl=l-1;while (nxtl>0 && str[nxtl]=='x') nxtl--;
        int nxtr=r+1;while (nxtr<=n && str[nxtr]=='x') nxtr++;
        int d1=l-nxtl-1,d2=nxtr-r-1;
        ans+=abs(d1-d2);
        l=nxtl,r=nxtr;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public static void Solve()
    {
        string s = NextString();
        int N = s.Length;
        int ans = 0;
        for (int i = 0; i < N / 2; i++) if (s[i] != s[N - 1 - i]) ans++;
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


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

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = A; i <= B; i++) {
    if ((i >= A && i < A + K) || (i > B - K && i <= B)) {
      cout << i << endl;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

vector<ll> sil(2000010), inv(2000010);

ll Pot(ll p, ll w)
{
    if (w == 0)
        return 1;
    if (w % 2 == 0)
    {
        ll pol = Pot(p, w / 2);
        return pol * pol % MOD;
    }
    return Pot(p, w - 1) * p % MOD;
}

ll C(ll n, ll k)
{
    return sil[n] * inv[n - k] % MOD * inv[k] % MOD;
}

ll Ile(ll a, ll b)
{
    ll il = b + 1;
    for (ll i = 1; i <= a; ++i)
        il = (il + C(i + b + 1, i + 1)) % MOD;
    return il;

}

int main()
{
    ios_base::sync_with_stdio(0);
    sil[0] = 1;
    inv[0] = 1;
    for (ll i = 1; i < 2000010; ++i)
    {
        sil[i] = (sil[i - 1] * i) % MOD;
        inv[i] = Pot(sil[i], MOD - 2);
    }
    ll a1, a2, b1, b2;
    cin >> a1 >> b1 >> a2 >> b2;
    ll odp = Ile(a2, b2) % MOD;
    odp -= Ile(a2, b1 - 1);
    if (odp < 0)
        odp += MOD;
    odp -= Ile(a1 - 1, b2);
    if (odp < MOD)
        odp += MOD;
    odp = (odp + Ile(a1 - 1, b1 - 1)) % MOD;
    cout << odp;
    return 0;
}


Measured memory_bytes: 31488
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;
const int INF = 1<<30;
string S;
vector<int> dp(200010, INF);
vector<int> best(1<<26, INF);

int main(){
  cin >> S;
  int sl = S.size();
  vector<int> A(sl+1);
  A[0] = 0;
  for(int i = 1; i <= sl; i++){
    A[i] = A[i-1] ^ (1<<(S[i-1] - 'a'));
  }
  best[0] = 0;
  dp[0] = 0;
  for(int i = 1; i <= sl; i++){
    int x = A[i];
    for(int j = -1; j < 26; j++){
      int nx = x;
      if(j >= 0) nx ^= (1<<j);
      dp[i] = min(dp[i], best[nx] + 1);
    }
    best[x] = min(best[x], dp[i]);
  }
  cout << dp[sl] << endl;
}


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

const int INF = LONG_LONG_MAX;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n,k;
  cin >> n >> k;

  vector<int> p(n + 1);
  vector<int> c(n + 1);

  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> c[i];

  vector<vector<int>> route;

  vector<int> visited(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if(visited[p[i]]) continue;

    vector<int> path;
    path.push_back(c[i]);
    visited[p[i]] = 1;

    int cur = p[i];
    while(true) {
      if(visited[p[cur]]) break;
      visited[p[cur]] = 1;
      path.push_back(c[cur]);
      cur = p[cur];
    }
    route.push_back(path);
  }

  int answer = -INF;

  for (vector<int> cycle : route) {
    int m = (int)cycle.size();
    for (int start = 0; start < m; start++) {
      int cycle_sum = 0;

      for (int i = 0; i < min(k,m); i++) {
        cycle_sum += cycle[(start + i) % m];
        answer = max(answer, cycle_sum);
      }

      if(k <= m || cycle_sum < 0) continue;

      int tmp = (k/m - 1) * cycle_sum;
      int cnt = k%m + m;

      answer = max(answer, tmp);

      for (int i = 0; i < cnt; i++) {
        tmp += cycle[(start + i) % m];
        answer = max(answer, tmp);
      }
    }
  }

  cout << answer << '\n';

}

Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf 9e18
#define mod 1000000007
#define mod1 998244353
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}


int main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o;
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin>>n>>k ;
   map<ll,ll> p ;
   for(i=0;i<k;i++)
   {
       cin>>x ;
       while(x--)
       {
           cin>>y ;
           p[y]++ ;
       }
   }
   cout<<n-p.size() ;
   return 0; }


Measured memory_bytes: 3652
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", (b - a) * 2 + a);
	
	Please AC;
}


Measured memory_bytes: 256