akhauriyash/Code-Regression huggingface dataset:
program main
    implicit none
    integer a, b, c, d
    read(*, *) a, b, c, d
    if(abs(a-c) <= d .or. (abs(a-b) <= d .and. abs(b-c) <= d)) then
        write(*, *) 'Yes'
	else
	    write(*, *) 'No'
	end if
end program main

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

int main() {
  string l;
  cin >> l;
  vector<vector<ll>> dp(l.size() + 1, vector<ll>(2));
  dp[0][0] = 1;
  for (int i = 0; i < l.size(); i++) {
    if (l[i] == '1') {
      dp[i + 1][0] += 2 * dp[i][0] % mod;
      dp[i + 1][0] %= mod;
      dp[i + 1][1] += dp[i][0];
      dp[i + 1][1] += 3 * dp[i][1] % mod;
      dp[i + 1][1] %= mod;
    } else {
      dp[i + 1][0] += dp[i][0];
      dp[i + 1][0] %= mod;
      dp[i + 1][1] += 3 * dp[i][1] % mod;
      dp[i + 1][1] %= mod;
    }
  }
  cout << (dp[l.size()][0] + dp[l.size()][1]) % mod << endl;
}


Measured memory_bytes: 5888
while 1:
    H,W=map(int,input().split())
    if H==W==0:
        break
    for h in range(H):
        for w in range(W):
            if (h+w)%2==0:
                print("#",end="",sep="")
            else:
                print(".",end="",sep="")
        print("")
    print("")


Measured memory_bytes: 7008
#include<cstdio>
#include<algorithm>

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

using namespace std;

char goal[3][3],gx,gy;

char T[3][3],F[3][3],R[3][3]; // top, front, right

int hstar(int ex,int ey,int gx,int gy){
	int cnt=0;
	rep(i,3) rep(j,3) if(!(i==ey && j==ex) && T[i][j]!=goal[i][j]) cnt++;
	return max(cnt,abs(ex-gx)+abs(ey-gy));
}

int ub;
bool dfs(int t,int ex,int ey,int pre){ // 経過ターン, スペースの位置, 直前移動した方向
	bool end=true;
	rep(i,3) rep(j,3) if(!(i==ey && j==ex) && T[i][j]!=goal[i][j]) end=false;
	if(end) return true;

	if(t+hstar(ex,ey,gx,gy)>ub) return false;

	// (ex,ey-1)
	char tmp1,tmp2,tmp3;
	if(ey>0 && pre!=1){
		tmp1=T[ey][ex]=F[ey-1][ex];
		tmp2=F[ey][ex]=T[ey-1][ex];
		tmp3=R[ey][ex]=R[ey-1][ex];
		if(dfs(t+1,ex,ey-1,0)) return true;
		F[ey-1][ex]=tmp1;
		T[ey-1][ex]=tmp2;
		R[ey-1][ex]=tmp3;
	}
	// (ex,ey+1)
	if(ey<2 && pre!=0){
		tmp1=T[ey][ex]=F[ey+1][ex];
		tmp2=F[ey][ex]=T[ey+1][ex];
		tmp3=R[ey][ex]=R[ey+1][ex];
		if(dfs(t+1,ex,ey+1,1)) return true;
		F[ey+1][ex]=tmp1;
		T[ey+1][ex]=tmp2;
		R[ey+1][ex]=tmp3;
	}
	// (ex-1,ey)
	if(ex>0 && pre!=3){
		tmp1=T[ey][ex]=R[ey][ex-1];
		tmp2=F[ey][ex]=F[ey][ex-1];
		tmp3=R[ey][ex]=T[ey][ex-1];
		if(dfs(t+1,ex-1,ey,2)) return true;
		R[ey][ex-1]=tmp1;
		F[ey][ex-1]=tmp2;
		T[ey][ex-1]=tmp3;
	}
	// (ex+1,ey)
	if(ex<2 && pre!=2){
		tmp1=T[ey][ex]=R[ey][ex+1];
		tmp2=F[ey][ex]=F[ey][ex+1];
		tmp3=R[ey][ex]=T[ey][ex+1];
		if(dfs(t+1,ex+1,ey,3)) return true;
		R[ey][ex+1]=tmp1;
		F[ey][ex+1]=tmp2;
		T[ey][ex+1]=tmp3;
	}
	return false;
}

