akhauriyash/Code-Regression huggingface dataset:
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(n):
  key = input()
  if key[0] == "M":
    m += 1
  if key[0] == "A":
    a += 1
  if key[0] == "R":
    r += 1
  if key[0] == "C":
    c += 1
  if key[0] == "H":
    h += 1

judge = [m, a, r, c, h]
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += judge[i]*judge[j]*judge[k]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
int main(void) {
	std::string S;
	std::string T;
	auto A = 0;
	auto B = 0;
	std::string U;
	std::cin >> S >> T >> A >> B >> U;
	if (S == U) {
		std::cout << A - 1 << " " << B;
	}
	else if (T == U) {
		std::cout << A << " " << B - 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

#ifdef ELEGIA
const int L = 10;
#else
const int L = 18;
#endif

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k, s, t;
  cin >> n >> k >> s >> t;
  if ((s & t) != s) {
    cout << "0\n";
    return 0;
  }
  vector<int> a;
  while (n--) {
    int x;
    cin >> x;
    if ((x & s) == s && (x & t) == x)
      a.push_back(x);
  }
  n = a.size();
  if (n == 0) {
    cout << "0\n";
    return 0;
  }
  k = min(n, k);
  for (int &x : a)
    x -= s;
  t -= s;
  s = 0;

  vector<vector<ll>> C(n + 1, vector<ll>(n + 1));
  vector<ll> sb(n + 1);
  for (int i = 0; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    sb[i] = accumulate(C[i].begin() + 1, C[i].begin() + k + 1, 0LL);
  }

  ll ans = 0;

  for (int i = 0; i < (1 << L); ++i) {
    if ((i & t) != i) continue;
    vector<int> x(n);
    for (int j = 0; j < n; ++j) x[j] = a[j] & i;
    sort(x.begin(), x.end());
    int cur = -1, cc = 0;
    ll val = 0;
    for (int v : x) {
      if (v != cur) {
        val += sb[cc];
        cur = v;
        cc = 1;
      } else
        ++cc;
    }
    val += sb[cc];
    if (__builtin_popcount(i) & 1)
      ans -= val;
    else
      ans += val;
  }

  cout << ans;

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N];
int main(){
	int n,m,k;scanf("%d%d%d",&n,&m,&k);
	int ans=0,num=0,w=0,l,r;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<m;i++)scanf("%d",b+i);
	for(r=0;r<n&&w+a[r]<=k;r++)w+=a[r];
	for(l=0;l<m&&w+b[l]<=k;l++)w+=b[l];
	ans=r+l;
	for(r=r-1;r>=0;r--){
		w-=a[r];
		while(l<m&&w+b[l]<=k)w+=b[l++];
		ans=max(ans,r+l);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 5292
#include<vector>
#include<climits>
#include<algorithm>
const int INF = INT_MAX;
const int NIL = -1;
class RangeMinimumQuery {
public:
  RangeMinimumQuery(int s) {
    size_ = 1;
    while(size_ < s) size_ <<= 1;
    node_ = std::vector<int>((size_ << 1) - 1, INF);
  }
  int find(int left, int right) const {
    return query(left, right, 0, 0, size_ - 1);
  }
  void update(int index, int value) {
    int i = index + size_ - 1;
    node_[i] = value;
    while((i = parent(i)) != NIL) node_[i] = std::min(node_[left_child(i)], node_[right_child(i)]);
  }
private:
  int parent(int node) const {return node == 0 ? NIL : (node - 1) >> 1;}
  int left_child(int node) const {return (node << 1) + 1;}
  int right_child(int node) const {return (node << 1) + 2;}
  int query(int a, int b, int k, int l, int r) const {
    if(b < l || r < a) return INF;
    if(a <= l && r <= b) return node_[k];
    int vl = query(a, b, left_child(k), l, (l + r) / 2);
    int vr = query(a, b, right_child(k), (l + r) / 2 + 1, r);
    return std::min(vl, vr);
  }
  int size_;
  std::vector<int> node_;
};

#include<iostream>
using namespace std;

struct Star {long long int x, y, b;};
bool operator<(const Star& lhs, const Star& rhs) {return lhs.b < rhs.b;}

int main() {
  int N, d;
  cin >> N >> d;
  vector<Star> star(N);
  for(auto& s: star) cin >> s.x >> s.y >> s.b;
  sort(begin(star), end(star));
  RangeMinimumQuery left(N), right(N), top(N), bottom(N);
  for(int i = 0; i < N; ++i) {
    left.update(i, star[i].x);
    right.update(i, -star[i].x);
    top.update(i, star[i].y);
    bottom.update(i, -star[i].y);
  }
  long long int answer = 0;
  int low, high;
  for(low = high = 0; low < N; ++low) {
    while(high < N - 1 && star[high + 1].b - star[low].b <= d) ++high;
    long long int area = -right.find(low, high) - left.find(low, high);
    area *= -bottom.find(low, high) - top.find(low, high);
    answer = max(answer, abs(area));
  }
  cout << answer << endl;
}

Measured memory_bytes: 14060
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
}

const LL MOD = 998244353;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    LL N, M, K; cin >> N >> M >> K;
    LL a = 1;  // C(N-1, 0)
    LL b = Number::mod_pow(M-1, N-1, MOD);
    LL ans = 0;
    if (M == 1) {
        cout << (K == N-1 ? 1 : 0) << endl;
        return 0;
    }
    for (LL i = 0; i <= K; ++i) {
        ans += (M * a % MOD) * b % MOD;
        ans %= MOD;
        // cout << a << ' ' << b << ' ' << ans << endl;
        a = a * (N-1-i) % MOD;
        a = a * Number::mod_inv(i+1, MOD) % MOD;
        b = b * Number::mod_inv(M-1, MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3696
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;
    ArrayList<Integer>[] g;
    boolean[] used;
    boolean[] qued;
    int N;
    int M;
    int[] dis;

    public static void main(String[] args) {
        new Main().solve();
    }

    boolean dfs(int v) {
        boolean res = true;
        Deque<Integer> q = new ArrayDeque<Integer>();
        q.push(v);
        dis[v] = 0;
        while (q.size() != 0) {
            int now = q.pop();
            used[now] = true;
            for (int i = 0; i < g[now].size(); i += 2) {
                int next = g[now].get(i);
                if (!used[next]) {
                    dis[next] = dis[now] + g[now].get(i + 1);
                    q.push(next);
                } else if (dis[next] != dis[now] + g[now].get(i + 1)) {
                    res = false;
                }
            }
        }
        return res;
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        g = new ArrayList[N];
        used = new boolean[N];
        qued = new boolean[N];
        dis = new int[N];
        for (int i = 0; i < N; i++) {
            g[i] = new ArrayList<Integer>();
        }
        Arrays.fill(used, false);
        Arrays.fill(qued, false);
        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            int D = sc.nextInt();
            g[L - 1].add(R - 1);
            g[L - 1].add(D);
            g[R - 1].add(L - 1);
            g[R - 1].add(-D);
        }
        for (int i = 0; i < N; i++) {
            dis[i] = INF;
        }
        boolean ans = true;
        for (int i = 0; i < N; i++) {
            if (!used[i]) {
                if (!dfs(i)) {
                    ans = false;
                }
            }
        }
        System.out.println(ans ? "Yes" : "No");

    }
}


Measured memory_bytes: 174288
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 

ull bin(ull a, ull b) {
    a %= mod;
    ull res = 1;
    while(b) {
        if(b&1) res = res%mod * a%mod;
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return res%mod;
}

int main() 
{
    fastio
    int n, k;
    cin>>n>>k;

    vector<ull> dp(k+1);
    for(int i = k; i>=1; --i) {
        dp[i] = bin(k/i, n);
        for(int j = 2*i; j<=k; j+=i) {
            dp[i] -= dp[j];
        }
    }

    ull ans = 0;
    for(int i = 1; i<=k; ++i) {
        ans += dp[i]*i;
        ans %- mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 3964
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int number[4],i,j,result;
    char op_1,op_2,op_3;
    for(i=0; i<4; i++)
        scanf("%1d",&number[i]);
    for(i=0; i<8; i++)
    {
        j=i;
        result=number[0];
        if(j/4==0)
        {
            result+=number[1];
            op_1='+';
        }
        else
        {
            result-=number[1];
            op_1='-';
        }
        j=j%4;
        if(j/2==0)
        {
            result+=number[2];
            op_2='+';
        }
        else
        {
            result-=number[2];
            op_2='-';
        }
        j=j%2;
        if(j==0)
        {
            result+=number[3];
            op_3='+';
        }
        else
        {
            result-=number[3];
            op_3='-';
        }
        if(result==7)
            break;
    }
    printf("%d%c%d%c%d%c%d=7\n",number[0],op_1,number[1],op_2,number[2],op_3,number[3]);
    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  string s;cin>>s;
  ll ans=0;
  ll cnt=0,acnt=0,bcnt=0,ccnt=0;
  ll dp[s.size()+10][5]={};
  dp[s.size()][3]=1;
  dp[s.size()][0]=dp[s.size()][1]=dp[s.size()][2]=0;
  for(int i=s.size()-1;i>=0;i--){
    for(int j=3;j>=0;j--){
      if(j==3){
	if(s[i]=='?'){
	  dp[i][j]=(3*dp[i+1][j])%MOD;
	}else{
	  dp[i][j]=dp[i+1][j];
	}
      }else{
	int m1=(s[i]=='?')?3:1;
	int m2=(s[i]=='?'||j==(s[i]-'A'))?1:0;
	dp[i][j]=(m1*dp[i+1][j]+m2*dp[i+1][j+1])%MOD;
      }
    }
  }
  cout<<dp[0][0]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  ll cur=0;
  ll ans=0;
  rep(i,0,n){
    cur+=a[i];
    if(i%2!=0){
      if(cur>=0){
        ans+=cur+1;
        cur=-1;
      }
    }
    if(i%2==0){
      if(cur<=0){
        ans+=1-cur;
        cur=1;
      }
    }
  }
  ll cur2=0;
  ll ans2=0;
  rep(i,0,n){
    cur2+=a[i];
    if(i%2==0){
      if(cur2>=0){
        ans2+=cur2+1;
        cur2=-1;
      }
    }
    if(i%2!=0){
      if(cur2<=0){
        ans2+=1-cur2;
        cur2=1;
      }
    }
  }
  cout<<min(ans,ans2)<<endl;
}

Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        t: f64, x: f64
    }

    println!("{}", t / x);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){	
  	cin.tie(0);
    ios::sync_with_stdio(0);
  	int A,B,K;
  	cin>>A>>B>>K;
  	if(B-A<2*K)for(int i=A;i<=B;i++)cout<<i<<"\n";
  	else for(int i=A;i<=B;i++)if(i<A+K||B-K<i)cout<<i<<"\n";
  	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

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

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<bool> ver;
void dfs(const graph &g,int v,int a,int b){
  ver[v]=true;
  for(auto i:g[v]){
    if(ver[i])continue;
    if((v==a && i==b) || (v==b && i==a))continue;
    dfs(g,i,a,b);
  }
}

int main(){
  int i,j,k,cnt=0;
  int n,m;
  cin>>n>>m;
  graph g(n);
  int a[m],b[m];
  for(i=0;i<m;i++){
    cin>>a[i]>>b[i];
    g[a[i]-1].push_back(b[i]-1);
    g[b[i]-1].push_back(a[i]-1);
  }
  int ans=0;
  for(i=0;i<m;i++){
    ver.assign(n,false);
    dfs(g,0,a[i]-1,b[i]-1);
    cnt=0;
    for(j=0;j<n;j++){
      if(ver[j])continue;
      else{
        cnt=1;
        break;
      }
    }
    if(cnt==1)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


    int cums[100001],cumt[100001];
int main(){
    string s,t;
    cin >> s >> t;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A') cums[i+1]+=1;
        else if(s[i]=='B') cums[i+1]+=2;
        cums[i+2]+=cums[i+1];
    }
        for(int i=0;i<t.length();i++){
        if(t[i]=='A') cumt[i+1]+=1;
        else if(t[i]=='B') cumt[i+1]+=2;
        cumt[i+2]+=cumt[i+1];
    }
    int q;
    cin >> q;
    while(q--){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        if((cums[b]-cums[a-1])%3==(cumt[d]-cumt[c-1])%3) puts("YES");
        else puts("NO");
    }
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

//#define int long long
#define endl '\n'
#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

int m[25][25];
int dp[1<<22];
int n;

int solve(int mask){
  if(mask == (1<<n)-1) return 1;
  if(dp[mask] != -1) return dp[mask];
  int i = __builtin_popcount(mask);
  int ans = 0;
  for(int j = 0; j < n; j++){
    if(!m[i][j] or mask&(1<<j)) continue;
    ans = (ans + solve(mask|(1<<j)))%MOD;
  }
  return dp[mask] = ans;
}

int32_t main(){
  fastio;
  memset(dp, -1, sizeof dp);
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> m[i][j];
    }
  }
  cout << solve(0)%MOD << endl;
  return 0;
}

Measured memory_bytes: 16640
#include<stdio.h>
#define N 100
#define INF 9999999
#define LEN 1000

int n, M[N][N];
int d[N];

int Q[LEN+1];
int head = 0, tail = 0;

void enqueue(int x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

int dequeue(){
  int x;
  x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

void bfs(int s){
  int i, u, v, swap;

  enqueue(s);
  for(i = 0; i < n; i++){
    d[i] = INF;
  }
  d[s] = 0;

  while(head != tail){
    u = Q[head];
    swap = dequeue();
    for(v = 0; v < n; v++){
      if(M[u][v] == 0)
        continue;
      if(d[v] != INF)
        continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
  for(i = 0; i < n; i++){
    printf("%d ",i + 1);
    if(d[i] == INF)
      printf("%d",-1);
    else
      printf("%d",d[i]);

    printf("\n");
  }

}

int main(){
  int i, j, u, k, v;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
              scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}



Measured memory_bytes: 2052
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: String -> String -> Int -> [(Int,Int,Int,Int)] -> [String]
solve bS bT q abcds = map ansF abcds
  where
  readStr s = VU.fromList $ scanl' (+) 0 $ map isANum s
  vS = readStr bS
  vT = readStr bT
  ansF (a,b,c,d) | equiv (fnAB a b vS) (fnAB c d vT) = "YES"
                 | otherwise = "NO"
  fnAB p q vec = (nA, nB)
    where nA = vec VU.! q - vec VU.! (p-1)
          nB = (q-p+1) - nA
  equiv (a1,b1) (a2,b2) = ((a1 + 2*b1) - (a2 + 2*b2)) `mod` 3 == 0

isANum 'A' = 1
isANum _   = 0


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [String]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bS]:remLines1 = remLines0
      bS = B.unpack bs_bS
      [bs_bT]:remLines2 = remLines1
      bT = B.unpack bs_bT
      [bs_q]:remLines3 = remLines2
      q = readBInt bs_q
      abcds = map (\[x1,x2,x3,x4] -> (readBInt x1,readBInt x2,readBInt x3,readBInt x4)) remLines3
  in solve bS bT q abcds

outAnswer :: [String] -> IO ()
outAnswer ss = putStr $ unlines ss

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4\n"
inp2 = "AAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 3 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 8 20\n7 20 3 14\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
test1 = tv1 == ["YES", "NO", "YES", "NO"]
test2 = tv2 == ["YES","YES","YES","YES","YES","YES","NO","NO","NO","NO"]
alltest = test1 && test2



Measured memory_bytes: 9852
#include<stdio.h>
int main(){

	char s[12];
	scanf("%s",s);
	printf("%c%c%c%c %c%c%c%c%c%c%c%c\n",s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11]);

	return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int P = scanner.nextInt();

    final long INF = 1_000_000_000;
    long[] dist = new long[N];
    Arrays.fill(dist, INF);
    dist[0] = 0;
    int[][] edges = new int[M][2];
    int[] cost = new int[M];
    Node[] forwardNodes = new Node[N];
    Node[] backNodes = new Node[N];
    for (int i = 0; i < N; i++) forwardNodes[i] = new Node();
    for (int i = 0; i < N; i++) backNodes[i] = new Node();
    for (int i = 0; i < M; i++) {
      edges[i][0] = scanner.nextInt() - 1;
      edges[i][1] = scanner.nextInt() - 1;
      cost[i] = -scanner.nextInt() + P;
      forwardNodes[edges[i][0]].adjacent.add(forwardNodes[edges[i][1]]);
      backNodes[edges[i][1]].adjacent.add(backNodes[edges[i][0]]);
    }

    dfs(forwardNodes[0]);
    dfs(backNodes[N - 1]);
    Set<Integer> possiblePath = new HashSet<>();
    for (int i = 0; i < N; i++) if (forwardNodes[i].reachable && backNodes[i].reachable) possiblePath.add(i);

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        int u = edges[j][0];
        int v = edges[j][1];
        long newValue = dist[u] + cost[j];
        if (dist[v] > newValue) dist[v] = newValue;
      }
    }

    for (int i = 0; i < M; i++) {
      int u = edges[i][0];
      int v = edges[i][1];
      if (dist[v] > dist[u] + cost[i] && possiblePath.contains(v)) {
        System.out.println(-1);
        return;
      }
    }

    System.out.println(Math.max(0, -dist[N - 1]));
  }

  private static void dfs(Node node) {
    node.reachable = true;
    for (Node n : node.adjacent) if (!n.reachable) dfs(n);
  }

  private static class Node {
    private boolean reachable;
    private final List<Node> adjacent = new ArrayList<>();
  }
}


Measured memory_bytes: 38792
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[105];
int main()
{
	int n;
	cin>>n>>s;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
		{
			ans++;
		}
	}
	cout<<ans<<"\n";
	return 0;
} 

Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
// #ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
       *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
