akhauriyash/Code-Regression huggingface dataset:
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: AmShZ6
 * Time: 2020-05-30 16:35:36
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , dp[MAXN][2] , prv[MAXN][2];
string s;

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

    cin >> s; n = SZ(s); s = "." + s;
    dp[0][1] = -MOD;
    for(int i = 1 ; i <= n ; i++){
        if(s[i] == 'P' || s[i] == '?'){
            dp[i][1] = max(dp[i - 1][0] , dp[i - 1][1]);
            prv[i][1] = (dp[i - 1][0] > dp[i - 1][1] ? 0 : 1);
        }
        if(s[i] == 'D' || s[i] == '?'){
            dp[i][0] = max(dp[i - 1][0] + 1 , dp[i - 1][1] + 2);
            prv[i][0] = (dp[i - 1][0] + 1 > dp[i - 1][1] + 2 ? 0 : 1);
        }
        if(s[i] == 'P') dp[i][0] = -MOD;
        if(s[i] == 'D') dp[i][1] = -MOD;
    }
    ll x = (dp[n][0] > dp[n][1] ? 0 : 1);
    string ans;
    for(int i = n ; i >= 1 ; i--){
        ans.push_back(x == 0 ? 'D' : 'P');
        x = prv[i][x];
    }
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 10044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int N;
    cin >> N;
    int L[2*N];
    for (int i = 0; i < 2*N; i++) {
        cin >> L[i];
    }

    sort(L, L+2*N);

    int ans = 0;
    for (int i = 0; i < 2*N; i+=2) {
        ans += L[i];
    }

    cout << ans << "\n";
    return 0;
}

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

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

  int cnt = 0;
  int num = 0;
  for( int i = 0; i < N; i++ ) {
    cin >> num;
    if( num == 2 ) {
      cnt +=1;
      continue;
    }
    if( num % 2 == 0 ) {
      continue;
    }

    double sqrtnum = sqrt( num );
    for( int j = 3; j <= sqrtnum; j += 2 ) {
      if( num % j == 0 ) {
        num = 0;
        break;
      }
    }
    if( num != 0 ) {
      cnt += 1;
    }
  }

  cout << cnt << endl;

  return 0;
}




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

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  m++;
  vector<ll> a(n);
  vector<ll> b(m);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=1;i<m;i++){
    cin >> b[i];
    b[i]+=b[i-1];
  }
  
  ll ans=0;
  if(b[m-1]<=k) ans=m-1;
  else{
    for(int i=0;i<m;i++){
      if(b[i]>k){
        break;
      }
      ans=i;
    }
  }
  
  for(int j=0;j<n;j++){
    k-=a[j];
    if(k<0) break;
    ll p;
    if(k>=b[m-1]) p=m-1;
    else if(k<b[1]) p=0;
    else{
      int r=1,l=m-1;
      while(1){
        int i=(r+l)/2;
        if(b[i]<=k&&b[i+1]>k){
          p=i;
          break;
        }
        else if(b[i]>k) l=i;
        else r=i;
      }
    }
    ans=max(ans,p+j+1);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 6432
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long k,a,b;
		//a b c 
	cin>>k>>a>>b;
	if(a>=k) {
		cout<<1<<endl;
		return 0;
	}
	if(b>=a) {
		cout<<-1<<endl;
		return 0;
	}
	if((k-b)%(a-b)>=1)cout<<((k-a)/(a-b)+1)*2+1<<endl;
	else cout<<((k-a)/(a-b))*2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  int a;
  cin>>a;
  vector<int> s(3);
  ll c=0;
  s[0]=(a-(a/1000*1000))/100;
  s[1]=(a-(a/100*100))/10;
  s[2]=a%10;
  for(int bit=0;bit<(1<<3);bit++){
    ll cu=a/1000;
    vll d(0);
    for(int i=0;i<3;i++){
      if(bit&(1<<i)){
        cu+=s[i];
        d.pb(1);
      }
      else{
        cu-=s[i];
        d.pb(0);
      }
    }
    if(cu==7){
      cout<<a/1000;
      if(d[0]==1) cout<<'+';
      else cout<<'-';
      cout<<s[0];
      if(d[1]==1) cout<<'+';
      else cout<<'-';
      cout<<s[1];
      if(d[2]==1) cout<<'+';
      else cout<<'-';
      cout<<s[2];
      cout<<'='<<7;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define v(n) vector<n>
using namespace std;
signed main(){
    int h,w; cin>>h>>w;
    v(v(char)) block(h+2,v(char)(w+2));
    rep(i,h+2){
        rep(j,w+2){
            if(i==0 or i==h+1 or j==0 or j==w+1){
                block.at(i).at(j)='#';
            }else{
                cin>>block.at(i).at(j);
            }
        }
    }
    rep(i,h+2){
        rep(j,w+2){
            cout<<block.at(i).at(j);
        }
        cout<<endl;
    }
}


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


int main(){
    ll n;cin>>n;
    ll a[111],cn=0;
    rep(i,0,n){
        cin>>a[i];
        if(i%2==0&&a[i]%2==1)cn++;
    }
    cout<<cn<<endl;
}

    









Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;cin >> a >> b;
	ll g = gcd(a,b), k = g;
	vector<ll> c;
	for(ll i = 2;i * i <= g; i++){
		if(k % i == 0){
			c.pb(i);
			k /= i;
			while(k % i == 0){
				k /= i;
			}
		}
	}
	if(k != 1) c.pb(k);
	ll ans = c.size() + 1;
	cout << ans << endl;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

struct UnionFind{/*{{{*/
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};/*}}}*/

int solve(){
  int n,m;cin>>n>>m;
  int p[n]; rep(i, n){ cin>>p[i]; p[i]--;}

  UnionFind uf(n);
  int x,y;
  rep(i, m){
    cin>>x>>y; x--;y--;
    uf.unite(x,y);
  }

  int cnt = 0;
  rep(i, n){
    if (uf.same(i, p[i])) cnt++;
  }

  cout << cnt << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 2560
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			int[] h = new int[10];
			for (int i = 0; i < 10; i++) {
				h[i] = Integer.parseInt(in.readLine());
			}
			Arrays.sort(h);
			for (int i = 0; i < 3; i++) {
				System.out.println(h[10 - 1 - i]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 9368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int main() {
	int n; scanf ("%d", &n);
	vector < int > a (n);
	for (int & x : a) scanf ("%d", &x);
	vector < vector < ll > > dp (n, vector < ll > (n));
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R) {
				dp[L][R] = a[L];
			} else {
				dp[L][R] = max ((ll) a[L] - dp[L + 1][R], (ll)a[R] - dp[L][R - 1]);
			}
		}
	}
	printf ("%lld\n", dp[0][n - 1]);
	return 0;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T, class T2> long long modpower(long long radix, T x, T2 mod) {
    // 高速階乗計算 radix^x
    long long ans = 1;
    while (0 < x) {
        if (x & 1) {
            ans = ans * radix % mod;
        }
        radix = radix * radix % mod;
        x >>= 1;
    }
    return ans == 0 ? 1 : ans;
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> cnt(N);
    for (auto &&i : A) {
        cin >> i;
        cnt[i]++;
    }
    if (N % 2 != 0)
        cnt[0]++;

    auto NG = []() {
        std::cout << 0 << '\n';
        exit(0);
    };
    for (auto &&i : cnt) {
        if (i != 0 && i != 2)
            NG();
    }
    std::cout << modpower(2, N / 2, MOD7) << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define NO 0
#define KABE 1
#define S 2
#define G 3
#define OUT 20*1000
int h,w;
int ban[20][20];

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int rec(int x, int y, int n){
  if( n>=10 )
    return OUT;

  int rtn = OUT, nn=n+1;
  for( int z=0;z<4;z++ ){
    int xx=x, yy=y;
    if( ban[yy+dy[z]][xx+dx[z]] == KABE )
      continue;

    while(true){
      xx += dx[z]; yy += dy[z];
      if( xx<0 || yy<0 || xx>=w || yy>=h )
	break;

      if( ban[yy][xx]==G ){
	rtn=nn;break;
      }

      if( ban[yy][xx]==KABE ){
	ban[yy][xx] = NO;
	rtn = min(rtn, rec(xx-dx[z], yy-dy[z], nn));
	ban[yy][xx] = KABE;
	break;
      }
    }
  }
  return rtn;
}

int main(){
  while( cin>>w>>h,w){
    int sx,sy;
    for( int i=0;i<h;i++ ){
      for( int j=0;j<w;j++ ){
	cin >> ban[i][j];
	if( ban[i][j]==S ){
	  ban[i][j] = NO; sx=j; sy=i;
	}
      }
    }
    int rtn = rec(sx, sy, 0);
    if( rtn == OUT )
      cout << -1 << endl;
    else 
      cout << rtn << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()


int main(){
  int n,ans=0;
  cin >> n;

  REP(i,1,n+1){
    if(i==10 || i==1000 || i==100000){
      i= i*10-1;
      continue;
    }
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int H,W;
    cin >> H >> W;
    char grid[H][W];
    bool check[H][W]={};
    bool line[H]={};
    rep(i,H) rep(j,W) cin >> grid[i][j];
    rep(i,H){
        bool che=0;
        rep(j,W) if(grid[i][j]=='#') che=1;
        if(che==0) rep(j,W) check[i][j]=1;
        if(che==0) line[i]=1;
    }
    rep(i,W){
        bool che=0;
        rep(j,H) if(grid[j][i]=='#') che=1;
        if(che==0) rep(j,H) check[j][i]=1;
    }
    rep(i,H){
        rep(j,W) if(check[i][j]==0) cout << grid[i][j];
        if(line[i]==0) cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  set<int> c;
  for(int i=0;i<s.size();i++){
    c.insert(s.at(i));
  }
  cout<<(c.size()==s.size()?"yes":"no");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int z = scanner.nextInt();
        int w = scanner.nextInt();
        int[] a = new int[n];
        Arrays.setAll(a, i -> scanner.nextInt());
        System.out.println(n == 1 ? Math.abs(a[0] - w) : Math.max(Math.abs(a[n - 1] - w), Math.abs(a[n - 2] - a[n - 1])));
    }
}

Measured memory_bytes: 26964
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    map<int,string> m;
    m[0]="pon";
    m[1]="pon";
    m[2]="hon";
    m[3]="bon";
    m[4]="hon";
    m[5]="hon";
    m[6]="pon";
    m[7]="hon";
    m[8]="pon";
    m[9]="hon";
    int n; cin>>n;
    cout<<m[n%10]<<endl;
}

Measured memory_bytes: 3632
#![allow(unused)]

use std::{cell, cmp, collections, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let n = parse_line::<usize>();
    let mut a = parse_vec::<i32>();

    a.sort();
    println!("{}", a[n - 1] - a[0]);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string imp="Impossible\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
// const int N=11;
const int N=5e6+5;
ll MOD=1e9+7;
ll n,m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;
int powmodp(ll a,ll b,ll mod){//log a
	a=a%mod;
	if(b==1)
		return a;
	ll res=1;
	while(b){
		if(b&1){
			res=res*a;
			res%=mod;
		}
		b=b>>1;
		a=a*a;
		a%=mod;
	}
	return res; 
}
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
	cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    while(tests--){
		int N=2e5+5;
		int dp[N];
		mem(dp,0);
		dp[1]=1;
		for(int i=2;i<N;i++){
			dp[i]=1+dp[(i%__builtin_popcount(i))];
		}
		int n;	cin>>n;
		string x;
		cin>>x;
		reverse(all(x));
		int cnt=0;
		for(int i=0;i<n;i++){
			if(x[i]=='1')	cnt++;
		}
		if(cnt==0){
			for(int i=0;i<n;i++)	cout<<"1\n";
			continue;
		}
		int res1=0,res2=0;
		for(int i=0;i<n;i++){
			if(x[i]=='1'&&cnt!=1){
				res1+=powmodp(2,i,cnt-1);
				res1%=(cnt-1);
			}
		}
		for(int i=0;i<n;i++){
			if(x[i]=='1'){
				res2+=powmodp(2,i,cnt+1);
				res2%=(cnt+1);
			}
		}
		vector<int>ans(n,1);
		for(int i=0;i<n;i++){
			if(x[i]=='1'){
				if(cnt==1)	ans[i]=0;
				else	ans[i]+=dp[(res1-powmodp(2,i,cnt-1)+cnt-1)%(cnt-1)];
			}
			else{
				ans[i]+=dp[(res2+powmodp(2,i,cnt+1))%(cnt+1)];
			}
		}
		for(int i=n-1;i>=0;i--)	cout<<ans[i]<<"\n";
    }
    return 0;
}



 



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

int main()
{
	
	long long int r,c,pro;
	cin>>r>>c;
	int k,l;
	
	pro=0;

	if(r==1)
	{
		if(c==1)
			pro=1;
		else if(c==2)
			pro=0;
		else
		{
			pro=c-2;
		}
	}

	else if(c==1)
	{
		
		if(r==2)
			pro=0;
		else
		{
			pro=r-2;
		}
	}
	else
	{
		pro=(r-2)*(c-2);
	}
	/*
	for(long long int i=1;i<=r;i++)
	{
		for(long long int j=1;j<=c;j++)
		{
			k=l=1;
			if((i-1)>=1)
				k++;
			if((i+1)<=r)
				k++;

			if((j-1)>=1)
				l++;
			if((j+1)<=c)
				l++;
			if((l*k)%2==1)
				pro++;
		}
	}
	*/
	cout<<pro<<"\n";
	return 0;
}


Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  int K;
  cin >> K;
  cin >> N;
  int n=N.size();
  if(n <= K){
  cout <<N<< endl;
  }
  else{
   string ans;
    for(int i=0;i<K;i++){
   ans.push_back(N[i]);
    }
    cout<< ans<<"..." <<endl;
  }
  return 0; 
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N, K, pos_st;
vector<int> v;

long long calc(int l, int r){
  long long res = 0LL;
  if(v[l] < 0 && v[r] > 0){
     res += min(2*abs(v[l]) + abs(v[r]), abs(v[l]) + 2*abs(v[r]));
  }
  else if(v[l] >= 0 && v[r] >= 0){
    res += abs(v[r]);
  } 
  else{
    res += abs(v[l]);
  }
  return res;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  v.resize(N);
  pos_st=-1;
  for(int i=0; i<N; ++i){ cin >> v[i];
    if(v[i] >= 0 && pos_st == -1)
      pos_st = i;
  }
  if(pos_st == -1) pos_st = N-1;
  long long res = 1e15 + 5;
  for(int i=0; i+K<=N && i <= pos_st; ++i){
    long long p = calc(i, i+K-1) ;
    res = min(p, res);
    //cout << "p: " << p << " i: " << i << " i+K-1: " << i+K-1 << "\n";
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 640
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long int
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();

    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
}

void show(vll &a)
{
    ll n = a.size();

    for(ll i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void SieveOfErat1sthenes(int n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (int p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

bool compare(pll a, pll b)
{
    return a.first>b.first;
}

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

    ll n, k;
    cin>>n>>k;

    vll a(n);
    enter(a);

    vvll dp(n+1, vll(k+1, 0));

    for(ll i=0;i<=n;i++) dp[i][0] = 1;

    for(ll i=1;i<=n;i++)
    {
        vll pre(k+1);
        pre[0] = dp[i-1][0];
        for(ll j=1;j<=k;j++)
        {
            pre[j] = mo(mo(pre[j-1]) + mo(dp[i-1][j]));
        }

        // cout<<"pre: "<<i<<": ";
        // show(pre);
        // cout<<"a[i-1]:"<<a[i-1]<<"\n";

        for(ll j=1;j<=k;j++)
        {
            dp[i][j] = mo(mo(pre[j]) - mo(((j-a[i-1]-1)>=0?pre[j-a[i-1]-1]:0)) + MOD);
        }

    }

    // for(ll i=0;i<=n;i++)
    // {
    //     for(ll j=0;j<=k;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }

    cout<<dp[n][k]<<"\n";

    return 0;
}


Measured memory_bytes: 83192
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long
#define pb push_back
#define mp make_pair
#define Mod 1000000007
#define limit 500008
using namespace std;
int n,cnt[limit],ans[limit],List[limit];
struct str
{
    int l,r,ind;
};
bool cmp(str a,str b)
{
    return a.r<b.r;
}
str query[limit];
void up(int ind,int key)
{
    while(ind<=n)
    {
        cnt[ind] += key;
        ind += (ind & -ind);
    }
}
int qu(int ind)
{
    int sum=0;
    while(ind>0)
    {
        sum += cnt[ind];
        ind -= (ind & -ind);
    }
    return sum;
}
void solve(int t)
{
    int i,j,q,m,k,l,r;          ///Binary index tree
    for(i=0; i<limit; i++)
    {
        List[i]=-1;
        cnt[i] = 0;
        ans[i] = 0;
    }
    cin >> n >> q;
    int D[n+5];
    for(i=1; i<=n; i++)
        cin >> D[i];
    for(i=1; i<=q; i++)
    {
        cin >> l >> r;
        query[i].l=l;
        query[i].r=r;
        query[i].ind=i;
    }
    sort(query+1,query+q+1,cmp);
    k = 1;
    for(i=1; i<=n; i++)
    {
        if(List[D[i]]!=-1)
        {
            up(List[D[i]],-1);
        }
        List[D[i]] = i;
        up(i,1);

        while(k<=q && query[k].r==i)
        {            //cout <<k<<" "<<qu(query[k].r)<<" "<<qu(query[k].l-1)<<" "<<query[k].ind<<endl;
            ans[query[k].ind] = qu(query[k].r) - qu(query[k].l-1);
            k++;
        }

    }
    for(i=1; i<=q; i++)
        cout <<ans[i]<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int tt=1,t;
//    cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}





Measured memory_bytes: 17348
//Optional FAST
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
 
//Required Libraries
 

#include <bits/stdc++.h>
//#include<iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
//Required namespaces
 
using namespace std;
using namespace __gnu_pbds;
//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
vector<ll> pr; 
//ll z[1001][11]={0};
int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    fio;
    */
    ll n;
    cin>>n;
     ll a;
     cin>>a;
    ll sum=0;
    forin(i,0,a-1)
    {
        ll q;
        cin>>q;
        sum+=q;
    }
    if(sum>=n)
    {
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
S = str(input()); N = len(S)
S = list(S); S.reverse() #1桁目からに変換
MOD = pow(10,9)+7
dp = [0 for _ in range(13)] #13で割ってi余る個数
dp[0] = 1
keta = 1
for i in range(N):
  p = [0 for _ in range(13)]
  dp,p = p,dp #dpが次。pが一個前。
  if i != 0:
    keta = (keta*10)%13
  if S[i] == "?":
    for x in range(10):
      amari = x*keta%13
      for j in range(13):
        if j >= amari:
          mae = j-amari
        else:
          mae = j-amari+13
        dp[j] += p[mae]%MOD
  else:
    amari = int(S[i])*keta%13
    for j in range(13):
      if j >= amari:
        mae = j-amari
      else:
        mae = j-amari+13
      dp[j] += p[mae]%MOD
#print(dp)
print(dp[5]%MOD)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  double sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  ll cnt = 0;
  REP(i, n) {
    if (a[i] >= sum / (4 * m)) ++cnt;
  }
  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def solve(a,k):
    a.sort()
    I = (np.abs(a)).argsort()
    a = a[I][::-1]
    if ( len(a) == k ): 
        return a
    if np.all( a<0 ):
        if ( k % 2 == 0 ):
            return a[:k]
        else:
            return a[-k:]
    p = a[a>=0]
    n = a[a<0]
    nums = [1]
    if k & 1:
        nums = [p[0]]
        p = p[1:]
        k -= 1
    if len(p) & 1:
        p = p[:-1]
    if len(n) & 1:
        n = n[:-1]
    p = p[::2] * p[1::2]
    n = n[::2] * n[1::2]
    a = np.concatenate([p,n])
    a.sort()
    a = a[::-1]
    return np.concatenate([nums,a[:k // 2]])

def main():
    n, k = map(int, readline().split())
    a = np.array(read().split(), np.int64)
    mod = 10**9 + 7
    b = solve(a,k).tolist()
    ans = 1
    for x in b:
        ans = ans * x % mod
    print(ans)

main()



Measured memory_bytes: 40412
/*input
10000000
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld         int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  10000005
lld spf[N];
void sieve(){
	rep(i,0,N){
		spf[i]=i;
	}
	rep(i,2,N){
		if(spf[i]==i){
			for(lld j=2*i;j<N;j+=i){
				if(spf[j]==j){
					spf[j]=i;
				}
			}
		}
	}
}
long long int get(lld x){
	long long int res=1;
	while(x!=1){
		lld t=spf[x];
		lld c=0;
		while(x%t==0){
			x/=t;
			c++;
		}
		res*=(1+c);
	}
	return res;
}
void solve()
{
	sieve();
	lld n;
	cin >> n;
	long long int ans=0;
	rep(i,1,n+1){
		ans+=i*get(i);
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    double R; cin >> R;
    printf("%.10Lf",PI*R*2);
    
    return 0;
}


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

int N,cost[10000];
int dp[5010][2];
const int INF=1e9;
int main(){
    scanf("%d",&N);
    for(int i=0;i<N-1;i++)scanf("%d",&cost[i]);

    fill_n(*dp,2*5010,INF);
    dp[1][0]=dp[0][1]=0;

    for(int i=0;i<N-1;i++){
        for(int j=N/2;j>=0;j--){
            dp[j+1][0]=min(dp[j][0],dp[j][1]+cost[i]);
            dp[j][1]=min(dp[j][0]+cost[i],dp[j][1]);
        }
    }

    printf("%d\n",min(dp[N/2][0],dp[N/2][1]));
    return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int n,x=0;
	cin >> n;
	if (n%2==1)
		cout << 0;
	else {
		n /= 2;
		REP(i, 100) {
			x += n / 5;
			n /= 5;
		}
		cout << x;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s, 0, sizeof(s))
const int MOD = 100000007;
const int MAXN = 1000000;
const int inf = 0x3f3f3f3f;
char str[100005];
int book[100005];
int main()
{
	int fo = 0, n, m, now = 0;
	scanf("%d%d", &n, &m);
	scanf("%s", str);
	for (int i = 1; i < n; i++)
	{
		if (str[i] == 'C' && str[i - 1] == 'A')
		{
			now++;
		}
		book[i] = now;
	}
	while (m--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		int ans = book[r - 1] - book[l - 1];
		//	printf("%d %d", book[r - 1], book[l - 1]);
		//if (l > 1 && str[l - 1] == 'C' && str[l - 2] == 'A') ans--;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

// 最大公約数のll版
ll gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	return b == 0 ? a : gcd(b, a%b);
}

// 最小公倍数のll版
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

	ll A,B,C,D;
	cin >> A >> B >> C >> D;

	ll c = B/C - (A-1)/C;
	ll d = B/D - (A-1)/D;
	ll cd = B/(lcm(C,D)) - (A-1)/(lcm(C,D));

	//cout << c << " " << d << " " << cd << endl;

	cout << (B - A + 1) - c - d + cd << endl;

	return 0;
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/PCK/Prelim/0338?year=2016

#include <bits/stdc++.h>

using namespace std;

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

    int g = __gcd(w, h);
    w /= g;
    h /= g;
    cout << w * h * c << endl;
    return 0;
}

/*
 *
 */


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

int main(void) {
    int P, Q, R;
    cin >> P >> Q >> R;
    vector< int > v;
    v.push_back(P + Q);
    v.push_back(P + R);
    v.push_back(R + Q);
    sort(v.begin(), v.end());
    printf("%d\n", v[0]);
    return 0;
}


Measured memory_bytes: 256
#サイコロの目からk個ずつ順にループで切り出して和をリストするとTLE
#累積和のリストから、k個の和のリスト → 期待値のリストでTLE解消

from itertools import accumulate

n, k = map(int,input().split())
l = list(map(int,input().split()))

p = [0] + list(accumulate(l))

q = [] #累積和'p'からから求めたk個ずつの和
r = [] #出目の期待値
for i in range(n-k+1):
    q.append(p[i+k] - p[i])
    r.append((q[i] + k) / 2)

print(max(r))


Measured memory_bytes: 31968
#include<bits/stdc++.h>
#define For(aa,bb,cc) for(int aa=(bb);aa<=(int)(cc);++aa)
using namespace std;
const int maxn=100;
int n;
int a[maxn];
map<string,int>G;

int main(){
	scanf("%d",&n);
	string s;int ans=0;
	For(i,1,n){
		cin>>s;scanf("%d",&a[i]);
		G[s]=i;
	}
	cin>>s;
	For(i,G[s]+1,n) ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

const double PI = acos(-1.0);

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

struct edge{int from, to,cost;};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

ll res,n,tmp;
bool flag=false;

int main()
{
    cin>>n;
    res=1;

    vec<ll> A(n+10,0);

    rep(i,n){
        cin>>A[i];
        if(A[i]==0){
            cout<<0<<endl;
            return 0;
        }
        // if(A[i]>1000000000000000000) flag=true;
    }

    // if(flag){
    //     cout<<-1<<endl;
    //     return 0;
    // }


    rep(i,n){
        if(res>=LONG_MAX/A[i]){ //オーバーフロー検出
            cout<<-1<<endl;
            return 0;
        }
        res*=A[i];
    }

    if(res>1000000000000000000){
        cout<<-1<<endl;
    }else{
        cout<<res<<endl;
    }

    return 0;

}




Measured memory_bytes: 4048
#include<stdio.h>
int a,b,c;
int main(void){
    scanf("%d%d",&a,&b);
    int i,ans;
  ans = 0;
    c= 1;
  if(b==1){
    printf("0");
  }else{
    for(i=1;i<=22;i++){
        c += a-1;
        ans +=1;
        if(c>=b){
        break;
        }
    }
    printf("%d",ans);
  }
    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    string s;
    cin >> s;
    char str = s[0];
    long long ans=0;
    for(int i=1;i<s.length();i++){
        if(s[i]==str){
        }else{
            ans++;
            str = s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(m)]
a1=sorted(a)
b1=sorted(b)
price=a1[0]+b1[0]
ans=float('inf')
for i in range(m):
    x=a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
    if x<ans:
        ans=x
print(min(price,ans))

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b)>(c+d)){
    cout << "Left\n";
  } else if((a+b) == (c+d)){
    cout << "Balanced\n";
  } else {
    cout << "Right\n";
  }
  
  return(0);
}


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

int n;

int main()
{
	cin >> n;

	if (n==3) {
		cout << "2 5 63\n";
		return 0;
	}
	int a = 2, b = 3;
	while (n>3 and b<30000) {
		cout << b << ' ' << b+6 << ' ';
		b += 12; n -= 2;
	}
	while (n>1 and a<30000) {
		cout << a << ' ' << a+2 << ' ';
		a += 6; n -= 2;
	}

	int c = 6;
	while (n) {
		cout << c << ' ';
		c += 6; n--;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m;
vector <string> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    for(auto &i : a) cin >> i;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if(j == 0 || a[i][j] == '#') cout << '#';
            else if(0 < i && i < n - 1 && 0 < j && j < m - 1 && i % 2) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
    cout << endl;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if(j == m - 1 || a[i][j] == '#') cout << '#';
            else if(0 < i && i < n - 1 && 0 < j && j < m - 1 && i % 2 == 0) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;

int f(ll n) {
  int res = 0;
  while (n) {
    n /= 10;
    res++;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = f(n);
  for (ll i = 2; i*i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, f(n/i));
    }
  }
  cout << ans << endl;
}

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

int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int tmp = gcd(a, b);
    int ans = 0;
    int j = 1;
    for(int i = tmp; i > 0; i--) {
        if(tmp % i == 0){
            if(j == k)ans = i;
            j ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
$count = 0
def merge(left_array, right_array)
  return_array = []
  left_index, right_index = 0, 0
  left_array << 10**9
  right_array << 10**9
  0.upto(left_array.length + right_array.length - 3) do
    $count += 1
    if left_array[left_index] < right_array[right_index]
      return_array << left_array[left_index]
      left_index += 1
    else
      return_array << right_array[right_index]
      right_index += 1
    end
  end
  return_array
end

def merge_sort(target_array)
  right = target_array.length
  mid = target_array.length / 2
  left_array = target_array[0...mid]
  right_array = target_array[mid...right]
  return target_array if target_array.length == 1
  return merge(merge_sort(left_array), merge_sort(right_array))
end

gets.to_i
input = gets.split(' ').map(&:to_i)
puts merge_sort(input).join(' '), $count


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

using namespace std;
 
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pi;

//#define int ll
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007
#define loop(n) for(int i = 0; i < n; i++)
#define rloop(n) for(int i = n-1; i >= 0; i--)

void io() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve() {
    int n, k; cin>>n>>k;
  vi sfreq(n+1,0);
  while(k--) {
    int d; cin>>d;
    while(d--) {
      int a; cin>>a;
      sfreq[a]++;
    }
  }
  int ans=0;
  forl(i,1,n+1) {
    if(sfreq[i]==0) ans++;
  }
  cout<<ans<<"\n";
    return;
}
int32_t main() {
    io();
    int t=1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100010;
int n,a[N];
LL Ans=0;

int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int lv=a[n],rv=a[n],l=1,r=n-1;
	for(int i=2;i<=n;i++) {
		int v=abs(a[l]-lv),id=l,p=0;
		if(v<abs(a[l]-rv))
			v=abs(a[l]-rv),p=1,id=l;
		if(v<abs(a[r]-lv))
			v=abs(a[r]-lv),p=0,id=r;
		if(v<abs(a[r]-rv))
			v=abs(a[r]-rv),p=1,id=r;
		//cout<<v<<' '<<id<<endl;
		Ans+=v;
		if(!p) {
			lv=a[id];
			if(id==l) l++;
			else r--;
		}
		else {
			rv=a[id];
			if(id==l) l++;
			else r--;
		}
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 640