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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, M; cin >> N >> M;
	vint A(M); cin >> A;
	int sum = accumulate(begin(A), end(A), 0);
	if (N - sum >= 0) {
		cout << N-sum << endl;
	} else {
		cout << -1 << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 105
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[maxn];
int main(){
	scanf("%d",&n);
	int ans = 0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) if(a[i] > a[i - 1]) ans += a[i] - a[i - 1];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char s[3];
    cin>>s;
    int count =0;
    for(int i=0;i<3;i++)
    {
            if(s[i]=='R')
              count++;
            else
              if(s[i]=='S' and s[i+1]=='R')
                 {count=1;
                  i++;}  
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main(void)
{
	int n;
	pair <char, int> input[128], bubble[128], select[128];

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> input[i].first >> input[i].second;
		bubble[i] = input[i];
		select[i] = input[i];
	}

	// bubble
	bool flag = true;
	for (int i = 0; flag; i++){
		flag = false;
		for (int j = n - 1; j >= i + 1; j--){
			if (bubble[j].second < bubble[j - 1].second){
				swap(bubble[j], bubble[j - 1]);
				flag = true;
			}
		}
	}

	// select
	for (int i = 0; i < n - 1; i++){
		int mini = i;
		for (int j = i; j < n; j++){
			if (select[mini].second > select[j].second) mini = j;
		}
		if (mini != i){
			swap(select[mini], select[i]);
		}
	}

	for (int i = 0; i < n; i++){
		cout << bubble[i].first << bubble[i].second << (i + 1 == n ? '\n' : ' ');
	}
	cout << "Stable" << endl;

	bool stable = true;
	for (int i = 0; i < n; i++){
		if (bubble[i] != select[i]) stable = false;
	}

	for (int i = 0; i < n; i++){
		cout << select[i].first << select[i].second << (i + 1 == n ? '\n' : ' ');
	}

	if (stable) cout << "Stable" << endl;
	else cout << "Not stable" << endl;


	return 0;
}

Measured memory_bytes: 3060
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]

Left= 0
Right = N + 1
for i in range(M):
    Left = max(Left,LR[i][0])
    Right = min(Right,LR[i][1])
    
if Right - Left < 0:
    print(0)
else:
    print(Right - Left + 1)

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

using namespace std;
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define in(x, a, b) a <= x && x < b
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p <<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int h, w;
vector<vector<char> > s;
vi idx;

bool cmp(int i, int j) {
  rep (k, w) {
    if (s[i][idx[k]] != s[j][idx[w - 1 - k]]) {
      return false;
    }
  }
  return true;
}


bool check() {
  vector<bool> used(h, false);
  rep (i, h) {
    if (used[i]) {
      continue;
    }
    for (int j = i + 1; j < h; j++) {
      if (used[j]) {
	continue;
      }
      if (cmp(i, j)) {
	used[i] = used[j] = true;
	break;
      }
    }
  }
  //DEBUG_VEC(used);
  int i0 = -1;
  rep (i, h) {
    if (!used[i]) {
      if (i0 == -1) {
	i0 = i;
      }
      else {	
	return false;
      }
    }
  }
  if (i0 == -1) {
    return true;
  }
  else {
    rep (j, w) {
      if (s[i0][idx[j]] != s[i0][idx[w - 1 - j]]) {
	return false;
      }
    }
    return true;
  }	
}
  
//#include <random>

int main() {
  auto start = clock();
  random_device seed_gen;
  mt19937 rand(seed_gen());
  cin >> h >> w;
  s.resize(h);
  idx.resize(w);
  rep (i, h) {
    s[i].resize(w);
    rep (j, w) {
      cin >> s[i][j];
    }
  }
  
  iota(all(idx), 0);
  while ((clock() - start) < 1.9 * CLOCKS_PER_SEC) {
    shuffle(all(idx), rand);
    //DEBUG_VEC(idx);
    if (check()) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';
constexpr int MAXN = 10000;

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

    vector<int> ans(MAXN + 1, 0);
    for (int x = 1; x <= 100; x++) {
        for (int y = 1; y <= 100; y++) {
            for (int z = 1; z <= 100; z++) {
                int sum = x * x + y * y + z * z + x * y + y * z + z * x;
                if (sum > MAXN) continue;
                ans[sum]++;
            }
        }
    }

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cout << ans[i] << newl;
    }

    return 0;
}

Measured memory_bytes: 3656
import bisect


