akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define N 10000010

long long prime[N+1];

void init_prime(long long n){
  memset(prime,0,sizeof(prime));
  for(long long i = 2; i < n+1; i++){
    if(prime[i] == 0){
      for(long long j = i*2; j < n+1; j += i){
        prime[j] = i;
      }
    }
  }
}

vector<long long> p_decom(long long a){
  vector<long long> ret;
  while(prime[a]!=0){
    ret.pb(prime[a]);
    a /= prime[a];
  }
  ret.pb(a);
  sort(ret.begin(),ret.end());
  return ret;
}

int main(){
  init_prime(10000008);
  ll n;
  cin>>n;
  ll ans = 1;
  rep(i,2,n+1){
    vector<ll> v = p_decom(i);
    map<ll,ll> ma;
    rep(j,0,v.sz){
      ma[v[j]]++;
    }
    map<ll,ll>::iterator itr = ma.begin();
    ll d = 1;
    while(itr!=ma.end()){
      ll a = (*itr).fi;
      ll b = (*itr).se;
      d *= (b+1);
      itr++;
    }
    ans += i*d;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81756
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  char c; 
  cin >> c;
  
  c += 1;
  
  cout << c << endl;
  
}

Measured memory_bytes: 3520
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int ans = 0;
	int N,K;
	cin >> N>>K;
	int H;
	rep(i, 0, N)
	{
		cin >> H;
		if (H >= K)ans++;
	}

	cout << ans << endl;

	return 0;
}

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

const int INF = 1 << 30;
enum {B, W};

template<class T> class Fenwick {
private:
    vector<T> dat;
    int n;
public:
    Fenwick(int _n) : dat(_n + 1), n(_n) {}
    // sum of [1, i]
    T sum(int i) {
        T s = 0;
        while(i > 0) s += dat[i], i -= i & -i;
        return s;
    }
    // sum of [l, r]
    T sum(int l, int r) {
        return l > r ? 0 : sum(r) - sum(l - 1);
    }
    void add(int i, T x) {
        while(i <= n) dat[i] += x, i += i & -i;
    }
};


int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(2 * N);
    vector<vector<int>> idx(2, vector<int>(N + 1));
    for(int i = 0; i < 2 * N; ++i) {
        char c; int a; cin >> c >> a;
        A[i] = make_pair(c == 'W', a);
        idx[c == 'W'][a] = i;
    }

    const int M = 2000;
    vector<vector<Fenwick<int>>> bit(2, vector<Fenwick<int>>(M + 1, Fenwick<int>(2 * N + 1)));
    for(int x = 0; x < M; ++x) {
        for(int i = 0; i < 2 * N; ++i) {
            if(A[i].second > x) bit[A[i].first][x].add(i + 1, 1);
        }
    }

    vector<vector<int>> dp(N + 1, vector<int>(N + 1, INF));
    dp[0][0] = 0;

    auto f = [&](auto &&f, int b, int w) -> int {
        if(dp[b][w] != INF) return dp[b][w];
        if(b) dp[b][w] = min(dp[b][w], f(f, b - 1, w) + bit[B][b].sum(idx[B][b]) + bit[W][w].sum(idx[B][b]));
        if(w) dp[b][w] = min(dp[b][w], f(f, b, w - 1) + bit[B][b].sum(idx[W][w]) + bit[W][w].sum(idx[W][w]));
        return dp[b][w];
    };
    cout << f(f, N, N) << '\n';
    return 0;
}


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

