akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

class UnionFind{
private:
  ::std::vector<int_fast32_t> par;
  size_t n;

public:
  UnionFind(){}
  UnionFind(size_t n):n(n){
    par.resize(n, -1);
  }

  uint_fast32_t find(uint_fast32_t x){
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }

  size_t size(uint_fast32_t x){
    return -par[find(x)];
  }

  bool unite(uint_fast32_t x, uint_fast32_t y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(size(x) < size(y)) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  bool same(uint_fast32_t x, uint_fast32_t y){
    return find(x) == find(y);
  }
};

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

	int64 N, M, K;
	cin >> N >> M >> K;
	map<PII, int> block, fr;
	UnionFind uf(N);
	REP(i, M) {
	  int64 a, b;
	  cin >> a >> b; a--; b--;
	  uf.unite(a, b);
	  fr[minmax(a, b)] = 1;
	}
	REP(i, K) {
	  int64 c, d;
	  cin >> c >> d; c--; d--;
	  block[minmax(c, d)] = 1;
	}
	vector<int64> bcnt(N, 0), fcnt(N, 0);
	for (auto& x : block) {
	  if (!uf.same(x.fs.fs, x.fs.sc)) continue;
	  bcnt[x.fs.fs]++;
	  bcnt[x.fs.sc]++;
	}
	for (auto& x : fr) {
	  if (!uf.same(x.fs.fs, x.fs.sc)) continue;
	  fcnt[x.fs.fs]++;
	  fcnt[x.fs.sc]++;
	}
	REP(i, N) {
	  cout << uf.size(i) - bcnt[i] - fcnt[i] - 1 << " ";
	}
	cout << endl;
}


Measured memory_bytes: 15744
//Minimization

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,k,a) int n,k;cin>>n>>k;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    double n,k;cin>>n>>k;
    vector<double>a(n);
    rep(i,0,n)cin>>a[i];
    int ans = ceil((n-k)/(k-1)+1);
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n;
long long a[100006];
long long b[100006];
long long c;
long long cc;
long long waru(long long p,long long q)
{
	p%=q;
	if(p==0)return 0;
	else return (q-p);
}
int main()
{
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	for(long long k=n-1;k>=0;k--)
	{
		a[k]+=c;
		cc=waru(a[k],b[k]);
		c+=cc;
	}
	cout<<c<<endl;
	return 0;
}

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

