akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int w, a, b; cin >> w >> a >> b;
    if (b < a)swap(a, b);
    cout << max(0, b - w - a) << "\n";
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(scan.next());
        }
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = Integer.parseInt(scan.next());
        }
        scan.close();

        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);

        int[] bc = new int[n];
        for (int i = 0; i < n; i++) {
            int okMinIndex = binarySearch(c, b[i]);
            bc[i] = n - okMinIndex;
        }

        long[] abc = new long[n];
        abc[n - 1] = bc[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            abc[i] = abc[i + 1] + bc[i];
        }

        long ans = 0;
        for (int i = 0; i < n; i++) {
            int okMinIndex = binarySearch(b, a[i]);
            if (okMinIndex == n) {
                continue;
            }
            ans += abc[okMinIndex];
        }

        System.out.println(ans);
    }

    private static int binarySearch(int[] array, int key) {
        int ng = -1;
        int ok = array.length;

        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if (array[mid] > key) {
                ok = mid;
            } else {
                ng = mid;
            }
        }

        return ok;
    }

}


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

int main(void) {
	int r, D, X0;
	cin >> r >> D >> X0;

	int X = X0;
	for (int i = 1; i <= 10; ++i) {
		X = r * X - D;
		cout << X << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
s = [input() for _ in range(N)]
a = 0
b = 0
c = 0
d = 0
for i in range(N):
    d += s[i].count("AB")
    if s[i][0] != 'B' and s[i][-1] == 'A':
        a += 1
    if s[i][0] == 'B' and s[i][-1] != 'A':
        b += 1
    if s[i][0] == 'B' and s[i][-1] == 'A':
        c += 1
if a == 0 and b == 0:
    if c == 0:
        print(d)
    else:
        print(d+c-1)
else:
    print(d+min(a+c,b+c))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) sort(v.begin(),v.end())
#define ALL(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    rep(i,k){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
    return 0;
}

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

using namespace std;

string a, b, c;
queue<int> d[3];

int main() {
	cin >> a >> b >> c;
	for(int i = 0; i < max(a.length(), max(b.length(), c.length())); i++) {
		if (i < a.length()) d[0].push(a[i] - 'a');
		if (i < b.length()) d[1].push(b[i] - 'a');
		if (i < c.length()) d[2].push(c[i] - 'a');
	}
	int turn = 0;
	while(1) {
		int tmp = d[turn].front();
		d[turn].pop();
		turn = tmp;
		if (!d[turn].size()) {
			if (turn == 0) cout << "A";
			else if (turn == 1) cout << "B";
			else cout << "C";
			break;
		} 
	}
	return 0;
}

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

typedef long long ll;

