akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"

signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n;
    map<int,int> mp;
    
    for(i=2;i<=sqrt(n);i++)
    {
        while(n%i==0)
        {
            mp[i]++;
            n=n/i;
        }
        
    }
    
    if(n!=1) mp[n]++;
    
    for(auto it: mp)
    {
        temp = it.second;
        i=1;
        while(temp>=i)
        {
            ans++;
            temp = temp -i;
            i++;
            
        }
    }
    
    cout<<ans<<endl;
    
    
    
}

Measured memory_bytes: 3676
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, num, sum = 0;
	cin >> N;
	rep(i, N) {
		cin >> num;
		sum += num - 1;
	}
	cout << sum;
}

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

vector<long long> num_divisors_table(long long n){
    vector<long long> table(n+1, 0);

    for(long long i = 1; i <= n; i++){
        for(long long j = i; j <= n; j = j+ i){
            table[j] += 1;
        }
    }
    return table;
}

int main(){
    long long n;
    cin >> n;

    vector<long long> table;
    table = num_divisors_table(n);
    long long cnt = 0;
    for(long long i = 1; i <= n; i++){
        if(i % 2 != 0 and table[i] == 8) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3604
package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scanf("%d", &n)
	costs := make([]int, n)
	for i:= 0; i < n; i++ {
		fmt.Scanf("%d", &costs[i])
	}
	answer := findMinCost(costs)
	fmt.Println(answer)
}

func findMinCost(costs []int) int {
	var dp [100001]int
	dp[0] = 0
	dp[1] = 0
	dp[2] = abs(costs[1] - costs[0])
	for i:= 3; i < len(costs) + 1; i++ {
		dp[i] = min(dp[i-1]+abs(costs[i-1] - costs[i-2]), dp[i-2] + abs(costs[i-1]- costs[i-3]))
	}
	return dp[len(costs)]
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  string a, b, c;
  cin >> a>>b >>c;
  cout << "A" << b[0] << "C" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[k] + L[j] > L[i]){
                    if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k])
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3636
S = input()
N = len(S)


def is_kaibun(s):
    _s = ''.join(list(reversed(s)))
    return s == _s


subset0 = S[0:(N - 2) // 2 + 1]
subset1 = S[(N + 2) // 2:]

ans = 'Yes' if is_kaibun(S) and is_kaibun(subset0) and is_kaibun(
    subset1) else 'No'
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,s=0; 
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(s%10!=0)
        {cout<<s<<endl;return 0;}
    else
    {
        sort(a,a+n);
        for(int i=0;i<n;i++)
        {
            if((s-a[i])%10!=0)
                {cout<<s-a[i]<<endl;return 0;}
        }
        cout<<"0"<<endl;
    }
}

Measured memory_bytes: 3660
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("in.txt",  "r",  stdin);
        freopen("out.txt", "w", stdout);
    #endif
//*/

 	       
	int n;
	cin>>n;
	string s;
	cin>>s;


	if(n&1)
	{
		cout<<"No";
		return 0;
	}
	bool val = true;
	forn(i,0,n/2)
	{
		if(s[i] != s[n/2 + i])
		{
			val = false;
			break;
		}
	}

	if(val)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}









    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();

		long count = 0;
		count = b / x;
		count -= a / x;
		if (a % x == 0) {
			count++;
		}

		System.out.println(count);
	}

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


Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

ll solve(ll n){
  if (n == 1) return 1;
  return 1 + 2 * solve(n/2);
}