def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]

  tail = []
  len_tail = 0
  for ai in a:
    idx = bisect.bisect_right(tail, -ai, lo=0, hi=len_tail) 
    if idx == len_tail:
      tail.append(-ai)
      len_tail += 1
    else:
      tail[idx] = - ai

  print(len_tail )


if __name__ == "__main__":
  main()

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b;
    cin >> a >> b;
    cout << ((a > 2 * b)?a - 2*b: 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
int A,B,T,sume,cokkie;
float sum;

cin>>A>>B>>T;
sum=T+0.5;
sume=(int)sum;
 cokkie=sume/A*B;

cout<<cokkie<<endl;
 return 0;
}   

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;


int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    
    while(A>0 && C>0){
        C-=B;
        if(C>0) A-=D;
    }

    if(A>0) cout << "Yes";
    else cout << "No";
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int n;


bool solve(ll mid,vector<ll> rsum){
    rep(i,n+1){
        ll start = rsum[i];
        
        int a=lower_bound(all(rsum),start  +mid)-rsum.begin();
        if(a>=i+n+1)continue;
        
        int b=lower_bound(all(rsum),rsum[a]+mid)-rsum.begin();
        if(b>=i+n+1)continue;
        
        int c=lower_bound(all(rsum),rsum[b]+mid)-rsum.begin();
        if(c>=i+n+1)continue;
        
        return true;
    }
    return false;

}


int main(){
    ll sum=0;
    cin>>n;
    vector<ll> vec(n);
    rep(i,n){
        cin>>vec[i];
        sum += vec[i];
    }

    vector<ll> rsum(2*n+1,0);
    rep(i,2*n)rsum[i+1] = rsum[i]+vec[i%n];

    
    ll left=0, right=rsum[n+1], mid=(left+right)/2LL;
    while(left+1<right){
        bool res = solve(mid,rsum);
        
        if(res) left = mid;
        else    right= mid;
        
        mid = (left+right)/2LL;
    }
    cout<<mid<<endl;
}

