akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;
int N;
string S;

int main() {
  cin >> N >> S;
  int ma = 0;
  int pos = 0;
  for (int i=0; i<N; i++) {
    if (S.at(i) == 'I') {
      pos++;
    } else {
      pos--;
    }
    ma = max(pos, ma);
  }

  cout << ma << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    LL N,D,A; cin >> N >> D >> A;
    vector<pair<LL,LL>> XH(N);
    REP(i,N){
        LL x,h; cin >> x >> h;
        XH[i] = make_pair(x,h);
    }
    sort(XH.begin(),XH.end());

    VL imos(N+10);
    LL now = 0;
    LL ans = 0;
    REP(i,N){
        now -= imos[i];
        LL x,h;
        tie(x,h) = XH[i];
        dump(x)
        dump(now)
        if(now >= h){
            ;
        }else{
            h -= now;
            LL add = (h+A-1) / A;
            dump(h)
            dump(add)
            ans += add;
            now += add * A;
            int idx = lower_bound(XH.begin(),XH.end(),PLL(x+2*D+1,0)) - XH.begin();
            //dump(idx)
            imos[idx] += add * A;
        }

    }
    cout << ans << endl;

}


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

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

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

using namespace std;


signed main() {
  int H, A;
  cin >> H >> A;

  cout << (H+A-1)/A << endl;

  return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  char s[h][w + 1];

  for (int i = 0; i < h; i++) cin >> s[i];

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

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a = 0;
      if (s[i][j] == '#') continue;

      for (int k = 0; k < 8; k++) {
        if (i + dy[k] >= 0 && i + dy[k] < h && 
            j + dx[k] >= 0 && j + dx[k] < w) {
          if (s[i + dy[k]][j + dx[k]] == '#') a++;
        }
      }

      s[i][j] = '0' + a;
    }
  }

  for (int i = 0; i < h; i++) cout << s[i] << endl;
  return 0;
}


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

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

#define REP(i  ,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)

int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	while(true){
		int sum,buf;
		cin>>sum;
		if(sum==0) break;

		REP(j, 9){
			cin>>buf;
			sum-=buf;
		}
		cout<<sum<<en;
	}

	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
long long int weight[110], value[110], dp[100100];
 
int main(){
    int n, w;   cin >> n >> w;
    for(int i=1;n>=i;i++){
        cin >> weight[i] >> value[i];
    }
    for(int i=1;n>=i;i++){
        for(int j=w;j>=0 and weight[i]<=j;j--){
            dp[j]=max(dp[j-weight[i]]+value[i], dp[j]);
        }
    }
    long long int ans=0;
    for(int i=1;w>=i;i++){
        ans=max(ans, dp[i]);
    }
    cout << ans;
}

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

N = int(input())
op = []
ed = []
mid = [0]
dg = 10**7

for _ in range(N):
    s = list(input())
    n = len(s)-1

    a,b,st = 0,0,0
    for e in s:
        if e == '(':
            st += 1
        elif e == ')':
            if st > 0:
                st -= 1
            else:
                a += 1
    st = 0
    for i in range(n-1,-1,-1):
        if s[i] == ')':
            st += 1
        else:
            if st > 0:
                st -= 1
            else:
                b += 1
    if a > b:
        ed.append(b*dg + a)
    elif a == b:
        mid.append(a)
    else:
        op.append(a*dg + b)

op.sort()
ed.sort()

p = 0
for e in op:
    a,b = divmod(e,dg)
    if p < a:
        print('No')
        exit()
    p += b-a

q = 0
for e in ed:
    b,a = divmod(e,dg)
    if q < b:
        print('No')
        exit()
    q += a-b

if p == q and p >= max(mid):
    print('Yes')