// #else
// sim dor(const c&) { ris; }
// #endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void solve(){
    int n;
    cin>>n;
    int d[n][2];
    bool flag=false;
    for(int i=0;i<n;i++){
        cin>>d[i][0]>>d[i][1];
        if(i<2){
            continue;
        }
        int cnt=0;
        for(int j=0;j<3;j++){
            if(d[i-j][0]==d[i-j][1]){
                cnt++;
            }
        }
        if(cnt==3){
            flag=true;
        }
    }
    if(flag){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main()
{
    int N,M;cin >> N>>M;
    int sum=0,home;
    for (int i=0;i<M;i++)
    {
        cin>>home;
        sum+=home;
    }
    if (sum>N) cout << -1 << endl;
    else cout << N-sum << endl;
return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef pair<xy_t, int> pci;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

constexpr double eps=1e-9;

inline int sgn(double x){
    if(x<-eps) return -1;
    if(x>eps) return 1;
    return 0;
}

inline bool EQ(double x, double y){
    return sgn(x-y)==0;
}

inline bool GE(double x, double y){
    return sgn(x-y)==1;
}

inline bool LE(double x, double y){
    return sgn(x-y)==-1;
}

inline bool GEQ(double x, double y){
    return sgn(x-y)>=0;
}

inline bool LEQ(double x, double y){
    return sgn(x-y)<=0;
}

struct Point{
    double x, y;
    Point(double x, double y): x(x), y(y){}

    Point operator+(const Point &p){
        return {x+p.x, y+p.y};
    }

    Point operator-(const Point &p){
        return {x-p.x, y-p.y};
    }

    Point operator*(const double k){
        return {k*x, k*y};
    }

    Point operator/(const double k){
        return {x/k, y/k};
    }

    double operator*(const Point &p){
        return x*p.x+y*p.y;
    }

    double operator^(const Point &p){
        return x*p.y-y*p.x;
    }

    bool operator==(const Point &p){
        return EQ(x, p.x) && EQ(y, p.y);
    }
};

using Vec=Point;
using pdi=pair<double, int>;

double abs(Point p){
    return hypot(p.x, p.y);
}

double arg(Point p){
    return atan2(p.y, p.x);
}

constexpr int CCW_COUNTER_CLOCKWISE=1;
constexpr int CCW_CLOCKWISE=-1;
constexpr int CCW_ONLINE_BACK=-2;
constexpr int CCW_ONLINE_FRONT=2;
constexpr int CCW_ON_SEGMENT=0;

inline int ccw(Point a, Point b, Point c){
    Vec v=b-a, w=c-a;
    if(GE(v^w, 0)) return CCW_COUNTER_CLOCKWISE;
    if(LE(v^w, 0)) return CCW_CLOCKWISE;
    if(LE(v*w, 0)) return CCW_ONLINE_BACK;
    if(LE((a-b)*(c-b), 0)) return CCW_ONLINE_FRONT;
    return CCW_ON_SEGMENT;
}

bool intersectSS(Point a, Point b, Point c, Point d){
    return ccw(a, b, c)*ccw(a, b, d)<=0 && ccw(c, d, a)*ccw(c, d, b)<=0;
}

Point getCrossPointLL(Point p, Vec v, Point q, Vec w){
    double s=((q-p)^w)/(v^w);
    return p+v*s;
}

int main(){
    int q;
    scanf("%d", &q);
    while(q--){
        vector<Point> p;
        rep(i, 4){
            double x, y;
            scanf("%lf%lf", &x, &y);
            p.emplace_back(x, y);
        }
        Point cp=getCrossPointLL(p[0], p[1]-p[0], p[2], p[3]-p[2]);
        printf("%.20lf %.20lf\n", cp.x, cp.y);
    }
}


Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int D = in.nextInt();
        int N = in.nextInt();
        if(D==0){
            if(N==100) System.out.println(101);
            else System.out.println(N);
        }
        else if(D==1){
            if(N==100) System.out.println(10100);
            else System.out.println(100*N);
        }
        else{
            if(N==100) System.out.println(1010000);
            else System.out.println(N*10000);
        }
    }
}