Measured memory_bytes: 6836
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    int N; cin >> N;
    vector<P> BA(N); 
    rep(i,N) cin >> BA[i].second >> BA[i].first;
    sort(BA.begin(), BA.end());
    ll tmp = 0; bool flag = true;
    rep(i,N){
        //cout << i << endl;
        if(tmp + BA[i].second <= BA[i].first){
            tmp += BA[i].second;
        }else{
            flag = false;
            break;
        }
        
    }

    cout << (flag?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 4840
input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumA = sum(A)
sumB = sum(B)
if sumA < sumB:
    print(-1)
    exit()

D = [a-b for a, b in zip(A, B)]
D.sort()

#print(D)
mi = 0
ans = 0
for d in D:
    if d < 0:
        mi += d
        ans += 1

for i, d in enumerate(D[::-1], 0):
    if mi >= 0:
        print(i+ans)
        exit()
    mi += d
print(i+ans)


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

int main(){
 int A,B,C,X,ans=0;
  cin >> A >> B >> C >> X;
  for(int i=0; i<=A; i++){
    for(int j=0; j<=B; j++){
      for(int k=0; k<=C; k++){
        if(500*i+100*j+50*k == X){
          ans++;
        }
        }
      }
    }
    cout << ans << endl;
}


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

bool IsPrime(int n) {
    for (int i=2; i*i<=n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return n != 1;
}

int main() {
    int i, n, tmp;
    int c = 0;

    cin >> n;
    for (i=0; i<n; i++) {
        cin >> tmp;
        if (IsPrime(tmp))
            c += 1;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const ll MOD=1'000'000'007;

ll N;
ll A[300000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    ll ans=0;
    for(int i=0;i<=60;i++){
        ll zero=0,one=0;
        rep(j,N){
            if(A[j]>>i&1) one++;
            else zero++;
        }
        ans+=(zero*one%MOD)*(((ll)1<<i)%MOD)%MOD;
        ans%=MOD;
    }
    if(ans<0) ans+=MOD;

    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  cout << (n-1 )*(m-1) << endl;
  return 0;
    

}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    
    ll x;
    cin >> x;
    ll dp[x+1] = {};
    dp[0] = 1;
    rep(i,100,x+1){
        rep(j,0,6){
            if(i >= 100+j) dp[i] = max(dp[i],dp[i-100-j]);
        }
    }
    cout << dp[x] << endl;

    return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
    rep(j,4){
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    }
  }
  return cnt;

}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  cin>>H>>W;
  rep(i,H)cin>>s[i];
  if(H==1&&W==1){
    cout<<"Yes"<<endl;
  }
  else{
    int mi=2500;
    for(int i=0;i<W;i++){
      for(int j=0;j<H; j++){
        if(s[i][j]=='#'){
          cnt=1;
          mi= min(dfs(i,j),mi);
        }
      }
    }
    if(mi==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}	





Measured memory_bytes: 384
from itertools import product
H,W,M = map(int,input().split())
h_list = [0] * M
w_list = [0] * M
for m in range(M):
    h_list[m],w_list[m] = map(int,input().split())
hh_list = [0] * H
ww_list = [0] * W
for m in range(M):
    hh_list[h_list[m]-1] += 1
for m in range(M):
    ww_list[w_list[m]-1] += 1
h_max = max(hh_list)
w_max = max(ww_list)

h_ans = []
w_ans = []

for hh in range(H):
    if hh_list[hh] == h_max:
        h_ans.append(hh)
for ww in range(W):
    if ww_list[ww] == w_max:
        w_ans.append(ww)
cnt = 0
h_set = set(h_ans)
w_set = set(w_ans)
for i,j in zip(h_list,w_list):
    if i-1 in h_set and j-1 in w_set:
        cnt += 1
if cnt == len(h_ans) * len(w_ans):
    print(h_max + w_max - 1)
else:
    print(h_max + w_max)

Measured memory_bytes: 162980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << b-d+c << " " << d+c-a << " " << a+b-d << " " << c-a+b << endl;
}
    
    
    
    

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

int main() {
	int c, n, a, b, ans = 0;
	cin >> n >> a >> b;
	while (n--) {
		scanf("%d", &c);
		if (c < a || c >= b)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  string s;
  cin >> s; 
  for(int i=0; i<s.size(); i=i+2){
  	cout << s.at(i); 
  }
  cout << endl;
}





Measured memory_bytes: 512
using System;
using System.Collections.Generic;
// using System.Linq;
// using System.Text;

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split();
        int K, X;
        K = int.Parse(arr[0]);
        X = int.Parse(arr[1]);
        List<int> ans = new List<int>();
        for (int i = X - K + 1; i < X + K; i++) ans.Add(i);
        Console.WriteLine(String.Join(" ", ans));
        return;
    }
}

Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

bool kaibun(string s) {
	int n = sz(s);
	bool res = true;
	rep(i, n/2 + 1) {
		if (s[i] != s[n - i - 1]) res = false;
	}
	return res;
}

void solve(){
	string S; cin >> S;
	int N = sz(S);
	bool f = true;
	f = kaibun(S);
	if (f) f = kaibun(S.substr(0, (N - 1) / 2));
	if (f) f = kaibun(S.substr((N + 3) / 2 - 1));
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    for(auto i:s)
    {
        if(i!='?')
            cout<<i;
        else
            cout<<'D';
    }
}


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

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        unordered_map<string,vector<string>> g;
        string ob;
        for (int i = 0; i < n; ++i) {
            string s, t = "",group="";
            cin >> s;
            bool semi = false;
            vector<string> ss;
            for (int j = 0; j < s.size(); ++j) {
                if (!semi && s[j] != ':')group += s[j];
                else if (s[j] == ':') {
                    if(i==0)ob=group;
                    semi = true;
                }
                else {
                    if (s[j] == ',' || s[j] == '.') {
                        ss.push_back(t);
                        t = "";
                    } else {
                        t += s[j];
                    }
                }
            }
            g[group] = ss;
        }
        /*for(auto i:g){
            for(auto j:i.second)cout<<j<<" ";
            cout<<endl;
        }*/
        //if(g.find("design")==g.end())cout<<"ok"<<endl;
        set<string> st;
        for(int i=0;;++i){
            if(i>=g[ob].size())break;
            if(g.find(g[ob][i])!=g.end()){
                if(st.find(g[ob][i])==st.end()){
                    st.insert(g[ob][i]);
                    copy(g[g[ob][i]].begin(),g[g[ob][i]].end(),back_inserter(g[ob]));
                }
            }
        }
        unordered_map<string,int> um;
        for (int i = 0; i < g[ob].size(); ++i) {
            if(g.find(g[ob][i])==g.end())um[g[ob][i]]=1;
        }
        cout<<um.size()<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
bool us[1000010]={false};
bool p[1000010] = {0};
int main(){
	/*Eratosthenes*/
	p[2] = true;
	for(int i = 0; i <= 1000010; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000010; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[i] = true;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000010; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(scanf("%d",&n),n){
		int x = 0;
		for(int i = 0; i <= n/2; i++){
			if(p[i] && p[n-i]){
				x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 2980
from sys import stdin
import math

def GCD(a,b):
    if(a%b==0):
        return b
    else:
        c = a%b
        return GCD(b,c)

def LCM(a,b):
    gcd = GCD(a,b)
    return int(a*b/gcd)

for line in stdin:
    a,b = line.split(" ")
    a = int(a)
    b = int(b)
    gcd = GCD(a,b)
    lcm = LCM(a,b)

    print(str(gcd)+" "+str(lcm))




Measured memory_bytes: 5652
def dfs(string, k):
  ans = 0
  if k == len(s):
    ans += sum(list(map(int, string.split('+'))))
  else:
    ans += dfs(string + s[k], k+1)
    if k != 0 and string[-1] != '+':
      ans += dfs(string + '+', k)
  return ans

s = input()
print(dfs("", 0))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	string s;
	std::cin >> n;
	std::cin >> s;
	std::cin >> k;

	string s_k = s.substr(k - 1, 1);
	vector<int> v;

	for (int i = 0; i < s.size(); ++i)
	{
		if (s.substr(i, 1) != s_k) s.replace(i, 1, "*");
	}
	cout << s << endl;
}

Measured memory_bytes: 256
var a,b,c:integer;
begin 
    read(a,b,c);
    if (a>=b) and (a>=c) then begin write(a*10+b+c);exit;end;
    if (a<=b) and (b>=c) then begin write(b*10+a+c);exit;end;
    if (a<=c) and (b<=c) then write(c*10+b+a);
end.


Measured memory_bytes: 128
s =[list(input()) for i in range(3)]
i = 0;j =0;
while len(s):
  if s[i] ==[]:
    print("A" if i==0 else "B" if i==1 else "C")
    break
  if s[i][j] =="a":
    del s[i][j]
    i =0
  elif s[i][j] =="b":
    del s[i][j]
    i =1
  else:
    del s[i][j]
    i =2

Measured memory_bytes: 9072
# -*- coding: utf-8 -*-

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]


def dfs(idx, a, b, c):

    if idx == N:
        if a == 0 or b == 0 or c == 0:
            return 1e9

        return abs(A - a) + abs(B - b) + abs(C - c)

    x = dfs(idx + 1, a, b, c)
    y = dfs(idx + 1, a + L[idx], b, c) + 10*(a != 0)
    z = dfs(idx + 1, a, b + L[idx], c) + 10*(b != 0)
    w = dfs(idx + 1, a, b, c + L[idx]) + 10*(c != 0)
    return min(x, y, z, w)


ans = dfs(0, 0, 0, 0)
print(ans)


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

int main() {
   int k;
   cin >> k;
   vector<string> data(8,"........");
   vector<int> perm(8);
   rep(i,8) perm[i] = i;
   vector<int> x(k), y(k);
   rep(i,k) {
      int X, Y;
      cin >> X >> Y;
      x[i] = X;
      y[i] = Y;
   }
   do {
      bool ok = true;
      rep(i,k) {
         if (perm[y[i]] != x[i]) ok = false;
      }
      if (ok) {
         bool ans = true;
         rep(i,7) {
            for (int j = 1; i+j < 8; j++) {
               if (perm[i] + j == perm[i+j]) ans = false;
               if (perm[i] - j == perm[i+j]) ans = false;
            }
         }
         if (ans) {
            rep(i,8) {
               data[perm[i]][i] = 'Q';
            }
            rep(i,8) {
               rep(j,8) {
                  cout << data[i][j];
               }
               cout << endl;
            }
            return 0;
         }
      }
   } while(next_permutation(perm.begin(),perm.end()));
}


Measured memory_bytes: 3168
#include <cstdio>
int exist[1001][1001][3]={};
char field[1001][1001];
int m,n,Q;
int main(){
	scanf("%d %d %d",&m,&n,&Q);
	for(int i=0;i<m;i++){
			scanf("%s",field[i]);
	}
	for(int i=0;i<m;i++){
		for(int j=i;j<m;j++){
			if(field[i][0]=='J'){
				exist[j][0][0]++;
			}else if(field[i][0]=='O'){
				exist[j][0][1]++;
			}else{
				exist[j][0][2]++;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(field[0][i]=='J'){
				exist[0][j][0]++;
			}else if(field[0][i]=='O'){
				exist[0][j][1]++;
			}else{
				exist[0][j][2]++;
			}
		}
	}
	if(field[0][0]=='J'){
		exist[0][0][0]=1;
	}else if(field[0][0]=='O'){
		exist[0][0][1]=1;
	}else{
		exist[0][0][2]=1;
	}
	for(int i=1;i<m;i++){
		for(int j=1;j<n;j++){
			for(int k=0;k<3;k++){
			exist[i][j][k]=exist[i][j-1][k];
			}
			for(int k=0;k<=i;k++){
				if(field[k][j]=='J'){
					exist[i][j][0]++;
				}else if(field[k][j]=='O'){
					exist[i][j][1]++;
				}else{
					exist[i][j][2]++;
				}
			}
		}
	}
	for(int i=0;i<Q;i++){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		if(a>=2 && b>=2){
		printf("%d %d %d\n",exist[c-1][d-1][0]-exist[c-1][b-2][0]-exist[a-2][d-1][0]+exist[a-2][b-2][0],exist[c-1][d-1][1]-exist[c-1][b-2][1]-exist[a-2][d-1][1]+exist[a-2][b-2][1],exist[c-1][d-1][2]-exist[c-1][b-2][2]-exist[a-2][d-1][2]+exist[a-2][b-2][2]);
		}else if(a<2){
		printf("%d %d %d\n",exist[c-1][d-1][0]-exist[c-1][b-2][0],exist[c-1][d-1][1]-exist[c-1][b-2][1],exist[c-1][d-1][2]-exist[c-1][b-2][2]);
		}else{
		printf("%d %d %d\n",exist[c-1][d-1][0]-exist[a-2][d-1][0],exist[c-1][d-1][1]-exist[a-2][d-1][1],exist[c-1][d-1][2]-exist[a-2][d-1][2]);
		}
	}
	return 0;
}

Measured memory_bytes: 13616
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int D; cin >> D;
		if (!D)break;
		int N, M; cin >> N >> M;
		vector<int>shops(N + 1);
		for (int i = 0; i < N - 1; ++i) {
			cin >> shops[i];
		}
		shops[N - 1] = 0;
		shops[N] = D;
		sort(shops.begin(), shops.end());
		int sum = 0;
		for (int i = 0; i < M; ++i) {
			int k; cin >> k;
			auto it = lower_bound(shops.begin(), shops.end(), k);
			int ans = 1e9;
			if (it != shops.begin()) {
				ans = min(ans, k - *prev(it));
			}
			if (it != shops.end()) {
				ans = min(ans, *it - k);
			}
			sum += ans;
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		int ret = 0, tmp = 0;
		for(int i=1; i < n; i++){
			if(a[i] <= a[i-1])tmp++;
			else{
				tmp = 0;
			}
			updmax(ret, tmp);
		}
		cout << ret << "\n";
		
		return;
	};
};

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    double n;cin>>n;
    cout<<fixed<<setprecision(10);
    out(n*n*n/27);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    vector<ll> a{x};
    vector<int> v(m, -1);
    v[x] = 0;
    ll now = (x*x)%m;
    int l, r;
    {
        int i = 1;
        for ( ; v[now] == -1; ++i) {
            a.emplace_back(now);
            v[now] = i;
            now = (now*now)%m;
        }
        l = v[now], r = i;
    }

    ll val = x, ans = 0;
    for (int i = 0; i < min<ll>(l, x); ++i) {
        ans += val;
        val = (val*val)%m;
    }
    for (int i = l; i < r; ++i) {
        ans += max(0LL, (n-i+r-l-1)/(r-l))*a[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4256
#define onlycc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

string num;

int main()
{
    onlycc;
    cin >> num;

    ll sum = 0;
    for(int i = 0; i < num.size(); i++)
    {
        sum += num[i]-'0';
    }

    if(sum%9 == 0) cout << "Yes";
    else cout << "No";

    return 0;
}


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

int h,w,a[100][100],flag[100][100];
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

int judge(int x,int y)
{
	if (x>0&&y>0&&x<=h&&y<=w) return 1;
	return 0;
}

int main()
{
	cin>>h>>w;
	char c;
	for (int i=0;i<100;i++) for (int j=0;j<100;j++) { a[i][j]=0;flag[i][j]=0;}
	for (int i=1;i<=h;i++)
	{
		for (int j=1;j<=w;j++)
		{
			cin>>c;
			if (c=='#') 
			{
				flag[i][j]=1;
				int x=i,y=j,xn=x,yn=y;
				for (int k=0;k<8;k++)
				{
					xn=x+dx[k];
					yn=y+dy[k];
					if (judge(xn,yn)) a[xn][yn]++;
				}
			}
		}
	}
	
	for (int i=1;i<=h;i++)
	{
		for (int j=1;j<=w;j++)
		{
			if (!flag[i][j]) cout<<a[i][j];
			else cout<<'#';
		}
		cout<<endl;
	}
}

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

const int maxn = 100010;
int n, f[maxn];
vector<int> G[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    function<void(int, int)> dfs = [&](int v, int fa) {
        for (int u : G[v]) if (u ^ fa) {
            dfs(u, v), f[v] ^= f[u] + 1;
        }
    };
    dfs(1, 0), printf("%s\n", f[1] ? "Alice" : "Bob");
    return 0;
}

Measured memory_bytes: 15488
a, b, c = map(int, input().split())
maxX = a
maxY = b
minX = minY = 0
for i in range(c):
    x, y, z = map(int, input().split())
    if z == 1:
        minX = max(minX, x)
    elif z == 2:
        maxX = min(maxX, x)
    elif z == 3:
        minY = max(minY, y)
    elif z == 4:
        maxY = min(maxY, y)
if minX >= maxX or minY >= maxY:
    print(0)
else:
    print(abs(minX - maxX) * abs(minY - maxY))


Measured memory_bytes: 3064
N, T = map(int, input().split())
list_t = list(map(int, input().split()))

total_emp_T = 0
ts = T
for t in list_t[1:]:
    if t > ts:
        total_emp_T += t - ts
    ts = t + T
ans = ts  - total_emp_T
print(ans)

    


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n;
VI A;

LL max_score()
{
	priority_queue<int, VI, greater<int>> pq1;	
	priority_queue<int> pq2;
	VL l, r;
	l = r = VL(3 * n + 1, 0);

	LL sum = 0;
	for(int i = 1; i <= 3 * n; ++i)
	{
		sum += A[i];
		pq1.push(A[i]);
		while(sz(pq1) > n)
		{
			sum -= pq1.top();
			pq1.pop();
		}
		l[i] = sum;
	}

	sum = 0;
	for(int i = 3 * n; i >= 1; --i)
	{
		sum += A[i];
		pq2.push(A[i]);
		while(sz(pq2) > n)
		{
			sum -= pq2.top();
			pq2.pop(); 
		}
		r[i] = sum;
	}

	LL ret = LLONG_MIN;
	for(int i = n; i <= 2 * n; ++i)
		ret = max(ret, l[i] - r[i + 1]);

	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	///freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	A.assign(3 * n + 1, 0);
	for(int i = 1; i <= 3 * n; ++i) cin >> A[i];
	
	cout << max_score() << endl;

	return 0;
}

Measured memory_bytes: 7288
/*input
999983
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 3000005;

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll k; cin >> k;
	ll now = 7 % k, step = 1;
	while(step < MX && now) {
		step++;
		now = ((now * 10) + 7) % k;
	}
	if(step == MX) {
		cout << "-1" << endl;
	}
	else {
		cout << step << endl;
	}
	return 0;
}




















Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 2000005;
int bit[MAX_N+1];
int nn = MAX_N; //　1-index

void adds(int a, int w){
    for(int x = a; x <= nn; x += x & -x) bit[x] += w;
}
int sums(int a){ // bit[1,a]の和を返す.
    int ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];  
    return ret;
}

int b[MAX_N];
int c[MAX_N];
int bc[MAX_N];

vector<P> G[MAX_N];
int ans[MAX_N];

int main() {
    int n, q;
    cin >> n >> q;



    srep(i,1,n+1){
        cin >> c[i];
        b[i] = bc[c[i]];
        bc[c[i]] = i;
    }

    /*
    srep(i,1,n+1) cout << b[i] << ' ';
    cout << endl;
    */
    

    srep(i,1,n+1){
        adds(i,1);
    }

    rep(i,q){
        int l, r;
        cin >> l >> r;
        G[r].push_back(P(l,i));
    }

    srep(i,1,n+1){
        if(b[i] != 0){
            adds(b[i],-1);
        }
        rep(j,G[i].size()){
            int ite = G[i][j].second;
            int l = G[i][j].first;
            ans[ite] = sums(i);
            if(l > 1) ans[ite] -= sums(l-1);
        }
    }

    rep(i,q) cout << ans[i] << endl;
    return 0;
}





Measured memory_bytes: 70412
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  ll a,b,c; cin >> a >> b >> c;
  if(a==b&&b==c) yes();
  else no();  
}

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

int main()
{
    ll n, b = 1, c, k;
    cin >> n;
    vector<ll> a(n);
    double ans;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        ans += 1. / a[i];
    }
    ans = 1. / ans;
    cout << setprecision(16) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();

        int[] r = new int[4000];
        int[] g = new int[4000];
        int[] b = new int[4000];
        int ir = 0;
        int ig = 0;
        int ib = 0;

        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'R') r[ir++] = i;
            else if (s.charAt(i) == 'G') g[ig++] = i;
            else if (s.charAt(i) == 'B') b[ib++] = i;
        }

        if (ir == 0 || ig == 0 || ib == 0) {
            System.out.println(0);
            return;
        }

        long dup = 0;
        for (int i = 0; i < ir; i++) {
            for (int j = 0; j < ig; j++) {
                int larger = Math.max(r[i], g[j]);
                int smaller = Math.min(r[i], g[j]);
                if (search(b, larger + (larger - smaller), ib)) {
                    dup++;
                }
                if (search(b, smaller - (larger - smaller), ib)) {
                    dup++;
                }
                if ((larger + smaller) % 2 == 0 && search(b, (larger + smaller) / 2, ib)) {
                    dup++;
                }
            }
        }

        System.out.println((long)ir * ig * ib - dup);
    }

    static boolean search(int[] a, int t, int length) {
        int ok = 0;
        int ng = length;
        int pivot = (ok + ng) / 2;
        while (ok < ng) {
            if (a[pivot] == t) return true;
            else if (a[pivot] < t) {
                ok = pivot + 1;
            } else {
                ng = pivot;
            }

            pivot = (ok + ng) / 2;
        }

        return false;
    }
}


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