int main() {
  ll n; cin >>n;
  cout <<solve(n) <<endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<vector<char>> s(N,vector<char>(10));
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
      cin>>s.at(i).at(j);
    }
    sort(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  long long ans=0;
  long long num=1;
  for(int i=0;i<N-1;i++){
    bool flag=true;
    for(int j=0;j<10;j++){
      if(s.at(i).at(j)!=s.at(i+1).at(j)){
        flag=false;
        break;
      }
    }
    if(flag){
      num++;
    }
    if(!flag||i==N-2){
      ans+=num*(num-1)/2;
      num=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID

#include <bits/stdc++.h>

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

#define ll long long
#define MP make_pair
#define ERR cout << "================================================\n"
#define fi first
#define se second
#define PB push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define print(v)          \
    for (auto x : v)      \
    {                     \
        cout << x << " "; \
    }
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define SP << " " <<
#define W(t)  \
    ll t;     \
    cin >> t; \
    while (t--)
#define FIO                           \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll INF = 1e18;
const ll NEG_INF = -1 * (1e18);
using namespace std;

void usaco(string prob)
{
    freopen((prob + ".in").c_str(), "r", stdin);
    freopen((prob + ".out").c_str(), "w", stdout);
}

/* Function to check primality in O(sqrt(n)) */
bool prime(int n)
{
    if (n < 2)
        return false;
    for (int x = 2; x * x <= n; x++)
    {
        if (n % x == 0)
            return false;
    }
    return true;
}

/* Function to get prime factorization of n */
vector<int> getFactors(int n)
{
    vector<int> f;
    for (int x = 2; x * x <= n; x++)
    {
        while (n % x == 0)
        {
            f.push_back(x);
            n /= x;
        }
    }
    if (n > 1)
        f.push_back(n);
    return f;
}

void solve()
{
    /* Write Solution Here */
    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
    {
        cout << "bust\n";
    }
    else
    {
        cout << "win\n";
    }
}

int main()
{
    //FIO
    FAST

        //usaco("cowlands");

        ll TC = 1;
    /*
	Uncomment when multiple test cases
	*/

    // cin>>TC;
    for1(tt, TC)
    {
        solve();
    }
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 3680
#include <iostream>

using namespace std;

int bh,bm,bs,ah,am,as;
int b_second,a_second,res_second;
int h,m,s;

int main(void){

  while( cin >> bh >> bm >> bs >> ah >> am >> as ){

    b_second = a_second = h = m = s = 0;
    b_second = bh*3600 + bm*60 + bs;
    a_second = ah*3600 + am*60 + as;
    res_second = a_second - b_second;

    while( res_second >= 3600 ){
      h++;
      res_second -= 3600;
    }
    while( res_second >= 60 ){
      m++;
      res_second -= 60;
    }
    cout << h << " " << m << " " << res_second << endl;

    for( int i = 0 ; i < 2 ; i++ ){

      cin >> bh >> bm >> bs >> ah >> am >> as;
      
      b_second = a_second = res_second = h = m = s = 0;
      b_second = bh*3600 + bm*60 + bs;
      a_second = ah*3600 + am*60 + as;
      res_second = a_second - b_second;
      
      while( res_second >= 3600 ){
	h++;
	res_second -= 3600;
      }
      while( res_second >= 60 ){
	m++;
	res_second -= 60;
      }
      cout << h << " " << m << " " << res_second << endl;
      
      
    }
    
    
  }
  
  
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    string s;
    cin >> s;
    if(s.length() % 2)
        for(int i = 0;i < s.length();i++){
            if(s[i] != s[s.length()-1-i]){
                cout << "No" << endl;
                return 0;
            }
        }
    else
        for(int i = 0;i < s.length();i++){
            if(s[i] != s[s.length()-1-i]){
                cout << "No" << endl;
                return 0;
            }
        }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(input())
h = [int(x) for x in input().split()]
a = h[0]
ans = 'Yes'
for i in range(1, n-1):
    a = max(h[i], a)
    b = h[i+1]
    if a - b >= 2:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 14224
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int d[1001][1001]; // d[u][v]は辺e=(u, v)のコスト（存在しない場合はINF、ただし[i][i]=0とする）
int V, N, M;
vector<pair<pair<int, int>, int> > v;

void warshall_floyd(){
	cin >> N >> M;
	V = N;
    rep(i, V){
        rep(j, V){
            d[i][j] = INTINF;
        }
    }


	rep(i, M){
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
		v.push_back({{a, b}, c});
	}

    rep(i, V) d[i][i] = 0;
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

	int cnt = 0;
	rep(k, M){
		auto e = v[k].first;
		int c = v[k].second;
		// print(e.first, e.second);
		bool ok = true;
		rep(i, N){
			rep2(j, i + 1, N){
				// print(i, j, d[i][j], c, d[i][e.first] + d[e.first][e.second] + d[e.second][j], d[i][e.second] + d[e.first][e.second] + d[e.first][j]);
				if(d[i][j] == d[i][e.first] + c + d[e.second][j] || d[i][j] == d[i][e.second] + c + d[e.first][j]){
					ok = false;
				}
			}
		}
		if(ok) {
			cnt++;
		}
	}

	cout << cnt << endl;
}


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	warshall_floyd();

	return 0;
}


Measured memory_bytes: 4024
def ncr(n, r):
    num, den = 1, 1
    if n - r < r:
        r = n - r
    for i in range(1, r + 1):
        num *= n - i + 1
        num %= MOD
        den *= i
        den %= MOD
    return num * pow(den, MOD - 2, MOD) % MOD


MOD = 10 ** 9 + 7
X, Y = map(int, input().split())
Z = X + Y

if Z % 3 or Y > 2 * X or Y < X // 2:
    print(0)
else:
    print(ncr(Z // 3, X - Z // 3))



Measured memory_bytes: 9140
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int p[] = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }

        int data[] = new int[n];
        init(n, data);
        for (int i = 0; i < m; i++) {
            link(sc.nextInt(), sc.nextInt(), data);
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (isSame(i + 1, p[i], data)) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    public void init(int n, int data[]) {
        for (int i = 0; i < n; i++) {
            data[i] = i + 1;
        }
    }

    public void link(int x, int y, int data[]) {
        data[root(x, data) - 1] = root(y, data);
    }

    public boolean isSame(int x, int y, int data[]) {
        return root(x, data) == root(y, data);
    }

    public int root(int p, int data[]) {
        return (data[p - 1] == p) ? p : (data[p - 1] = root(data[p - 1], data));
    }

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


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

using namespace std;
typedef long long ll;
const int N = 200010;
int n, a[N], b[N], cnt, tot;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[n - i + 1];
    int l = 1, r = n, st = 0, ed = -1;
    for (int i = 1; i <= n; i++)
        if (a[i] == b[i]) {
            if (!st) st = i;
            ed = i;
        }
    for (int j = st; j <= ed; j++) {
        if (a[l] ^ b[j] && b[l] ^ b[j]) swap(b[j], b[l++]);
        else if (a[r] ^ b[j] && b[r] ^ b[j]) swap(b[j], b[r--]);
        else puts("No"), exit(0);
    }
    puts("Yes");
    for (int i = 1; i <= n; i++) printf("%d%c", b[i], " \n"[i == n]);
    return 0;
}


Measured memory_bytes: 5284
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    char c;
    cin>>c;
    
    if(c>='A' && c<='Z')
         cout<<"A";
    else
     cout<<"a";
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N=15;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
char s[N];

signed main()
{
	int n=read(),a=0,b=0,ba=0,ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		int m=strlen(s+1);
		for (int j=1;j<m;j++)
		if (s[j]=='A'&&s[j+1]=='B')
		ans++;
		if (s[1]=='B'&&s[m]=='A') ba++;
		else
		{
			if (s[1]=='B') b++;
			if (s[m]=='A') a++;
		}
	}
	if (ba) ans+=ba-1;
	if (ba)
	{
		if (a) a--,ans++;
		if (b) b--,ans++;
	}
	ans+=min(a,b);
	print(ans);

	return 0;
}

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

int main() {
  int n, L;
  std::cin >> n >> L;
  int sum = 0, ans = 0;
  for (int i = 1; i <= n; ++i)
    sum += L + i - 1;
  ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; ++i) {
    int tmp = sum - (L + i - 1);
    if (std::abs(tmp - sum) < std::abs(ans - sum))
      ans = tmp;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

void solve() {
  int K, q;
  cin >> K >> q;
  vector<int> d(K);
  rep(i, K) cin >> d[i];

  while (q--) {
    int n, x, m;
    cin >> n >> x >> m;
    int k = K;

    if (k >= n - 1) {
      vector<int> a(n);
      a[0] = x % m;
      rep3(i, 1, n) a[i] = (a[i - 1] + d[i - 1]) % m;

      int cnt = 0;
      rep(i, n - 1) if (a[i] < a[i + 1]) cnt++;
      cout << cnt << endl;
      continue;
    }

    vector<int> d2 = d;
    rep(i, k) d2[i] %= m;

    // ">" を計算
    // a は単調増加数列だから普通 "<"
    // ">" となるのは, d2 < m に注意して, 商が 1 大きくなったとき
    ll a0 = x;
    ll an_1 = a0;

    ll sum = 0;
    rep(i, k) sum += d2[i];

    an_1 += n / k * sum;
    if (n % k == 0) {
      an_1 -= d2[k - 1]; // debuged
    } else {
      rep(i, n % k - 1) {
        an_1 += d2[i];
      }
    }

    ll ans = an_1 / m - a0 / m;
    // cout << endl << ans << endl;

    // "=" を計算
    sum = 0;
    rep(i, k) if (d2[i] == 0) sum++;
    ans += n / k * sum;
    if (n % k == 0) {
      if (d2[k - 1] == 0) ans--;
    } else {
      rep(i, n % k - 1) {
        if (d2[i] == 0) ans++;
      }
    }

    ans = n - 1 - ans; // "<" = 全体 - "=" - ">"
    cout << ans << endl;
  }
}


Measured memory_bytes: 384
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 2e5+10;
const ll m = 1e9+7;

ll fact[N] , ifact[N];
ll pow(ll a , ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b&1)
			ans= (ans*a)%m;
		b/=2;
		a = (a*a)%m;
	}
	return ans;
}
ll modinv(ll k)
{
	return pow(k , m-2);
}

void precompute()
{
	fact[0] = fact[1] = 1;
	rep(i,2,N)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %=m;
	}
	ifact[N-1] = modinv(fact[N-1]);
	for(ll i = N-2 ; i>=0 ; --i)
	{
		ifact[i] = ifact[i+1]*(i+1);
		ifact[i]%=m;
	}
}

ll ncr(ll n , ll r)
{
	if(r > n)
		return 0;
	return ((fact[n]*ifact[r])%m * ifact[n-r])%m;
}
ll h ,w;
vector< pll > v;

ll ways(pll a , pll b)
{
	ll n = abs(a.ff - b.ff);
	ll m = abs(a.ss - b.ss);
	return ncr(n+m , n);
}
ll dp[3005];

signed main()
{
	fast;
////////////////////////////////////////////////////////////////////////////////////////////
	precompute();

	ll n;
	cin >> h >> w >>n;

	while(n--)
	{
		ll i,j;
		cin >> i >> j;
		v.pb({i,j});
	}
	v.pb({h,w});
	v.pb({1,1});
	sort(all(v));

	n = v.size();

	for(ll i = 1 ; i< n ; ++i)
	{
		dp[i] = ways(v[i] , {1,1});
		for(ll j = 1 ; j<i ; ++j)
		{
			if(v[j].ff <= v[i].ff and v[j].ss <= v[i].ss)
			{
				dp[i] = (dp[i] - dp[j]*ways(v[i],v[j])+ m)%m;
			}
		}
	}

	dp[n-1]+=m;
	dp[n-1]%=m;

	cout<<dp[n-1]<<endl;


	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int n;
string s[1000];

int get_dot(string S) {
	return count(S.begin(), S.end(), '.');
}

int parse(int pos) {
	int retv = -1145141919;
	int nest = get_dot(s[pos]) + 1;
	bool enzan;
	if (s[pos][nest - 1] == '*')enzan = true;
	if (s[pos][nest - 1] == '+')enzan = false;

	for (int i = pos + 1; i < n && get_dot(s[i]) >= nest; i++) {
		if (get_dot(s[i]) == nest) {
			if (s[i][nest] >= '0' && s[i][nest] <= '9') {
				//数字である場合

				if (retv == -1145141919)retv = s[i][nest] - '0';
				else {
					if (enzan)retv *= s[i][nest] - '0';
					else retv += s[i][nest] - '0';
				}
			}
			else {
				//演算子である場合
				
				if (retv == -1145141919)retv = parse(i);
				else {
					if (enzan)retv *= parse(i);
					else retv += parse(i);
				}
				//現在のネストの場所まで進める
				i++;
				while (i < n && get_dot(s[i]) > nest)i++;

				i--;

			}			
		}
	}
	return retv;
}

int main() {
	while (1) {

		cin >> n;
		if (n == 0)return 0;
		for (int i = 0; i < n; i++)cin >> s[i];
		if (n == 1 && s[0][0] <= '9' && s[0][0] >= '0')cout << s[0] << endl;
		else cout << parse(0) << endl;
	}
	return 0;
}


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

const int m=1000000007;

int main(){
  int s;
  cin >> s;
  
  vi a(s+1);
  vi b(s+1);
  a[3]=1;b[3]=1;
  for(int i=4;i<=s;i++){
    a[i]=1+b[i-3];a[i]%=m;
    b[i]=b[i-1]+a[i];b[i]%=m;
  }
  cout << a[s];
  
  return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int res = 0;
    for(int i = 0; i < S.size(); ++i) {
        if(S[i] == '1') ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main(){
    int n,a,min=1000000,max=-1000000;
    long long sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        if(min>a) min=a;
        if(max<a) max=a;
        sum=sum+a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2704
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  ll p[a],q[b],r[c];
  for(int i=0;i<a;i++) cin>>p[i];
  for(int i=0;i<b;i++) cin>>q[i];
  for(int i=0;i<c;i++) cin>>r[i];
  sort(p,p+a,greater<ll>());
  sort(q,q+b,greater<ll>());
  sort(r,r+c,greater<ll>());
  ll ans=0;
  int cur_p=x-1,cur_q=y-1,cur_r=0;
  for(int i=0;i<x+y;i++){
    if(cur_p<=-1 and cur_q<=-1) {
      ans+=r[cur_r];
      cur_r++;
      continue;
    }
    if(cur_r>=c){
      break;
    }
    if(cur_p>=0 and cur_q<=-1){
      if(p[cur_p]>=r[cur_r]){
        break;
      }
      else{
        ans+=r[cur_r];
        cur_r++;
        cur_p--;
        continue;
      }
    }
    if(cur_q>=0 and cur_p<=-1){
      if(q[cur_q]>=r[cur_r]){
        break;
      }
      else{
        ans+=r[cur_r];
        cur_r++;
        cur_q--;
        continue;
      }
    }
    if(p[cur_p]>q[cur_q]){
      if(q[cur_q]>=r[cur_r]){
        break;
      }
      else{
        ans+=r[cur_r];
        cur_r++;
        cur_q--;
        continue;
      }
    }
    if(p[cur_p]<=q[cur_q]){
      if(p[cur_p]>=r[cur_r]){
        break;
      }
      else{
        ans+=r[cur_r];
        cur_r++;
        cur_p--;
        continue;
      }
    }
  }
  if(cur_p>-1){
    for(int i=0;i<=cur_p;i++){
      ans+=p[i];
    }
  }
  if(cur_q>-1){
    for(int i=0;i<=cur_q;i++){
      ans+=q[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a, b;

  top = 0;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else {
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}
       
    
	       



Measured memory_bytes: 2060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
 
int main() {
	int A, B; cin >> A >> B;
	for (int i = 0; i <= 100000; i++) {
		int t1 = i * 8 / 100;
		int t2 = i * 10 / 100;
		if (t1 == A && t2 == B) { cout << i << endl; return 0; }
	}
	cout << "-1" << endl;
	return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for(i = 0; i < n; i++)
#define Fo(i, k, n) for(i=k; i < n; i++)

template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
template<typename... T>
void write(T&&... args) {
    ((cout << args << " "), ...);
}

using ll = long long;
using v_int = vector<int>;
using v_bool = vector<bool>;
using v_str = vector<string>;
using v_chr = vector<char>;

#define BSTi(L, R, M, V, X) while(L <= R) { M = L + (R - L) / 2 if(V[M] == X) return true else if(V[M] < X) L = M + 1 else if(V[M] > X) R = M - 1 } return false

int main() {

    int n;

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

    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == "AC") ac++;
        if(s[i] == "WA") wa++;
        if(s[i] == "TLE") tle++;
        if(s[i] == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}



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

/*int main() {
	int H, W;
	cin >> H >> W;
	char C[H][W + 1];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> C[i][j];
		}
	}

	for (int i = 0; i < 2 * H; i++) {
		for (int j = 0; j < W; j++) {
			cout << C[(i) / 2][j];
		}
		cout << endl;
	}
}*/

int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		cout << s + "\n" << s + "\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,n,t=0,s=0,p;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		p=i;
		t=0;
		while(p!=0)
		{
			t+=p%10;
			p=p/10;
			
		}
		if(t<=b&&t>=a)
		s+=i;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int nails[5005][5005];

signed main()
{
    omajinai;
    int N, M; cin >> N >> M;

    rep(i, M) {
        int A, B, X; cin >> A >> B >> X;

        nails[A - 1][B - 1]++;
        nails[A - 1][B]--;
        nails[A + X][B - 1]--;
        nails[A + X][B + X + 1]++;
        nails[A + X + 1][B]++;
        nails[A + X + 1][B + X + 1]--;
    }

    rep(i, N + 2) {
        rep(j, N + 2) {
            nails[i][j + 1] += nails[i][j];
        }
    }

    rep(i, N + 2) {
        rep(j, N + 2) {
            nails[j + 1][i] += nails[j][i];
        }
    }

    rep(i, N + 2) {
        int y = i + 1;
        int x = 1;

        while (y <= N && x <= N) {
            nails[y][x] += nails[y - 1][x - 1];
            y++;
            x++;
        }
    }

    int ans = 0;

    rep(i, N + 2) {
        rep(j, N + 2) {
            ans += nails[i][j] > 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 101016
//
//  main.cpp
//  F
//
//  Created by 曾憲揚 on 2020/8/11.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

const int maxn = 3005;
const int MOD = 998244353;
int a[maxn];

long long dp[maxn][maxn];

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n, s; cin >> n >> s;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    
    memset(dp, 0, sizeof(dp));
    
    dp[0][0] = 1;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=s; j++){
            dp[i][j] += (2*dp[i-1][j]);
            dp[i][j] %= MOD;
            
            if(j+ a[i] <= s){
                dp[i][j + a[i]] += dp[i-1][j];
                dp[i][j] %= MOD;
            }
        }
    }
    
    cout << dp[n][s] << endl;
    
    return 0;
}


Measured memory_bytes: 74216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string s;
    int k;
    cin >> s >> k;
    map<char, int> mp;
    rep (i, 0, s.size()) mp[s[i]]++;
    set<string> ans;
    for (auto p : mp) {
        rep (i, 0, s.size()) {
            if (s[i] == p.first) {
                rep (j, 1, 6) {
                    if (i + j <= s.size()) {
                        ans.insert (s.substr (i, j));
                    }
                }
            }
        }
        if (ans.size() > k) continue;
    }
    int cnt = 0;
    for (auto p : ans) {
        cnt++;
        if (cnt == k) {
            cout << p << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 4748
H = []
W = []
cnt = 0
while 1:
	stdin = raw_input().split()
	h = int(stdin[0])
	w = int(stdin[1])
	if h == 0 and w == 0:
		break
	H.append(h)
	W.append(w)
	cnt += 1

str1 = '#.' * 150
str2 = '.#' * 150
for i in range(cnt):
	for j in range(H[i]):
		if(j%2 == 0):
			print str1[:W[i]]
		else:
			print str2[:W[i]]
	print ''


Measured memory_bytes: 4656
n = int(input())
s =[]
p = []
for _ in range(n):
    si, pi = input().split()
    s.append(si)
    p.append(int(pi))
s_ord = sorted(list(set(s)))
for c in s_ord:
    ind = [i for i, x in enumerate(s) if x == c]
    p_ord = sorted([point for num, point in enumerate(p) if num in ind], reverse = True)
    for r in p_ord:
        print(p.index(r) + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353



int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif  
 
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      ll a,b,c,d;
      cin>>a>>b>>c>>d;

      cout<<max({a*c,b*c,a*d,b*d});





    }
     
      

      

    

    
return 0;
}     



Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
  int N, tmp;
  cin >> N;
  int ans = 0;
  for (int i=0; i<N; i++){
    cin >> tmp;
    if ((i % 2) == 0 && tmp % 2 == 1) ans++;
  }
  cout << ans << "\n";
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 X, Y; cin >> X >> Y;

    auto prize = [](i64 p) {
        i64 res = 300000 - (p - 1) * 100000;
        return max((i64)0, res);
    };

    i64 ans = prize(X) + prize(Y);
    if (X == 1 && Y == 1) {
        ans += 400000;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; 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(a) (a).begin(), (a).end()

int main() {
    int N, ac = 0, wa = 0, tle = 0, re = 0;
    cin >> N;
    REP(i, N) {
        string S;
        cin >> S;
        if (S == "AC") ac++;
        else if (S == "WA") wa++;
        else if (S == "TLE") tle++;
        else re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N; int K;
	while (~scanf("%d%d", &N, &K)) {
		vector<int> A(N);
		vector<int> B(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d%d", &A[i], &B[i]);
		ll ans = 0;
		int mask = 0;
		for (int k = 30; k >= 0; -- k) {
			if (K >> k & 1) {
				ll cost = 0;
				rep(i, N) if ((A[i] & (mask | 1 << k)) == 0)
					cost += B[i];
				amax(ans, cost);
			} else {
				mask |= 1 << k;
			}
		}
		{
			ll cost = 0;
			rep(i, N) if ((A[i] & mask) == 0)
				cost += B[i];
			amax(ans, cost);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1152
from itertools import product
n = input()
ans = 0

for i in range(3,len(n)+1):
    for p in product("357",repeat=i):
        if int("".join(list(p))) > int(n): continue
        if p.count("3")*p.count("5")*p.count("7") != 0: ans += 1

print(ans)

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

signed
main(){
		int N;
		cin >> N;
		vector<ll> a(N+1);
		for(int i=0;i<N;i++){
				cin >> a[i] >> a[i+1];
		}
	
		vector<vector<ll> > m(N+1, vector<ll>(N+1,INT_MAX));

		for(int i=0;i<=N;i++)
				m[i][i] = 0;
		for(int i=0;i<N;i++)
				m[i][i+1] = 0;


		for(int sa=2;sa<=N;sa++){
				for(int b=0;b<=N-sa;b++){
						int e = b + sa;
						for(int med=b;med<=e;med++){
								m[b][e] = min(m[b][e], m[b][med] + m[med][e] + a[b]*a[med]*a[e]);
						}
				}
		}
		cout << m[0][N] << endl;

}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//__uint128_t
const ll MOD = 1e9+7;


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    ll N, M; cin >> N >> M;
    UnionFind tree(N);
    for(int i = 0; i < M; i++){
        ll a, b; cin >> a >> b; a--; b--;
        tree.unite(a, b);
    } 
    map<ll, ll> MP;
    for(int i = 0; i < N; i++) MP[tree.root(i)]++;
    ll ans = 0;
    for(auto m : MP) ans = max(ans, m.second);
    cout << ans << endl;

}

Measured memory_bytes: 16260
def main():
    h, w = map(int, input().split())
    field = [list(input()) for _ in range(h)]
    dp = [[float('inf')] * w for _ in [0] * h]
    dp[0][0] = (field[0][0] == "#")

    for i in range(h):
        for j in range(w):
            if i > 0:
                dp[i][j] = min(dp[i][j], dp[i - 1][j] +
                               (field[i - 1][j] == "." and field[i][j] == "#"))
            if j > 0:
                dp[i][j] = min(dp[i][j], dp[i][j-1] +
                               (field[i][j - 1] == "." and field[i][j] == "#"))
    print(dp[-1][-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
from scipy.sparse.csgraph import floyd_warshall 

n,m = map(int, input().split())
s = [[float('inf')]*n for i in range(n)]
d = [list(map(int, input().split())) for i in range(m)]
ans = 0

for a,b,c in d:
    s[a-1][b-1] = c
    s[b-1][a-1] = c

cost = floyd_warshall(s)

for a,b,c in d:
    #print(cost[a-1][b-1], c)
    #例えば1(a)→2(b)に行くとき他の経路を使った方がコストが低い場合は1→2は絶対使われず、他の経路が使われる
    if cost[a-1][b-1] != c:
        ans += 1
        
print(ans)

Measured memory_bytes: 26384
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iterator>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
    else if(abs(a - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int N; cin>>N;
  vector<int> A(N);
  ll ans = 0;
  int mae = 0;
  REP(i,N) cin>>A[i];
  REP(i,N){
    if(mae <= A[i]) mae = A[i];
    else{
      ans += mae-A[i];
    }
  }
  cout << ans;
}

Measured memory_bytes: 3960
from itertools import permutations
l = list(range(3))
l = list(permutations(l, 2))
C = [[0]*3 for i in range(3)]
r = 'Yes'
for i in range(3):
    C[i] = list(map(int, input().split()))
for i in l:
    if not C[0][i[0]]-C[0][i[1]]==C[1][i[0]]-C[1][i[1]]==C[2][i[0]]-C[2][i[1]]:
        r = 'No'
        break
print(r)

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

typedef long long int ll;

set <string> st;

int main()
{
	ll i,j,k,l,m,n,t,a,b,c,d;

	cin >> n;

	string s;

	for(i=0;i<n;i++)
	{
		cin >> s;
		st.insert(s);
	}

	cout << st.size() << '\n';
}

Measured memory_bytes: 19176
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}



int main() {
    int a, b, c, ans = 0, sum = 0;
    cin >> a;
    if (a % 2 == 1){
        cout << a / 2 + 1 <<endl;
    }else{
        cout << a / 2 <<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int N, num[101] = {0};
    int i, j, count = 0;
    int min,temp;

    scanf("%d", &N);

    for(i = 0; i < N; i++){
        scanf("%d", &num[i]);
    }
    for(i = 0; i< N; i++){
        min = i;
        for(j = i; j < N; j++){
            if(num[j] < num[min]){
                min = j;
            }
        }
        if(num[i] > num[min]){
            temp = num[i];
            num[i] = num[min];
            num[min] = temp;
            count++;
        }
    }
    for(i = 0; i < N; i++){
        printf("%d", num[i]);
        if(i != N-1){printf(" ");
    }
    }

    printf("\n%d\n", count);

    return 0;
}

Measured memory_bytes: 604