Measured memory_bytes: 21844
def li():
    return [int(x) for x in input().split()]

S = input()
T = input()

diffs = []

for i in range(len(S)-len(T)+1):
    s = ''
    for j in range(len(T)):
        s += S[i+j]
    diff = 0
    for k in range(len(s)):
        if s[k] != T[k]:
            diff += 1
    diffs.append(diff)

print(min(diffs))

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD ll(998244353)
#define fi first
#define se second
#define endl '\n'
    
ll modexp(ll b, ll e) {
    ll res = 1;
    b = b % MOD;
    while (e>0) {
        if (e % 2) {
            res *= b;
            res %= MOD;
        }
        e /= 2;
        b *= b;
        b %= MOD;
    }
    return res;
}

void solve() {
    int n;
    cin >> n;

    vector<int> d(n);
    vector<int> cnt(1e5, 0);
    for (int i=0; i<n; ++i) {
        cin >> d[i];
        cnt[d[i]] += 1;
    }

    if (d[0]!=0) {
        cout << 0 << endl;
        return;
    }

    ll ans = 1;
    int used = 1;
    int p = 1;
    ll prev = 1;
    while (used<n) {
        if (cnt[p]==0) {
            cout << 0 << endl;
            return;
        }
        ans *= modexp(prev, cnt[p]);
        ans %= MOD;
        used += cnt[p];
        prev = cnt[p];
        p += 1;
    }

    cout << ans << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 1024
from sys import stdin


def main():
    n = next_int()
    t = [next_int() for _ in range(n)]

    ans = []
    m = next_int()

    for i in range(m):
        p = next_int() - 1
        x = next_int()
        ans += [sum(t) - t[p] + x]

    print("\n".join(map(str, ans)))


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int main(){
    int c=0;
   string s;
   cin>>s;
    if((s[0]==s[1]&&s[1]==s[2]&&s[2]==s[3])||(s[1]==s[2]&&s[2]==s[3])||(s[0]==s[1]&&s[1]==s[2]))
    cout<<"Yes";
   else cout<<"No";

 return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	string s; cin >> s;

	sort(s.begin(), s.end());
	s.resize(unique(s.begin(), s.end()) - s.begin());

	cout << (s.size() == 1 ? "No" : "Yes") << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()



ll combination(int n, int r)
{
	//nCr = nC(n-r)を使用して計算量を節約
	if (n - r < r) r = n - r;

	//自明な場合の戻り値
	if (r == 0) return 1;
	if (r == 1) return n;

	//組み合わせの数の定義に登場する分母・分子の要素
	vector<int> numerator(r, 0);
	vector<int> denominator(r, 0);

	//初期化
	rep(k, r)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	//分子を分母で割っていく。
	reple(p, 2, r)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				//分子は割り切れる場所までスライド
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	rep(k, r)
	{
		//残りを全部乗算
		if (numerator[k] > 1)
		{
			result *= numerator[k];
			result %= mod;
		}
	}

	return result;
}

int main()
{

	int x, y;
	cin >> x >> y;

	double a = (-(double)x + 2 * (double)y) / 3;
	if (a < 0 || a != floor(a))
	{
		cout << 0 << endl;
		return 0;
	}

	double b = (2 * (double)x - (double)y) / 3;
	if (b < 0 || b != floor(b))
	{
		cout << 0 << endl;
		return 0;
	}

	int cntA = (int)a;
	int cntB = (int)b;

	ll count = combination(a + b, b);

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 2816
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

const int nax = 1e5;
vi adj[nax];
int dp[nax], vis[nax];

void dfs(int k, int par){
	vis[k]=1;
	for(auto it: adj[k]){
		if(!vis[it]){
			dfs(it, k);
		}
		dp[k] = max(dp[k], dp[it]+1);
	}
}

signed main() {
	tezz
 
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	int n,m,p,q;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		cin >> p >> q;
		--p, --q;
		adj[p].pb(q);
	}
	for(int i=0; i<n; i++){
		if(!vis[i]){
			dfs(i, i);
		}
	}
	int ans=0;
	for(int i=0; i<n; i++)ans=max(ans, dp[i]);
		cout << ans << endl;
 
	return 0;
}  

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

using namespace std;

long long int calc(string str, int ind) {
    long long int ret=0;
    bool flag=true;
    for(int i=0; i<ind; i++) {
        ret += (long long int)(str[i]-'0');
        // cout << str[i];
    }
    if(ind==str.size()) {
        return ret;
    }
    ret += (long long int)(str[ind]-'0')-1;
    if((long long int)(str[ind]-'0')-1<0) {
        flag=false;
    }
    // cout << (long long int)(str[ind]-'0')-1;
    for(int i=ind+1; i<str.size(); i++) {
        // cout << 9;
        ret += 9;
    }
    // cout << endl;
    if(flag) {
        return ret;
    } else {
        return -1;
    }
}

int main() {
    string N;
    cin >> N;
    long long int ans=0;
    for(int i=0; i<N.size()+1; i++) {
        ans = max(ans, calc(N, i));
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int N;
    std::cin >> N;
    int result = 0;
    for (int i = 0; i < N; ++i) {
        int l, r;
        std::cin >> l >> r;
        result += r - l + 1;
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  long long x,y;
  int i;
  cin >> x >> y;
  for(i=0;true;i++){
      long long n = pow(2,i);
      long long p = x*n;
      if(p>y) break;
  }
  cout << i<< endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
	    int n = IO.GetInt();
	    List<int> p = IO.GetIntList();
	    List<int> q = IO.GetIntList();
	    List<int> r = new List<int>(); //残っている数字
	    for(int i=0;i<n;i++){
	        r.Add(i+1);
	    }
	    Console.WriteLine(Math.Abs(GetNo(n,p,new List<int>(r))-GetNo(n,q,new List<int>(r))));
	    
	}
	
	static int GetNo(int n,List<int> a,List<int> r,int index=0,int no=1){
	    no += GetP(n-1-index) * GetLessCount(a[index],r);
	    r.Remove(a[index]);
	    index++;
	    if(index==n)return no;
	    return GetNo(n,a,r,index,no);
	    
	}
	
	//階乗を取得
	static int GetP(int n,int temp=1){
	    if(n==0)return temp;
	    return GetP(n-1,temp * n);
	}
	
	static int GetLessCount(int a,List<int> r){
	    List<int> temp = new List<int>(r).Where(x => x < a).ToList();
	    return temp.Count();
	}

}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}

Measured memory_bytes: 13396
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int res = 0,cnt=0;   
    rep(i,n){
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
            cnt++;
        }else cnt=0;
        res = max(res,cnt);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
# Aizu Problem 0076: Treasure Hunt II
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


positions = {0: [0, 0], 1: [1, 1]}
direction = 135 * math.pi / 180
x, y = 1, 1
for step in range(2, 1001):
    x += math.cos(direction)
    y += math.sin(direction)
    positions[step] = [x, y]
    direction = math.atan2(x, -y)

while True:
    n = int(input())
    if n == -1:
        break
    print("%.2f" % positions[n-1][0])
    print("%.2f" % positions[n-1][1])
    

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

int main() {
	
	int n;
	cin >> n;
	int a[n];
	int i;
	for(i=0;i<n;i++)
	{
	    cin >> a[i];
	}
	int ans = 1;
	int min = a[0];
	for(i=1;i<n;i++)
	{
	    if(a[i] <= min)
	    {
	        min = a[i];
	        ans +=1;
	    }
	}
	cout << ans ;
	return 0;
}


Measured memory_bytes: 1024
h, w = map(int, input().split())
a = []
H = [0]*h
W = [0]*w
for i in range(h):
    a.append(input())

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            H[i] += 1
            W[j] += 1

for i in range(h):
    if H[i] != 0:
        for j in range(w):
            if W[j] != 0:
                print(a[i][j], end = '')
        print()

Measured memory_bytes: 75188
k()=readline()|>chomp
s()=[parse(Int,x)for x=k()|>split]
n,q=s()
t=k()
a=zeros(Int,n)
c=0
for i=1:n-1
if t[i:i+1]=="AC"
c+=1
end
a[i+1]=c
end
for i=1:q
l,r=s()
println(a[r]-a[l])
end

Measured memory_bytes: 155144
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function upper_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<=e?a=c:b=c;return d[a]<=e?b:a};

console.log(main());
function main(){
  var b = o.a(1);
  if(b === "A")return "T";
  if(b === "T")return "A";
  if(b === "C")return "G"
  return "C";
}

Measured memory_bytes: 22076
#include<iostream>
using namespace std;
 
int main(){
    while(1){
        int d,c;
        cin >> d >>c;
         
        if(d==0 && c==0)break;
        for(int i=0;i<c;i++){
            cout<<"#";
        }
        cout<<"\n";
		
        for(int j=0+1;j<d-1;j++){
            cout<<"#";
            for(int j=0+1;j<c-1;j++){
                cout<<".";
            }
            cout<<"#";
            cout<<"\n";
			
        }
        for(int i=0;i<c;i++){
            cout<<"#";
        }
        cout<<"\n";
        cout<<"\n";
    }
     
    return 0;
}

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define endl "\n"
#define pb push_back
ll N,S;
vec v,sum;
int judge(ll K,ll x){
  ll i=lower_bound(all(v),x)-v.begin();
  K-=S-i;
  if(!i||K<=0)return 1;
  if(sum[i-1]/K>=x){
    return 1;
  }
  return 0;
}
int main(){
  ll i,N,cnt=1;
  cin>>N;
  vec a(N);
  rep(i,N)cin>>a[i];
  vsort(a);
  rep1(i,N){
    if(a[i]==a[i-1]){
      cnt++;
    }else{
      v.pb(cnt);
      cnt=1;
    }
  }
  v.pb(cnt);
  vsort(v);
  S=v.size();
  sum.resize(S);
  sum[0]=v[0];
  rep1(i,S)sum[i]=sum[i-1]+v[i];
  rep1(i,N+1){
    if(i>S){
      cout<<0<<endl;
      continue;
    }
    ll ng=N/i+1,ok=0,mid;
    while(ng-ok>1){
      mid=(ok+ng)/2;
      if(judge(i,mid)){
        ok=mid;
      }else{
        ng=mid;
      }
    }
    cout<<ok<<endl;
  }
  return 0;
}

Measured memory_bytes: 9324
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){
    char a[4]={0}, b[4]={0}, c[8]={0};
    int  x, y;

    scanf("%s %s", a, b);
    sprintf(c, "%s%s", a, b);

    x = atoi(c);
    y = (int)sqrt((double)x);

    if( pow((double)y, 2) != x ){ printf("No\n");  }
    else                        { printf("Yes\n"); }
    return 0;
}

Measured memory_bytes: 2112