using ll = long long;
#define sz(x) ((int)x.size())
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

map<string,int>cnt;
vector<string>ver={"AC","WA","TLE","RE"};

int main() {
	fastio();
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		string s;cin>>s;
		cnt[s]++;
	}
	for(auto s:ver){
		cout<<s<<" x " << cnt[s]<<endl;
	}
}


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



int main(){
	
	int N;
	cin>>N;
	
	int x[N],y[N],h[N];
	
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i]>>h[i];
	}
		
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			int X = i;
			int Y = j;
			int H = -1;
			for(int k=0;k<N;k++){
				if(h[k]==0)continue;
				int temp = h[k]+abs(x[k]-X)+abs(y[k]-Y);
				if(temp>0){
					H=temp;
					break;
				}
			}
			if(H==-1)continue;
			
			bool is_ok = true;
			
			for(int k=0;k<N;k++){
				if(max(0,H-abs(x[k]-X)-abs(y[k]-Y))!=h[k]){
					is_ok=false;
					break;
				}
			}
			
			if(is_ok){
				cout<<X<<' '<<Y<<' '<<H<<endl;
				return 0;
			}
		}
	}
			
			
		
	
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main{
    public static void main (String[] args) throws IOException{
	
	BufferedReader br=
	    new BufferedReader(new InputStreamReader(System.in));
	String buf;
	while((buf=br.readLine())!= null){
	    String[] buf2=buf.split(" ");
	    int  data2=0;
	    for(int i=0;i!=buf2.length;i++){
		data2+=Integer.parseInt(buf2[i]);
	    }
	    String ans=(new Integer(data2)).toString();
	    System.out.println(ans.length());
	}
    }
}