int c[105][105];

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int temp = 1, num;
    int x = 0, y = 0;
    for (int i = 1; i <= n; i++) {
        cin >> num;
        while (num--) {
            c[x][y] = i;
            y += temp;
            if (y == w) {
                x++;
                y = w - 1;
                temp = -temp;
            }
            if(y==-1){
                x++;
                y=0;
                temp=-temp;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (j == 0)
                cout << c[i][j];
            else
                cout << " " << c[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

const int mo=998244353;

int n,Ans;

struct Point{
	int x,y;
	Point() {}
	Point(int x,int y):x(x),y(y) {}
	Point operator + (const Point &p) {return Point(x+p.x,y+p.y);}
}P[210];

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,j,k;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d%d",&P[i].x,&P[i].y);
	Ans=power(2,n);
	for (i=1;i<=n;i++)
	for (j=i+1;j<=n;j++)
	{
		int cnt=0;
		for (k=j+1;k<=n;k++)
			cnt+=(P[i].x-P[j].x)*(P[i].y-P[k].y)==(P[i].x-P[k].x)*(P[i].y-P[j].y);
		(Ans+=mo-power(2,cnt))%=mo;
	}
	(Ans+=mo-n-1)%=mo;
	printf("%d\n",Ans);
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b,c,d = list(map(int, input().split()))
diff = a-b
for i in range(n):
    if c*(n-1-i)-i*d <= diff <= d*(n-1-i)-i*c:
        ans = "YES"
        break
else:
    ans = "NO"
print(ans)

Measured memory_bytes: 64284
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(min(A+1, X//500+1)):
    for b in range(min(B+1, X//100+1)):
        for c in range(min(C+1, X//50+1)):
            if 500*a + 100*b + 50*c == X:
                count += 1

print(count)

Measured memory_bytes: 3064
N, K = map(int, input().split())
L = [0]*N
for i in range(min(K-1,N)):
  n = 1
  while (i+1)*(2**n) < K:
    n = n+1


  L[i] = (1/2)** n

if N >= K:
  for j in range(K-1,N):
    L[j] = 1

print(sum(L)/N)

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, M, X;
    cin >> N >> M >> X;

    vi c(N);
    vvi a(N, vi(M));

    REP(n, N) {
        cin >> c[n];
        REP(m, M) cin >> a[n][m];
    }

    // for (int n : c) cout << n << ", " ;
    // cout << endl;
    // for (vi v : a) {
    //     for (int n : v) cout << n << ", " ;
    //     cout << endl;
    // }
    int int_ans = 10000*12*100;
    int ans = int_ans;
    REP(bit, (1<<N)) {
        vi idx;
        REP(i, N) if (bit & (1<<i)) idx.emplace_back(i);

        
        vi und(M, 0);
        for (int id : idx) REP(ai, M) und[ai] += a[id][ai];

        bool ok = true;
        for (int u : und) if (u < X) ok = false;

        if (ok) {
            int tmp = 0;
            for (int id : idx) tmp += c[id];
            ans = min(ans, tmp);
        }
    }

    if (ans != int_ans) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3664
import java.util.*;

class Main{
    Scanner sc = new Scanner(System.in);
    
    Main(){
    double r = sc.nextDouble();
    System.out.printf("%.10f %.10f\n",r*r*Math.PI,(2*r)*Math.PI);
    
    }
    public static void main(String[] args){
    new Main();
    }    
}


Measured memory_bytes: 28328
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int>D(N);
  map<int,int>k;
  for(int i=0;i<N;i++){
    cin>>D[i];
    k[D[i]]++;
  }
  if(D[0]!=0||k[0]!=1){cout<<0<<endl;}
  else{
    int64_t ans=1;
    for(int i=0;i<N;i++){
      if(D[i]!=0){
        ans*=k[D[i]-1];
        ans%=998244353;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 8240
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e7 + 5, M = 2 * N + 5;

vector<int> res;
void KMP(const string &s, const string &k){
    res.clear();
    if (k.empty())
        return ;
    vector<int> tmp(k.size(), 0);
    for (int i = 1, j = 0; i < k.size(); ++i){
        while (j && k[j] != k[i])
            j = tmp[j - 1];
        if (k[j] == k[i])
            ++j;
        tmp[i] = j;
    }
    for (int i = 0, j = 0; i < s.size(); ++i){
        while (j && k[j] != s[i])
            j = tmp[j - 1];
        if (k[j] == s[i])
            ++j;
        if (j == k.size())
            res.push_back(i - j + 1);
    }
}

int n, m;

string a, b;

int f(){
    n = res.size();
    int mx = 0;
    int len = a.size();
    vector<int> sum(len, 0);
    for(auto i : res){
        if(i - m >= 0)
            sum[i] = sum[i - m] + 1;
        else sum[i] = 1;
        mx = max(mx, sum[i]);        
    }
    return mx;
}


int main(){
    IO;
    cin >> a >> b;
    m = b.size();
    while(a.size() <= m)
        a += a;
    a += a;
    a += a;
    KMP(a, b);
    int hna = f();
    a += a;
    KMP(a, b);
    if(f() > hna)return cout << -1 << endl, 0;
    if(n == 0)return cout << n << endl, 0;
    cout << hna << endl;
}

Measured memory_bytes: 74368
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  long long x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[200101];
int l[631010];
int j[200102];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[1];
queue<int> q;

//stack<int> s;
set<int> s;
map<int,int> p;
vector<P> v[200101];

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

long long f(long long n,long long m)
{
  if(m<n) return 0;
  long long x=(n+m)*(m-n+1)/2;
  return x*c;
}

int main()
{
  scanf("%d %d %d",&a,&b,&c);
  if(c==0)
  {
     if(b) printf("%d",a+1);
    else puts("1");
    return 0;
  }
  d=abs(2*c);
  for(long long t=0;t<=a;t++)
  {
    y=t*b-(a-t)*b;
    int i;
    if(p[(y%d+d)%d]) i=p[(y%d+d)%d];
    else e++,p[(y%d+d)%d]=i=e;
    v[i].push_back({y-f(t,a-1)+f(0,t-1),y+f(a-t,a-1)-f(0,a-t-1)});
    if(v[i].back().x>v[i].back().y) swap(v[i][v[i].size()-1].x,v[i][v[i].size()-1].y);
    //printf("%lld %lld\n",v[i].back().x,v[i].back().y);
  }
  for(int t=1;t<=e;t++)
  {
    sort(v[t].begin(),v[t].end(),as);
    z=v[t][0].x-1;
    //x++;
    for(int i=0;i<v[t].size();i++)
    if(z<v[t][i].y)
    {
      if(z>=v[t][i].x)x+=abs((v[t][i].y-z)/(2*c));
      else x+=abs((v[t][i].y-v[t][i].x)/(2*c))+1;
      z=v[t][i].y;
    }
  }
  printf("%lld",x);
}




Measured memory_bytes: 22016
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,c;vi a(N),p(N),no(N);
void solve(){
  cin>>n;cin>>a[0];

  rep(i,1,n)cin>>a[i],p[i]=p[i-1]+a[i];
  no[0]=1LL-a[0]; 
  rep(i,1,n){
    no[i]=2*no[i-1]-a[i];
    //for every leaf we lose we have atmost 1 vertex
    no[i]=min(no[i],p[n]-p[i]);
    if(no[i]<0){
      cout<<-1;return;
    }
    // cout<<no[i]<<p[n]-p[i]<<"\n";
  }
  if(a[0]>1){cout<<-1;return;}
  rep(i,0,n)c+=no[i]+a[i];cout<<c;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 50124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();

		int mod = 998244353;

		fact[0] = 1;
		factInv[0] = 1;
		for(int i = 0; i < fact.length - 1; i++){
			fact[i+1] = fact[i]*(i+1) % mod; // n!(mod M)
	        factInv[i+1] = (int)(factInv[i]*repeatablePow(i+1, mod-2, mod) % mod);
		}

		if(m == 1){
			if(k == n - 1){
				System.out.println(1);
				return;
			}
			else {
				System.out.println(0);
				return;
			}
		}

//		long dp[] = new long[k + 1];
//		dp[0] = m;
//
//		for(int i = 1; i < n; i++){
//			dp[0] *= m - 1;
//			dp[0] %= mod;
//		}
//
//		System.out.println(dp[0]);
//
//		for(int i = 1; i <= k; i++){
//			dp[i] = dp[i - 1];
//
//			dp[i] %= mod;
//
//			System.out.println(dp[i]);
//		}

		long result = 0;
		long baseColorNum[] = new long[n + 1];

		for(int i = 1; i <= n; i++){
			if(i == 1){
				baseColorNum[i] = m;
			}
			else {
				baseColorNum[i] = baseColorNum[i - 1]*(m - 1);
				baseColorNum[i] %= mod;
			}
//			System.out.println("i = "+i+" base = "+baseColorNum[i]);

			int remain = n - i;

			if(remain > k){
				continue;
			}

//			long tmp = repeatablePow(i, remain, mod) * baseColorNum[i];
			long tmp = combination(n - 1, i - 1, mod)*baseColorNum[i];
			tmp %= mod;

//			System.out.println("i = "+i+" tmp = "+tmp);

			result += tmp;
			result %= mod;

		}

		System.out.println(result);
//		long dp[] = new long[n];
//		dp[n - 1] = m;
//		for(int i = n - 2; i >= 0; i--){
//			dp[i] = dp[i + 1]*(m - 1);
//			dp[i] %= mod;
//			dp[i] = dp[i]*(n - 1);
//
//			dp[i] %= mod;
//		}
//
//		for(int i = 0; i <= k; i++){
//			System.out.print(dp[i] + " ");
//		}
//
//		System.out.println();

	}

	static long repeatablePow(int x, int n, int mod){
		if(n == 0){
			return 1;
		}
		long result = repeatablePow((int)((long)x*x%mod), n/2, mod);
		if(n % 2 == 1){
			result = result*x%mod;
		}
		return result;
	}

	static long combination(int a, int b, int mod){ //aCbをmod計算
	    if(a == 0 && b == 0)return 1;
	    if(a < b || a < 0)return 0;

	    long tmp = factInv[a - b]* factInv[b] % mod;
	    return tmp * fact[a] % mod;
	}

	static long fact[] = new long[2000002];
	static long factInv[] = new long[2000002];

}


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

int main() {
  int N; cin>>N;
  string s; cin>>s;
  int count=0;
  if(N%2!=0) cout<<"No"<<endl;
  else{
    for(int i=0;i<N/2;i++){
      if(s.at(i)!=s.at(N/2+i)) count++;
    }
    if(count==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  } 
}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

//-----------------------
const int MOD = (int)1e9 + 7;
struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }
mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0;
    while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); }
    return mint(u); }
mint operator^(mint a, long long n) { mint r = 1;
    while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
//-----------------------

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto &vi: vec) os << vi << " "; return os;
}
template<class T> struct Matrix {
    vector<vector<T>> val;
    Matrix(int n = 1, int m = 1, T x = 0) { val.assign(n, vector<T>(m, x)); }
    size_t size() const { return val.size(); }
    vector<T>& operator[](int i) { return val[i]; }
    const vector<T>& operator[](int i) const { return val[i]; }
    friend ostream& operator<<(ostream& os, const Matrix<T> M) {
        for (int i = 0; i < M.size(); ++i) os << M[i] << " \n"[i != M.size() - 1];
        return os;
    }
};
template<class T> Matrix<T> operator^(Matrix<T> A, long long n) {
    Matrix<T> R(A.size(), A.size());
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; }
    return R;
}
template<class T> Matrix<T> operator*(const Matrix<T>& A, const Matrix<T>& B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j)
        for (int k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];
    return R;
}
template<class T> vector<T> operator*(const Matrix<T> &A, vector<T> &B) {
    vector<T> v(A.size());
    for (int i = 0; i < A.size(); ++i)
        for (int k = 0; k < B.size(); ++k) v[i] += A[i][k] * B[k];
    return v;
}

int main() {
    int n; long long k; cin >> n >> k;
    Matrix<mint> trans(n, n);
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> trans[i][j];
    vector<mint> state(n, 1);
    auto res = (trans ^ k) * state;
    cout << accumulate(res.begin(), res.end(), mint(0)) << endl;
    return 0;
}

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

int main() {
    int n, k;
    scanf("%d %d ", &n, &k);
    string s;
    cin>>s;
    char tbs, tbr;
    if (n==1) {
        printf("0\n");
        return 0;
    }
    if (s[0]=='L') {
        tbs = 'R';
        tbr = 'L';
    }
    else {
        tbr = 'R';
        tbs = 'L';
    }
    int beg;
    int l = 0;
    for (int i=1; i<n; i++) {
        if (s[i]==tbs) {
            for (int j=i; j<n; j++) {
                if (s[j]==tbs) s[j]=tbr;
                else break;
            }
            l++;
            if (l==k) break;
        }
    }
    if (l<k && s[0]!=s[n-1]) {
        printf("%d\n", n-1);

    } else {
        int ans = 0;
        for (int i=1; i<n-1; i++) {
            if (s[i]=='L') {
                if (s[i-1]=='L') {
                    ans++;
                } 
            } else {
                if (s[i+1]=='R') {
                    ans++;
                }
            }
        }
        if (s[0]=='R' && s[1]=='R') ans++;
        if (s[n-1]=='L' && s[n-2]=='L') ans++;
        printf("%d\n", ans);
    }
    // cout << s << endl;
}

Measured memory_bytes: 512
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

n=I()

lis = []

for i in range(9):
    for j in range(9):
        lis.append((i+1)*(j+1))

if n in lis:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
	int minv;
	int d[MAX],color[MAX];
	
	for(int i=0;i<n;i++){
		d[i]=INFTY;
		color[i]=WHITE;
	}
	
	d[0]=0;
	color[0]=GRAY;
	while(1){
		minv=INFTY;
		int u=-1;
		for(int i=0;i<n;i++){
			if(minv>d[i]&&color[i]!=BLACK){
				u=i;
				minv=d[i];
			}	
		}
		if(u==-1)break;
		
		color[u]=BLACK;
		for(int v=0;v<n;v++){
			if(color[v]!=BLACK && M[u][v]!=INFTY){
				if(d[v]>d[u]+M[u][v]){
					d[v]=d[u]+M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	
	for(int i=0;i<n;i++){
		cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
	}
	
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=INFTY;
		}
	}
	
	int k,c,u,v;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){	
			cin>>v>>c;
			M[u][v]=c;
		}
	}
	
	dijkstra();
	
	return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int ll;
int main()
{
	int n;
	cin >> n;
	int a;
	ll mp=0, pm=0;
	ll mp_tmp=0, pm_tmp=0;
	for(int i=0; i<n; i++){
		cin >> a;
		mp_tmp += a;
		pm_tmp += a;
		if(i%2==0){
			if(mp_tmp>=0){
				mp += (mp_tmp+1);
				mp_tmp=-1;
			}
			if(pm_tmp<=0){
				pm += (1-pm_tmp);
				pm_tmp=1;
			}
		}else{
			if(mp_tmp<=0){
				mp += (1-mp_tmp);
				mp_tmp=1;
			}
			if(pm_tmp>=0){
				pm += (pm_tmp+1);
				pm_tmp=-1;
			}
		}
	}
	cout << min(mp, pm) << endl;
	return 0;
}

Measured memory_bytes: 256
/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>
#include <map>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <functional>
*/
#include <bits/stdc++.h>

#define _USE_MATH_DEFINES

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int d[1000][1000];

void Daijkstra() { //単一始点最短経路

	priority_queue< P, vector<P>, greater<P> > Q;


}

void Warshall(){ //全点対最短経路 O(V^3)

	int n, m;
	cin >> n >> m;

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

	for (int i = 0; i < m; i++) {//m : 節の数
		int a, b, t;
		cin >> a >> b >> t;
		d[a - 1][b - 1] = d[b - 1][a - 1] = t;
	}

	for (int k = 0; k < n; k++) { //n : 頂点数
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}


int main() {

	string s;
	cin >> s;

	for (int i = 0; i < s.length(); i += 2)
		cout << s[i];
	cout << endl;
	

	return 0;

}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//modint 2^61-1
class RHint {
private:
	const ull MASK30 = (1UL << 30) - 1;
	const ull MASK31 = (1UL << 31) - 1;
	const ull RMOD = (1UL << 61) - 1;
	inline ull Mul(ull a, ull b) {
		ull au = a >> 31;
		ull ad = a & MASK31;
		ull bu = b >> 31;
		ull bd = b & MASK31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30;
		ull midd = mid & MASK30;
		return (au * bu * 2 + midu + (midd << 31) + ad * bd);
	}
	//mod 2^61-1を計算する関数
	inline ull CalcMod(ull a) {
		a = (a & RMOD) + (a >> 61);
		if (a > RMOD) a -= RMOD;
		return a;
	}
public:
	ull val;

	RHint() { val = 0; };
	RHint(ull a) {
		val = CalcMod(a);
	}

	inline RHint operator+(const RHint& r) {
		return RHint(CalcMod(this->val + r.val));
	}
	inline RHint operator*(const RHint& r) {
		return RHint(Mul(this->val, r.val));
	}
	inline RHint& operator=(const RHint& r) {
		val = r.val;
		return *this;
	}
	inline RHint& operator+=(const RHint& r) {
		*this = *this + r;
		return *this;
	}
	inline RHint& operator*=(const RHint& r) {
		*this = *this * r;
		return *this;
	}
};
inline bool operator==(const RHint& l,const RHint& r) {
	return l.val == r.val;
}
inline bool operator!=(const RHint& l, const RHint& r) {
	return l.val != r.val;
}
class RollingHash {
private:
	const ull RMOD = (1UL << 61) - 1;
	const ull PV = RMOD * 3;
	RHint base;
public:
	vector<RHint> hash, pow;
	RollingHash(string s,ull b) {
		int l = s.size();
		base = RHint(b);
		hash = vector<RHint>(l + 1, 0);
		pow = vector<RHint>(l + 1, 1);
		for (int i = 0; i < l; i++) {
			hash[i + 1] = (hash[i] + RHint(s[i])) * base;
			pow[i + 1] = pow[i] * base;
		}
	}
	RHint get(int l, int r) {
		return RHint(hash[r].val + PV - (hash[l] * pow[r - l]).val);
	}
	RHint connect(RHint h1, RHint h2, int h2l) {
		return  (h1 * pow[h2l] + h2);
	}
	int lcp(RollingHash& b, int l1, int r1, int l2, int r2) {
		int len = min(r1 - l1, r2 - l2);
		int low = -1, high = len + 1;
		while (high - low > 1) {
			int mid = (low + high) / 2;
			if (get(l1, l1 + mid) == b.get(l2, l2 + mid))low = mid;
			else high = mid;
		}
		return low;
	}
};


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

	int N;
	cin >> N;
	string s;
	cin >> s;
	RollingHash S(s, 581409097);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			while (ans < j - i && j + ans < N && S.get(i, i + ans + 1) == S.get(j, j + ans + 1))ans++;
		}
	}
	cout << ans << endl;
}

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

#define      ll     long long int

int main()
{
    int n, i, j;
    set<int> st;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        st.insert(j);
    }
    cout << (int) st.size() << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
pair<int,int>ducati[200010],b6e0[200010];
bool cmp1(pair<int,int>x,pair<int,int>y){
	return x.first+x.second<y.first+y.second;
}
bool cmp2(pair<int,int>x,pair<int,int>y){
	return x.first-x.second<y.first-y.second;
}
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//MessageBox(GetForegroundWindow(),"标题","内容",MB_YESNO);
	int n;
	cin>>n;
	int x,y;
	int sum[n+1];
	for(int i=1;i<=n;i++){
		cin>>ducati[i].first>>ducati[i].second;
		b6e0[i]=ducati[i];
	}
	sort(ducati+1,ducati+n+1,cmp1);
	sort(b6e0+1,b6e0+n+1,cmp2);
	cout<<max(llabs(ducati[1].first-ducati[n].first)+llabs(ducati[n].second-ducati[1].second),llabs(b6e0[1].first-b6e0[n].first)+llabs(b6e0[n].second-b6e0[1].second))<<endl;
	return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n), left_gcd(n), right_gcd(n);
    REP(i, n) cin >> a[i];

    left_gcd[0] = a[0];
    REP(i, n - 1) left_gcd[i + 1] = gcd(a[i + 1], left_gcd[i]);
    right_gcd[n - 1] = a[n - 1];
    FORR(i, n - 2, 0) right_gcd[i] = gcd(a[i], right_gcd[i + 1]);

    int ans = right_gcd[1];
    REP(i, n - 2) ans = max(ans, gcd(left_gcd[i], right_gcd[i + 2]));
    ans = max(ans, left_gcd[n - 2]);
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  ll k, a, b;
  cin >> k >> a >> b;
  ll t = ((k - (a - 1)) / 2) * (b - a);
  ll rem = k - (a - 1) % 2;
  if (rem & 1)
    t++;
  ll ans = t + a;
  cout << max(ans, k + 1) << endl;
}


Measured memory_bytes: 3616
n = int(input())
l = list(map(int, input().split()))
d = {1:0,2:0,0:0}
for i in l:
    m = i % 4
    if m == 2:
        d[1] += 1
    elif m == 0:
        d[2] += 1
    else:
        d[0] += 1

if d[1] == 0:
    print('Yes' if d[2] + 1 >= d[0] else 'No')
    exit()

print('Yes' if d[2] >= d[0] else 'No')

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c=0,d,i;
    cin>>n>>m;
    int arr[m];
    for(i=0;i<m;i++)
    {
        cin>>arr[i];
        c+=arr[i];
    }
    d=n-c;
    if(d>=0)
    {
        cout<<d<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }
}


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 1e5 + 10;
using namespace std;
set<string> st;

bool valid(string s) {
    map<char, int> cnt;
    for (auto i:s) cnt[i]++;
    return cnt['3'] > 0 and cnt['5'] > 0 and cnt['7'] > 0;
}

void solve(string s) {
    if (s.size() > 9) return;
    if (valid(s)) st.insert(s);
    solve(s + '3');
    solve(s + '5');
    solve(s + '7');
}

int main() {
    IO;
    int n;
    cin >> n;
    solve("");
    int cnt = 0;
    set<int> ans;
    for (auto i:st) {
        ans.insert(stoi(i));
    }
    for (auto i:ans) {
        if (i > n) break;
        cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 6972
use proconio::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: i32, M: i32, X: i32,
        A: [[i32; M + 1]; N],
    }
    let mut ans = std::i32::MAX;
    for bit in 0..1 << N {
        let mut v: Vec<i32> = vec![0; (M + 1) as usize];
        for i in 0..N {
            if bit & (1 << i) != 0 {
                for j in 0..M + 1 {
                    v[j as usize] += A[i as usize][j as usize];
                }
            }
        }
        if (1..M + 1).filter(|&x| v[x as usize] >= X).count() == M as usize {
            ans = if ans > v[0] { v[0] } else { ans };
        }
    }
    ans = if ans == std::i32::MAX { -1 } else { ans };
    println!("{}", ans);
}


Measured memory_bytes: 2204
program main
  implicit none
  integer :: n, m, i, pos, l, r, dice(100000), idice
  character(100001) :: s
  logical, allocatable :: ls(:)
  read *, n, m
  read *, s
  allocate (ls(0:n))
  do i = 0, n
    ls(i) = (s(i + 1:i + 1) == "0")
  end do
  pos = n
  idice = 0
  outer: do
    l = max(0, pos - m)
    r = pos - 1
    do i = l, r
      if (ls(i)) then
        idice = idice + 1
        dice(idice) = pos - i
        pos = i
        if (i == 0) then
          exit outer
        else
          cycle outer
        end if
      end if
    end do
    print "(i0)", -1
    return
  end do outer
  print "(100000(i0, ' '))", dice(idice:1:-1)
end program main


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> row_cnt(h + 1, 0);
    vector<int> col_cnt(w + 1, 0);
    pair<int,int> target[m + 1];
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        row_cnt[x]++;
        col_cnt[y]++;
        target[i].first = x;
        target[i].second = y;
    }
    int mx_row = *max_element(row_cnt.begin(), row_cnt.end());
    int mx_col = *max_element(col_cnt.begin(), col_cnt.end());
    int mx_row_cnt = 0;
    int mx_col_cnt = 0;
    vector<int> mx_cols;
    for (int i = 1; i <= h; i++) {
        if (row_cnt[i] == mx_row) mx_row_cnt++;
    }
    for (int i = 1; i <= w; i++) {
        if (col_cnt[i] == mx_col) mx_col_cnt++;
    }
    int ans = mx_row + mx_col;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int x = target[i].first;
        int y = target[i].second;
        if (row_cnt[x] == mx_row and col_cnt[y] == mx_col)
            cnt++;
    }
    cout << ans - (mx_row_cnt * mx_col_cnt == cnt) << '\n'; 
    return 0;
}

Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}