int main() {
    int64_t H, W, K;
    cin >> H >> W >> K;
    vector<string> A(H);
    for (int64_t i = 0; i < H; i++) {
        cin >> A[i];
    }

    int64_t Sx, Sy;
    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            if (A[i][j] == 'S') {
                Sx = j;
                Sy = i;
                i = H;
                j = W;
            }
        }
    }

    //Sから深さKのDFSでどこに到達できるか調べる
    int64_t dx[] = { 1, 0, -1, 0 };
    int64_t dy[] = { 0, 1, 0, -1 };

    struct Element {
        int64_t x, y, cost;
        bool operator<(const Element& rhs) const {
            return cost < rhs.cost;
        }
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    vector<vector<int64_t>> cost(H, vector<int64_t>(W, LLONG_MAX));
    queue<pair<int64_t, int64_t>> st;
    cost[Sy][Sx] = 0;
    pq.push({ Sx, Sy, 0 });

    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.y][t.x] || t.cost >= K) {
            continue;
        }

        for (int64_t i = 0; i < 4; i++) {
            int64_t nx = t.x + dx[i];
            int64_t ny = t.y + dy[i];
            if (nx < 0 || nx >= W || ny < 0 || ny >= H || A[ny][nx] == '#') {
                continue;
            }

            int64_t new_cost = cost[t.y][t.x] + 1;
            if (new_cost < cost[ny][nx]) {
                cost[ny][nx] = new_cost;
                pq.push({ nx, ny, new_cost });
            }
        }
    }

    int64_t ans = LLONG_MAX;
    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            if (cost[i][j] == LLONG_MAX) {
                continue;
            }

            int64_t min_distance = min({ i, j, H - 1 - i, W - 1 - j });

            ans = min(ans, 1 + (min_distance + K - 1) / K);
        }
    }

    cout << ans << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int N;
vector<int> n, d;
P coordinates[201];
/**********************************************/

void solve(){
    coordinates[0] = P(0, 0);
    REP(i, N-1){
        int cur = i+1;
        int y = coordinates[n[i]].first + dy[d[i]];
        int x = coordinates[n[i]].second + dx[d[i]];
        coordinates[cur] = P(y, x);
    }
    
    int x_max_num = -INF; 
    int y_max_num = -INF; 
    int x_min_num = INF; 
    int y_min_num = INF; 
    REP(i, N){
        x_max_num = max(x_max_num, coordinates[i].second);
        x_min_num = min(x_min_num, coordinates[i].second);
        y_max_num = max(y_max_num, coordinates[i].first);
        y_min_num = min(y_min_num, coordinates[i].first);
    }

    cout << x_max_num - x_min_num + 1 << " " << y_max_num - y_min_num + 1 << endl;
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(cin >> N, N){
        n.resize(N-1);
        d.resize(N-1);
        REP(i, N-1) cin >> n[i] >> d[i];
        solve();
    }

}



Measured memory_bytes: 3124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
#define debug(output) cout<<#output<<"= "<<output<<endl
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int h,w;cin>>h>>w;
  vector<vector<int>> a(h,vector<int>(w,0));
  vector<vector<int>> b(h,vector<int>(w,0));
  rep(i,h){
      rep(j,w)cin>>a[i][j];
  }
  rep(i,h){
      rep(j,w)cin>>b[i][j];
  }
  
  vector<vector<int>> sub(h+5,vector<int>(w+5,0));
  
  rep(i,h){
      rep(j,w){
          sub[i+1][j+1]=abs(a[i][j]-b[i][j]);
      }
  }
  vector<vector<vector<bool>>> dp(h+1,vector<vector<bool>>(w+1,vector<bool>(6500,false)));
  dp[1][1][sub[1][1]]=true;
  
  rep1(i,h){
      rep1(j,w){
          if(i==1&&j==1){
              continue;
          }
          rep(x,6401){
              int nxt=abs(x-sub[i][j]);
              dp[i][j][nxt]=dp[i][j][nxt]||dp[i-1][j][x];
              dp[i][j][nxt]=dp[i][j][nxt]||dp[i][j-1][x];
              dp[i][j][x+sub[i][j]]=dp[i][j][x+sub[i][j]]||dp[i-1][j][x];
              dp[i][j][x+sub[i][j]]=dp[i][j][x+sub[i][j]]||dp[i][j-1][x];
          }
      }
  }
  int res=inf;
  rep(i,6405){
      if(dp[h][w][i]){
          res=i;
          break;
      }
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 9148
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    int N,M;
    cin >>N>>M;
    vl H(N);
    vi G(N,1);
    rep(i,N) cin >>H[i];
    rep(i,M){
        int A,B;
        cin >>A>>B;
        A--;
        B--;
        if(H[A]>H[B]) G[B]=0;
        else if(H[A]<H[B]) G[A]=0;
        else {
            G[A]=0;
            G[B]=0;
        }
    }
    int ans=0;
    rep(i,N){
        if (G[i]==1) ans++;
    }
    cout <<ans<<endl;
}

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