Measured memory_bytes: 10000
x, y = map(int, input().split())
ans = 0
if x >= 0 and y >= 0:
    if x <= y:
        ans = y - x
    elif y == 0:
        ans = x + 1
    else:
        ans = x - y + 2
elif (x > 0 and y < 0) or (x < 0 and y > 0):
    ans = abs(abs(x) - abs(y)) + 1
elif x <= 0 and y <= 0:
    if x <= y:
        ans = y - x
    elif x == 0:
        ans = - y + 1
    else:
        ans = x - y + 2
print(ans)


Measured memory_bytes: 3188
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()

c = collections.Counter(a)
mod = 10 ** 9 + 7

val = list(c.values())
key = list(c.keys())
check = len(a) % 2
if check == 1:
    if val.count(1) != 1:
        print(0)
        exit()
    if key[val.index(1)] != 0:
        print(0)
        exit()
    else:
        if val.count(2) != len(val) - 1:
            print(0)
            exit()
        else:
            print(2 ** (val.count(2)) % mod)
else:
    if val.count(2) != len(val):
        print(0)
        exit()
    else:
        print(2 ** (len(val)) % mod)


Measured memory_bytes: 14748
#include <iostream>
#include <cmath>


using namespace std;

long int Sq(long int n){
 long int r = sqrt(n);
  if(r*r==n)
    return r;
  r++;
  if(r*r==n)
    return r;
  return -1;
}