else:
    print('No')


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int Cmax = C;
  
  if(B>A){
    for(int i=0; i<K ;i++){
    Cmax = Cmax*2;
    }
    if(Cmax>B){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    int Bmax = B;
    for(int i=0; i<K ;i++){
      Bmax = Bmax*2;
      if(Bmax>A){
        for(int j=0; j<K-i-1 ;j++){
          Cmax = Cmax*2;
        }
        if(Cmax>Bmax){
        cout << "Yes" << endl;
        }
        else{
        cout << "No" << endl;
        }
        break;
      }
    }
    
    if(Bmax<=A){
      cout << "No" << endl;
    }
  }
  
}



Measured memory_bytes: 3576
/*　　　　　　　{:i:i:|:i:i:/l/--　 　 　 --l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:iィi芥ミ 　 　 .ィi芥ミｉ:ｉ:|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ: {::’:} 　 　 　 {:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨´ 　 　　　 ｀¨¨´:i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　 
*/
#include <bits/stdc++.h>
using namespace std;
int k,a,b;
int main(){
    cin>>k>>a>>b;
    if(a%k==0)k=a;
    else k=a/k*k+k;
    if(a<=k&&k<=b)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

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

    double answer = 0;
    for(int i = 1; i <= n; i++) {
      int c = 0;
      int s = i;
      while(s < k) {
        s = s*2;
        c++;
      }

      double p = 1;
      for(int j = 0; j < c; j++) {
        p = p/2;
      }
      answer += p/n;
    }

    System.out.println(answer);
  }
}

Measured memory_bytes: 21844
import sys, itertools, collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n, x = lmi()
l = lmi()
c = 1
d = 0
for i in range(n):
    d += l[i]
    if d <= x:
        c += 1
    else:
        break

print(c)


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if (s < t) cout << "Yes" << endl;
    else       cout << "No" << endl;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n , A , B;