int main() {
  ll n, k;
   cin >> n >> k;
   vector<ll> v(n);
   for (int i = 0; i < n; i++) cin >> v[i];
 
   ll ans = 0;
   for (int i = 0; i < n; i++) {
     ll migi = 0, zentai = 0;
     for (int j = i; j < n; j++)
       if (v[i] > v[j]) migi++;
     for (int j = 0; j < n; j++)
       if (v[i] > v[j]) zentai++;
 
     ans += migi * k % MOD;
     ans %= MOD;
     ans += (k - 1) * k / 2 % MOD * zentai % MOD;
     ans %= MOD;
   }
   cout << ans << endl;
    
}

Measured memory_bytes: 3724
import std.string;
import std.stdio;
import std.algorithm;

void main() {
	auto s = readln.chomp.dup;
	auto t = readln.chomp.dup;

	if (t.length < s.length) {
		swap(s, t);
	}

	auto dp0 = new char[][s.length + 1];
	auto dp1 = new char[][s.length + 1];
	foreach (ref e;dp0) {
		e = new char[0];
	}
	dp1[0] = new char[0];

	foreach (te;t) {
		foreach (size_t i, se;s) {
			if (te == se) {
				dp1[i + 1] = dp0[i];
				dp1[i + 1] ~= te;
			} else if (dp0[i + 1].length >= dp1[i].length) {
				dp1[i + 1] = dp0[i + 1];
			} else {
				dp1[i + 1] = dp1[i];
			}
		}
		swap(dp0, dp1);
	}

	writeln(dp0[s.length]);
}