int main(){
  int X;
  cin >>X;
  for(long i=1; i<=X; i++){
   if(X%i ==0){
    long d = X/i;
    long r = Sq(5*i*i*i*i+20*d);
     if(r==-1)
       continue;
     long m;
     
     m= -5*i*i+r;
     if(m%10==0){
      m/=10;
      long dsum = i*i+2*m;
       for(long A=1; A*A<=dsum; A++){
         long B=Sq(dsum-A*A);
         if(B!=-1&&A-B==i&&A*B==m){
           cout <<A<<" "<<B<<endl;
			return 0;
         }
         
         B=-B;
         if(B!=-1&&A-B==i&&A*B==m){
           cout <<A<<" "<<B<<endl;
			return 0;
         }
       }
     }
     
     m= -5*i*i-r;
     if(m%10==0){
      m/=10;
      long dsum = i*i+2*m;
       for(long A=1; A*A<=dsum; A++){
         long B=Sq(dsum-A*A);
         if(B!=-1&&A-B==i&&A*B==m){
           cout <<A<<" "<<B<<endl;
			return 0;
         }
         B=-B;
         if(B!=-1&&A-B==i&&A*B==m){
           cout <<A<<" "<<B<<endl;
			return 0;
         }
         
       }
     }
       
   }
  }
 return -1; 
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	string s;
	int k;
	cin >> s >> k;
	rep(i,s.size()) {
		if (s[i] == 'z') {
			if (k > 0) {
				s[i] = 'a';
				k--;
			}
		} 
		else if (s[i] == 'a') continue; 
		
		else {
			for (int j = 0; j <= min(25,k-1); j++) {
				if (char(s[i] + j) == 'z') {
					s[i] = 'a';
					k -= (j+1);
					break;
				}
			}
		}
	}
	int l = s.size();
	k = k % 26;
	rep(i,k) {
		if (s[l-1] == 'z') s[l-1] = 'a';
		else s[l-1] = char(s[l-1]+1);
	}
	cout << s << endl;
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  char o;
  if(c == 'a') {
    o = 'b';
  }
  if(c == 'b') {
    o = 'c';
  }
  if(c == 'c') {
    o = 'd';
  }
  if(c == 'd') {
    o = 'e';
  }
  if(c == 'e') {
    o = 'f';
  }
  if(c == 'f') {
    o = 'g';
  }
  if(c == 'g') {
    o = 'h';
  }
  if(c == 'h') {
    o = 'i';
  }
  if(c == 'i') {
    o = 'j';
  }
  if(c == 'j') {
    o = 'k';
  }
  if(c == 'k') {
    o = 'l';
  }
  if(c == 'l') {
    o = 'm';
  }
  if(c == 'm') {
    o = 'n';
  }
  if(c == 'n') {
    o = 'o';
  }
  if(c == 'o') {
    o = 'p';
  }
  if(c == 'p') {
    o = 'q';
  }
  if(c == 'q') {
    o = 'r';
  }
  if(c == 'r') {
    o = 's';
  }
  if(c == 's') {
    o = 't';
  }
  if(c == 't') {
    o = 'u';
  }
  if(c == 'u') {
    o = 'v';
  }
  if(c == 'v') {
    o = 'w';
  }
  if(c == 'w') {
    o = 'x';
  }
  if(c == 'x') {
    o = 'w';
  }
  if(c == 'y') {
    o = 'z';
  }
  cout << o << endl;
}


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

using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int b[60] = {};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 60; j++) {
			if ((a[i] >> j) & 1 == 1) {
				b[j]++;
			}
		}
	}

	long long x = 0;
	for (int i = 59; i >= 0; i--) {
		if ((1LL << i) <= k) {
			if (b[i] <= n - b[i]) {
				long long tmp = x | (1LL << i);
				if (tmp <= k) {
					x = tmp;
				}
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += x ^ a[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024