int main(){
	for(int x0,y0;scanf("%d%d",&x0,&y0),x0;){
		x0--; y0--;
		rep(i,3) rep(j,3) {
			scanf(" %c",goal[i]+j);
			if(goal[i][j]=='E') gx=j, gy=i;
			T[i][j]='W';
			F[i][j]='R';
			R[i][j]='B';
		}

		for(ub=0;ub<=30&&!dfs(0,x0,y0,-1);ub++);

		printf("%d\n",ub<=30?ub:-1);
	}

	return 0;
}

Measured memory_bytes: 1028
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
int *array;
int *appearance;
int ope_num;
int n;
int count;
/*****その他関数置き場*****/
int Operation(){
	static int *app_old = new int [n];
	int num;
	int appear;
	int check;
	for(int i=0;i<n;i++){
		num = array[i];
		appear = 0;
		for(int j=0;j<n;j++)
			if(array[j] == num)
				appear ++;
		appearance[i] = appear;
	}
	for(check=0;check<n;check++)
		if(appearance[check] != array[check])
			break;
	for(int i=0;i<n;i++)
		array[i] = appearance[i];
	if(check == n)	return 1;
	count++;
	return 0;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	/*****処理部*****/
	while(1){
		cin >> n;
		if(n==0)	break;
		array = new int [n];
		appearance = new int [n];
		for(int i=0;i<n;i++){
			cin >> array[i];
			appearance[i] = array[i];
		}
		count = 0;
		while(!Operation());
		cout << count << endl;
		for(int i=0;i<n;i++){
			if(i!=0)	cout << " ";
			cout << appearance[i];
		}
		cout << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 65;
const int M = 1000005;
const int mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

int n, r, c, ans, x[N], y[N], cnt_x[M], cnt_y[M], idx_x[M], idx_y[M], siz_x[M], siz_y[M], dis[N][N];
bool vis[N][N];
queue <pii> q;

inline void Solve(int *cnt, int *idx, int *siz, int r, int c) {
  int u = c - cnt[0], d = (1LL * r * c - n - u) % mod;
  siz[0] = 1;
  for (int i = 1; i < r; ++i) {
    idx[i] = idx[i - 1];
    if (!cnt[i] && !cnt[i - 1]) {
      ans = (2LL * u * d + ans) % mod;
    } else {
      ++idx[i];
    }
    ++siz[idx[i]];
    u = (u + c - cnt[i]) % mod, d = (d + cnt[i] - c + mod) % mod;
  }
}

inline int Siz(int x, int y) {
  return 1LL * siz_x[x] * siz_y[y] % mod;
}

inline void BFS(int s_x, int s_y) {
  for (int i = 0; i <= idx_x[r - 1]; ++i) {
    for (int j = 0; j <= idx_y[c - 1]; ++j) {
      dis[i][j] = -1;
    }
  }
  dis[s_x][s_y] = 0, q.push(mp(s_x, s_y));
  while (!q.empty()) {
    int x = q.front().X, y = q.front().Y;
    q.pop(), ans = (1LL * Siz(x, y) * Siz(s_x, s_y) % mod * dis[x][y] + ans) % mod;
    for (int i = 0; i < 4; ++i) {
      int u = x + dx[i], v = y + dy[i];
      if (u >= 0 && u <= idx_x[r - 1] && v >= 0 && v <= idx_y[c - 1] && !vis[u][v] && !~dis[u][v]) {
        dis[u][v] = dis[x][y] + 1, q.push(mp(u, v));
      }
    }
  }
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(r), Read(c), Read(n);
  for (int i = 0; i < n; ++i) {
    Read(x[i]), Read(y[i]);
    ++cnt_x[x[i]], ++cnt_y[y[i]];
  }
  Solve(cnt_x, idx_x, siz_x, r, c);
  Solve(cnt_y, idx_y, siz_y, c, r);
  for (int i = 0; i < n; ++i) {
    vis[idx_x[x[i]]][idx_y[y[i]]] = true;
  }
  for (int i = 0; i <= idx_x[r - 1]; ++i) {
    for (int j = 0; j <= idx_y[c - 1]; ++j) {
      if (!vis[i][j]) {
        BFS(i, j);
      }
    }
  }
  printf("%d\n", 1LL * ans * (mod + 1) / 2 % mod);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 18688
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;

	int[][] wf = new int[][](n, n);
	foreach(i; 0 .. n) foreach(x; 0 .. n) wf[i][x] = -1;

	foreach(i; 0 .. n){
		int a = rint;
		foreach(j; 0 .. a){
			int x = rint - 1, y = rint;
			wf[i][x] = y;
		}
	}

	int ans = 0;
	A: foreach(m; 0 .. 1L << n){
		foreach(i; 0 .. n) foreach(x; 0 .. n){
			if(m & (1L << i)){
				 if(wf[i][x] == 1 && ! (m & (1L << x))) continue A;
				 if(wf[i][x] == 0 && (m & (1L << x))) continue A;
			}
		}
		int tmp = 0;
		foreach(i; 0 .. n) if(m & (1L << i)) tmp += 1;
		ans.chmax(tmp);
	}

	ans.writeln;
}

Measured memory_bytes: 256
n = int(input())
cou = 0
num = 1000
for i in range(n):
  a = int(input())
  if a % 10 != 0:num = min(a,num)
  cou += a
if cou % 10 == 0:
  if num % 10 == 0:
    print(0)
  else:
    print(cou -num)
else:
  print(cou)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  static int N,D,X,A[110],B[110]={0};
  cin>>N>>D>>X;
  for(int t=1;t<=N;t++)cin>>A[t];

  int eaten=0;
  for(int t=1;t<=D;t++){
    for(int i=1;i<=N;i++){
      int temp=B[i]*A[i]+1;
      if(t==temp){
        eaten++;
        B[i]++;
      }
    }
  }

  cout<<eaten+X<<"\n";
  return 0;
}


Measured memory_bytes: 256
#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};
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 n,k;cin  >> n >>k;
    ll r,s,p;cin >> r >>s >>p;
    string st;cin >> st;
    ll ans=0;
    rep(i,n){
        if(k>i){
            if(st[i]=='r')ans+=p;
            if(st[i]=='s')ans+=r;
            if(st[i]=='p')ans+=s;
        }
        else{
            if(st[i]==st[i-k]){
                st[i]='z';
            }
            else{
                if(st[i]=='r')ans+=p;
                if(st[i]=='s')ans+=r;
                if(st[i]=='p')ans+=s;
            }
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1e7
#define mod 1000000007

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;


int main()
{
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<int>>G(H,vector<int>(W));
    for(int i = 0 ; i < H; i++) 
    {
        string tmp; cin >> tmp;
        for(int j = 0; j < W; j++)
        {
            G[i][j] = tmp[j] - '0';
        }
    }
    int ans = 0;
    for(int h = 0; h < H; h++)
    {
        for(int w = 0; w < W; w++)
        {
            vector<vector<int>>g = G;
            g[h][w] = -1;
            for(int i = h; i >= 1; i--) swap(g[i][w],g[i-1][w]);
            int cnt = 0;
            int point = 0;
            while(1)
            {
                vector<deque<tii>>v(H);
                for(int i = 0; i < H; i++)
                {
                    for(int j = 0; j < W; j++)
                    {
                        if(j == 0) v[i].push_back(make_tuple(g[i][j],0,0));
                        else
                        {
                            auto p = v[i].back();
                            if(get<0>(p) != g[i][j]) v[i].push_back(make_tuple(g[i][j],j,j));
                            else 
                            {
                                v[i].pop_back();
                                v[i].push_back(make_tuple(g[i][j],get<1>(p),j));
                            }
                        }
                    }
                }
                bool f = true;
                for(int i = 0; i < H; i++)
                {
                    while(!v[i].empty())
                    {
                        auto p = v[i].front();
                        v[i].pop_front();
                        if(get<0>(p) == -1) continue;
                        if(get<2>(p)-get<1>(p)+1 >= K) 
                        {
                            f = false;
                            point += pow(2,cnt)*get<0>(p)*(get<2>(p)-get<1>(p)+1);
                            for(int j = get<1>(p); j <= get<2>(p); j++) g[i][j] = -1;
                        }
                    }
                }
                if(f) break;
                vector<deque<int>>x(W);
                for(int j = 0; j < W; j++)
                {
                    int num = 0;
                    for(int i = H-1; i >= 0; i--)
                    {
                        if(g[i][j] == -1) 
                        {
                            num++;
                            continue;
                        }
                        x[j].push_back(g[i][j]);
                    }
                    for(int i = 1; i <= num; i++) x[j].push_back(-1);
                }
                for(int j = 0; j < W; j++)
                {
                    for(int i = H-1; i >= 0; i--)
                    {
                        g[i][j] = x[j].front();
                        x[j].pop_front();
                    }
                }
                cnt++;
            }
            ans = max(ans,point);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
int n, m, dp[1010][1010], d[1010], c[1010];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> d[i];
	for (int j = 1; j <= m; j++)cin >> c[j];
	for (int j = 0; j <= m; j++)dp[0][j] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			dp[i][j] = mod;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= m; j++) {
			dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + d[i] * c[j]);
		}
	}
	cout << dp[n][m] << endl;
}


Measured memory_bytes: 9504
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll s=0;
    vector <ll> a(n);
    rep(i,n){
        for(int j=i;j<=n;j+=i){
            a[j]++;
        }
    }
    rep(i,n){
        s+=a[i]*i;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 81404
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{

	int i = 1;

	int x, y;

	while (1) {

		scanf("%d", &x);  scanf("%d", &y);

		if (x == 0 && y == 0)
			break;
		else if (x > y)
			printf("%d %d\n", y, x);
		else  
			printf("%d %d\n", x, y);

	}

	return 0;
}


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

int N,M,K;
const ll mo=998244353;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	
	ll sum=0;
	for(i=0;i<=K;i++) {
		sum+=comb(N-1,i)*M%mo*modpow(M-1,N-i-1)%mo;
	}
	cout<<sum%mo<<endl;
}
int main()
{
	solve();
}

Measured memory_bytes: 12896
h,w,m = map(int,input().split())
s = set([])
H = [0]*(h+1)
W = [0]*(w+1)
for i in range(m):
    x,y = map(int,input().split())
    H[x] += 1
    W[y] += 1
    s.add((x,y))
    
p = [0]*(h+1)
q = [0]*(w+1)
for i in range(h+1):
    p[i] = [i, H[i]]
for i in range(w+1):
    q[i] = [i, W[i]]
    
p.sort(key= lambda val : val[1],reverse=True)
q.sort(key= lambda val : val[1],reverse=True)

mh = max(H)
mw = max(W)
I = H.count(mh)
J = W.count(mw)

sw = 0
for i in range(I):
    if sw == 1:
        break
    for j in range(J):
        if (p[i][0], q[j][0]) in s:
            pass
        else:
            sw = 1
            break

print(mh+mw-1+sw)


Measured memory_bytes: 221764
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;

	S = min( S, min(Q * 4, H * 2));

	if (S * 2 <= D) {
		cout << S * N;
	}
	else {
		cout << D * (N / 2) + S * (N % 2);
	}




}


Measured memory_bytes: 256
main = do
  s <- getLine
  putStrLn . show $ solve s

solve :: String -> Int
solve s = min (calc 0 s) (calc 1 s)

calc _ [] = 0
calc k (x:xs) =
  (if k == (read [x]) then 0 else 1) + (calc ((k+1) `mod` 2) xs)


Measured memory_bytes: 8956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    rep (i, n) cout << "ACL";
    cout << "\n";
    /***************************************************/
    /* Use "submit code (with ACL v1)" when using ACL! */
    /***************************************************/
    return 0;
}

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