int main(){
  int n;cin>>n;
  int x[n];int X[n];
  for(int i=0;i<n;++i){
    cin>>x[i];
    X[i]=x[i];
  }
  
  sort(x,x+n);
  int a=x[n/2-1];
  int b=x[n/2];
  for(int i=0;i<n;++i){
    if(X[i]<=a){
      cout<<b<<endl;
    }else{
      cout<<a<<endl;
    }
  }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll a,b,c,d;cin >> a >>b >>c >>d;
    while(1){
        c-=b;
        if(c<=0){
            cout << "Yes" <<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" <<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e5+10;

char s[MR], res[MR];

int main()
{
	int N;
	scanf("%d%s", &N, s);
	REP(i,2)REP(j,2)
	{
		res[0] = i ? 'W' : 'S';
		res[1] = j ? 'W' : 'S';
		FOR(k,2,N)
		{
			if(res[k-1] == 'S')
			{
				if(s[k-1] == 'o')
					res[k] = res[k-2];
				else
					res[k] = res[k-2] == 'S' ? 'W' : 'S';
			}
			else
			{
				if(s[k-1] == 'x')
					res[k] = res[k-2];
				else
					res[k] = res[k-2] == 'S' ? 'W' : 'S';
			}
		}

		bool ok = 1;
		REP(k,N)
		{
			if(res[k] == 'S' && s[k] == 'o' && res[(k+N-1)%N] != res[(k+1)%N])
			{
				ok = 0;
				break;
			}
			if(res[k] == 'S' && s[k] == 'x' && res[(k+N-1)%N] == res[(k+1)%N])
			{
				ok = 0;
				break;
			}
			if(res[k] == 'W' && s[k] == 'o' && res[(k+N-1)%N] == res[(k+1)%N])
			{
				ok = 0;
				break;
			}
			if(res[k] == 'W' && s[k] == 'x' && res[(k+N-1)%N] != res[(k+1)%N])
			{
				ok = 0;
				break;
			}
		}

		if(ok)
		{
			printf("%s\n", res);
			return 0;
		}
	}

	printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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





int main(){
    int H, W, A, B; cin >> H >> W >> A >> B;
    REP(i, H){
        REP(j, W){
            cout << ((i<B)^(j<A) ? 0 : 1);
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

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

// ford-fulkerson
template <typename T> class Graph {
  struct Edge {
    int to, rev;
    T cap;
    Edge(int to, int rev, T cap) : to(to), rev(rev), cap(cap) {}
  };
  vector<vector<Edge>> g;
  T inf;
  vector<int> visited;

public:
  Graph(int n) {
    g.resize(n);
    inf = numeric_limits<T>::max() / 3;
    visited.resize(n, false);
  }
  void add_edge(int from, int to, T cap) {
    g[from].emplace_back(to, g[to].size(), cap);
    g[to].emplace_back(from, (int)g[from].size() - 1, 0);
  }
  T dfs(int i, T curf, int sink) {
    if (i == sink) return curf;
    visited[i] = true;
    for (auto &&e : g[i]) {
      if (visited[e.to] or e.cap == 0) continue;
      auto tmpf = dfs(e.to, min(e.cap, curf), sink);
      if (tmpf > 0) {
        e.cap -= tmpf;
        g[e.to][e.rev].cap += tmpf;
        return tmpf;
      }
    }
    return 0; // 流せなかった
  }
  T ford(int source, int sink) {
    T maxf = 0;
    while (true) {
      fill(visited.begin(), visited.end(), false);
      auto f = dfs(source, inf, sink);
      if (f > 0) {
        maxf += f;
      } else {
        break;
      }
    }
    return maxf;
  }
};

int main() {

  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  int sy, sx, gy, gx;
  rep(i, h) rep(j, w) {
    cin >> a[i][j];
    if (a[i][j] == 'S') {
      sy = i;
      sx = j;
    } else if (a[i][j] == 'T') {
      gy = i;
      gx = j;
    }
  }
  if (sy == gy or sx == gx) {
    cout << -1 << endl;
    return 0;
  }

  auto n = h + w;
  Graph<int> g(n + 2);
  auto S = n, T = n + 1;
  auto inf = numeric_limits<int>::max() / 3;
  g.add_edge(S, sy, inf); // S は壊せない
  g.add_edge(S, sx + h, inf);
  g.add_edge(gy, T, inf); // T は壊せない
  g.add_edge(gx + h, T, inf);
  rep(i, h) rep(j, w) if (a[i][j] == 'o') {
    g.add_edge(i, j + h, 1); // 壊すとコスト1かかる
    g.add_edge(j + h, i, 1);
  }

  cout << g.ford(S, T) << endl;

  return 0;
}


Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

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

    vector<vector<pii> > G(n+1);
    map<pii, bool> used;

    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(c,b);
        G[b].emplace_back(c,a);
        if(a > b) swap(a,b);
        used[{a,b}] = true;
    }


    reps(s,n){
        reps(g,n){
            if(s == g) continue;
            vector<int> min_cost(n+1,INF), pre(n+1);
            min_heap<pii> pq;
            min_cost[s] = 0;
            pq.emplace(0,s);

            while(!pq.empty()){
                int now_cost, now_node;
                tie(now_cost, now_node) = pq.top();
                pq.pop();
                if(now_cost > min_cost[now_node]) continue;
                for(auto e : G[now_node]){
                    int cost, next_node;
                    tie(cost, next_node) = e;
                    if(chmin(min_cost[next_node], min_cost[now_node] + cost)){
                        pre[next_node] = now_node;
                        pq.emplace(min_cost[next_node], next_node);
                    }
                }
            }

            int now = g;
            while(now != s){
                int a, b;
                a = now;
                b = pre[now];
                if(a > b) swap(a,b);
                used[{a,b}] = false;
                now = pre[now];
            }
        }
    }

    int res = 0;
    for(auto e : used){
        res += e.second;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 384
int _a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k;

int parse(char *p){
  switch(*p){
    case 'F': return 0;
    case 'T': return 1;
    case 'a': return _a;
    case 'b': return _b;
    case 'c': return _c;
    case 'd': return _d;
    case 'e': return _e;
    case 'f': return _f;
    case 'g': return _g;
    case 'h': return _h;
    case 'i': return _i;
    case 'j': return _j;
    case 'k': return _k;
    case '-': return !parse(p+1);
    case '(': {
                int x=0;
                p++;
                char *q=p;
                for(;;p++){
                  if(*p=='(')x++;
                  if(*p==')')x--;
                  if(x==0&&*p!='-')break;
                }
                p++;
                switch(*p){
                  case '*': return parse(q)&parse(p+1);
                  case '+': return parse(q)|parse(p+1);
                  case '-': return !parse(q)|parse(p+2);
                }
              }
  }
}

int main(){
  char p[1001],*q;
  while(1){
    scanf("%s",p);
    if(*p=='#')return 0;
	q=strchr(p,'=')+1;
    for(_a=0;_a<2;_a++)
      for(_b=0;_b<2;_b++)
        for(_c=0;_c<2;_c++)
          for(_d=0;_d<2;_d++)
            for(_e=0;_e<2;_e++)
              for(_f=0;_f<2;_f++)
                for(_g=0;_g<2;_g++)
                  for(_h=0;_h<2;_h++)
                    for(_i=0;_i<2;_i++)
                      for(_j=0;_j<2;_j++)
                        for(_k=0;_k<2;_k++)
                          if(parse(p)!=parse(q))goto fail;
    puts("YES");continue;
	fail:puts("NO");
  }
}

Measured memory_bytes: 556
li1=[1,3,5,7,8,10,12]
li2=[4,6,9,11]
li3=[2]
a,b=map(int,input().split())
if a in li1 and b in li1:
  print("Yes")
elif a in li2 and b in li2:
  print("Yes")
elif a in li3 and b in li3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define mod 1000000007
#define pi acos(-1.0)

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll s=0,x=0;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        s+=l1[i];x=max(x,l1[i]);
    }
    x<s-x?cout<<"Yes\n":cout<<"No\n";
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll r, g, b;
    cin >> r >> g >> b;
    if ((g * 10 + b) % 4 == 0)
        ce("YES");
    else
        ce("NO");
}

Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;



int n, m;
long long a[100005], dp[100005];

int main(int argc, const char * argv[]) {
//    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (i == 1) continue;
        dp[i] = 1e18;
        for (int j = i - 1; j > 0 && j >= i - m; --j) {
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n] << '\n';
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
string lcs(string a,string b,int m,int n)
{
 int l[m+1][n+1];


 for(int i=0;i<=m;i++){
     for(int j=0;j<=n;j++){
         if(i==0||j==0)
            l[i][j]=0;
         else if(a[i-1]==b[j-1]){
            l[i][j]=l[i-1][j-1]+1;
         }
         else{
            l[i][j]=max(l[i-1][j],l[i][j-1]);
         }
     }
 }
int index = l[m][n]; 
char lcs[index+1]; 
lcs[index] = '\0'; 

   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 

      if (a[i-1] == b[j-1]) 
      { 
          lcs[index-1] = a[i-1]; 
          i--; j--; index--;     
      } 
  
 
      else if (l[i-1][j] > l[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
  return lcs;

}

int main()
{
  string a,b;cin>>a>>b ;
  int m = a.length();
  int n = b.length();
  cout<<lcs(a, b, m, n);  
  return 0;
}


Measured memory_bytes: 38812
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000+9;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, last, cnt, ans, a[400000];
Pll sum[400000], flag[400000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Combination {
	LL mod;
	vector<LL> mfact, rfact;

	Combination(LL sz, LL mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
		mfact[0] = 1;
		for (LL i = 1; i < mfact.size(); i++) {
			mfact[i] = mfact[i - 1] * i % mod;
		}
		rfact[sz] = inv(mfact[sz]);
		for (LL i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % mod;
		}
	}

	LL fact(LL k) const {
		return (mfact[k]);
	}

	LL pow(int64_t x, int64_t n) const {
		LL ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= mod;
			(x *= x) %= mod;
			n >>= 1;
		}
		return (ret);
	}

	LL inv(LL x) const {
		return (pow(x, mod - 2));
	}

	LL P(int n, int r) const {
		if (r < 0 || n < r) return (0);
		return (mfact[n] * rfact[n - r] % mod);
	}

	LL C(int p, int q) const {
		if (q < 0 || p < q) return (0);
		return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
	}

	LL H(int n, int r) const {
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum[i + 1].fir += sum[i].fir + a[i];
		sum[i + 1].sec = i + 1;
	}
	sort(sum, sum + n + 1);
	LL sz = 0;
	rep(i, n+1) {
		if (sum[i].fir == flag[sz].fir) {
			flag[sz].second++;
		}
		else {
			sz++;
			flag[sz].sec++;
			flag[sz].first = sum[i].first;
		}
	}
	rep(i, sz+1) {
		ans += flag[i].sec*(flag[i].sec - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

	int num, a, b;
	cin >> num>>a>>b;
    
    cout << ((a * num <= b) ? a * num : b) << endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split("\n");
    tmp = input[0].split(" ");
    var N = parseInt(tmp[0],10);
    var M = parseInt(tmp[1],10);
    var L = [];
    var R = [];
    var output;
    var maxL = 1;
    var minR = N;

    for(var i = 1; i <= M; i++){
        L[i-1] = parseInt(input[i].split(" ")[0],10);
        R[i-1] = parseInt(input[i].split(" ")[1],10);
        if(maxL < L[i-1]){
            maxL = L[i-1];
        }
        if(minR > R[i-1]){
            minR = R[i-1];
        }
    }
    output = minR - maxL + 1;
    if(output < 0){
        output = 0;
    }
    console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long LL;
typedef long double Lf;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {//→or↓のみ と 最短経路 は 同値
	int h,w,sh=0;char c[9];
	scanf("%d%d",&h,&w);
	rep(i,h){
		scanf("%s",c);
		rep(j,w)if(c[j]=='#')sh++;
	}
	printf(sh==h+w-1?"Possible":"Impossible");
}

Measured memory_bytes: 128
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    # X = 100
    # N = 100
    # P = list(range(1, 101, 1))

    if N == 0:
        print(X)
        exit()

    sel_X = -1
    diff_X = float("inf")
    for x in range(-200, 200, 1):
        if x in P:
            continue
        if abs(x - X) < diff_X:
            sel_X = x
            diff_X = abs(x - X)
    print(sel_X)



if __name__ == '__main__':
    main()

Measured memory_bytes: 65436
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])


Measured memory_bytes: 8572
N = int(input())
A = [0] + [int(i) for i in input().split()] + [0]
S = ans = 0
for i in range(N+1):
    S += abs(A[i]-A[i+1])
for j in range(1,N+1):
    ans =  S+abs(A[j-1]-A[j+1])-(abs(A[j-1]-A[j])+abs(A[j]-A[j+1]))
    print(ans)


Measured memory_bytes: 14048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc080
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var sum = 0;
            for (var i = 0; i < n.Length; i++) {
                int firstDigit = (int)(n.ToString()[i]) - 48;
                sum += firstDigit;
            }

            if (int.Parse(n) % sum == 0)
            {
                Console.WriteLine("Yes");
            } else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int f(Int N, vector<Int>& A, vector<Int>& B) {
    for (int i = 1; i < 3; i++) {
        if (A[i] < B[i]) {
            swap(A[0], A[i]), swap(B[0], B[i]);
        }
    }
    Int ans = 0;
    for (int i = 0; i <= (A[0] < B[0] ? N / A[0] : 0); i++) {
        Int M = N - i * A[0];
        for (int j = 0; j <= (A[1] < B[1] ? M / A[1] : 0); j++) {
            Int L = M - j * A[1];
            int k = (A[2] < B[2] ? L / A[2] : 0);
            Int val = i * B[0] + j * B[1] + k * B[2] + L - k * A[2];
            ans = max(ans, val);
        }
    }
    return ans;
}
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    Int N; cin >> N;
    vector<Int> A(3), B(3);
    for (auto &a : A) cin >> a;
    for (auto &b : B) cin >> b;
    cout << f(f(N, A, B), B, A) << '\n';
    return 0;
}


Measured memory_bytes: 256
//
//$$$$$$$$$$$$$$$$$$$$$$
//$$                  $$
//$$   gyoubu_oniwa   $$
//$$                  $$
//$$$$$$$$$$$$$$$$$$$$$$
//
#include<bits/stdc++.h>
using namespace std;
#define DBG(a) if(DBGDO) cout<<#a<<':'<<a<<endl;
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
#define pow(a,b) (pow(a,b)+0.5)

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--) 
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<string> vs;typedef vector<vector<string>> vvs;

#define unmp unordered_map

#define PRIME ((lli)(1e9+7ll))
#define PRIME2 (998244353ll)
const lli TEN_18 = 1e18;
const lli TEN_9 = 1e9;
const lli TEN_5 = 1e5;

inline void debugORfast(int a=1,int b=1){
    if(a){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
        #endif
    }
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}}

template<typename T>
void print(const T &v, int begin=-1, int end=-1, int w=2)
{
	if(begin<=end){
		if(begin==-1) fl(i,0,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) fl(i,begin,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else fl(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;}
	else{
		if(begin==-1) flr(i,v.SZ-1,-1) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) flr(i,begin,-1) cout<<setw(w)<<v[i]<<' ';
		else flr(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;
	}
}

void pans(char v){
	switch(v){
		case 'y' : cout<<"yes"<<endl; break;
		case 'n' : cout<<"no"<<endl; break;
		case 'Y' : cout<<"Yes"<<endl; break;
		case 'N' : cout<<"No"<<endl; break;
		case 'B' : cout<<"YES"<<endl; break;
		case 'S' : cout<<"NO"<<endl; break;
	}
}

int DBGDO=0;

lli brute(){
	return 0;
}

lli solve(){
    return 0;
}

int main()
{
	debugORfast(0,1);
	//w(ttt)
	{
		char a; cin>>a;
		if(a>='A' and a<='Z') cout<<'A'<<endl;
		else cout<<'a'<<endl;
	}
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

const char a='.', b='#';

int main(){
  int A,B; cin>>A>>B; A--,B--;
  cout<<"100 100"<<endl;
  rep(i,50){
    rep(j,100){
      if(A>0&&(i%2==0)&&(j%2==1)){
        cout<<a;
        A--;
      }else cout<<b;
    }
    cout<<endl;
  }
  rep(i,50){
    rep(j,100){
      if(B>0&&(i%2==1)&&(j%2==1)){
        cout<<b;
        B--;
      }else cout<<a;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define LL long long
#define R register int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=1e5+9;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
    G;while(*ip<'-')G;
    R x=*ip&15;G;
    while(*ip>'-'){x*=10;x+=*ip&15;G;}
    return x;
}
int k,l[N],r[N];LL f[N];bool b[N];
struct Node{
    int r;mutable int v;
    inline Node(R a,R b=0):r(a),v(b){}
    inline bool operator<(const Node&a)const{return r<a.r;}
};
typedef set<Node>::iterator IT;
set<Node>s;
inline IT Split(R p){
    IT i=s.lower_bound(Node(p));
    return i->r!=p?s.insert(Node(p,i->v)).first:i;
}
inline void Set(R l,R r,R v){
    if(l>r)return;
    IT il=Split(l-1),ir=Split(r);
    ir->v=v;s.erase(++il,ir);
}
inline LL Calc(R p){
    R j=s.lower_bound(Node(p))->v;
    return j?f[j]+(p-r[j]+k)%k:0;
}
int main(){
    R n=in();LL k=::k=in(),a=0,a1=0,ans=1e18;
    s.insert(Node(-1));
    s.insert(Node(k-1));
    for(R i=1;i<=n;++i){
        a1=a;a+=in();
        if(!(b[i]=in()&1))continue;
        if(2*(a-a1)>k)return puts("-1"),0;
        l[i]=(-2*a1%k+k)%k;r[i]=(-2*a%k+k)%k;
        f[i]=Calc(r[i]);
        if(l[i]>r[i])Set(r[i]+1,l[i]-1,i);
        else Set(0,l[i]-1,i),Set(r[i]+1,k-1,i);
    }
    for(R i=1;i<=n;++i)
        if(b[i])ans=min(ans,Calc(l[i]));
    cout<<ans+2*a<<endl;
    return 0;
}

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N), F(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  for (long i = 0; i < N; i++) cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  vector<long> V(N);
  for (int i = 0; i < N; i++) V.at(i) = A.at(i) * F.at(i);
  long L = -1, R = 2e18;
    while (R - L > 1) {
      long M = (L + R) / 2;
      long sum = 0;
      for (long i = 0; i < N; i++) {
        if (V.at(i) > M) sum += ((V.at(i) - M) + F.at(i) - 1) / F.at(i);
      }
      (sum <= K) ? R = M : L = M;
    }
  cout << R << "\n";
}


Measured memory_bytes: 7976
import java.util.Scanner;

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

        int n = sc.nextInt(); sc.nextLine();

        int r = 0;
        for (int i = 1; i <= n; i++){
            if (i % 2 == 1) r++;
        }

        System.out.println((double)r / n);
    }
}

Measured memory_bytes: 22484
char*C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",*strchr();
L[]={6,8,4,4,3,5,8,6,4,8,4,5,8,8,5,3,8,4,5,5,8,8,6,8,8,8,3,6,6,8,6,6};
B[]={
	0x25,0x9a,0x05,0x01,0x06,0x09,0x9b,0x10,0x07,0x98,0x06,0x04,0x99,0x9e,0x05,0x07,
	0x9f,0x08,0x06,0x07,0x9c,0x9d,0x02,0x92,0x93,0x90,0x05,0x11,0x03,0x91,0x00,0x01
};
int main(){
	int c,b=0,l=0,i;
	while(c=getchar(),c+1){
		if(c==10){
			if(l){
				b<<=5-l;
				putchar(C[b&31]);
				l=0;
			}
			putchar(10);
		} else {
			i=strchr(C,c)-C;
			b=b<<L[i]|B[i];
			l+=L[i];
			while(l>=5){
				l-=5;
				putchar(C[b>>l&31]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[2003][2003],tmtmp;
int l[2003][2003],r[2003][2003];
int main(){
	cin>>n>>m;
	tmtmp=getchar();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			c[i][j]=getchar();
		tmtmp=getchar();
	}
	for(int i=0;i<n;i++){
		int x=(c[i][0]!='#');
		for(int j=1;j<m;j++)
			if(c[i][j]=='.')
				x++;
			else{
				for(int k=0;k<x;k++)
					l[i][j-k-1]=x;
				x=0;
			}
		for(int j=0;j<x;j++)
			l[i][m-1-j]=x;
		x=0;
	}
	for(int i=0;i<m;i++){
		int x=(c[0][i]!='#');
		for(int j=1;j<n;j++)
			if(c[j][i]=='.')
				x++;
			else{
				for(int k=0;k<x;k++)
					r[j-k-1][i]=x;
				x=0;
			}
		for(int j=0;j<x;j++)
			r[n-1-j][i]=x;
		x=0;
	}
	int ans=-1;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			ans=max(ans,l[i][j]+r[i][j]-1);
	cout<<ans;
}

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

#define INF 1e9

using namespace std;

// n 円を m 種類のコインで支払う
int n, m;
// 各コインの価値
int c[21];
// dp[v] := 価値 v 円を支払うときに使用するコインの最小枚数
int dp[50001];

// メモ化再帰
int memo_rec(int n) {
    if (dp[n] != INF) {
        return dp[n];
    }
    int ret;

    for (int i = 0; i < m; i++) {
        ret = min(memo_rec(n - c[i]) + 1, dp[n]);
    }

    return dp[n] = ret;
}

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

    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }

    fill(dp, dp + 50001, INF);

    dp[0] = 0;

    for (int i = 0; i < m; i++) {
        for (int j = 0; j + c[i] <= n; j++) {
            dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3308
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;



int main() {
    ll ans;
    vector<ll>x(5);
    rep(i, 5) cin >> x[i];
    rep(i, 5) {
        if (x[i] == 0) {
            ans = i + 1;
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
 }


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

using namespace std;

const int MOD = (int)1e9+7;

int main(){
  long long N,K;
  cin >> N >> K;

  if(K%2!=0){
    long long a=N/K;
    cout << a*a*a << endl;
  }
  else{
    long long a1=N/K;
    long long a2=N/(K/2) -a1;
    cout << a1*a1*a1 + a2*a2*a2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int MAX_PRIME = 55555;

int is_prime[MAX_PRIME + 1];

void init_primes()
{
    rep(i, 0, MAX_PRIME + 1) is_prime[i] = 1;
    is_prime[0] = is_prime[1] = 0;

    rep(i, 0, MAX_PRIME + 1)
    if (is_prime[i])
    {
        for(ll j = (ll)i * i; j < MAX_PRIME + 1; j += i)
            is_prime[j] = 0;
    }
}


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

    vector<int> ans;
    rep(i, 0, MAX_PRIME + 1)
    {
        if (is_prime[i] and  i % 5 == 1)
            ans.push_back(i);
        if (ans.size() == n) break;
    }

    rep(i, 0, ans.size())
        cout << ans[i] << ' ';
    cout << endl;

    // int cnt = 0;
    // rep(i, 0, MAX_PRIME + 1) cnt += int(is_prime[i]);
    // cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
def main():
    N = int(input())
    A = list(map(int, input().split()))
    money = 1000
    kab = 0
    cand = [A[0]]
    pre = A[0]
    for i in range(1,N):
        if A[i] < pre:
            cand.append(A[i-1])
            cand.append(A[i])
        pre = A[i]
    if pre <= A[-1]:
        cand.append(A[-1])
    if len(cand) % 2 == 1:
        cand.pop(-1)
    for i in range(len(cand)):
        if i % 2 == 0:
            cnt = money // cand[i]
            kab += cnt
            money -= cand[i] * cnt 
        else:
            money += cand[i] * kab
            kab = 0
    
    print(money)

if __name__ == "__main__":
    main()

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

int main(void){
    
    int n, k;
    cin >> n >> k;
    k--;
    
    string s;
    cin >> s;
    
    if (s[k] == 'A') s[k] = 'a';
    else if (s[k] == 'B') s[k] = 'b';
    else s[k] = 'c';
    
    cout << s << endl;
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int n;
string s[200000];
int a1;
int a2;
int ab;
lint ans;
int tt;
int siz[200000];

int main(){
  cin >> n;
  REP(i,n){
    char moji[1000];
    scanf("%s",moji);
    string kkk = "";
    for(tt=0; moji[tt]!='\0'; ++tt);
    //dump(tt);
    siz[i] = tt;
    for(int i = 0;i<tt;i++){
      kkk += moji[i];
    }
    s[i] = kkk;
  }
  REP(i,n){
    if(s[i][0]=='B'&&s[i][siz[i]-1]=='A') ab ++;
    else if(s[i][0]=='B') a2 ++;
    else if(s[i][siz[i]-1]=='A') a1 ++;
    REP(j,siz[i]-1){
      if(s[i][j]=='A'&&s[i][j+1]=='B') ans ++;
    }
  }
  if(ab==0){
    ans += min(a1,a2);
  }
  else{
    ans += ab-1;
    if(a1 ==0 && a2==0){
      ans += 0;
    }
    else if(a1 ==0 || a2==0){
      ans ++;
    }
    else{
      ans += min(a1,a2);
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2304
let () =
  Scanf.scanf "%d %d %s" @@ fun n k s ->
  let s = Array.init n (fun i -> s.[i]) in
  s.(k-1) <- (match s.(k-1) with 'A' -> 'a' | 'B' -> 'b' | _ -> 'c');
  Array.iter print_char s;
  print_newline ()

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=100000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 233333;
int T;
int n;
int a[2333];


int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//    cin >> T;
    T =1;
    while(T--)
    {
        cin >> n;
        int f = 0;
        rep(i,0,n)
        {
            cin >> a[i];
            if(a[i] % 2 == 0)
            {
                if(a[i] % 3 == 0 || a[i] % 5 == 0)
                {
                    continue;
                }
                else
                {
                    f = 1;
                }
            }
        }
        if(f==0)
        {
            cout << "APPROVED" << endl;
        } else
        {
            cout << "DENIED" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
# ARC068C - X: Yet Another Die Game (ABC053C)
def main():
    x = int(input())
    ans, r = x // 11 * 2, x % 11  # r: remainder
    if r != 0:
        ans += 1 if x % 11 <= 6 else 2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
length = int(input())
eles = [int(l) for l in input().split()]

times = 0
for i in range(length):
    flag = 1
    while flag > 0:
        flag = 0
        for j in range(length-1, i, -1):
            if eles[j] < eles[j - 1]:
                _temp = eles[j]
                eles[j] = eles[j-1]
                eles[j-1] = _temp
                flag = 1
                times += 1

print(*eles)
print(times)

Measured memory_bytes: 7700
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>

class UnionFind {
	std::vector<int> vec;
public:
	UnionFind(int size) : vec(size, -1) {};
	int root(int a) {
		if (vec[a] < 0) {
			return a;
		}
		else {
			return vec[a] = root(vec[a]);
		}
	}
	int size_of(int a) {
		return -vec[root(a)];
	}
	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (vec[a] > vec[b]) std::swap(a, b);
		vec[a] += vec[b];
		vec[b] = a;
	}
};
struct Point {
	int x, y;
};
int main() {
	int n; std::cin >> n;
	std::vector<Point> points(n);
	for (auto& p : points) 
		std::cin >> p.x >> p.y;
	UnionFind uft(200001);
	for (const auto p : points) {
		uft.unite(p.x, p.y + 100000);
	}
	std::vector<std::vector<int>> edges(200001);
	for (auto i = 0; i <= 200000; ++i) {
		edges[uft.root(i)].push_back(i);
	}
	long long int sum = 0;
	for (const auto& edge : edges) {
		long long int x{ 0 }, y{ 0 };
		for (const auto e : edge) {
			if (e > 100000) {
				++y;
			}
			else {
				++x;
			}
		}
		sum += x * y;
	}
	std::cout << sum - n << '\n';
}

Measured memory_bytes: 15452
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string s;
  ll w,n;
  cin >> s >> w;
  n = s.size();
  for(int i=0;i<n;i++){
    if(i%w==0) cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
/***************************************** START OF TEMPLATE *********************************************/

#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  f              first
#define  s              second
#define  pb             push_back
#define  INPa(a,n)      foo(i,1,n) cin>>a[i];
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ll   MOD   =  1e+9 + 7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5 + 8;

vll adj[N]; ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, k , u, v, a[N], mark = 0;
stack<ll> sk;
vll path;
/***************************************** FUNCTION IMPLEMENTATIONS **************************************/
void dfs(ll v, ll p, ll d) {
    vis[v] = 1;
    sk.push(v);
    if (d == k) {
        cout << v;
        exit(0);
    }
    for (auto to : adj[v]) {
        if (vis[to] == 1) {
            mark = d + 1;
            while (sk.top() != to) {
                path.pb(sk.top());
                sk.pop();
            }
            path.pb(sk.top()); sk.pop();
            reverse(all(path));
        }

        if (mark > 0) return;
        if (vis[to] == 0)dfs(to, v, d + 1);
    }
    vis[v] = 2;
}

/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc) {
    cin >> n >> k;
    foo(i, 1, n) cin >> a[i];
    foo(i, 1, n) adj[i].pb(a[i]);
    dfs(1, -1, 0);
    ll sz = path.size();
    k -= mark;
    cout << path[k % sz];

}

int main() {
    SPEED;

    //cin>>test_cases;
    foo(i, 1, test_cases) {
        MAIN(i);
    }
}

Measured memory_bytes: 33168
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int L=Integer.parseInt(sc.next());
        int A=Integer.parseInt(sc.next());
        int B=Integer.parseInt(sc.next());
        int C=Integer.parseInt(sc.next());
        int D=Integer.parseInt(sc.next());
        int K=A/C;
        int S=B/D;
        if(A%C!=0){
            K++;
        }
        if(B%D!=0){
            S++;
        }
        int ans;
        if(K>S){
            ans=L-K;
        }else{
            ans=L-S;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 17320
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int tmp = 0;
        for(int j = 0; j < m; j++)
        {
            tmp += b[j] * a[i][j];
        }
        tmp += c;
        if(tmp > 0) ans++;
    }
    cout << ans << endl;
}




Measured memory_bytes: 256