int main() {
  string s;
  int K;
  cin >> s >> K;
  for(int i=0;i<s.length();i++){
    if(s[i]=='a')continue;
    else if(K>='z'-s[i]+1){
      K-='z'-s[i]+1;
      s[i]='a';
    }
  }
  K=K%26;
  s[s.length()-1]=s[s.length()-1]+K;
  cout << s;
}

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

int main(){
    int N;
    cin >> N;
    string ans = "";

    while (N!=0){
        if(N%2 != 0){
            N--;
            ans = "1" + ans;
        }else{
            ans = "0" + ans;
        }

        N /= -2;
    }

    if(ans == ""){
        ans = "0";
    }

    cout << ans << endl;

    return 0;

    
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class DXorSum4 {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll mo = 1e+9+7;
        ll n;
        in >> n;
        vector<ll> a(n);
        rep(i,n){
            in >> a[i];
        }
        vector<ll> b(60,0);
        rep(i,n){
            rep(j,60){
                if(a[i]>>j&1){
                    b[j]++;
                }
            }
        }
        ll ans = 0;
        rep(i,60){
            ll t=(b[i]*(n-b[i]))%mo;
            t*=binpow(2,i,mo);
            t%=mo;
            ans+=t;
            ans%=mo;
        }
        out <<ans << endl;
	}
	ll binpow(ll a,ll b,ll mod){
	    ll ret=1;
	    while(b>0){
	        if(b&1){
	            ret=ret*a%mod;
	        }
	        a=a*a%mod;
	        b=b>>1;
	    }
	    return ret;
	}
};