char f[10][10];
int main() {
	string s;
	while (cin >> s, s != "#") {
		int x = 0, y = 0;
		for (char c : s) {
			if ('1' <= c&&c <= '9') {
				rep(i, c - '0')f[x][y++] = '.';
			}
			else if (c == 'b')f[x][y++] = 'b';
			else {
				x++; y = 0;
			}
		}x++;
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); a--; b--; c--; d--;
		f[a][b] = '.'; f[c][d] = 'b';
		rep(i, x) {
			int cnt = 0;
			rep(j, y) {
				if (f[i][j] == '.')cnt++;
				else {
					if (cnt)printf("%d", cnt);
					printf("b"); cnt = 0;
				}
			}
			if (cnt)printf("%d", cnt);
			if (i != x - 1)printf("/");
		}
		printf("\n");
	}
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	ll i, j, n, z;
	
	cin>>n;
	
	vector < ll > a(n+1);
	
	for(i=0; i<n; i++){
		cin>>a[i];
	}
	
	z=0;
	for(i=0; i<n; i++){
		for(j=n-1; j>i; j--){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
				z++;
			}
		}
	}
	
	for(i=0; i<n-1; i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n-1]<<"\n";
	cout<<z<<"\n";
}


Measured memory_bytes: 3100
import sys
input = sys.stdin.readline
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i],b[i],c[i] = [int(i) for i in input().split()]
dp = [[0] * 3 for _ in range(N)]
dp[0] = [a[0],b[0],c[0]]
for i in range(1,N):
    dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1])