int main(){
  scanf("%d%d%d",&n,&A,&B);
  if(A + B - 1 <= n && n <= 1ll * A * B) {
    int s = 1 , remain = n - A - B + 1;
    vi v;
    auto add = [&](int from,int to) {
      per(i,from,to) v.pb(i);
    };
    add(s , s + B);
    s += B;
    rep(i,1,A) {
      int inc = min(remain , B - 1);
      remain -= inc;
      add(s , s + 1 + inc);
      s += 1 + inc;
    }
    rep(i,0,sz(v)) printf("%d%c",v[i]," \n"[i+1==sz(v)]);
  } else
    puts("-1");
  return 0;
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
bool ok(string s,string t){
	for(int i=0;i<s.size();i++){
		if(s[i]!='?'&&s[i]!=t[i])return false;
	}
	return true;
}
int main(){
	string s,t;
	cin>>s>>t;
	string res="";
	for(int i=0;i<s.size()-t.size()+1;i++){
		string s2=s.substr(i,t.size());
		if(ok(s2,t)){
			string cnt=s;
			for(int j=0;j<t.size();j++){
				cnt[i+j]=t[j];
			}
			for(int j=0;j<i;j++){
				if(cnt[j]=='?')cnt[j]='a';
			}
			for(int j=i+t.size();j<s.size();j++){
				if(cnt[j]=='?')cnt[j]='a';
			}
			if(res==""||cnt<res)res=cnt;
		}
	}
	if(res==""){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	else cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-9;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAXN = 1e5;
const int MAX = 45;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	
	LL n, k;
	cin >> n >> k;

	if (k == 0)
	{
		LL ans = n * n;
		cout << ans;
		return 0;
	}

	LL ans = 0;

	FOR(b, 1, n + 1)
	{
		if (k >= b)
			continue;

		LL x = (n + 1) / b - 1;
		ans += (b - k) * (x + 1);
		int y = (x + 1) * b + k;
		if (y <= n)
			ans += (n - y + 1);
	}

	cout << ans;
	cin >> n;
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  LCIN(X);

  if (X == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 0ll;
  
  FOR(i, 1, 1001) {
    ll tmp = (ll)i;
    FOR(j, 2, 1001) {
      tmp *= (ll)i;
      if (tmp > X) break;
      ans = max(ans, tmp);
      // debug(i);
      // debug(j);
      // debug(tmp);
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    string a, b, c;
    long long d;
    cin >> a >> b;
    c = a + b;
    d = atoi(c.c_str());

        for (long long j = 1; j * j <= d; j++)
        {
            if(j*j==d){
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}

int dp[200005][2];
void solve()
{
  
  string s;
  cin >> s;
  
  forf(j,0,sz(s))
  {
    if(s[j]=='?') s[j]='D';
  }
  
  cout<<s<<endl;
}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }
      

Measured memory_bytes: 3748
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
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;}
const long long INF = 1LL << 60;

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

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    N, D = map(int, input().split())
    x_list = []
    for i in range(N):
        x_list.append(list(map(int, input().split())))

    def dist(x, y):
        d = 0
        for xi, yi in zip(x, y):
            d += (xi-yi)**2
        return d

    import math
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            d = math.sqrt(dist(x_list[i], x_list[j]))

            if d - int(d) == 0:
                cnt += 1

    print(cnt)
solve()

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

int main(){
    int n;
    cin >> n;
    int d1, d2;
    int cnt = 0;
    rep(i,n){
        cin >> d1 >> d2;
        // cout << d1 << " " << d2 << endl;
        if(d1 == d2){
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
#include<vector>


using namespace std;


//比較数列vector とkeyを受け取ってあれば1,なければ0

int binarysea(vector<int> S,int key){
  int left = 0;
  int right = S.size();
  int mid =0;
  while(left<right){
      mid = (left+right)/2;
       if(S[mid]==key)return 1;
       else if(key<S[mid])right = mid;
       else left = mid+1;
  }
  return 2;
}





int main(){

    int N =0;
    int q = 0;
    int x = 0;
    int temp=0;
    int count =0;

    cin >> N;
    vector<int> S;
    vector<int> T;

    for(int i=0;i<N;i++){
       cin >> temp;
       S.push_back(temp);
    }

    cin >> q;

    for(int i=0;i<q;i++){
        cin >> temp;
        T.push_back(temp);
     }

     for(int i=0;i<q;i++){
         x=binarysea(S,T[i]);
        if(x==1)count++;
     }


      cout << count<<endl;
 
    return 0;
}


Measured memory_bytes: 4176
#include<stdio.h>
#include<math.h>
 
int main(void)
{
    int n;
    int i;
    int x[100];
    int y[100];
    int z[100];
    double L_1 = 0, L_2 = 0, L_3 = 0, L_inf;
     
    scanf("%d\n", &n);
    for(i = 0; i<n; i++)
        scanf("%d", &x[i]);
    for(i = 0; i<n; i++)
        scanf("%d", &y[i]);
    for(i = 0; i<n; i++) {
        z[i] = (x[i] - y[i]>0)? x[i] - y[i]: y[i] - x[i];
        if(i == 0) L_inf = z[0];
        else {
            if(z[i] > L_inf) L_inf = z[i];
        }
    }
     
    for(i=0; i<n; i++) {
        L_1 += z[i];
        L_2 += z[i] * z[i];
        L_3 += z[i] * z[i] * z[i];
    }
     
    L_2=pow(L_2, 1.0/2);
    L_3=pow(L_3, 1.0/3);
     
    printf("%f\n%f\n%f\n%f\n", L_1, L_2, L_3, L_inf);
     
    return 0;
}



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

typedef long long ll;
const ll INF = numeric_limits<ll>::max();

ll getMinCount (const vector <ll> &arr) {
    int n = arr.size();
    vector <vector <ll>> dp(n, vector <ll> (n, INF));

    for (int left = n - 1; left >= 0; --left) {
        for (int right = left; right < n; ++right) {
            if (left == right) {
                dp[left][right] = 0;
            } else {
                dp[left][right] = INF;
                ll sum = accumulate(arr.begin() + left, (arr.begin() + right + 1), (ll)0);
                for (int i = left; i < right; ++i) {
                    dp[left][right] = min(dp[left][right], dp[left][i] + dp[i + 1][right] + sum);
                }
            }
        }
    }
    return dp[0][n - 1];
}

int main() {
    int n;
    cin >> n;
    vector <ll> arr(n);
    for (ll &a : arr) {
        cin >> a;
    }
    ll result = getMinCount(arr);
    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, a, b;
	cin >> n >> a >> b;
	if (a + b - 1 <= n && n <= a * b) {
		int cn = a * b;
		vector<int> bl(b);
		int pnt = cn - a;
		for (int i = 0; i < b; i++) {
			bl[i] = pnt;
			pnt -= a;
		}
		vector<int> ans;
		int delta = cn - n;
		for (int i = 0; i < b; i++) {
			int skip = min(delta, a - 1);
			if (i == 0) skip = 0;
			delta -= skip;
			for (int j = skip; j < a; j++) {
				ans.push_back(bl[i] + j);
			}
		}
		{
			vector<int> v = ans;
			sort(v.begin(), v.end());
			for (auto &t : ans) {
				t = lower_bound(v.begin(), v.end(), t) - v.begin();
			}
		}
		for (auto t : ans) {
			cout << t + 1 << ' ';
		}
		cout << '\n';
	} else {
		cout << -1 << endl;
	}
}


Measured memory_bytes: 7404
#!/usr/bin/env python3
N = int(input())

d = {}

m = 0
for i in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
    if d[S] > m: m = d[S]

ans_l = []

for k, v in d.items():
    if v==m: ans_l.append(k)

ans_l = sorted(ans_l)

for ans in ans_l:
    print(ans)


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

const int MOD = 1e4 + 7;

int conv[256];
int n;
int sche[1001];
int dp[1001][1 << 3];

int search(int i, int peo)
{
	int &res = dp[i][peo];
	if ((peo & sche[i]) == 0) return res = 0;
	if (~res) return res;
	if (i == n) return res = 1;
	
	res = 0;
	for (int x = 1; x < (1 << 3); x++){
		if ((x & peo) == 0) continue;
		res += search(i + 1, x);
		res %= MOD;
	}
	return res;
}

int main()
{
	conv['J'] = 1;
	conv['O'] = 1 << 1;
	conv['I'] = 1 << 2;
	
	memset(dp, -1, sizeof(dp));
	
	sche[0] = 1;
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		char c;
		scanf(" %c", &c);
		sche[i + 1] = conv[c];
	}
	
	printf("%d\n", search(0, 1));
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans;
    if (N <= K) 
    {
        ans = min(N, abs(K - N));
    }
    else
    {
        ll div = N / K;
        ll num = N - div * K;
        ans = min(num, abs(num - K));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
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; }
int r,D,x;

int solve(int X){
    int Y = r*X-D;
      return Y;
}

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

    cin >> r >> D >> x;
    int ans  = 0;
    REPP(i,2001,2011){
        cout << solve(x) << endl;
        x = solve(x);
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include<bits/stdc++.h>
typedef long long int ll;
const int maxn=1e6+7;
using namespace std;
//四步走，
//确定状态 1、最后一步2、化成子问题
//转移方程
//初始条件和边界情况
//计算顺序，确保要用到的都算过
ll aa[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>aa[i];
    ll ans=0;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(aa[i]>ans)ans=aa[i];
        else{
            sum+=ans-aa[i];
        }
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,len,pdA[110000],pdB[110000];
struct atom{
	int w,where;
}A[210000];
int compare(atom k1,atom k2){
	return k1.w<k2.w;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		int k1; scanf("%d",&k1);
		A[++len]=(atom){k1,i};
	}
	for (int i=1;i<=m;i++){
		int k1; scanf("%d",&k1);
		A[++len]=(atom){k1,-i};
	}
	sort(A+1,A+len+1,compare);
	int num1=m+1,num2=n+1;
	long long ans=0;
	for (int i=1;i<=len;i++)
		if (A[i].where>0){
			num2--; ans+=1ll*A[i].w*num1;
		} else {
			num1--; ans+=1ll*A[i].w*num2;
		}
	cout<<ans<<endl;
}
	

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    int n_odd = 0;
    int n_even = 0;
    for (int i = 0; i != N; ++i){
        int a;
        cin >> a;
        if (a & 1){
            ++n_odd;
        }else{
            ++n_even;
        }
    }
    if (P == 1 and n_odd == 0){
        cout << 0 << endl;
    }else if (n_odd == 0){
        cout << (1LL << n_even) << endl;
    }else{
        cout << (1LL << (N - 1)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	char a[101], b[101];
	scanf("%s%s", a, b);
	int cnt = 100, lenA = strlen(a), lenB = strlen(b);
	for (int i = lenA; i >= 0; i--) {
		a[cnt] = a[i];
		cnt--;
	}
	for (int i = 0; i < 100 - lenA; i++) {
		a[i] = '0';
	}
	cnt = 100;
	for (int i = lenB; i >= 0; i--) {
		b[cnt] = b[i];
		cnt--;
	}
	for (int i = 0; i < 100 - lenB; i++) {
		b[i] = '0';
	}
	// printf("%s\n%s\n", a, b);
	int cmp = strcmp(a, b);
	if (cmp == 0) {
		printf("EQUAL\n");
	} else if (cmp < 0) {
		printf("LESS\n");
	} else {
		printf("GREATER\n");
	}

	return 0;
}

Measured memory_bytes: 128
def main():
    S = input()
    a = S[:2]
    b = S[2:]

    if int(a) > 0 and int(a) < 13 and int(b) > 0 and int(b) < 13:
        print('AMBIGUOUS')
    elif int(a) > 0 and int(a) < 13:
        print('MMYY')
    elif int(b) > 0 and int(b) < 13:
        print('YYMM')
    else:
        print('NA')


if __name__ == '__main__':
    main()


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

namespace AGC030
{
    class A
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            int A = int.Parse(s1[0]);
            int B = int.Parse(s1[1]);
            int C = int.Parse(s1[2]);

            int avail = Math.Min(C, A + B + 1) + B;
            Console.WriteLine(avail);
        }
    }
}


Measured memory_bytes: 13140
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  int n; cin >> n;
  vector <ll> a(n);
  for(auto &x : a) cin >> x;
  ll xr = 0;
  for(int i = 2; i < n; i++) xr ^= a[i];
  ll sum = a[0] + a[1];
  
  if(sum % 2 != xr % 2) {
    print(-1);
    return;
  }
  
  // a[0] ^ a[1] = xr ... (1)
  // we know,
  // a[0] + a[1] = a[0] ^ a[1] + 2 * a[0] & a[1]
  // a[0] + a[1] = xr + 2 * a[0] & a[1] (from (1))
  // (a[0] & a[1]) = (a[0] + a[1] - xr) / 2
  
  ll ando = (sum - xr) / 2ll;
  if((ando > a[0]) or (ando & xr)) {
    print(-1);
    return;
  }
  for(int i = 40; i >= 0; i--) {
    if(!((xr >> i) & 1)) continue;
    if((ando | (1LL << i)) > a[0]) continue;
    ando |= (1LL << i);
  }
  if(ando == 0) print(-1);
  else print(a[0] - ando);
}

int main() {
  int t; t = 1;
  while(t--) solve();
}




Measured memory_bytes: 3580
N, L = map(int, input().split())
A = [L+(x+1)-1 for x in range(N)]
min_abs = abs(A[0])
eat = A[0]
for i in range(len(A)):
  if min_abs > abs(A[i]):
    min_abs = abs(A[i])
    eat = A[i]
print(sum(A)-eat)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n ; cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    REP(i,n){
        if (a[i] % 2 == 0){
            if (a[i]%3!=0 && a[i]%5!=0){
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
template <class T>
vector<ll> countVector(vector<T>v,T guard=0){
    ll size=v.size();
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}
ll gcd(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(){
	init();
	ll N;cin>>N;
	WeightedGraph<ll>g(N);
	for(int i=0;i<N-1;i++){
		ll a,b,c;cin>>a>>b>>c;
		a--;b--;
		g[a].emplace_back(b,c);
		g[b].emplace_back(a,c);
	}
	auto v=dijkstra(g,0);
	for(int i=0;i<N;i++)cout<<v[i]%2<<endl;
}


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

const long double EPS = 1e-15;

long double dp[3010][3010];
long double p[3010];

int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	dp[1][0] = 1 - p[1], dp[1][1] = p[1];
	for (int i = 2; i <= n; i++){
		for (int j = 0; j <= i; j++){
			if (j) dp[i][j] += dp[i - 1][j - 1] * p[i];
			dp[i][j] += dp[i - 1][j] * (1 - p[i]);
		}
	}
	long double ans = 0;
	for (int i = (n + 1) / 2; i <= n; i++){
		ans += dp[n][i];
	}
	cout << fixed << setprecision(11) << ans << endl;
	return 0;
}


Measured memory_bytes: 139904
import * as fs from "fs";

let [N_str, A_str, B_str, C_str] = fs.readFileSync("/dev/stdin", "utf8").trim().split('\n');
let N = Number(N_str);
let A = A_str.split(' ').map(Number).sort((a, b) => {return a-b;});
let B = B_str.split(' ').map(Number).sort((a, b) => {return a-b;});
let C = C_str.split(' ').map(Number).sort((a, b) => {return a-b;});


let B_lower = new Array(N).fill(0);
let B_higher = new Array(N).fill(0);

let lowerCount = 0, higherCount = 0;
for(let i=0; i<N; i++) {
    while (lowerCount < N && A[lowerCount] < B[i]) {
        lowerCount += 1;
    }
    while (higherCount < N && C[N-(higherCount+1)] > B[N-i-1]) {
        higherCount += 1;
    }
    B_lower[i] = lowerCount;
    B_higher[N-i-1] = higherCount;
}

let answer = 0;
for(let i=0; i<N; i++) {
    answer += B_lower[i]*B_higher[i];
}

console.log(answer);


Measured memory_bytes: 58236
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (int& x : a) cin >> x;
	
	long long ans = 0;
	int l = 0, r = 0;
	int sub;
	while (l < n) {
		if (r <= l) {
			r = l + 1;
			sub = a[l];
		}
		while (r < n) {
			if ((sub & a[r]) == 0) {
				sub |= a[r];
				r++;
			}
			else break;
		}
		
		ans += (long long)(r - l);
		sub ^= a[l];
		l++;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 1024
#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);

  string a;
  cin >> a;
  vector<ll> cnt(26,0);
  ll n=a.size();
  rep(i,n){
    int idx = a[i]-'a';
    cnt[idx]++;
  }
  ll ans = n*(n-1)/2+1;
  rep(i,26){
    ans -= cnt[i]*(cnt[i]-1)/2;
  }
  
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 720
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    long X;
    long Y;

    Main(long X, long Y) {
        this.X = X;
        this.Y = Y;
    }

    public static void main(String args[]) {
        Scanner Input = new Scanner(System.in);
        long N = Input.nextLong();
        long M = Input.nextLong();
        ArrayList<Main> Student = new ArrayList();
        ArrayList<Main> Checkpoint = new ArrayList();
        ArrayList<Long> Values = new ArrayList();
        for (int I = 0; I < N; I++) {
            Student.add(new Main(Input.nextLong(), Input.nextLong()));
        }
        for (int I = 0; I < M; I++) {
            Checkpoint.add(new Main(Input.nextLong(), Input.nextLong()));
        }
        long LastIndex = 1;
        for (int I = 0; I < Student.size(); I++) {
            long Min = 1999999999;
            for (int J = 0; J < Checkpoint.size(); J++) {
                long X = Math.abs(Student.get(I).X - Checkpoint.get(J).X) + Math.abs(Student.get(I).Y - Checkpoint.get(J).Y);
                //System.out.println(X + "X");
                if (X < Min) {
                    Min = X;
                    //System.out.println(X + "XXX");
                    LastIndex = J + 1;
                    //System.out.println(LastIndex + "JJJ");
                }
            }
            System.out.println(LastIndex);
        }

    }
}// You Wont Learn If You Always Copy

Measured memory_bytes: 23764
# encoding:utf-8
import copy
import numpy as np
import random

s = int(input())


def func(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1

a = [s]
tmp = s
for i in range(1,10**6):
    tmp = func(tmp)
    if tmp in a:
        print(i+1)
        exit()
    else:
        a.append(tmp)


Measured memory_bytes: 20236
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


int pref[N];
void solve()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	rep(i, sz(s) - 1){
		if(s[i] == 'A' && s[i + 1] == 'C') pref[i + 1] = 1;
		if(i) pref[i + 1] += pref[i];
	}
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << pref[r - 1] - pref[l - 1] << '\n';
	}
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<double > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;
    
    ll ans = 0;
    vector<ll > A(N, 0);
    vector<ll > B(N, 0);
    vector<ll > sum(N, 0);

    for(ll i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        sum[i] = A[i] + B[i];
        ans -= B[i];
    }

    sort(sum.rbegin(), sum.rend());

    for(ll i = 0; i < N; i++){
        if(i % 2 == 0) ans += sum[i];
    }

    cout << ans << endl;

}



Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
    int a[100] = {};
    int n = 0;
    int i = 0;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (i = n - 1; i >= 0; i--)
    {
        printf("%d", a[i]);
        if (i == 0) 
        {
            printf("\n");
            break;
        }
        printf(" ");
    }
}


Measured memory_bytes: 2588
#include<cstdio>
#include<vector>
#include<queue>
#include<utility>
#include<climits>
#include<algorithm>
 
using namespace std;
 
typedef long long ll;
typedef pair<pair<long, long>, pair<int, int> > P;
 
int main(){
    int n,d;
    while(scanf("%d%d", &n, &d) && n){
        vector<ll> missile[n];
        int m;
        ll min_ = LLONG_MAX, max_ = 1LL;
        bool ans = true;
        for(int i=0;i<n;i++){
            scanf("%d", &m);
            ll c[m], total = 0;
            for(int j=0;j<m;j++){
                scanf("%lld", &c[j]);
                total += c[j];
            }
            missile[i].resize(m+1);
            missile[i][0] = total;
            for(int j=0;j<m;j++) missile[i][j+1] = missile[i][j] - c[m-1-j];
        }
 
        vector<ll> indexes(n, 0);
        while(max_){
            ll mindiff = INT_MAX, diff_i, mindiff_min;
            for(int i=0;i<n;i++){
                if(missile[i][indexes[i]] == 0) continue;
                min_ = INT_MAX;
                max_ = 0LL;
                for(int j=0;j<n;j++){
                    int jj = indexes[j] + ((j==i && missile[j][indexes[j]])?1:0);
                    min_ = min(min_, missile[j][jj]);
                    max_ = max(max_, missile[j][jj]);
                }
                if(max_ - min_ >= 0 && mindiff > max_ - min_){
                    mindiff = max_ - min_;
                    diff_i = i;
                    mindiff_min = min_;
                }
            }
 
            indexes[diff_i]++;
            min_ = mindiff_min;
            max_ = mindiff_min + mindiff;
            if(max_ - min_ > d){
                ans = false;
                break;
            }
            // for(int i=0;i<n;i++)printf("%5lld", missile[i][indexes[i]]);
            // printf("\n");
        }
 
        printf("%s\n", ans?"Yes":"No");
    }
}


Measured memory_bytes: 2652
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> Point;
#define X real()
#define Y imag()
#define LE(n,m) ((n)<(m)+EPS)
#define GE(n,m) ((n)+EPS>(m))
#define EQ(n,m) (abs((n)-(m))<EPS)
const double EPS=1e-8;

//center of circle going through two given points of which radius equals to r
vector<Point> centergivenradius(const Point &a,const Point &b,const double &r){
    vector<Point> cs;
    Point ls=(b-a)*0.5;
    double dist=abs(ls);
    if (dist==0.0||dist>r) return cs;
    double len=sqrt(r*r-dist*dist);
    Point n=ls*Point(0.0,1.0)*(len/dist);
    cs.emplace_back(a+ls+n);
    if (GE(len,0.0)) cs.emplace_back(a+ls-n);
    return cs;
}

void solve(int N){
    vector<Point> P;
    for (int i=0;i<N;++i){
        double x,y; cin >> x >> y;
        P.emplace_back(x,y);
    }
    int ans=1;
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            double dist=norm(P[i]-P[j]);
            if (GE(dist,4.0)) continue;
            vector<Point> center=centergivenradius(P[i],P[j],1.0);
            for (int l=0;l<2;++l){
                int cnt=2;
                for (int k=0;k<N;++k){
                    if (k==i||k==j) continue;
                    cnt+=(LE(norm(P[k]-center[l]),1.0));
                }
                ans=max(ans,cnt);
            }
        }
    }
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while(cin >> N,N){
        solve(N);
    }
}


Measured memory_bytes: 3352
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int r;
    cin >> r;
    cout << setprecision(15) << 2 * M_PI * r << endl;
    return 0;
}

Measured memory_bytes: 3260
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(int i =(a);i<(n);i++)
#define urep(i,a,n) for(int i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

ll W, H, N,ans,a,b,w,n,m,d;
ll A[200000];
string s;
int main() {
	cin >> n >> m >> d;
	int d1 = d;
	int d2 = n - d;
	if(d!=0)ans = (n- 2*d) * 2;
	if (ans < 0)ans = 0;
	if (n / 2 < d)d = n - d;
	ans += d*2;
	if (d == 0)ans += n;
	ans *= m - 1;
	double num = ans;
	for (ll i = 0; i < 2; i++) {
		num /= n;
	}
	cout << setprecision(7)<<num << endl;
	cin >>ans;
	return 0;
}

Measured memory_bytes: 256
def calculate_mp(a, b, path, mp_sum):
    if a == b:
        return mp_sum
    cand = [k for k in range(10) if k not in path]
    mp_sum_list = []
    for c in cand:
        mp_sum_list.append(calculate_mp(c, b, path + [c], mp_sum + C[a][c]))
    return min(mp_sum_list)

H, W = [int(i) for i in input().split()]
C = []
for i in range(10):
    c = [int(i) for i in input().split()]
    C.append(c)
D = [0 for i in range(10)]
for i in range(10):
    D[i] = calculate_mp(i, 1, [i], 0)
cnt = 0
for i in range(H):
    A = [int(i) for i in input().split()]
    for a in A:
        if a != -1:
            cnt += D[a]
print(cnt)


Measured memory_bytes: 48108
import numpy as np

A,B,H,M = map(int,input().split())

th_a = 30*H + 0.5 * M
th_b = 6*M

theta = th_a -th_b

if theta <= 0:
  theta = -theta
if theta >= 180:
  theta = 360 - theta

if theta == 0:
  if A >= B:
    print(A-B)
  else:
    print(B-A)

elif theta == 180:
  print(A+B)

else:
  print(np.sqrt(A**2 + B**2 - 2*A*B*np.cos(theta*np.pi/180)))

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

map<long long,long long> mp;
long long n,m,a,b,c,ans;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a;
		mp[a]++;
	}
	for(int i=0;i<m;i++){
		cin>>b>>c;
		mp[c]+=b;
	}
	map <long long,long long > :: iterator it;
	for(it=--mp.end();;it--){
		ans+=min(n,it->second)*it->first;
		n-=it->second;
		if(n<0) break;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16076
#include<iostream>
#define M 250000
int b[M+1],i,j,c;main(){for(b[0]=b[1]=i=1;++i<=M;)for(j=i+i;j<=M;j+=i)b[j]=1;for(;std::cin>>j,j;printf("%d\n",c))for(c=0,i=j;++i<=2*j;)c+=!b[i];}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  string s; cin >> s;
  int n = s.size();
  int w = 0;
  rep(i,n) if(s[i] == 'o') w++;
  if(15-n+w >= 8) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 256