akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define pll pair<ll,ll>
#define pii pair<int32_t,int32_t>
#define loop(i,n) for(int64_t i=0; i<n; i++)
#define loop1(i,a,b) for(int64_t i=a; i<=b; i++)
#define rloop(i,n) for(int64_t i=n-1; i>=0; i--) 
#define rloop1(i,a,b) for(int64_t i=a; i>=b; i--) 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define print(val) cout << #val << ": " << val << "\n";
#define print_c(a) cout<<#a<<": ";for(auto it=begin(a);it!=end(a);it++)cout<<*it<<" ";cout<<"\n";
#define fill(c,v) fill(begin(c),end(c),v);
template <typename T> T flip(T val) {reverse(begin(val),end(val)); return val;}

int main() {
  fast_io
  int h,w,k; cin >> h >> w >> k;
  string data[h];
  for(int i=0; i<h; i++) {
    cin >> data[i];
  }
  int ans = 0;
  for(ll i=0; i<(1<<h); i++) 
    for(ll j=0; j<(1<<w); j++) {
      ll b_count=0;
      for(int a=0; a<h; a++) {
        for(int b=0; b<w; b++) {
          if(data[a][b]=='#' and (i>>a & 1) and (j>>b & 1) ) {
            b_count++;
          }
        }
      }
      if(b_count==k) ans++;
    }
  
  cout << ans << "\n";
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
    int i, n, q;
    char s[100000 + 1];
    int sum[100000 + 1] = {0};
    scanf("%d%d", &n, &q);
    //char s[n + 1], sum[n + 2];
    scanf("%s", s);

    for (i = 0; i < n ; i++)
    {
        sum[i + 2] = sum[i + 1];
        if(s[i - 1] == 'A' && s[i] == 'C'){
            sum[i + 2]++;
        }
    }

    int l[q], r[q];
    for (i = 0; i < q; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
    }

    for (i = 0; i < q; i++)
    {
        printf("%d\n", sum[r[i] + 1] - sum[l[i] + 1]);
    }

    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
 ll a,b,c;
  cin>>a>>b>>c;
  map<ll,int> mp;
  mp[a]++;
  mp[b]++;
  mp[c]++;
  auto it = mp.begin();
  while(it!=mp.end()){
   if(it->second==2){
   cout<<"Yes\n";
     return 0;
  }
   it++;
}
 cout<<"No\n";
return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

ll calc(ll r1, ll r2, ll r3){
    ll r = 0;
    // if (H < 10 && W < 10) {fprintf(stderr, "%lld %lld %lld \n", r1, r2, r3);}
    r = max(r, r1 - r3);
    r = max(r, r1 - r2);
    r = max(r, r2 - r1);
    r = max(r, r2 - r3);
    r = max(r, r3 - r1);
    r = max(r, r3 - r2);
    return r;
}

ll H, W;
int main() {
    cin >> H >> W;
    fprintf(stderr, "H:%lld W:%lld \n", H, W);
    ll ret = H * W;

    for(int h = 1; h < H; h++){
        ll r1 = h * W;
        ll w = W / 2;
        ll r2 = (H - h) * w;
        ll r3 = (H - h) * (W - w);
        ret = min(ret, calc(r1, r2, r3));
    }

    for(int h = 1; h < H; h++){
        ll r1 = h * W;
        ll hh = (H - h) / 2;
        ll r2 = hh * W;
        ll r3 = (H - h - hh) * W;
        ret = min(ret, calc(r1, r2, r3));
    }

    swap(H, W);
    for(int h = 1; h < H; h++){
        ll r1 = h * W;
        ll w = W / 2;
        ll r2 = (H - h) * w;
        ll r3 = (H - h) * (W - w);
        ret = min(ret, calc(r1, r2, r3));
    }

    for(int h = 1; h < H; h++){
        ll r1 = h * W;
        ll hh = (H - h) / 2;
        ll r2 = hh * W;
        ll r3 = (H - h - hh) * W;
        ret = min(ret, calc(r1, r2, r3));
    }

	cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void rle(string &s, vector<pair<char,int>> &t){
    int j=0;
    t={make_pair(s[0],1)};
    for(int i=1; i<s.size(); ++i){
        if(s[i]==s[i-1]){
            ++t[j].second;
        }else{
            t.push_back(make_pair(s[i],1));
            ++j;
        }
    }
}
int main(){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(0);
	int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<pair<char,int>> t;
    rle(s, t);

    int cnt=0;
    for(auto i : t) cnt += i.second-1;

    int lr=0, rl=0;
    for(int i=0; i<n-1; ++i){
        if(s.substr(i,2)=="LR") ++lr;
        if(s.substr(i,2)=="RL") ++rl;
    }
    
    int ans=(cnt+2*min({k,lr,rl}));
    if(k-min(lr,rl)>0 && abs(lr-rl)>0) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 1480
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
int main() {
    int i,j,k,ans=0,temp=0;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
            temp++;
        }else{
            ans=max(temp,ans);
            temp=0;
        }


    }
    ans=max(temp,ans);
    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;

const int m = 2e6;

long long cnt,X,Y;

vector<vector<int>> to; vector<bool> visited;
vector<int> v;

int dfs( int a, int depth){ visited[a] = true;
  if( depth % 2){ X++;}
  else{ Y++;} v.push_back(a);
  for(int j = 0; j < to[a].size(); j++){
    int p = to[a][j];
    if( visited[p] ){ continue;}
    else{
      //p番目の点に移動する
      dfs( p, depth + 1); cnt++;}
  }
                          }
                          
      


int main(){
int N;  cin >> N;
 to.resize(m); visited = vector<bool> ( m, false);
 
   
  for(int i = 0; i < N; i++){
    int x,y; cin >> x >> y; 
    // x　は　1から　100000まで、y　は100001 から　200000までを占有
    to[x].push_back(y + 100000); to[y + 100000].push_back(x);}
  
  
  long long ans = 0;
  
  for(int i = 0; i <= 200000; i++){//X集合についてのみ調べれば十分である
    X = 0; Y = 0; cnt = 0; v.clear();
    if( visited[i] || !(to[i].size())){ continue;}
       //すでに訪れたことのあるか、孤立している場合ははスルー
    else{ 
      //点iとつながっている点全てをdfsで探す
      dfs(i,1); //ans更新 
      long long res = 0;
      for(int p = 0; p < (int) v.size(); p++){
        res += (long long) to[v[p]].size();}
      res /= 2;
      ans += X * Y - res;
      
    }
  }

  cout << ans << endl; return 0;}
    
    

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

const ll mod = 1000000007;

int main(void)
{
	string s[] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	string t;
	cin >> t;
	for (int i = 0; i < 7; i++) {
		if (s[i] == t) {
			cout << (7 - i) << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	ll k;
	cin >> k;
	ll p, q;
	p = k / 50;
	q = k % 50;

	cout << 50 << endl;
	rep(i, q)cout << p - q + 100 << " ";
	rep(i, 50 - q) {
		cout << 49 + p - q;
		if (i < 50 - q - 1)cout << " ";
		else cout << endl;
	}

}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[3*n+5];
	rep(i,0,3*n)
	{
		cin >> a[i];
		//cout << a[i] <<" ";
	}
	ll suml = 0;
	set<pii> s1,s2;
	for ( int i =0; i < n; i++)
	{
		s1.insert({a[i],i});
		suml += a[i];
	}
	ll dp[3*n+1],dp2[3*n+1];
	 dp[n-1] = suml;
	//int k = n-1;
	for ( int i = n; i < 2*n; i++)
	{
		//k++;
		dp[i] = dp[i-1];
		int x = (*s1.begin()).fi;
		int y = a[i];
		if ( x > y)
			continue;
		suml -= x;
		suml += y;
		s1.insert({y,i});
		s1.erase(s1.begin());
		dp[i] = suml;
	}
	ll sumr = 0;
	for ( int i = 3*n-1; i>= 2*n; i--)
	{
		sumr += a[i];
		s2.insert({-a[i],i});
	}
	dp2[2*n] = sumr;
	ll ans = dp[2*n-1] - dp2[2*n];
	//k = 2*n;
	for ( int i = 2*n-1; i >= n; i--)
	{
		//k--;
		dp2[i] = dp2[i+1];
		int x = (*s2.begin()).fi * -1;
		int y = a[i];
		if ( x > y)
		{
			sumr -= x;
			sumr += y;
			s2.erase(s2.begin());
			s2.insert({-y,i});
			dp2[i] = sumr;
			
		}
		ans = max(ans,dp[i-1]-dp2[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 13952
#include<stdio.h>
int main(void)
{
    char N[4];
    int i;
  
    scanf("%s",N);
  
    for(i=0;i<3;i++){
      if(N[i]=='7'){
        printf("Yes\n");
        return 0;
      }
    }
  
    printf("No\n");
    
    return 0;
}


Measured memory_bytes: 1644
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const ll INF = 1e9;


/******************************************************************************************/


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	

	cout << "square1001" << endl;


	return 0;
}



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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 50 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, A, a[MN];
ll dp[MN][MN][2505];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> A;
    int sum = 0;
    for (int i = 1; i <= N; i++) cin >> a[i], sum += a[i];
    dp[0][0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= sum; k++) {
                dp[i][j][k] += dp[i - 1][j][k];
                if (j > 0 && k >= a[i]) {
                    dp[i][j][k] += dp[i - 1][j - 1][k - a[i]];
                }
            }
        }
    }
    ll ret = 0;
    for (int i = 1; i <= N; i++) ret += dp[N][i][i * A];
    cout << ret << '\n';
    return 0;
}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9)+7>;

const int MAXN = 1.1e6;
int N;
num dp[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	dp[0] = 1;
	dp[1] = -1;

	num ans = 0;
	for (int i = 0; i < N-1; i++) {
		// take a 1
		dp[i+1] += dp[i];
		dp[i+2] -= dp[i];

		// take a non-one and a non-one
		ans += dp[i] * num(N-1) * num(N-1);

		// take a non-one and ones
		ans += (N+1 - max(2, N-1-i)) * dp[i];
		if (i+3 <= N-1) {
			dp[i+3] += dp[i];
			dp[N] -= dp[i];
		}

		// fix the prefix
		dp[i+1] += dp[i];
	}

	ans += N * dp[N-1];

	dp[N] += dp[N-1];
	assert(dp[N] == 0);

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>
 int edge[10][10];
 int size[10];
 int used[10];
 int v,e;
 int res=0;
 void dfs(int x,int n){
 	if(used[x]) return;
 	if(n==v-1){
 		res++;
 		return;
 	}
 	used[x]=1;
 	for(int i=0;i<size[x];i++){
 		dfs(edge[x][i],n+1);
 	}
 	used[x]=0;
 	return;
 }
 int main(void)
 {
 	scanf("%d %d",&v,&e);
 	for(int i=0;i<e;i++){
 		int a,b;
 		scanf("%d %d",&a,&b);
 		edge[a][size[a]++]=b;
 		edge[b][size[b]++]=a;
 	}
 	dfs(1,0);
 	printf("%d\n",res);
 	return 0;
 }

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    for(int i=m/n; i>0 ; i--){
        if(!(m%i)) {
            cout << i  << endl;
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 55;
const int M = 2555;

ll dp[N][M];
int arr[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, A;
	cin>>n>>A;
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int k = n - 1; k >= 0; k--){
			for(int sum = 0; sum + arr[i] < M;  sum++){
				dp[k + 1][sum + arr[i]] += dp[k][sum];
			}
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += dp[i][A*i];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;


int main() {

    lli N;
    cin >> N;

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

    for (lli i = N - 1; i > 0; --i) {
        lli num = H[i];
        lli nextNum = H[i - 1];

        if (nextNum > num + 1) {
            // もう終わり
            cout << "No" << endl;
            return 0;
        } else if (nextNum - 1 == num) {
            // 一つ高い時は小さくする
            H[i - 1] = nextNum - 1;
        }
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  int ar[n];
  for(int i=0;i<n;i++) cin >> ar[i];
  map<int,int> mp;

  for(int i=0;i<n;i++) mp[ar[i]]++;

  int choose[n+1] = {0};
  int total = 0;

  for(auto p : mp){
    int have = p.second;
    choose[p.first] = (have*(have-1))/2;
    total+=choose[p.first];
  }

  for(int i=0;i<n;i++){
    int ans = total - choose[ar[i]];
    int have = mp[ar[i]] - 1;
    ans = ans + (have*(have-1)/2);
    cout << ans << '\n';
  }

  

  return 0;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {

	string s; cin >> s;
	
	s = s.substr(0,s.size()-8);
	cout << s << endl;
	return 0;
}


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> l(q), r(q);
  REP(i, q){
    cin >> l[i] >> r[i];
  }
  vector<int> res(n);
  bool before_a = false;
  int val = 0;
  REP(i, n){
    if (before_a and s[i] == 'C'){
      before_a = false;
      val++;
      res[i] = val;
    }
    else if(s[i] == 'A') {
      before_a = true;
      res[i] = val;
  }
    else{
      before_a = false;
      res[i] = val;
    }}
  REP(i, q){
    cout << res[r[i]-1] - res[l[i]-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 2240
n, m = list(map(int, input().split()))
l, r = [], []

for _ in range(m):
    a, b = list(map(int, input().split()))
    l.append(a)
    r.append(b)

if min(r) < max(l):
    print("0")
else:
    print(min(r) - max(l) + 1)

Measured memory_bytes: 11048
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n,x;
	cin >> n >> x;
	if(x == 1 || x == 2*n-1){
		puts("No");
	}
	else {
		puts("Yes");
		if(x <= n){
			rep1(i,x-2){
				printf("%d\n",i);
			}
			rep1(i,n-x){
				printf("%d\n",x+i);
			}
			printf("%d\n%d\n",x-1,x);
			for(int i = n+1 ; i <= 2*n-1 ; i ++){
				printf("%d\n",i);
			}
		}
		else {
			rep1(i,n-1)printf("%d\n",i);
			printf("%d\n%d\n",x,x+1);
			for(int i = n ; i < x ; i ++)printf("%d\n",i);
			for(int i = x+2 ; i <= 2*n-1 ; i ++)printf("%d\n",i);
		}
	}
}



Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>
#include <functional>
#include <set>
#include <cmath>

using namespace std;
#define get(x) if (DEBUG) cout << #x << " : " << x << endl;
#define print(x) if (DEBUG) cout << x << endl;
#define int long long
#define double long double

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

const int MAX = (int)1e6;
const long long INF = 1e18;

signed main() {
    fast();
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    int dp[n][n][2];
    for (int i = 0; i < n; ++i) {
        dp[i][i][0] = a[i];
        dp[i][i][1] = 0;
    }
    for (int len = 1; len < n; ++len) {
        for (int i = 0; i < n - len; ++i) {
            dp[i][i + len][0] = max(dp[i][i + len - 1][1] + a[i + len],
                                    dp[i + 1][i + len][1] + a[i]);
            dp[i][i + len][1] = min(dp[i][i + len - 1][0], dp[i + 1][i + len][0]);
        }
    }
    cout << 2 * dp[0][n - 1][0] - sum;

    return 0;
}

Measured memory_bytes: 140928
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A_ConnectionAndDisconnection solver = new A_ConnectionAndDisconnection();
        solver.solve(1, in, out);
        out.close();
    }

    static class A_ConnectionAndDisconnection {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            long k = in.nextLong();
            int[] groups = new int[s.length];
            int numGroups = 0;
            for (int i = 0; i < s.length; ) {
                int j = i;
                while (j < s.length && s[i] == s[j]) {
                    ++j;
                }
                groups[numGroups++] = j - i;
                i = j;
            }
            groups = Arrays.copyOf(groups, numGroups);
            if (numGroups == 1) {
                out.println(s.length * k / 2);
                return;
            }
            if (s[0] != s[s.length - 1]) {
                long each = 0;
                for (int g : groups) {
                    each += g / 2;
                }
                out.println(each * k);
                return;
            }
            long ans = 0;
            for (int i = 1; i + 1 < numGroups; i++) {
                ans += (groups[i] / 2) * k;
            }
            ans += ((groups[0] + groups[numGroups - 1]) / 2) * (k - 1);
            ans += groups[0] / 2;
            ans += groups[numGroups - 1] / 2;
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000

int main()
{
	int n;
	
	char t[2];
	int num;

	int flag[4][14] = { 0 };

	scanf("%d", &n);

	int i, j;

	for (i = 0; i < n; i++)
	{
		scanf("%s%d", t, &num);
		if (t[0] == 'S')
			flag[0][num] = 1;
		if (t[0] == 'H')
			flag[1][num] = 1;
		if (t[0] == 'C')
			flag[2][num] = 1;
		if (t[0] == 'D')
			flag[3][num] = 1;

	}

	for (i = 0; i < 4; i++)
	{
		for (j = 1; j <= 13; j++)
		{
			if (flag[i][j] == 0)
			{
				switch (i)
				{
				case 0:
					printf("S");
					break;
				case 1:
					printf("H");
					break;
				case 2:
					printf("C");
					break;
				case 3:
					printf("D");
					break;
				default:
					break;
				}

				printf(" %d\n", j);
			}
		}
	}

//	printf("\n");
	return 0;
}


Measured memory_bytes: 2056
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int VMAX = 16, INF = VMAX * 1000;
int dist[VMAX][VMAX];

int dp[1 << VMAX][VMAX];

void init(int V) {
  REP(i, V) {
    REP(j, V) {
      dist[i][j] = INF;
    }
  }
  REP(i, 1 << V) {
    REP(j, V) {
      dp[i][j] = INF;
    }
  }
}

void solve(int V) {
  dp[(1 << V) - 1][0] = 0;
  for (int S = (1 << V) - 1; S >= 0; S--) {
    for (int v = 0; v < V; v++) {
      for (int u = 0; u < V; u++) {
        if (!((S >> u) & 1)) {
          dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + dist[u][v]);
        }
      }
    }
  }
}

int main() {
  int V, E;
  cin >> V >> E;
  init(V);
  REP(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    dist[s][t] = d;
  }

  solve(V);

  cout << (dp[0][0] == INF ? -1 : dp[0][0]) << endl;
}

Measured memory_bytes: 5252
#include <math.h>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  cin >> N;

  vector<int> V(N);
  vector<int> C(N);

  rep(i, N) { cin >> V.at(i); }
  rep(i, N) { cin >> C.at(i); }

  int ans = 0;

  rep(i, N) {
    if (V.at(i) > C.at(i)) {
      ans += V.at(i) - C.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
   public static void main(String[] args){
     Scanner scanner = new Scanner(System.in);
     int S = scanner.nextInt();
     int h=S/3600;
     int m=(S-h*3600)/60;
     int s=S-h*3600-m*60;
       System.out.println(h+":"+m+":"+s);
      
   }   
}

Measured memory_bytes: 26076
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
int main(void){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  
  vector<int> q;
  int num = 1;
  int cnt = 0;
  for(int i=0; i<N; i++){
    char c = S[i];
    if(num == (c - '0')){
      cnt++;
    }else{
      q.push_back(cnt);
      num = 1-num;
      cnt = 1;
    }
  }
  if(cnt != 0) q.push_back(cnt);
  if(q.size()%2 == 0) q.push_back(0);
//  for(int i:q) cout << i << endl;
  
  int n = q.size();
  int sum[n+1];
  sum[0] = 0;
  for(int i=0; i<n; i++) sum[i+1] = sum[i] + q[i];
//  for(int i=0; i<n; i++) cout << q[i] << endl;
//  for(int i=0; i<=n; i++) cout << sum[i] << endl;
  int ans = 1;
  int k = 2*K+1;
  k = min(k, n);
  for(int i=0; 2*i+k<=min(n, N); i++){
    ans = max(ans, sum[2*i+k] - sum[2*i]);
//    cout <<  sum[2*i+k] - sum[2*i] << endl;
  }
  cout << ans << endl;
  return 0;
}

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

#define INF 102030405060708090

using P = pair<long long,tuple<int,int,int>>;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w,k;
  cin >> h >> w >> k;
  int sh,sw,gh,gw;
  cin >> sh >> sw >> gh >> gw;
  sh--;
  sw--;
  gh--;
  gw--;
  vector<vector<char>> c(h,vector<char>(w));
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cin >> c[i][j];
    }
  }
  vector<vector<vector<long long>>> mins(h,vector<vector<long long>>(w,vector<long long>(4,INF)));
  priority_queue<P,vector<P>,greater<P>> pq;
  vector<int> dh={0,1,0,-1};
  vector<int> dw={1,0,-1,0};
  for (int i=0;i<4;i++) {
    mins[sh][sw][i] = 0;
    pq.push(make_pair(0,make_tuple(sh,sw,i)));
  }
  while (!pq.empty()) {
    P nowp = pq.top();
    pq.pop();
    tuple<int,int,int> pos = nowp.second;
    long long dist = nowp.first;
    int nh = get<0>(pos);
    int nw = get<1>(pos);
    int dir = get<2>(pos);
    if (mins[nh][nw][dir] < dist) {
      continue;
    } 
    for (int i=0;i<4;i++) {
      if (i == dir) {
        int toh = nh+dh[i];
        int tow = nw+dw[i];
        if (toh < 0 || toh >= h || tow < 0 || tow >= w) {
          continue;
        }
        if (c[toh][tow] == '@') continue;
        if (mins[toh][tow][dir] > mins[nh][nw][dir]+1) {
          mins[toh][tow][dir] = mins[nh][nw][dir]+1;
          pq.push(make_pair(mins[nh][nw][dir]+1,make_tuple(toh,tow,dir)));
        }
      }
      else {
        long long kdis = mins[nh][nw][dir];
        kdis = (kdis+k-1)/k*k;
        if (mins[nh][nw][i] > kdis) {
          mins[nh][nw][i] = kdis;
          pq.push(make_pair(kdis,make_tuple(nh,nw,i)));
        }
      }
    }
  }
  long long ans = INF;
  for (int i=0;i<4;i++) {
    ans = min(ans,mins[gh][gw][i]);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << (ans+k-1)/k << endl;
}

Measured memory_bytes: 144720
#include <stdio.h>

int main(void)
{
	int field[20][20];
	int i, j, n;
	int x, y;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)	field[i][j] = 0;
		
		field[n / 2 + 1][n / 2] = 1;
		x = n / 2;
		y = n / 2 + 1;
		
		for (i = 1; i < n * n; i++){
			
			x++;y++;
			
			while (1){
				
				if (n <= x){
					x = 0;
				}
				else if (x < 0){
					x = n - 1;
				}
				else if (n <= y){
					y = 0;
				}
				else if (field[y][x] != 0){
					x--; y++;
				}
				else {
					break;
				}
			}
			field[y][x] = i + 1;
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++)	printf("%4d", field[i][j]);
			
			printf("\n");
		}
	}
	
	return (0);
}

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

int main()
{
	int N;
	while(cin >> N, N)
	{
		int b[100];
		for(int i=0; i<N; i++)
			cin >> b[i];
		
		int s, lo=0, hi=N-1, cnt=0;
		cin >> s;
		
		while(hi>=lo)
		{
			cnt++;
			int mi=(hi+lo)/2;
			if(b[mi]==s) break;
			
			s>b[mi]?lo=mi+1:hi=mi-1;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,b,r;
    cin>>n>>b>>r;
    ll ans=n/(b+r)*b;
    ll c=b;
    ll amari=n%(b+r);
    if(b==0){
        cout<<0<<endl;
        return 0;
    }
    if(amari==0){
        cout<<ans<<endl;
        return 0;
    }
    if(amari>=b){
        ans+=b;
    }
    else{
        ans+=amari;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
        LL n,W;
        cin>>n>>W;
        LL val[n];
        LL wt[n];
        fr(i,0,n) cin>>wt[i]>>val[i];
         LL i, w; 
         LL K[n + 1][W + 1]; 
  
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 

        cout<< K[n][W]<<endl;
    return 0;
}

Measured memory_bytes: 82324
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define ll long long
using namespace std;
struct node{
    ll t,l,h;
};
bool cmp(node a,node b){
    if(a.t!=b.t){
        return a.t<b.t;
    }else{
        return a.l<b.l;
    }
}
int main(){
    ll n;
    string ptr;
    cin>>n;
    map<string,int> mp;
    while(n--){
        cin>>ptr;
        mp[ptr]++;
    }
    map<string,int>::iterator it;
    int maxt=-1;
    for(it=mp.begin();it!=mp.end();it++){
    	if(it->second>maxt){
    		maxt=it->second;
		}
	}
	string arr[200005];
	int t=0;
	for(it=mp.begin();it!=mp.end();it++){
		if(it->second==maxt){
			arr[t++]=it->first;
		} 
	}
	sort(arr,arr+t);
    for(int i=0;i<t;i++){
    	cout<<arr[i]<<endl;
	}
    return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){ 
    int n, m;
    cin >> n >> m;
    int dis, dis_min, dis_min_index;
    long a[n], b[n], c[m], d[m];
    REP(i, n) cin >> a[i] >> b[i];
    REP(i, m) cin >> c[i] >> d[i];
    REP(i, n) {
        dis = 0;
        dis_min = (int)1e9;
        dis_min_index = 0;
        REP(j, m) {
            dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dis < dis_min) {
                dis_min = dis;
                dis_min_index = j;
            }
        }
        cout << dis_min_index + 1 << "\n";
    }
}

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

int main(){
  string s;
  int q;
  cin >> s >> q;
  deque<char> s_2;
  int l=s.size();
  //cout << l << endl;
  for(int i=0;i<l;i++){
    s_2.push_back(s[i]);
  }
  vector<int> t(q);
  vector<int> f(q);
  int count=0;
  for(int i=0;i<q;i++){
    cin >> t[i];
    if(t[i]==1){
      //reverse(s.begin(),s.end());
      count+=1;
    }else{
      cin >> f[i];
      char x;
      cin >> x;
      //cout << x << endl;
      if((f[i]+count)%2==0){
        s_2.push_back(x);
      }else{
        s_2.push_front(x);
      }
    }
  }
  if(count%2==1){
    reverse(s_2.begin(),s_2.end());
  }
  int l_1=s_2.size();
  //cout << l_1 << endl;
  for(int i=0;i<l_1;i++){
    cout << s_2[i];
  }
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<set>
#define int long long
using namespace std;

signed main() {
	int a, b,e;
	scanf("%lld", &a);
	e=b = a;
	for (int c = 2; c*c <= e; c++) {
		if (a%c == 0) {
			b = b*(c - 1) / c;
			while (a%c == 0) {
				a /= c;
			}
		}
	}
	if (a != 1) {
		b=b*(a - 1) / a;
	}
	cout << b << endl;
}

Measured memory_bytes: 3192
function getLines(input){
	return input.split("\n").map((s)=>s.trim())
}
function parseLine(line){
	return line.split(" ").map((s)=>s.trim());
}
function parseLineToInt(line){
	return line.split(" ").map((s)=>parseInt(s.trim()));
}
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.	
	input = getLines(input).map(parseLineToInt);
	var a = input[1];
	var n=input[0][0];
	var x=input[0][1];
	a.sort((z,t)=>(z-t));
	i=0;
	var ans =0;
	while(x>0 && i<n){
		if(x>=a[i]){
			x-=Math.min(x,a[i++]);
			ans++;
		}else{
			break;
		}
	}
	if(x>0 && i==n)
		ans--;
	console.log(ans);
}
// Don't edit this line!
//Main(require("fs").readFileSync(__dirname+'/in.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

struct P{
    string name;
    int win;
    int lose;
    int even;
    int total;
    static bool more (const P& left,const P& right){
        return left.total > right.total;
    }
};

int main(){
    int n;
    int cnt;
    bool b = false;
    while(1){
        cnt = 0;
        cin >> n;
        if(n == 0) break;
        if(b) cout << endl;
        else b = true;
        vector <P> data;
        P tmp;
        for(int i=0;i<n;i++){
            cin >> tmp.name >> tmp.win >> tmp.lose >> tmp.even;
            tmp.total = tmp.win*3 + tmp.even;
            data.push_back(tmp);
            cnt++;
        }
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<cnt;i++){
            cout << data[i].name << "," << data[i].total << endl;
        }
    }
}

Measured memory_bytes: 1220
n,m = map(int,input().split())
a = list(map(int,input().split()))
#合計で何日かかるかを計算して
s = sum(a)
#遊べる日数はn-sで、n-s<0になったら宿題終わらないので-1を出す
print(max(-1,n-s))


Measured memory_bytes: 9984
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M, X;
  cin >> N >> M >> X;
  usll A;
  REP(i, 0, M) {
    ll a;
    cin >> a;
    A.emplace(a);
  }

  ll v0 = 0;
  REV(i, X, -1) {
    if (A.find(i) != A.end()) {
      v0++;
    }
  }

  ll v1 = 0;
  REP (i, X, N+1) {
    if (A.find(i) != A.end()) {
      v1++;
    }
  }

  cout << min(v0, v1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
int n, p;
cin >> n;
int min = n;
int count = 0;  
for (int i=0; i<n; i++){
  	
	cin >> p;
  	if(p==1){
      count++;
      break;
    }
        
	if (p <= min){
      count++;
      min = p;        
    }
	}
  cout << count << endl;
}


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

using namespace std;

int a, b, c, count = 0;

int main(){
    cin >>a >> b >> c;
    for(int i=a; i<=b; ++i){
        if(c%i==0) count++;
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int N, K;
string S;

int main() {
    cin >> N >> K >> S;
    char target = S[K-1];
    char upper = target - 'A' + 'a';
    cout << S.substr(0, K-1) << upper << S.substr(K,N-1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  int F[100][10] = {};
  int P[100][15] = {};
  REP(i, n) {
    REP(j, 10) {
      cin >> F[i][j];
    }
  }
  REP(i, n) {
    REP(j, 11) {
      cin >> P[i][j];
    }
  }
  ll ret = -10000000000;
  for (int bit = 1; bit < (1<<10); bit++) {
    int x = 0;
    for (int i = 0; i < n; i++) {
      int t = 0;
      for (int j = 0; j < 10; j++) {
	if (bit&(1<<j) && F[i][j]) {
	  t++;
	}
      }
      x += P[i][t];
    }
    if (ret < x) {
      ret = x;
    }
  }
  dump(ret);
  return 0;
}


Measured memory_bytes: 256
import scala.io._

// e.g
// 1 2 3
// val Array(a, b) = readLine.split(" ").map(_.toInt) => Array(1, 2, 3)
// 5
// 1 2 3
// 4 5 6
// 7 8 9
// val lines = Source.stdin.getLines()
// データ個数読み取り
// val n = lines.next().toInt
// データ行n個読み取り
// val data = lines.take(n).map{ line => line.split(" ").map(_.toInt).toList }.toList => List(List(1, 2, 3), List(4, 5, 6), List(7, b, 9))

object Main {
  def main(args: Array[String]): Unit = {
    val s: String = readLine
    if (s(1) == '9' || s(0) == '9') {
      println("Yes")
    }else {
      println("No")
    }

  }
}


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

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



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

struct Card{
    char suit;
    int value;
};

void BubbleSort(Card C[], int N){
    int i, j;
    for(i=0; i<N; i++){
        for(j=N-1; j>i; j--){
            if(C[j].value < C[j - 1].value) swap(C[j], C[j-1]);
        }
    }
}

void SelectionSort(Card C[], int N){
    int i, j, minj;
    for(i=0; i<N; i++){
        minj = i;
        for(j=i; j<N; j++){
            if(C[j].value < C[minj].value) minj = j;
        }
        swap(C[i], C[minj]);
    }
}

void print(Card C[], int N){
    int i;
    for(i=0; i<N; i++){
        if(i) printf(" ");
        printf("%c%d", C[i].suit, C[i].value);
    }
    printf("\n");
}

bool isStable(Card C1[], Card C2[],  int N){
    int i;
    for(i=0; i<N; i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(){
    int N, i;
    Card C1[36], C2[36];

    scanf("%d", &N);
    for(i=0; i<N; i++) cin >> C1[i].suit >> C1[i].value;
    for(i=0; i<N; i++) C2[i] = C1[i];

    BubbleSort(C1, N);
    SelectionSort(C2, N);
    print(C1, N);
    printf("Stable\n");
    print(C2, N);
    if(isStable(C1, C2, N)) printf("Stable\n");
    else printf("Not stable\n");

    return 0;  
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000009
int main()
{ 		
 string s;
  cin >> s;
  int x = (s[0] - '0') * 10 + s[1] - '0';
  int y = (s[2] - '0') * 10 + s[3] - '0';
  if(x > 0 && x <= 12 && y > 0 && y <= 12)
   return  cout << "AMBIGUOUS" , 0;
  if(x > 0 && x <= 12 )
  	return cout << "MMYY" ,0;
  if(y > 0 && y <= 12 )
    return cout << "YYMM",0;
  cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

void yay(bool f){
    if(f) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    if(k>1)cout << (n-k)<< endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 764
import sys
n = int(input())
ls = [0] * n
for i in range(n):
    ls[i] = int(input())
ls.sort()
# 長さ2なら例外処理する
if n == 2:
    print(abs(ls[0]-ls[1]))
    sys.exit()
if n % 2 == 1:
    # biggerを2つとる方
    smaller = ls[:n//2+1]
    bigger = ls[n//2+1:]
    diff_1 = 2 * sum(bigger) - 2*sum(smaller) + smaller[-1] + smaller[-2]
    # smallerを2つとる方
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff_2 = -2 * sum(smaller) + 2 * sum(bigger) - bigger[0] - bigger[1]
    diff = max(diff_1,diff_2)
else:
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff = 2 * sum(bigger) - min(bigger) - 2 * sum(smaller) + max(smaller)

print(diff)

Measured memory_bytes: 14100
//in the name of GOD//
#include <bits/stdc++.h>

using namespace std;

int n, g, x, y;
bool b = false;

int main()
{
	cin >> n;
	
	for(int i = 0; i<n; i++)
	{
		cin >> x>> y;
		if(x == y)
		{
			g++;
		}
		else
		{
			g = 0;
		}
		if(g == 3)
		{
			b = true;
		}	
	}
	
	b == true? cout << "Yes":cout << "No";
	
	
	return 0;
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int a[N];
int main() {
	ios_base::sync_with_stdio(0);
	int a,b,c;
	cin >> a >> b >> c;
	int x = x * 100 + b * 10 + c;
	if (x % 4 == 0)
		cout << "YES\n";
	else
		cout << "NO\n";
  	return 0;
}




Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()

print(s.count('ABC'))

Measured memory_bytes: 31136