dp[N-1].sort()
print(dp[N-1][-1])

Measured memory_bytes: 34676
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, j, x, y, n, a[15][15];

	while(scanf("%d", &n) != EOF){

		x = n/2 + 1;
		y = n/2;

		for(i=1; i<=n*n; i++){
			if(i % n != 0){
				a[x][y] = i;
				x = (x+1) % n;
				y = (y+1) % n;
			} else {
				a[x][y] = i;
				x = (x+2) % n;
			}
		}

		for(i=0; i<n; i++){
			for(j=0; j<n; j++){
				printf("%4d", a[i][j]);
			}
			printf("\n");
		}

	}

	return 0;

}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, magic_num = 0;
    cin >> N;
    int A[110];
    for (int i = 0; i < N; i++){ cin >> A[i];}
    
    for (int i = 1; i < N; i++){
        if (A[i - 1] == A[i]){
            A[i] = 0;
            magic_num++;
        }
    }
    cout << magic_num << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A ,B ,K;
    cin >> A >> B >> K;
    int count =0;
    int ans = 0;
    int i;
    
    for(i=min(A,B);i>=1;i--)
    {
        if(A%i == 0 && B%i==0)
        {
            count ++;
            ans = i;
            if(count == K)
            {
                break;
            }
        }
    }
    cout << ans <<endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		
		boolean flagA = false;
		boolean flagB = false;
		boolean flagC = false;
		
		for(int i = 0; i < 3; i++)
		{
		
			if(s.charAt(i) == 'a')
			{
				flagA = true;
			}
			else if(s.charAt(i) == 'b')
			{
				flagB = true;
			}
			else if(s.charAt(i) == 'c')
			{
				flagC = true;
			}
		}
		
		if(flagA && flagB && flagC)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35544