int main() {
	DXorSum4 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

map<int,int> mp;

signed main(){
	
	int n;cin>>n;
	rep(i,n)
	{
		int x;cin>>x;
		mp[x]++;
	}
	int m; cin >>m;
	rep(i,m)
	{
		int y;cin>>y;
		if(mp[y]==0)
		{
			cout << "NO"<<endl;
			return 0;
		}
		mp[y]--;
	}
	cout <<"YES"<<endl;
	
	
	
}

//cout << ans << endl;

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 200003

long long fak[mx], inv[mx];

long long POW(long long a, int b){
	long long ret = 1;
	while(b > 0){
		if(b & 1)
			ret = ret * a % MOD;
		b >>= 1;
		a = a * a % MOD;
	}
	return ret;
}

long long C(int n, int k){
	if(k > n)
		return 0;
	return fak[n] * inv[k] % MOD * inv[n - k] % MOD;
}

long long hitung(int atas, int bawah){
	return C(atas + bawah, atas);
}

int main(){
	fak[0] = 1;
	for(int i = 1; i <= 200000; i++)
		fak[i] = fak[i - 1] * i % MOD;
	inv[200000] = POW(fak[200000], MOD - 2);
	for(int i = 200000 - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1) % MOD;
	int n, m, r, c;
	cin >> n >> m >> r >> c;
	long long ans = hitung(n - 1, m - 1);
	for(int i = n - r + 1; i <= n; i++){
		int x = i, y = c;
		long long satu = hitung(x - 1, y - 1);
		long long dua = hitung(n - x, m - y - 1);
		long long tot = satu * dua % MOD;
		ans = ans - tot;
		ans %= MOD;
		if(ans < 0)
			ans += MOD;
	}
	cout << ans << endl;

}

Measured memory_bytes: 3328
#include<iostream>
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define _ <<" "<<
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vi dp;

int main(){
	int t=1;
	while(t--){
		int n,k;
		cin>>n>>k;
		vi a(n);
		rep(i,n) cin>>a[i];
		// db(n);
		dp.clear();
		dp.resize(n);
		// cout<<words(a,s.length(),s)<<endl;
		for(int i=1;i<n;i++){
			dp[i]=INT_MAX;
			for(int j=1;j<=i&&j<=k;j++){
				dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
			}
		}
		cout<<dp[n-1]<<endl;
	}
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n,m,d;
    cin>>n>>m>>d;

    int x=max(0ll,n-d-(d+1)+1);

    int z;
    if(d==0)z=n;
    else z=x*2+n-x;
    printf("%.20f\n",1.0*z/n/n*(m-1));
    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	unsigned size_; 
	std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	//unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	unsigned root(unsigned x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, Q;
	
	cin >> N >> Q;

	string s;
	cin >> s;

	int len = s.size();

	int count[len];
	memset(count, 0, sizeof(count));

	bool is_a = false;
	int cnt = 0;
	rep(i, len)
	{
		if (s[i] == 'C')
		{
			if (is_a)
			{
				cnt++;
			}
			is_a = false;
		}

		if (is_a)
		{
			is_a = false;
		}

		if (s[i] == 'A')
		{
			is_a = true;
		}

		count[i] = cnt;
	}
	/*
	rep(i, len)
	{
		cout <<"i=" << i << "; count = " << count[i] << endl;
	}
	*/

	rep(i, Q)
	{
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << count[r] - count[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 1488
#include <iostream>
#include <string>
#define st string
#define ei else if

using namespace std;
int main(void) {
	int d;
	cin >> d;
	if(d == 25) {
		cout << "Christmas" << endl;
	}
	ei(d == 24) {
		cout << "Christmas Eve" << endl;
	}
	ei(d == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	ei(d == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	
	return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; ++i) cin >> T[i];

    int M;
    cin >> M;
    vector<pair<int, int>> px(M);
    for (int i = 0; i < M; ++i) {
        int p, x;
        cin >> p >> x;
        px[i] = make_pair(p, x);
    }
    for (int i = 0; i < M; ++i) {
        int total = 0;
        for (int j = 0; j < N; ++j) {
            if (j == px[i].first - 1) total += px[i].second;
            else total += T[j];
        }
        cout << total << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var C = input[2];
        var B = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var cnt = 0;
        for(var i = 0;i < N;i++){
            var temp = 0;
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for(var j = 0;j < M;j++){
                temp += A[j] * B[j];
            }
            temp += C;
            if(temp > 0)cnt++;
        }
        Console.WriteLine(cnt);
        
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  char str[222];
  scanf("%s", str);
  int n = strlen(str);
  for (int i = n - 2; i >= 1; i -= 2) {
    if (strncmp(str, str + i / 2, i / 2) == 0) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
	vector<int> W, K;
	for(int i = 0; i < 10; i++){
		int point;
		cin >> point;
		W.push_back( point );
	}
	sort( W.begin(), W.end() );
	for(int i = 0; i < 10; i++){
		int point;
		cin >> point;
		K.push_back( point );
	}
	sort( K.begin(), K.end() );

	cout << W[9] + W[8] + W[7] << ' ' << K[9] + K[8] + K[7] << '\n';

	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double,P> PP;
struct edge { int to; int cost; };
int v[55];
int dp[50][50][105];
int rv[55];
signed main() {
	int n, k; cin >> n >> k;
	rep(i, n)cin >> v[i];
	rep(i, n)rv[i + 1] = v[i];
	rep(i, n)rv[i + 1] += rv[i];
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n-i; j++) {
		//0~I,J~n-1
			int I = i - 1;
			int J = n - j;
			int cnt = i + j;
			if (cnt > k)continue;
			int res = rv[I+1] + rv[n] - rv[J];
			vector<int>V;
			rep(l, i)V.push_back(v[l]);
			rep(l,j)V.push_back(v[n-l-1]);
			sort(V.begin(), V.end());
			rep(l, min(k - cnt,cnt)) {
				if (V[l] < 0)res -= V[l];
			}
			ans = max(ans, res);
			//cout << i << ' ' << j << ' ' << res << endl;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int INF = 1000000000;
const int N = 500005;
int n,k;
int a[N];
priority_queue<ii> pq;
int ans[N];
int done[N];
int ct;
///Segment tree with range min, range add with lazy propagation
#include <bits/stdc++.h>
using namespace std;
struct node {
    int s, e, m;
    ii v;
    node *l, *r;
    node(int _s, int _e) {
        s = _s; e = _e; m = (s+e)/2;
        v = ii(0,s);
        if (s != e) {
            l = new node(s, m);
            r = new node(m+1, e);
        }
    }
    void up(int x, int nv) {
        if (s == e){
            v.first = nv; return;
        }
        else if (x > m) r->up(x,nv);
        else l->up(x,nv);
        v =  max(l->v,r->v);
    }
    ii rmq(int x, int y) {
        y = min(y,e);
        x = max(s,x);
        if (s==x && e==y) {
            return v;
        }
        if (x>m) return r->rmq(x, y);
        if (y<=m) return l->rmq(x, y);
        return max(l->rmq(x, m), r->rmq(m+1, y));
    }
} *root;
void check(int bk){
    if (bk < 0 || bk > n/k) return;
    if (bk*k+1 > n) return;
    ii cur = root->rmq(bk*k+1,(bk+1)*k);
    //printf("bucket: %d <%d %d>: value %d pos %d\n",bk,bk*k+1,(bk+1)*k,cur.first,cur.second);
    if (done[cur.second]) return;
    int d = cur.second;
    ii check = root->rmq(d-k+1,d+k-1);
    if (check.second == d){
        //printf("CHECK CORRECT: found value %d pos %d\n",check.first,check.second);
        ///local maximum found
        pq.push({cur.second,cur.first});
    }
}
int main(){
    scanf("%d%d",&n,&k);
    root = new node(1,n);
    for (int i = 1; i <= n; i++){
        scanf("%d",&a[i]);
        //printf("up %d %d\n",i,a[i]);
        root->up(i,a[i]);
    }
    for (int i = 0; i <= n/k; i++){
        check(i);
    }
    ct = n;
    while (pq.size()){
        ii cur = pq.top(); pq.pop();
        //printf("FOUND NEW LEXI pq: pos %d value %d\n",cur.first,cur.second);
        int d = cur.first;
        if (done[d]) continue;
        ans[d] = ct--;
        done[d] = true;
        root->up(d,-INF);
        int bk = (d-1)/k;
        //printf("checking bucket %d\n",bk);
        check(bk);
        check(bk-1);
        check(bk+1);
    }
    for (int i = 1; i <= n; i++){
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 60272
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
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; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	cout << (s[0] == 'S' ? "Cloudy" : (s[0] == 'C' ? "Rainy" : "Sunny")) << endl;
}


Measured memory_bytes: 256
#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(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int D;
vi c(26);
vvi s;

int calc (vi v,int num = D) {
    vi last(26,-1);
    int ret = 0;
    rep(i,num) {
        ret += s[i][v[i]];
        last[v[i]] = i;
        rep(j,26) ret -= c[j]*(i-last[j]);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> D;
    s.resize(D);
    rep(i, D) s[i].resize(26);
    cin >> c >> s;
    vi t(D);
    cin >> t;
    rep(i,D) t[i]--;
    int m;
    cin >> m;
    rep(_,m) {
        int d,q;
        cin >> d >> q;
        d--; q--;
        t[d] = q;
        cout << calc(t) << "\n";
    }
}


Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)

constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,C_h,C_w,D_h,D_w;

  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  vector<string> S(H);
  rep(i,H)cin>>S[i];

  vector dist(H,vector(W,INF));
  vector seen(H,vector(W,false));
  dist[C_h][C_w] = 0;
  deque<pair<int,int>> deq;
  deq.emplace_front(C_h,C_w);
  while(!deq.empty()){
    auto [y,x] = deq.front();
    deq.pop_front();
    if(seen[y][x])continue;
    seen[y][x] = true;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]){
          dist[ny][nx] = dist[y][x];
          deq.emplace_front(ny,nx);
        }
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]+1){
          dist[ny][nx] = dist[y][x]+1;
          deq.emplace_back(ny,nx);
        }
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}


Measured memory_bytes: 8824
def solve():
    N, A = map(int, input().split())
    x = [int(i) for i in input().split()]
 
    # 3d DP
    max_x = max(x)
 
    dp = [[[0] * (max_x * N + 1) for j in range(N + 1)]
                                 for i in range(N + 1)]
 
    dp[0][0][0] = 1
 
    for i in range(0, N):
        for k in range(0, N + 1):
            for y in range(max_x * N + 1):
                if dp[i][k][y]:
                    dp[i + 1][k][y] += dp[i][k][y]
                    dp[i + 1][k + 1][y + x[i]] += dp[i][k][y]
                    
    cnt = 0
    for k in range(1, N + 1):
        for y in range(1, max_x * N + 1):
            if y // k == A and y % k == 0:
                cnt += dp[N][k][y]
 
    print(cnt)
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 62960
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	if(a*n<b){
		cout << a*n << endl;
	}
	else{
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#include <cmath>
using namespace std;
typedef long long ll;

int main(){
  int K;
  cin >>K;
  int x =7%K;
  set<int> s;
  int i =1;
  while(s.count(x)==0){
    if(x==0){
      cout << i <<endl;
      return 0;
    }
    s.insert(x);
    x=(x*10+7)%K;
    i++;
  }
  cout << -1 <<endl;
  return 0;
}


Measured memory_bytes: 50440
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

int main(){
  int x[5],y[5];
  int s;
  int j;
  int temps;
  temps=10;
  for (int i=0;i<5;i++){
    cin>>x[i];
    s=x[i]%10;
    if (s==0){
      y[i]=x[i];
    }
    else {
      y[i]=x[i]+10-s;
    }
    if (s>0&&s<=temps){
      temps=s;
    }
  }
  int sum;
  sum=0;
  for (int i=0;i<5;i++){
    sum+=y[i];
  }
  if (temps!=10){
    sum+=temps-10;
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int N;
int main() {
	cin >> N;
	vector<int> A(N);
	rep(i, N)cin >> A[i];

	vector<int> rev(N);

	rep(i, N)rev[A[i] - 1] = i+1;
	rep(i, N)cout << rev[i] << " ";

	return 0;
}

Measured memory_bytes: 1664
l, r = [int(i) for i in input().split()]

if l//2019 == r//2019:
  min_mod = 2017*2018
  for i in range(l, r):
    for j in range(l+1, r+1):
      temp = (i*j)%2019
      if temp < min_mod:
        min_mod = temp
  print(min_mod)
  
else:
  print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int a,b;
  cin >> a >> b;
  
  if(a*b % 2 == 0){
    cout << "Even" << endl;
  }
  if(a*b % 2 != 0){
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import numpy as np

INP = input()
N = int(INP.split()[0])
D = int(INP.split()[1])

ANS = 0
for i in range(N):
  INP = input()
  X=int(INP.split()[0])
  Y=int(INP.split()[1])
  if np.sqrt(X**2+Y**2) <= D:
    ANS = ANS+1
print(ANS)
  

Measured memory_bytes: 27096
import unittest
import collections


def solve_b(n, m, a):
    print(a)
    b = [0]*(n+1)
    for i in range(n):
        b[i+1] = (a[i] + b[i]) % m
    print(c)
    print(b)
    cnt = 0
    for i in range(n):
        for j in range(i+1, n+1):
            if (b[j] - b[i]) % m == 0:
                cnt += 1
    return cnt


def solve(n, m, a):
    b = [0]*(n+1)
    for i in range(n):
        b[i+1] = (a[i] + b[i]) % m
    c = collections.Counter(b[1:])
    total = 0
    for k, v in c.items():
        if k != 0:
            v -= 1
        if v == 0:
            continue
        total += v * (v+1)//2
    return total


def main():
    n, m = map(int, input().split())
    a = list(map(lambda x: int(x) % m, input().split()))
    print(solve(n, m, a))


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def get_a(self, a, m):
        return list(map(lambda x: int(x) % m, a.split()))

    def test1(self):
        n = 3
        m = 2
        a = self.get_a("4 1 5", m)
        expected = 3
        self.assertEqual(solve(n, m, a), expected)

    def test2(self):
        n = 13
        m = 17
        a = self.get_a("29 7 5 7 9 51 7 13 8 55 42 9 81", m)
        expected = 6
        self.assertEqual(solve(n, m, a), expected)

    def test3(self):
        n = 10
        m = 400000000
        a = self.get_a(
            "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", m)
        expected = 25
        self.assertEqual(solve(n, m, a), expected)


Measured memory_bytes: 28868
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
ll MOD=1e9+7;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    if((n%2 && a[0]!=0) || (!n%2 && (a[0]!=0 || a[1]!=0))) {
        cout << '0' << endl;
        return 0;
    }

    int i=n%2;
    ll ans=1;
    while(i<n) {
        if(a[i]!=a[i+1]) {
            cout << '0' << endl;
            return 0;
        }
        ans = (ans*2)%MOD;
        i+=2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N,M;
    cin >> N >> M;
    vector<int> wrong(N);
    vector<bool> AC(N);
    int ACn = 0;
    REP(i,M){
        int num;
        cin >> num;
        num--;
        string wa;
        cin >> wa;
        if(wa == "WA"){
            if(AC[num] == 0){
                wrong[num]++;
            }
        }else{
            if(AC[num] == 0){
                ACn++;
                AC[num] = 1;
            }
        }
    }
    int penalty = 0;
    REP(i,N){
        if(AC[i])penalty += wrong[i];
    }
    cout << ACn << " " << penalty << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;
typedef pair<int, int> P;


int route[100005][3];

const int INF = 1000000000;



int main() {
  vector<vector<int> > path(100000);
  int N, M;
  cin >> N >> M;
  rep(i, N + 5) rep(j, 3) route[i][j] = INF;

  rep(i, M) {
    int u, v;
    cin >> u >> v;
    path[u].push_back(v);
  }
  int S, T;
  cin >> S >> T;

  queue<P> q;
  q.push(make_pair(S, 0));

  while (!q.empty()) {
    int node = q.front().first;
    int step = q.front().second;
    q.pop();
    // cout << node << endl;
    for (int n: path[node]) {
      int mod_step = ((step + 1) % 3);
      // cout << ": " << n << ", mod_step: " << mod_step << endl;
      if (route[n][mod_step] != INF) continue;
      route[n][mod_step] = step + 1;
      q.push(make_pair(n, step + 1));

    }
  }
  cout << (route[T][0] == INF ? -1 : (route[T][0]  / 3)) << endl;

  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <set>

struct SubRect {
    int x, y;
    int count;
    SubRect(int _x, int _y) {
        x = _x;
        y = _y;
        count = 1;
    }
    bool operator<(const SubRect& other) const {
        return x == other.x ? y < other.y : x < other.x;
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    long long h, w, n;
    std::cin >> h >> w >> n;
    std::set<SubRect> set;
    for (int i = 0; i < n; ++i) {
        int a, b;
        std::cin >> a >> b;
        for (int x = a - 2; x <= a; ++x) {
            for (int y = b - 2; y <= b; ++y) {
                if (x > 0 && y > 0 && x < h - 1 && y < w - 1) {
                    SubRect cur(x, y);
                    auto itr = set.find(cur);
                    if (itr != set.end()) {
                        cur.count += itr->count;
                        set.erase(*itr);
                    }
                    set.emplace(cur);
                }
            }
        }
    }
    long long res[10] = { 0 };
    for (SubRect rect : set) {
        ++res[rect.count];
    }
    long long sum = 0;
    for (int i = 1; i < 10; ++i) {
        sum += res[i];
    }
    res[0] = (h - 2) * (w - 2) - sum;
    for (long long count : res) {
        std::cout << count << '\n';
    }
    return 0;
}

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

int main(){
  string s,t;
  int ans=0;
  cin>>s>>t;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]!=t[i]) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> P(n);
    rep(i, n) {
        cin >> P[i];
        int k = i + 1;
        if(k == P[i]) P[i] = 0;
    }
    ll ans = 0;
    rep(i, n) {
        if(P[i] == 0) {
            int k = i + 1;
            if(k == n) ans++;
            else if(k < n && P[k] != 0) {
                ans++;
            } else if(k < n && P[k] == 0) {
                ans++;
                i++;
            }
        } 
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 768
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    AB = [0,0,0]
    ans = 0
    for _ in range(N):
        s = input()
        l = len(s)
        if s[0] == "B" and s[-1] == "A":
            AB[2] += 1
        else:
            if s[0] == "B":
                AB[1] += 1
            if s[-1] == "A":
                AB[0] += 1
        for i in range(l-1):
            if s[i] == "A" and s[i+1] == "B":
                ans += 1

    if (AB[0]+AB[1] == 0 and AB[2] != 0):
        print(ans+AB[2]-1)
    else:
        print(ans+min(AB[0],AB[1])+AB[2])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int x = 0,max = 0;
    for(int i = 0;i < n;i++)
    {
        if(s[i] == 'I')
        {
            x++;
        }
        else
        {
            x--;
        }
        if(x > max)
        {
            max = x;
        }
    }
    cout << max;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

int main()
{
  int N, M, ans = 1;
  scanf("%d %d", &N, &M);

  /*int d = M - N;
  FOR(i,2,M) {
    d -= N;
    if (d % i == 0 && d >= 0) ans = i;
    else if (d < 0) break;
  }*/

  RFOR(i,M/N+1,2) {
    if (M / i >= N) {
      if (M % i == 0) ans = i;
      else continue;
    }
    break;
  }

  /*
  FOR(i,2,M/N+1) {
    if (M / i >= N) {
      if (M % i == 0) ans = i;
    } else break;
  }*/

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

  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    for i in range(30):
        nokori = N - 7 * i
        if nokori >= 0 and nokori % 4 == 0:
            print("Yes")
            return
    print("No")
    return

main()



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

int main() {
	int t;
	cin>>t;
	while(t--){
		long long int a,b;
		cin>>a>>b;
		if(a&1){
			cout<<(a-1)*127+b<<endl;
		}
		else
		cout<<(a-1)*127+(127^b)<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    counter = Counter(A)
    sorted_cnter = sorted(list(counter.items()), key=lambda x: x[1])
    will_rewrite = sorted_cnter[:-K]

    ans = 0
    for t in will_rewrite:
        ans += t[1]
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 105032
use std::collections::HashMap;
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let (n, a): (usize, i32) = stdin.lock().gets().split(' ').values();
    let xs = stdin.lock().gets().split(' ').take(n)
        .map(|x| x.parse::<i32>().unwrap() - a).collect::<Vec<_>>();
    let mut cnt = HashMap::new();
    cnt.insert(0, 1u64);
    for x in xs.iter() {
        let prev = cnt;
        cnt = HashMap::new();
        for (k, v) in prev.into_iter() {
            *cnt.entry(k).or_insert(0) += v;
            *cnt.entry(k + x).or_insert(0) += v;
        }
    }
    println!("{}", *cnt.entry(0).or_insert(0) - 1);
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N, K;
  cin >> N >> K;
  vector<long long> tree(N);
  for(int i = 0; i < N; i++) cin >> tree[i];
  sort(tree.begin(), tree.end());
  long long Min = 9999999999;
  for(int i = 0; i + K - 1< N; i++){
    Min = min(Min, tree[i+K-1] - tree[i]);
  }
  cout << Min <<endl;
}


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

int main(){
    int n = 0;
    string s;
    cin >> s;

    for(int i = 0; i < 3; i++){
        if(s.at(i) == '1'){
            n += 1;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
from math import gcd
from collections import defaultdict

MOD = 10 ** 9 + 7

n = int(input())
d = defaultdict(int)
tmp = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == b == 0:
        tmp += 1
    else:
        if b < 0 or (b == 0 and a <= 0):
            a = -a
            b = -b
        g = gcd(a, b)
        a = a // g
        b = b // g
        d[(a, b)] += 1
        if a <= 0:
            d[(b, -a)]
        else:
            d[(-b, a)]
ans = 1
for k, v in d.items():
    a, b = k
    if a <= 0:
        continue
    c = d[(-b, a)]
    ans *= pow(2, v) + pow(2, c) - 1
    ans %= MOD
print((ans + tmp - 1) % MOD)


Measured memory_bytes: 174436
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
A = tuple(map(int, input().split()))

bit = BinaryIndexedTree(N)
res = list()

for i, a in enumerate(A):
    bit.add(i + 1, a)

for _ in range(Q):
    q, x, y = map(int, input().split())
    if q == 0:
        bit.add(x + 1, y)
    else:
        res.append(bit.sum(y) - bit.sum(x))

print('\n'.join(map(str, res)))

Measured memory_bytes: 189084
using System;

namespace A___Falling_Asleep
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var st = new Tuple<string, int>[n];
            for (var i = 0; i < n; i++)
            {
                var input = Console.ReadLine ().Split (' ');
                st[i] = Tuple.Create (input[0], int.Parse (input[1]));
            }
            var x = Console.ReadLine ();
            var a = false;
            var time = 0;
            var xi = 0;
            for (var i = 0; i < n; i++)
            {
                if (st[i].Item1 == x)
                {
                    a = true;
                    xi = i;
                }

                if (a == true)
                    time += st[i].Item2;
            }
            Console.WriteLine (time - st[xi].Item2);
        }
    }
}

Measured memory_bytes: 11220