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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

ll a[16][16];
ll dp[1 << 16];
ll gain[1 << 16];

int main2() {
  int N = nextInt();
  REP(i, N) REP(j, N) a[i][j] = nextInt();
  CLR(dp, 0);
  
  REP(s, 1 << N) {
    ll sum = 0;
    REP(i, N) if (s >> i & 1) 
    REP(j, i) if (s >> j & 1)
    {
      sum += a[i][j];
    }
    gain[s] = sum;
  }

  int MASK = (1 << N) - 1;
  for (int done = 0; done < (1 << N); done++) {
    int ini = ~done & MASK;
    for (int nxt = ini; nxt != 0; nxt = (nxt - 1) & ini) {
      chmax(dp[done | nxt], dp[done] + gain[nxt]);
    }
  }
  ll ans = dp[MASK];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1408
def is_odd_by_2(n):
    r = (n+1) // 2
    return r % 2 == 1

def is_odd_by_n(n, d):
    m = n % d
    if m >= (d // 2):
        return m % 2 == 0
    else:
        return False

A, B = [int(v) for v in input().split()]

bin_num = ''
if is_odd_by_2(B) ^ is_odd_by_2(A - 1):
    bin_num += '1'
else:
    bin_num += '0'

div_max = 1
while B >= (2 ** div_max):
    div_max += 1

for i in range(2, div_max + 1):
    d = 2 ** i
    is_odd = is_odd_by_n(B, d)
    if A >= 1:
        is_odd = is_odd ^ is_odd_by_n(A - 1, d)
    if is_odd:
        bin_num = '1' + bin_num
    else:
        bin_num = '0' + bin_num

print(int(bin_num, 2))


Measured memory_bytes: 3064
#!/usr/bin/env ruby
n, k = gets.chomp.split.map(&:to_i)
mod = 10 ** 9 + 7


ans = 0

k.upto(n + 1) do |i|
  min = i * (i - 1) / 2
  max = i * (2 * n - i + 1) / 2

  ans += (max - min + 1)
  ans %= mod
end

puts ans


Measured memory_bytes: 14308
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////////////////////

// c++17での名前衝突を避けるためdefine
#define gcd nyagcd
#define lcm nyalcm
ll nyagcd(ll x, ll y){
  ll z;
  if(x > y) swap(x,y);
  while(x){
    x = y % (z = x); y = z;
  }    
  return y;
}
ll nyalcm(ll x,ll y){
  return 1LL * x / gcd(x,y) * y;
}

void solve(){
  /*
  inl(N , M);
  vl a(N); in(a);
  ll nya = 1;
  rep(i , N){
    nya = lcm(nya , a[i] / 2);
    if(nya > M) die(0);
  }
  rep(i , N){
    if(nya % a[i] == 0) die(0);
  }
  if(nya == M) die(1);
  M -= nya;
  nya *= 2;
  out(M / nya + 1);
  */
  ini(N); ins(S);
  ll ans = 0;
  rep(i , N - 2){
    if(S.substr(i , 3) == "ABC") ans++;
  }
  out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
string s;
int main(){
  cin >> s;
  for (size_t i = 0; i < 8; i++) {
    s.pop_back();
  }
  cout << s << endl; 
}


Measured memory_bytes: 256
using System;

namespace Sumple1
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            long  n = cin.NextLong();
            long sum = 0;
            for (long i = 1; i <= n; i++)
            {
                if((i%3)==0 & (i%5) == 0)
                {
                    //FizzBuzz
                }else if ((i % 3) == 0)
                {
                    //Fizz
                }else if ((i % 5) == 0)
                {
                    //Buzz
                }
                else
                {
                    sum += i;
                }

            }
            Console.WriteLine(sum);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 27488
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

#define MAX_N   (200000)                  // 10^5
#define MAX_K   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

ll N, K;
ll CNT[MAX_N + 1];
Pl P[MAX_N + 1];

void merge(int l, int r) {
  if (r - l <= 1) return;
  int m = (l + r) / 2;
  merge(l, m); merge(m, r);

  int nl = m - l, nr = r - m;
  vector<Pl> vl(nl), vr(nr);
  for (int i = 0; i < nl; i++) vl[i] = P[l + i];
  for (int i = 0; i < nr; i++) vr[i] = P[m + i];

  int il = 0, ir = 0;
  while(true) {
    if (il >= nl && ir >= nr) {
      break;
    } else if (il >= nl || (ir < nr && vr[ir].FST >= vl[il].FST)){
      P[l + il + ir] = vr[ir]; ir++;
    } else {
      CNT[vl[il].SND] += ir;
      P[l + il + ir] = vl[il]; il++;
    }
  }
}

void solve() {
  for (int i = 0; i < N + 1; i++) CNT[i] = 0;

  merge(0, N + 1);

  #ifdef DEBUG
  for (int i = 0; i < N + 1; i++) cout << CNT[i] << " ";
  cout << endl;
  #endif

  ll ans = 0;
  for (int i = 0; i < N + 1; i++) ans += CNT[i];

  cout << ans << endl;
}

int main() {
  cin >> N >> K;
  P[0] = Pl(0, 0);
  ll sum = 0;
  for (int i = 1; i <= N; i++) {
    ll a;
    cin >> a;
    sum += a;
    P[i] = Pl(sum - K * i, i);
  }

#ifdef DEBUG
  for (int i = 0; i < N + 1; i++) cout << P[i].FST << " ";
  cout << endl;
#endif

  solve();

  return 0;
}


Measured memory_bytes: 8204
#include<bits/stdc++.h>
using namespace std;
typedef struct{int to,w;}dat;
main(){
  int n;
  cin>>n;
  vector<vector<dat>> adj(n);
  vector<bool> col(n),vis(n,false);
  for(int i=1;i<n;++i){
    int a,b,c;
    cin>>a>>b>>c;
    a--; b--; c=2-c%2;
    adj[a].push_back({b,c});
    adj[b].push_back({a,c});
  }
  queue<int> que;
  col[0]=false;
  que.push(0);
  while(!que.empty()){
    int q = que.front(); que.pop();
    vis[q]=true;
    for(auto d:adj[q])if(!vis[d.to]){
      col[d.to]=(d.w%2)^(col[q]);
      que.push(d.to);
    }
  }
  for(auto i:col)cout<<i<<endl;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int A,B,K;
  cin>>A>>B>>K;
  if ((B-A+1)>2*K) {
    for (int i=0; i<K; i++) {
      cout<<A+i<<endl;
    }
    for (int i=K-1; i>=0; i--) {
      cout<<B-i<<endl;
    }
  } else {
    for (int i=A; i<=B; i++) {
      cout<<i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() {
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if(a + b < 2 * c) {
        if(x > y) {
            ans = (a + b) * y + min(2 * c * (x - y), a * (x - y));
        }
        else {
            ans = (a + b) * x + min(2 * c * (y - x), b * (y - x));
        }
    }
    else {
        if(x > y) {
            ans = y * 2 * c + min(a, 2 * c) * (x - y);
        }
        else {
            ans = x * 2 * c + min(b, 2 * c) * (y - x);
        }
    }
    cout << ans << 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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,l,r,ans=0;
    cin>>n;
    rep(i,n){
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

ll mod_pow(ll x, ll n, int mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;

}
int n;
int s[100001];
int ans[100001];

int dp [100001] [2] [2] [2] [2];

bool dfs(int cur, int bbk, int bk, int ck, int ek) {
	if (cur == n - 1) {
		ans[n-1] = ek;
		
		bool f = 0;
		if (ck) {
			if (s[cur] && ans[0] == ans[n - 2])
				f = 1;
			else if (!s[cur] && ans[0] != ans[n - 2])
				f = 1;
		}
		else {
			if (s[cur] && ans[0] != ans[n - 2])
				f = 1;
			else if (!s[cur] && ans[0] == ans[n - 2])
				f = 1;
		}
		if (f && ck == ek) {
			REP(i,n) {
				printf("%c",ans[i]?'S':'W');
			}
			printf("\n");
			return 1;
		}
		return 0;

	}
	if (dp[cur][bbk][ck][ck][ek] != -1)
		return dp[cur][bbk][ck][ck][ek];

	int nk;
	if (ck) {
		if (s[cur])
			nk = bk;
		else
			nk = 1 - bk;
	}
	else {
		if (s[cur])
			nk = 1-bk;
		else
			nk = bk;
	}
	ans[cur] = ck;
	ans[cur-1] = bk;
	return  dp[cur][bbk][ck][ck][ek] = dfs(cur + 1, bk, ck, nk, ek);
}

signed main() {
	scanf("%d%*c", &n);
	REP(i, n) {
		char c;
		scanf("%c", &c);
		s[i] = c == 'o';
	}
	Fill(dp, -1);
	if (s[0]) {
		if (dfs(1, 1, 1, 1, 1))
			return 0;
		if(dfs(1, 0, 1, 0, 0))
			return 0;
		if (dfs(1, 1, 0, 0, 1))
			return 0;
		if (dfs(1, 0, 0, 1, 0))
			return 0;
	}
	else {
		if (dfs(1, 1, 1, 0, 1))
			return 0;
		if (dfs(1, 0, 1, 1, 0))
			return 0;
		if (dfs(1, 1, 0, 1, 1))
			return 0;
		if (dfs(1, 0, 0, 0, 0))
			return 0;
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  
  for(int i = n - 1; i >= n - k; i--){
    ans += a[i];
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
lr=[]
for i in range(n):
  x,l=map(int,input().split())
  lr.append((x-l,x+l))
lr.sort(key=lambda x: x[1])
ans=0
l=-10**18
r=0
for i in range(n):
  if i==0:
    tl,tr=lr[i]
    l=tl
    r=tr
    ans+=1
    continue
  tl,tr=lr[i]
  if tl>=r:
    ans+=1
    r=tr
    l=tl
print(ans)





Measured memory_bytes: 18260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N; cin >> N;
	int MAX_A = 0, MIN_B = 1000000000;
	rep(i, N) {
		int A, B; cin >> A >> B;
			MAX_A = max(MAX_A, A); MIN_B = min(MIN_B, B);
	}
	cout << MAX_A + MIN_B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
using namespace std;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



int main(void){
    ll n,m,a,b,c,sa,sc,sb;
    vector<vector<ll>> x(8);
    cin>>n>>m;
    rep(j,n){
        cin>>a>>b>>c;
        rep(i,8){
            sa=sb=sc=1;
            if (i&(1<<0))sa=-1;
            if (i&(1<<1))sb=-1;
            if (i&(1<<2))sc=-1;
            x[i].push_back(a*sa+b*sb+c*sc);
        }
    }
    rep(i,8){sort(x[i].begin(),x[i].end());}
    //long long ans=0;
    vector<ll> ans(8);
    rep(i,8){ans[i]=0;}
    
    rep(i,8){
        rep(j,m){
            ans[i]+=x[i][n-1-j];
        }
    }
    cout<<*max_element(ans.begin(),ans.end())<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
vector<int> a;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	for(int i=0;i<k;i++){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
	int n, k;
	while(cin >> n >> k) {
		if (n == 0 && k == 0) {
			break;
		}
		vector<int> data(n+1, 0);
		int a;
		for (int i = 0; i < k; i++) {
			cin >> a;
			data[a] = 1;
		}
		int MAX = data[n];
		for (int i = n-1; i > 0; i--) {
			if (data[i] == 0 || data[i+1] == 0) {
			} else {
				data[i] += data[i+1];
			}
			MAX = max(MAX, data[i]);
		}
		if (data[0] == 1) {
			for (int i = 1; i <= n; i++) {
				if (data[i] > 0) {
					if (i+data[i] < n) {
						MAX = max(MAX, data[i]+1);
						if (i+data[i]+1 < n) {
							MAX = max(MAX, data[i]+data[i+data[i]+1]+1);
						}
					}
				} else {
					MAX = max(MAX, 1);
					if (i+1 < n) {
						MAX = max(MAX, data[i+1]+1);
					}
				}
			}
		}
		cout << MAX << endl;
	}
	return 0;
}

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

ll check(vector<ll> a) {
    int n = a.size();

    ll ans = 0;
    while (1) {
        bool f = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] >= n) {
                f = 1;
                ll k = a[i] / n;
                ans += k;
                a[i] %= n;
                for (int j = 0; j < n; j++) if (i != j) a[j] += k;
            }
        }
        if (!f) break;
    }

    return ans;
}

/*ll check(vector<ll> a) {
    int n = a.size();

    ll l = -1, r = 1e18;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll need = 0;
        for (int i = 0; i < n; i++) {
            need += a[i] / (n + 1) + (a[i] % (n + 1) == n);
            if (need > m) need = m + 1;
        }
        if (need <= m) r = m;
        else l = m;
    }

    ll ans = r;
    return ans;
}*/

const ll INF = 1e16 + 100;

vector<ll> gen(ll k) {
    int n = 50;
    vector<ll> a(n);

    ll t = (k + n - 1) / n;
    for (int i = 0; i < n; i++) a[i] = t + i;

    int x = (n - k % n) % n;
    for (int i = 0; i < x; i++) {
        a[n - 1 - i] -= n;
        a[n - 1 - i] += x - 1;
    }
    for (int i = x; i < n; i++) {
        a[n - 1 - i] += x;
    }

    //cerr << check(a) << " instead of " << k << endl;
    assert(check(a) == k);
    return a;
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    //gen(1e16);
    //cerr << check(vector<ll>(50, 1e16 + 100)) << endl;

    /*for (int it = 0;; it++) {
        ll x = abs(rand());
        cerr << it << " " << x << endl;
        gen(x);
    }*/
    /*int n;
    while (cin >> n) {
        vector<ll> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        cout << check(a) << endl;
    }*/

    ll k;
    while (cin >> k) {
        auto a = gen(k);
        cout << a.size() << endl;
        for (int i = 0; i < (int)a.size(); i++) cout << a[i] << " \n"[i + 1 == (int)a.size()];
    }

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end

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

    string s;
    in >> s;
    stack<char> output;
    REP(i, s.size()){
        if(s[i] == '0'){
            output.push('0');
        }else if(s[i] == '1'){
            output.push('1');
        }else{
            if(!output.empty()){
                output.pop();
            }
        }
    }
    int n = output.size();
    string ans[n];
    REP(i, n){
        ans[i] = output.top();
        output.pop();
    }
    REP(i, n){
        out << ans[n-i-1];
    }
    out << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b >> x;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
  if(x >= a && a+b >= x) anss = "YES";
  else anss = "NO";

  cout << anss << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
X = int(input())

ans = 1
b = 2
while X >= b :
  p = 2
  while X >= b**p :
    ans = max(ans, b**p)
    p += 1
  b += 1
print (ans)


Measured memory_bytes: 38256
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll, ll>
#define ALL(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define forab(i,a,b) for(ll i=a;i<b;i++)
#define clr(x) memset(x, 0, sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define endl "\n"
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define eps 1e-10
#define nedl endl
const ll sz = 1e6;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;

ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}

int main() {
    IOS;
    
    
	
    ll T = 1; //cin >> T;
    while (T--) {
		ll k;cin>>k;
		ll xx=0;
		forn1(a,k+1){
			forn1(b,k+1){
				forn1(c,k+1){
					xx+=__gcd(a,__gcd(b,c));
					
					
				}}}
			cout<<xx<<endl;
		
		
		
    }
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
long long q,h,s,x,y,ans,k;
int main()
{
    cin>>q>>h>>s>>x>>y;
    k=min(q*4,min(h*2,s));
    if(k*2<=x)
    {
        cout<<k*y<<endl;
    }
    else
    {
        cout<<((y%2)*k)+y/2*x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int maxx = 0;
    int sub = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(maxx <= a[i]){
            sub = maxx;
            maxx = a[i];
            
        }else if(sub < a[i]){
            sub = a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i] == maxx)cout << sub << endl;
        else cout << maxx<<endl;
    }
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define maxn 505050

using namespace std;
typedef long long ll;
ll dp[maxn],a[maxn],n,k;
int main(){
    cin >> n >> k;
    for (int i=1;i<=n;i++) cin >> a[i];
    dp[1]=0;
    for (ll i=2;i<=n;i++){
        dp[i]=1e18;
        for (int j=1;j<min(k+1,i);j++)
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int x = scanner.nextInt();

    if ( a > x ) {
      System.out.println("NO");
    } else if ( (a + b) < x ) {
      System.out.println("NO");
    } else {
      System.out.println("YES");
    }

  }

}

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

const int SIZE=200000;
bool f[SIZE];
int main(){
    vector<int>p;
    f[0]=f[1]=true;
    for(int i=2;i<SIZE;i++){
        if(f[i])continue;
        p.push_back(i);
        for(int j=i+i;j<SIZE;j+=i)f[j]=true;
    }

    for(int i=1;i<p.size();i++)p[i]+=p[i-1];
    
    int n;
    while(cin>>n,n)cout<<p[--n]<<endl;

    return 0;
}

Measured memory_bytes: 1540
N = int(input())
A = [int(_) for _ in input().split()]
L = sorted(A)[::-1]
mul = []
flag = 0
tmp = 0

for i in range(1, N):
    if flag == 1 and i == tmp + 1:
        continue
    if L[i] == L[i-1] and flag == 0:
        mul.append(L[i])
        tmp = i
        flag += 1
    elif L[i] == L[i-1] and flag == 1:
        mul.append(L[i])
        flag += 1
        break

print(mul[0]*mul[1] if flag == 2 else 0)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        double xa,ya,ra,xb,yb,rb;
        cin>>xa>>ya>>ra>>xb>>yb>>rb;
        double a_b=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
        double rab=ra+rb;
        int ans;
        if(a_b-rab>0)ans=0;
        else if(rb-(a_b+ra)>0)ans=-2;
        else if(ra-(a_b+rb)>0)ans=2;
        else ans=1;
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 1232
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(H: int, W: int, S: "List[str]"):
    S = [list(s) for s in S]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue
            counter = 0
            for k in [-1, 0, 1]:
                for l in [-1, 0, 1]:
                    if k == 0 and l == 0:
                        continue
                    if i+k <= -1 or i+k >= H:
                        continue
                    if j+l <= -1 or j+l >= W:
                        continue
                    if S[i+k][j+l] == "#":
                        counter += 1
            S[i][j] = str(counter)

    print(*["".join(s) for s in S], sep="\n")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int a[10];
    for(int i = 1; i <= 5; i++)cin>>a[i];
    int k;
    cin>>k;
    bool flag = true;
    for(int i = 1; i <= 5; i++)
    {
        for(int j = i+1; j <= 5; j++)
        {
            int s = fabs(a[i]-a[j]);
            if(s > k)
            {
                flag = false;
                break;
            }
        }
    }
    if(!flag){
        cout<<":("<<endl;
    }else
    {
        cout<<"Yay!"<<endl;
    }

    return 0;
}


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

// THINK: INT vs LONG LONG?

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

	int n; cin >> n;
	vector<int> a(n);
	for (auto& x : a) cin >> x;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] ^ a[j]) {
				for (int k = j + 1; k < n; ++k) {
					if (a[i] ^ a[k] && a[j] ^ a[k] && (ll) a[i] + a[j] + a[k] > (ll) 2 * max(a[i], max(a[j], a[k]))) {
						ans++;
					}
				}
			}
		}
	}
	cout << ans << '\n';

	return 0;
}

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

using namespace std;

bool exist[31];
int n;
int main(){
	for(int i = 0;i < 28;i++){
		cin >> n;
		exist[n] = true;
	}
	for(int i = 1;i <= 30;i++){
		if(!exist[i]) cout << i << endl;
	}
	return 0;
}

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

int R, G, B, N;

int main() {
  cin >> R >> G >> B >> N;

  int cnt = 0;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if ((N - R * i - G * j) % B == 0 && (N - R * i - G * j) >= 0) cnt++;
    }
  }
  cout << cnt << endl;
}


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

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

  int ans = 1;
  for (int b = 2; b <= x; ++b) {
    for (int p = 2; pow(b, p) <= x; ++p) {
      ans = max(ans, (int)pow(b, p));
    }
  }

  cout << ans << endl;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  int A = 1;
  int counter = 0;
  
  for(int i = 0; i < N; i++){
    if(A < K){
      A *= 2;
    }else{
      A += K;
    }
  }

  cout << A << endl;
  
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>> 
#define pqmin priority_queue <int,vector <int>,greater<int>> 
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define ps(x,y) fixed << setprecision(y) << x
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(int x=y;x<z;x++)
#define si size()
#define ps(x,y) fixed << setprecision(y) << x
#define countdigit(x) floor( log10(x) +1)
#define M 1000000007  
//Use (k%M+m)%m always where k is any no
#define PI 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> pdbs; 
// null for set,mapped_type for map; 
//less for assending greater for descending
//ceil(a/b)=(a+b-1)/b
#define ee "\n"
#define re return 
 
 
 
//Author Rahul Sannigrahi
 
vector<int> take(int n)
{
    int i,j;
    vi v;
    f(i,0,n)
    {
        cin>>j;
        v.pb(j);
    }
    return v;
}
 
void show(vector<int>v)
{
    int i;
    for(i=0;i<v.si;i++)
    {
     cout<<v[i]<<" ";   
    }
    cout<<ee;
}
 
int decode()
{
   int x;
   cin>>x;
   cout<<!x<<ee;
    re 0;
}
 
int32_t main()
{
    IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif 
    
    int t=1;
    //cin>>t;
    while(t--)
    decode();
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  int ans = (a+b+1)/2;
  cout<<ans;
  

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        double ans;
        if (n % 2 == 0) {
            ans = 0.5;
        } else {
            ans = (n / 2 + 1.0) / n;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	int S, W;
	
	scanf("%d %d", &S, &W);
	
	if(S <= W) {
		printf("unsafe\n");
	} else {
		printf("safe\n");
	}
	
	return 0;
}


Measured memory_bytes: 1656
N = int(input())
S = 0
Tri = [0,1,3,6,10,15,21,28,36,45,55,66,78,91]
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
A = factorization(N)

if N > 1:
    for i in range (len(A)):
        T = A[i][1]
        j = 0
        while(T>=Tri[j]):
            j += 1
        S += (j-1)
                

print(S) 

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

int main() {
  int H , W;
  cin >> H >> W;
  vector<vector<char>> data(H,vector<char>(W));
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      cin >> data.at(i).at(j);
    }
  }
  int count1=0;
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      if (data.at(i).at(j)=='#'){
        break;
      }
      if (j==W-1){
        for (int k=0;k<W;k++){
          data.at(i).at(k)='&';
        }
      }
    }
  }
  for (int j=0;j<W;j++){
    for (int i=0;i<H;i++){
      if (data.at(i).at(j)=='#'){
        break;
      }
      if (i==H-1){
        for (int k=0;k<H;k++){
          data.at(k).at(j)='&';
        }
      }
    }
  }
  for (int i=0;i<H;i++){
    int sum=0;
    for (int j=0;j<W;j++){
      if (data.at(i).at(j)!='&'){
        cout << data.at(i).at(j);
      }
      else{
        sum++;
      }
      if (sum<W && j==W-1){
        cout << endl;        
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

int main(){
  ll n,h,w,ans=0;cin>>n>>h>>w;
  vector<ll>a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    if(h<=a[i] && w<=b[i])ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void putcolor(int[10][10],int,int);

int main(void) {
	int paper[10][10];
	int x,y,size;
	int nocolor,mostkoi;
	for(y=0;y<10;y++) {
		for(x=0;x<10;x++)paper[x][y]=0;
	}
	while(1) {
		if(scanf("%d,%d,%d",&x,&y,&size)==-1)break;
		switch(size) {
			case 3:
				putcolor(paper,x-2,y);
				putcolor(paper,x+2,y);
				putcolor(paper,x,y-2);
				putcolor(paper,x,y+2);
			case 2:
				putcolor(paper,x-1,y-1);
				putcolor(paper,x+1,y-1);
				putcolor(paper,x-1,y+1);
				putcolor(paper,x+1,y+1);
			case 1:
				putcolor(paper,x-1,y);
				putcolor(paper,x+1,y);
				putcolor(paper,x,y-1);
				putcolor(paper,x,y+1);
		}
		putcolor(paper,x,y);
	}
	mostkoi=0;nocolor=0;
	for(y=0;y<10;y++) {
		for(x=0;x<10;x++) {
			if(paper[x][y]==0)nocolor++;
			if(paper[x][y]>mostkoi)mostkoi=paper[x][y];
		}
	}
	printf("%d\n",nocolor);
	printf("%d\n",mostkoi);
	return 0;
}

void putcolor(int paper[10][10],int x,int y) {
	if(x<0 || x>=10 || y<0 || y>=10)return;
	paper[x][y]++;
}

Measured memory_bytes: 0
N=int(input())

#f(N)を入れるリスト。f(1)=ans_list[0], f(N)=ans_list[N-1]
ans_list=[0]*N

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            s=x**2+y**2+z**2+x*y+y*z+z*x
            if s<=N:
                ans_list[s-1]+=1
            
   
for i in range(N):
   print(ans_list[i])
            


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
int main(){
  ll x ;
  cin >> x ;
  if(digsum(x)==1) cout <<10<<endl ;
  else
   cout<<digsum(x)<<endl; 
    return 0;
}

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

int sum(int n){
  int x=0;
  while(n>0){
    x+=n%10;
    n/=10;
    }
    return x;
    }
    
int main() {
int n,a,b,s;
cin>>n>>a>>b;
s=0;
for(int i=1;i<=n;i++){
  int p =sum(i);
  if(p>=a&&p<=b)s+=i;
  }
  cout<<s<<endl;

return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;




int main()
{
	IOS;
	ll check = 0;
	string str;
	cin >> str;
	for (auto ele : str) {
		check += ele - '0';
	}
	if (check % 9 == 0)cout << "Yes";
	else cout << "No";





}

Measured memory_bytes: 3732
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

int sum[101010];

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

	int pre = 0;
	rep(i, 0, n) {
		if (s[i] == 'A') { 
			pre = 1; 
			continue;
		}
		else if (s[i] == 'C' && pre) { 
			sum[i+1] = 1;
		}
		pre = 0;
	}
	rep(i, 0, 101005) {
		sum[i + 1] += sum[i];
	}

	rep(i, 0, q) {
		int l, r;
		cin >> l >> r;
		if (l >= 2 && s[l-1] == 'C' && s[l-2] == 'A') {
			cout << sum[r] - sum[l] << endl;
		}
		else {
			cout << sum[r] - sum[l - 1] << endl;
		}
	}
	return 0;
}

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

int dp[3002][3002];
string s, t;

int solve(int x, int y) {
	if(x == s.size() || y == t.size()) return 0;
	int &ret = dp[x][y];
	if(ret != -1) return ret;
	if(s[x] == t[y]) ret = solve(x+1, y+1) + 1;
	else {
		ret = max(solve(x+1, y), solve(x, y+1));
	}
	return ret;
}

string ans;
void build(int x, int y) {
	if(x == s.size() || y == t.size()) return;
	if(s[x] == t[y]) {
		ans.push_back(s[x]);
		build(x+1, y+1);
	}
	else {
		if(solve(x+1, y) >= solve(x, y+1)) build(x+1, y);
		else build(x, y+1);
	}
}

int main() {
	memset(dp, -1, sizeof(dp));
	cin>>s>>t;
	int temp = solve(0, 0);
	build(0, 0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;


int n;
int dp[100100];

int main() {
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  rep(i,100100) dp[i] = INF;
  dp[0] = 0;
  rep(i,n) {
    if(i<n-1) dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    if(i<n-2) dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

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

int main() {
    int H, N;  cin >> H >> N;
    for (int i = 0; i < N; ++i) {
        int a;  cin >> a;
        H -= a;
    }
    if (H <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, r = 0; cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j * i < n; j++) {
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


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

int n;
int dp[3];

main()
{
    scanf("%d",&n);
    scanf("%d %d %d",&dp[0],&dp[1],&dp[2]);
    for(int i=1;i<n;i++)
    {
    	int be[3];
    	for(int j=0;j<3;j++)
    	{
    		be[j]=dp[j];
		}
    	int a,b,c;
    	scanf("%d %d %d",&a,&b,&c);
    	dp[0]=max(be[1]+a,be[2]+a);
    	dp[1]=max(be[0]+b,be[2]+b);
    	dp[2]=max(be[0]+c,be[1]+c);
	}
	int ans=max(dp[0],dp[1]);
	ans=max(ans,dp[2]);
	printf("%d\n",ans);
}


Measured memory_bytes: 256
N = int(input())

S = [["" for i in range(10)] for j in range(N)]
for i in range(N):
    tmp = list(input())
    tmp_s = sorted(tmp)
    S[i] = tmp_s
S_s = sorted(S)
res = 0
i = 0
while i<N:
    j = 1
    count = 1
    while i+j<N and S_s[i] == S_s[i+j]:
        j = j + 1
        count = count + 1

    if count > 1:
        res += count*(count-1)//2
    else:
        res += 0
    i = i + j

print(res)


Measured memory_bytes: 25392
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, R; cin >> N >> R;
    cout << R + 100 * (10 - min(10, N)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int a[30];

signed main(){
	string s;
	cin>>s;
	string ans="No";
	lp(i,4){
		a[s[i]-'A']++;
	}
	int cnt=0;
	lp(i,30){
		if(a[i]==2)cnt++;
	}
	if(cnt==2)ans="Yes";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())

ans = 0

if (x == 3) : ans += 100000
if (x == 2) : ans += 200000
if (x == 1) : ans += 300000
if (y == 3) : ans += 100000
if (y == 2) : ans += 200000
if (y == 1) : ans += 300000

if ((x == 1)&(y == 1)) : ans += 400000

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

struct Transition{
    int x, y, nx, ny;
    Transition() = default;
    Transition(int x, int y, int nx, int ny) : x(x), y(y), nx(nx), ny(ny) {}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a[i][j];
        }
    }
    vector<Transition> res;
    for(int i = 0; i < h - 1; ++i){
        for(int j = 0; j < w; ++j){
            if(a[i][j] % 2 == 0)    continue;
            a[i][j] -= 1;
            a[i+1][j] += 1;
            res.emplace_back(Transition(i, j, i+1, j));
        }
    }
    for(int i = 0; i < w - 1; ++i){
        if(a[h-1][i] % 2 == 0)  continue;
        a[h-1][i] -= 1;
        a[h-1][i+1] += 1;
        res.emplace_back(Transition(h -1, i, h-1, i+1));
    }
    int sz = res.size();
    cout << sz << "\n";
    for(int i = 0; i < sz; ++i){
        int x = res[i].x, y = res[i].y, nx = res[i].nx, ny = res[i].ny;
        cout << x + 1 << " " << y + 1 << " " << nx + 1 << " " << ny + 1 << "\n";
    }
}

Measured memory_bytes: 5236