#include<bits/stdc++.h>
using namespace std;
int rd(){
	int x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x;
}
int len,cnt[65];
char ch[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklnmopqrstuvwxyz0123456789"};
bool check(string S){
	cout<<"? "<<S<<endl;
	return len-S.size()==rd();
}
string merge(int l,int r){
	if(l==r) return string(cnt[l],ch[l]);
	int mid=(l+r)>>1;
	string A=merge(l,mid),B=merge(mid+1,r),C="";
	int i=0,j=0;
	while(i<A.size() && j<B.size()){
		if(check(C+A[i]+B.substr(j))) C+=A[i],++i;
		else C+=B[j],++j;
	}
	while(i<A.size()) C+=A[i],++i;
	while(j<B.size()) C+=B[j],++j;
	return C;
}
const int S=62;
int main(){
	//cout<<strlen(ch)<<endl; 
	for(int i=0;i<strlen(ch);++i){
		string s(128,ch[i]);
		cout<<"? "<<s<<endl;
		cnt[i]=128-rd(); len+=cnt[i];
	}
	string ans=merge(0,62);
	cout<<"! "<<ans;
	return 0;
}

Measured memory_bytes: 3772
import java.util.Arrays;
import java.util.Scanner;
 
    class Main {
      public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
    int N = sc.nextInt();
    int S[] = new int[N];
    for(int i = 0; i < N; i++) {
    S[i] = sc.nextInt();
    }
    
    int s = 0;
    for(int i = 0; i < N; i++) {
    s += S[i];
    }
    Arrays.sort(S);
            if(s % 10 != 0) {
                System.out.println(s);
                return;
            }else {
              for(int i = 0; i < N; i++)
                  if(S[i] % 10 != 0) {
                     System.out.println(s -= S[i]);
                     return;
            }
        }
        System.out.println(0);
        return ;
  }
}

Measured memory_bytes: 22100
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
#print(*a,sep='\n')
mod=10**9+7

dp=[[0]*W for i in range(H)]
dp[0][0]=1
for h in range(H):
    for w in range(W):
        if a[h][w]=='#':continue
        if h>=1:dp[h][w]+=dp[h-1][w]
        if w>=1:dp[h][w]+=dp[h][w-1]
#print(*dp,sep='\n')
print(dp[-1][-1]%mod)

Measured memory_bytes: 251996
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
ll mod = 1e9 + 7;
/* CELEBW23 */
#include <stdio.h>                                                              
#include <wchar.h>                                                              