Measured memory_bytes: 36604
#include <bits/stdc++.h>
using namespace std;
pair<int, int> gao(pair<int, int> a, pair<int, int> b) {
	int c[] = {a.first, a.second, b.first, b.second};
	sort(c, c + 4);
	return {c[3], c[2]};
}
int n;
pair<int, int> a[262145];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < 1 << n; i++) {
		scanf("%d", &a[i].first);
	}
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < 1 << n; i++) {
			if (i >> j & 1) {
				a[i] = gao(a[i], a[i ^ (1 << j)]);
			}
		}
	}
	for (int i = 1, z = 0; i < 1 << n; i++) {
		z = max(z, a[i].first + a[i].second);
		printf("%d\n", z);
	}
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
 int i,j,k,ans,n;
  ans = 0;
  cin >> n;
  string s;
  cin >> s;
  for(i=0;i<n-2;i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
      ans++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys

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

# rstrip().decode('utf-8')
# map(int,input().split())


def main():
	n=int(input())
	
	li=[[] for i in range(n)]
	for i in range(n):
		a=int(input())
		for j in range(a):
			x,y=map(int,input().split())
			li[i].append((x-1,y))
	
	ans=0
	
	for i in reversed(range(1<<n)):
		aa=[0]*n
		f=1
		for j in range(n):
			if (i>>j)&1==1:
				aa[j]=1
				
		for k in range(n):
			if aa[k]==1:
				for x,y in li[k]:
					if aa[x]!=y:
						f=0
		if f==1:
			ans=max(ans,str(bin(i)).count("1"))
	
	print(ans)
	
	
	
	
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 44656
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>

using namespace std;

int N;
int main() {
    while (cin >> N) {
        int a[N], box[N], M = 0;
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        for (int i = N; i > 0; i--) {
            int ball = a[i - 1];
            for (int j = 2; i * j <= N; j++) {
                // cout << "DEBUG: i = " << i << ", " << (i * j - 1) << ", " << box[i * j - 1] << endl;
                ball += box[i * j - 1];
            }
            // cout << "DEBUG: " << i << " " << ball << endl;
            if (ball % 2 == 1) {
                box[i - 1] = 1;
                M++;
            } else {
                box[i - 1] = 0;
            }
        }
        cout << M << endl;
        if (M != 0) {
            for (int i = 0; i < N; i++) {
                if (box[i] == 1) {
                    cout << (i + 1) << " ";
                }
            }
            cout << endl;
        }
    }
    return 0;
}



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

int main() {
    ios::sync_with_stdio(false); 
    int n; cin >> n; 
    vector<int> a(100010, 0); 
    for (int i = 1; i <= n; i++) cin >> a[i]; 

    sort(a.begin() + 1, a.begin() + n + 1); 

    cout << a[n/2 + 1] - a[n/2] << "\n"; 

}

Measured memory_bytes: 640
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#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__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;

int main(){
    fastio
    int arr[5];
    for (int i = 0; i < 5; i++)
    {
        cin>>arr[i];
    }
    int k;
    cin>>k;
    for( int i=0;i<5;i++)
    {
        for( int j=0;j<5;j++)
        {
            if(arr[i]>=arr[j])
            {
                if(arr[i]-arr[j]<=k)
                continue;
                else
                return cout<<":(",0;
            }
        }
    }
    cout<<"Yay!"<<endl;
    
    
    return 0 ;
}

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

#define ll long long
#define pb push_back
#define pf push_front
#define np next_permutation
#define pp prev_permutation
#define all(x) (x).begin(),(x).end()

using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
        c[i]=i+1;

    vector<vector<int> >d;

    do d.pb(c);
    while(np(all(c)));

    int x,y;
    for(int i=0; i<d.size(); i++)
    {
        if(d[i]==a) x=i;
        if(d[i]==b) y=i;
    }
    cout<<abs(x-y);
    return 0;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <typename Monoid> struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

  private:
    int n;
    vector<Monoid> node;
    Monoid E;
    F f;

  public:
    SegmentTree(vector<Monoid> v, Monoid e, const F func) : f(func), E(e) {
        int sz = v.size();
        n = 1;
        while(n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, E);
        for(int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for(int i = n - 2; i >= 0; i--) {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void update(int i, Monoid val) {
        i += (n - 1);
        node[i] = val;
        while(i > 0) {
            i = (i - 1) / 2;
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Monoid query(int a, int b, int i = 0, int l = 0, int r = -1) {
        if(r < 0) {
            r = n;
        }
        if(r <= a || b <= l) {
            return E;
        }
        if(a <= l && r <= b) {
            return node[i];
        }
        Monoid vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

    Monoid operator[](const int &i) const { return node[i + n - 1]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    bool f = true;
    SegmentTree<int> segmin(
        h, INF, [](const int &a, const int &b) { return min(a, b); });
    for(int i = 0; i < n - 1; i++) {
        int mn = segmin.query(i + 1, n);
        if(h[i] - mn > 1) {
            f = 0;
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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;
}

int main() {
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a.at(i)=x-(i+1);
    }
    sort(a.begin(),a.end());
    int index=n/2;
    ll center=0;
    if(n%2==1){
        center=a.at(index);
    }
    else{
        center=(a.at(index)+a.at(index-1))/2;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=abs(a.at(i)-center);
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
 
 
using namespace std;
 
 
 
 
int main(){
 
  char str[6];
 scanf("%s",str);



if (strstr(str,"AC")==NULL) cout<<"No"<<endl;
else cout<<"Yes"<<endl; 
 
return 0;
}

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

const int maxn=1e9;

int a[100100],b[100100];

int main()
{
    int n,k,tem,len1=1,len2=1,flag=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)a[i]=maxn,b[i]=maxn;
    a[0]=b[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&tem);
        if(tem<0)a[len1++]=-tem;
        else if(tem>0)b[len2++]=tem;
        else flag=1;
    }
    int r=len1-1,l=1;
    while(l<r)
    {
        tem=a[l];
        a[l]=a[r];
        a[r]=tem;
        l++;r--;
    }
    int ans=maxn,left,right;
    len1--;
    len2--;
    if(flag)k--;
    len1=min(len1,k);
    for(int i=0;i<=len1;i++)
    {
        left=a[i];right=b[k-i];
        ans=min(ans,min(2*left+right,2*right+left));
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024