int main(void)
{
	int n;
	cin >> n;
	cout << n * n * n << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, deque

    n = int(readline())
    edge = defaultdict(list)

    for _ in range(n - 1):
        a, b = map(int, readline().split())
        a, b = a - 1, b - 1
        edge[a].append(b)
        edge[b].append(a)

    que1 = deque()
    que1.append(0)
    que2 = deque()
    que2.append(n - 1)

    df = [-1] * n
    ds = [-1] * n
    df[0] = 0
    ds[n - 1] = 0

    while que1:
        u = que1.popleft()
        for v in edge[u]:
            if df[v] == -1:
                que1.append(v)
                df[v] = df[u] + 1

    while que2:
        u = que2.popleft()
        for v in edge[u]:
            if ds[v] == -1:
                que2.append(v)
                ds[v] = ds[u] + 1

    cf, cs = 0, 0
    for f, s in zip(df, ds):
        if f <= s:
            cf += 1
        else:
            cs += 1

    if cf > cs:
        print("Fennec")
    else:
        print("Snuke")


if __name__ == '__main__':
    main()


Measured memory_bytes: 94400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if (s.length() < t.length()) {
            System.out.println("UNRESTORABLE");
            return;
        }
        int idx = -1;
        for (int i = 0; i <= s.length() - t.length(); i++) {
            boolean isMatch = true;
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i + j) == '?') {
                    continue;
                }
                if (s.charAt(i + j) != t.charAt(j)) {
                    isMatch = false;
                    break;
                }
            }
            if (isMatch) {
                idx = i;
            }
        }
        if (idx == -1) {
            System.out.println("UNRESTORABLE");
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (i >= idx && i < idx + t.length()) {
                sb.append(t.charAt(i - idx));
            } else if (s.charAt(i) == '?'){
                sb.append('a');
            } else {
                sb.append(s.charAt(i));
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 23508
n,m,c = map(int, input().split())
b = list(map(int,input().split()))
ans = 0
for _ in range(n):
  a = list(map(int,input().split()))
  result = c
  for i in range(m):
    result += a[i] * b[i]
  if result > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
x=Array.new(4)
x=gets.split("").map(&:to_i)

op=Array.new(3)
[0,1].repeated_permutation(3).to_a.each do |bit|
    count=x[0]
    3.times do |i|
        if bit[i]==0
            op[i]="+"
            count+=x[i+1]
        else
            op[i]="-"
            count-=x[i+1]
        end
    end
    if count==7
        puts "#{x[0]}#{op[0]}#{x[1]}#{op[1]}#{x[2]}#{op[2]}#{x[3]}=7"
        return
    end
end


Measured memory_bytes: 14300
N,A,B = map(int,input().split())

if N==1 and A!=B : print(0)
elif N==1 and A==B : print(1)
elif A>B : print(0)
elif N==2: print(1)
else: print((B*(N-1)+A) - (A*(N-1)+B) + 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main(){
    int n,p,sum;cin>>n>>p>>sum;
    vector<int> ans;
    for(int i=0;i<p;i++)cout<<sum<<" ";
    for(int i=0;i<n-p;i++){
        if(sum>1e5){
            cout<<1<<" ";
        }else cout<<sum+1<<" ";
    }
    cout<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, d, x, y, ans;

int main() {
	fastio; cin >> n >> d; d *= d;
	FOR(i, 1, n) {
		cin >> x >> y;
		ans += (x*x + y*y <= d);
	}
	cout << ans;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    double x1,x2,y1,y2,x,y,d;
    cin>>x1 >>y1 >>x2 >>y2;
    x=(x2-x1)*(x2-x1);
    y=(y2-y1)*(y2-y1);
    d=sqrt(x+y);
    printf("%f",d);
    return 0;
}





Measured memory_bytes: 3200
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll A[3],K;

int main(){
    cin>>A[0]>>A[1]>>A[2]>>K;
    sort(A,A+3);
    A[2]*=pow(2.0,K);
    out(A[0]+A[1]+A[2]);
}


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

using namespace std;

const int maxn = 5555;

long long a[maxn][maxn];

const long long inf = -100000000;

int main() {
	int N, M, n, m;
	cin >> N >> M >> n >> m;
	long long nm = n * m;
	long long NM = N * M;
	long long k = (N / n) * (M / m);
	long long opt_l = -1;
	long long opt_x = -1;
	for (long long l = 1; l <= (long long)(1e8); l++) {
		long long X = -l * (nm - 1) - 1;
		if (X < inf)
			break;
		if (k * X + (NM - k) * l > 0) {
			opt_l = l;
			opt_x = X;
			break;
		}
	}
	long long all_sum = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (i % n == 0 && j % m == 0)
				a[i][j] = opt_x;
			else
				a[i][j] = opt_l;
			all_sum += a[i][j];
		}
	}
	if (opt_l == -1) {
		cout << "No\n";
		return 0;
	}
	if (all_sum > 0) {
		cout << "Yes\n";
		for (int i = 1; i <= N; i++)
		{
			for (int j = 1; j <= M; j++) {
				cout << a[i][j] << " ";
			}
			cout << "\n";
		}
		return 0;
	}
	cout << "No";
	return 0;
}

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

int main(){
        int A,B,C,D;
        int HP_T,HP_A;
        cin>>A>>B>>C>>D;
        HP_T=A;
        HP_A=C;
        for(;;){
                /*HP_T=HP_T-D;
                if(HP_T<=0){
                        cout<<"No"<<endl;
                        return 0;
                }*/
                HP_A=HP_A-B;
                if(HP_A<=0){
                        cout<<"Yes"<<endl;
                        return 0;
                }
                HP_T=HP_T-D;
                if(HP_T<=0){
                        cout<<"No"<<endl;
                        return 0;
                }

        }
        return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
int N, Memo[200005]; // idx番目の座標+2*D版目以内の最大のidx
ll D, A, Sm[200005], Ans[200005];
P C[200005];

// 尺とりで前処理
void init() {
  int left = 0, right = 1;
  while(left<N) {
    if (C[right].first - C[left].first<=2*D) right++;
    else {
      Memo[left] = min(right-1, N-1);
      left++;
    }
  }
}

ll solve() {
  int left_bomb_idx = 0;
  ll ret = 0ll;
  rep(i, N) {
    ll requred_bomb = C[i].second;
    if (i==0) {
      Sm[0] = requred_bomb;
      Ans[0] = requred_bomb;
      ret+=requred_bomb;
      continue;
    }
    while (Memo[left_bomb_idx] < i) left_bomb_idx++;
    ll total_bomb_at_this = Sm[i-1]-(left_bomb_idx==0?0:Sm[left_bomb_idx-1]);
    Ans[i] = max(0ll, requred_bomb-total_bomb_at_this);
    ret+=Ans[i];
    Sm[i] = Ans[i] + Sm[i-1];
  }
  return ret;
}

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

  cin >> N >> D >> A;
  ll x, h;
  rep(i, N) {
    cin >> x >> h;
    C[i] = P(x,(h+A-1)/A); // secondは何回の攻撃で死ぬか 
  }
  sort(C, C+N);
  init();
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 7296
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n, i = 0, cnt = 0;
    string s;
    cin >> n >> s;
    while ((i = s.find("ABC", i)) != string::npos) {
        cnt++;
        i++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, result;
  int* d = new int[N];
  
  result = 0;
  cin >> N;
  
  for (int i=0; i < N; i++) {
    cin >> d[i];
  }
  
  for (int i=0; i < N; i++) {
    for (int j=i+1; j < N; j++) {
      result += d[i]*d[j];
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt,m,G[11]={1,4,13,40,121,364,1093,3280,9841,29524,88573};
void insertSort(int *a,int n,int g){
	int v,j;
	for(int i=g;i<n;i++){
		v = a[i];
		j = i - g;
		while(j>=0&&a[j]>v){
			a[j+g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j+g] = v;
	}
}
void shellSort(int *a,int n){
	cnt = 0;
	m = 11;
	for(int i=0;i<11;i++)
		if(G[i]>n){
			m = i;
			break;
		}
	for(int i=m-1;i>=0;i--){
		insertSort(a,n,G[i]);
	}
}
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	shellSort(a,n);
	cout<<m<<endl;
	for(int i=m-1;i>=0;i--){
		if(i==0)
			cout<<G[i]<<endl;
		else
			cout<<G[i]<<" ";
	}
	cout<<cnt<<endl;
	//insertSort(a,n,1);
	for(int i=0;i<n;i++){
		cout<<a[i]<<endl;
	}
	return 0;
} 


Measured memory_bytes: 7004
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<(b-a)*(b-a-1)/2-a<<endl;
}

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


int main(){
    int64_t A,B,N;
    cin >> A >> B >> N;
    
    int64_t x;
    if ( N >= B-1 ){
        x = B-1;
    } else {
        x = N;
    }
    
    int64_t res,res0,res1;
    res0 = A * x / B;
    res1 = A * ( x / B );
    res = res0 - res1;
        
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int check(string t) {
  int ret = 0;
  for(int i=0; i<t.size()-1; i++) {
    if(t[i] == 'A' && t[i+1] == 'B') ret++;
  }
  return ret;
}

int main(){
  // BXXA
  // XXA
  // BXX
  // XX
  int n; cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) cin >> s[i];
  vector<int> ss(3);
  int cnt = 0;
  for(int i=0; i<n; i++) {
    string t = s[i];
    cnt += check(t);
    if(t[0] == 'B' && t[t.size()-1] == 'A') {
      ss[0]++;
    } else if(t[0] == 'B') {
      ss[1]++;
    } else if(t[t.size()-1] == 'A') {
      ss[2]++;
    } else {
    }
  }
  // BxxA
  // Bxx
  // xxA
  if(ss[0] == 0) {
    cnt += min(ss[1], ss[2]);
  }else{
    cnt += ss[0]-1;
    if(ss[1] > 0){ cnt++; ss[1]--; };
    if(ss[2] > 0){ cnt++; ss[2]--; };
    cnt += min(ss[1], ss[2]);
  }

  cout << cnt << endl;

  return 0;
}

// EOF


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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n / x + (n % x > 0)) * t << endl;
}


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func rollerCoaster(n, k int, l []int) int {
	stack := make([]int, 0, n)
	for _, v := range l {
		if v >= k {
			stack = append(stack, v)
		}
	}
	return len(stack)
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)

	high := strings.Split(readLine(reader), " ")

	var h = make([]int, 0)
	for _, v := range high {
		num, err := strconv.ParseInt(v, 10, 64)
		checkError(err)
		h = append(h, int(num))
	}
	fmt.Print(rollerCoaster(n, k, h))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 7552
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;

  int ans1 = a * x + b * y;
  int ans2 = [&]{
    int res = min(x, y) * c * 2;
    if (x > y) {
      res += (x - y) * a;
    } else {
      res += (y - x) * b;
    }
    return res;
  }();
  int ans3 = c * max(x, y) * 2;

  ans = min(ans1, min(ans2, ans3));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

int main()
{
    std::map<std::string, int> m;

    std::string s, max_len_str = "";
    int max_freq = 0;
    while (std::cin >> s) {
        if (max_len_str.size() < s.size()) max_len_str = s;
        ++m[s];
        if (max_freq < m[s]) max_freq = m[s];
    }

    for (std::map<std::string, int>::iterator it = m.begin(); it != m.end(); ++it) {
        if (it->second == max_freq) {
            std::cout << it->first << ' ' << max_len_str << std::endl;
            break;
        }
    }
}

Measured memory_bytes: 1196
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 0;

int gcd(int a,int b)
{
	if(!b) return a;
	return gcd(b,a%b);
}

int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}

int main()
{
	ios::sync_with_stdio(0);
	int n;
	double x;
	cin>>n;
	cout<<fixed<<setprecision(10);
	if(~n&1) x=1.0/2;
	else
	{
		x=1.0*(n+1)/2/n;
	}
	cout<<x<<endl;
	return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

using ll = long long;
using namespace std;

int main(){
    int N,ans=0,p1,p2;
    cin >> N;
    string S;
    cin >> S;

    rep(i,10){
        rep(j,10){
            rep(k,10){
                int p1 = N+1, p2 = N+1, p3 = N+1;
                for(int i_s = 0;i_s < N - 2;i_s++){
                    if(S[i_s] == '0' + i){
                        p1 = i_s;
                        break;
                    }
                }
                if(p1 > N) continue;
                for(int j_s = p1+1; j_s < N-1; j_s++){
                    if(S[j_s] == '0' + j){
                        p2 = j_s;
                        break;
                    }
                }
                if(p2 > N) continue;
                for(int k_s = p2+1; k_s < N; k_s++){
                    if(S[k_s] == '0' + k){
                        p3 = k_s;
                        break;
                    }
                }
                if(p3 > N) continue;
                ans++;
            }
        }
    }
        
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
	std::string n;
	std::cin >> n;

	int iss = false;
	if( ( n[ 0 ] == n[ 1 ] and n[ 1 ] == n[ 2 ] ) or
			( n[ 1 ] == n[ 2 ] and n[ 2 ] == n[ 3 ] ) ) {
		iss = true;
	}

	std::cout << ( iss ? "Yes" : "No" ) << std::endl;
	return 0;
}



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

int main(void) {
  string S = "";
  cin >> S;

  auto ACGT = vector<string>{"A", "C", "G", "T"};
  auto ans_candidate = 0;
  auto ans = 0;
  for (auto i = 0; i < S.length(); i++) {
    if (count(ACGT.begin(), ACGT.end(), string(1, S[i]))) {
      ans_candidate++;
    } else {
      ans_candidate = 0;
    }

    if (ans_candidate > ans) {
      ans = ans_candidate;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n,k,q=map(int, input().split())
a=[int(input()) for i in range(q)]
start_score=[k for i in range(n)]
def cal_score(n):
    return n-q
end_score=list(map(cal_score, start_score))
for i in a:
    end_score[i-1]+=1
#print(end_score)
for j in end_score:
    if j<=0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 12580
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void assert_NO(T condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
template<class T> inline void assert_No(T condition){ if(!condition){ cout << "No" << endl; exit(0); } }
template<class T> inline void assert_minus_1(T condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main(){
    lint N, K;
    cin >> N >> K;
    N %= K;
    cout << min(N, K - N) << endl;
}


Measured memory_bytes: 256