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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<bool> dp(1000000+1, true);
    long long int count = 0;
    for(int i = 0; i < N; i++) {
        if(dp[A[i]] == false) {
            continue;
        }
        if(i == N || A[i] != A[i + 1]) {
            count++;
        }
        for(int j = A[i]; j <= 1000000; j += A[i]) {
            dp[j] = false;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4300
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

ll a,b,c,d;
map<ll,ll> dp;
ll fun(ll n)
{
	if(n==0) return dp[n] = 0;
	if(n==1) return dp[n] = d;
	if(dp.find(n)!=dp.end()) return dp[n];

	ll ans = inf;
	ans=min(ans,fun(n/5) + c*((n/5)!=0) + d*(n%5));
	ans=min(ans,fun(n/5+1) + c + d*(5-(n%5)));

	ans=min(ans,fun(n/3) + b*((n/3)!=0) + d*(n%3));
	ans=min(ans,fun(n/3+1) + b + d*(3-(n%3)));

	ans=min(ans,fun(n/2) + a*((n/2)!=0) + d*(n%2));
	if(n/2+1<n) ans=min(ans,fun(n/2+1) + a + d*(2-(n%2)));

	if((double)n<=(double)ans/(double)d) ans = min(ans,n*d);

	return dp[n]=ans;

}
int solve()
{
	ll n;cin>>n>>a>>b>>c>>d;
	dp.clear();

	cout<<fun(n)<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

//constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/


int main() {

	int x; cin >> x;

	if (x < 4) { cout << 1 << endl; return 0; }

	int ans = 1;

	for (int i = 2; i*i<=1000; i++) {
		for (int j = 2; pow(i, j) <= x; j++) {
			ans = max(ans, (int)pow(i, j));
		}
	}

	cout << ans << endl;

	return 0;
}



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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int A[110000];
multiset<int> aset;
signed main() {
    cin>>N;
    int ans=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]*=-1;
        auto it=aset.upper_bound(A[i]);
        if(it!=aset.end()){
            aset.erase(it);
            cerr<<i<<endl;
        }
        else ans++;
        aset.insert(A[i]);
        //cerr<<aset.size()<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
H = int(input())
x = 0
list_1 = []
for i in range(H+1):
    if H == 1:
        list_1.append(x)
        break
    else:
        H = H // 2
        list_1.append(x)
        x += 1
list_2 = list(map(lambda a: 2**a,list_1))
print(sum(list_2))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int a,b,c;
    char s[101];
    scanf("%s",s);
 if(s[0]=='A'){printf("T");}
 if(s[0]=='T'){printf("A");}
 if(s[0]=='C'){printf("G");}
 if(s[0]=='G'){printf("C");}
   
  
    return 0;
}

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

int main(){
  long n,k,sum =0,ans;
  cin >> n >> k;
  for(long i = k; i<=n+1; i++){
    sum += i*n+i-(i*(i+1)/2)-(i*(i-1)/2)+1;
    
  }
  ans = sum % 1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
struct edge {
    int to, cap, rev;// 行先　容量　逆辺
};
vector<edge> g[1010]; bool used[1010];
void add(int u, int v, int f) {
    g[u].push_back(edge{ v,f,(int)g[v].size() });
    g[v].push_back(edge{ u,0,(int)g[u].size() - 1 });
}
int dfs(int pos, int to, int f) {
    if (pos == to) return f;
    used[pos] = 1;
    rep(i, g[pos].size()) {
        if (g[pos][i].cap == 0 || used[g[pos][i].to]) continue;
        int D = dfs(g[pos][i].to, to, min(g[pos][i].cap, f));
        if (D >= 1) {
            g[pos][i].cap -= D;
            g[g[pos][i].to][g[pos][i].rev].cap += D;
            return D;
        }
    }return 0;
}
int max_flow(int s, int t) {
    int F = 0; for (;;) {
        fill(used, used + 1001, 0);
        int F2 = dfs(s, t, (1e9));
        F += F2;
        if (F2 == 0) return F;
    }return MOD;
}
int n, m, a, b, c[1000],E;
int main() {
    cin >> n >> m >> E;
    rep(i, n) add(n + m, i, 1);
    rep(i, m) add(i + n, n + m + 1, 1);
    rep(i, E) {
        cin >> a >> b;
        add(a, b + n, 1);
    }cout << max_flow(n + m , n + m + 1) << endl;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=(int)1e5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s,t;
	cin>>s>>t;
	int ans=t.length();
	for(int i=0;i+t.length()<=s.length();i++){
		int curr=0;
		for(int j=0;j<t.length();j++)
			if(s[i+j]!=t[j])
				curr++;
		ans=min(ans,curr);
	}
	cout<<ans<<"\n";

}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=4000+10;
char s[maxn];

int id(char ch){
	if(ch=='R') return 1;
	if(ch=='G') return 2;
	return 3;
}

int sum[maxn][4];

int main()
{
	int n;
	cin>>n;
	scanf("%s",s+1);
	rep(i,1,n){
		rep(j,1,3) sum[i][j]=sum[i-1][j];
		++sum[i][id(s[i])];
	}

	ll ans=0;	
	rep(i,1,n){
		rep(j,i+2,n) if(s[i]!=s[j]){
			int v=1;
			for(;v<=3;++v){
				if(v!=id(s[i]) && v!=id(s[j])) break;
			}
			ans+=sum[j][v]-sum[i-1][v];
			if(((i+j)&1) == 0 && id(s[(i+j)/2]) == v) --ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>
#include <malloc.h>
#include <string.h>

int cmpStr(char *str, int s1, int l1, int s2, int l2)
{
    int i;
    if (l1 != l2)
    {
        return 1;
    }

    for (i = 0; i < l1; i++)
    {
        if (str[s1 + i] != str[s2 + i])
        {
            return 1;
        }
    }

    return 0;
}

int main(void)
{
    int i, j, k, len;
    int prev = 1, curr = 1;
    int count = 0;
    char *str = (char *)calloc(200001, sizeof(char));

    scanf("%s", str);

    len = strlen(str);

    i = 0;
    j = 1;
    prev = 1;
    curr = 1;

    while (j <= len)
    {
        if (0 == cmpStr(str, i, prev, j, curr))
        {
            curr++;
        }
        else
        {
            /*
            printf("i = %d, curr = %d, ", i, curr);
            for (k = i; k < i + prev; k++)
            {
                printf("%c", str[k]);
            }
            printf("\n");
            */
            count++;
            prev = curr;
            i = j;
            j += curr;
            curr = 1;
        }
    }

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

    free(str);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, t;
    int n = 1;
    int count = 0;
    cin >> a >> b >> t;

    for (int i = 0; i < t + 0.5; i++) {
        if(i == a * n){
            count = count + b;
            n++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define mp make_pair
#define pb push_back
#define pf push_front
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >p;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,p;
    cin>>a>>p;
    a*=3;
    a+=p;
    cout<<a/2;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N, X, T;
int cnt;

int main(){
	cin >> N >> X >> T;
	while (1){
		N -= X;
		cnt++;
		if (N <= 0)break;
	}

	cout << cnt*T << endl;

	return 0;
}

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

using namespace std;
const int mod = 1e9+7;
int main(){

    int rows,cols;
    cin>>rows>>cols;
    char a[rows+1][cols+1];
    for(int i=1;i<=rows;i++){
        for(int j=1;j<=cols;j++){
            cin>>a[i][j];
        }
    }
    int dp[rows+1][cols+1];
    for(int i=0;i<=rows;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=cols;i++){
        dp[0][i]=0;
    }
    dp[1][1]=1;
    for(int i=1;i<=rows;i++){
        for(int j=1;j<=cols;j++){
            if(i==1&&j==1)continue;
            if(a[i][j]=='#'){
                dp[i][j]=0;
            }
            else{
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }


        }
    }
    cout<<dp[rows][cols];
    return 0;
}


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

int main(void){
    
    int n;
    int x;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        
        if(i % 3 == 0) {
            cout << " " << i;
        } else {
            x = i;
            do{
                if(x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            } while (x);
        } 
    }
    cout << endl;
    
    return 0;
    
}

Measured memory_bytes: 3088
#include <stdio.h>
         
  int main(void){
      int a = 0;
      char b[4];
      scanf("%s",b);
         for(int i=0;i<4;i++){
           if(b[i] == '+')a++;
            else if(b[i] == '-')a--;
            }
      printf("%d\n",a);
      return 0;
}

Measured memory_bytes: 128
import Control.Monad

main :: IO ()
main = do
    -- [a, x, y, z, b, k] <- map (read :: String -> Int) . words <$> getLine
    [a, _, _, _, b, k] <- getInts 6

    putStrLn $ if b - a > k then ":(" else "Yay!"

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getInts :: Int -> IO [Int]
getInts n = fmap read <$> getLines n

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int main(void){

 
    int h, a, b = 0;

    cin >> h >> a;

    while(1){
        h -=a;
        b++;
        if(h <= 0)
            break;
    }
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let (a, b): (i32, i32) = parse_line().unwrap();
    let ans: i32;
    if b == 1 {
        ans = 0;
    } else if b <= a {
        ans = 1;
    } else if (b - 1) % (a - 1) == 0 {
        ans = (b - a) / (a - 1) + 1;
    } else {
        ans = (b - a) / (a - 1) + 2;
    }
    println!("{}", ans);
}


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

#define MAX 100000

int partition(int* A, int p, int r)
{
    int i, j, x;
    x = A[r];
    i = p - 1;
    for(j = p; j < r; j++){
        if(A[j] <= x){ i++; swap(A[i], A[j]); }
    }
    swap(A[i + 1], A[r]);

    return i + 1;
}

int main()
{
    int i, n, A[MAX], q;
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];

    q = partition(A, 0, n - 1);

    for(i = 0; i < q; i++){ cout << A[i] << " "; }

    cout << "[" << A[q] << "]";

    for(i = q + 1; i < n; i++){ cout << " " << A[i]; }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1552
#include <stdio.h>

#define max(a,b) ((a)>(b))?a:b

#define MAX 100000

int main(void)
{
  int N, H[MAX];
  int tmp=0, count=0;
  int i;

  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&H[i]);

  i = 0;
  while(i<=N-2){
    tmp = 0;
    while(H[i]>=H[i+1]){
      i++;
      tmp++;
      if(i>=N-1)break;
    }
    i++;
    count = max(tmp,count);
  }
  printf("%d\n",count);

  return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

struct UnionFind{
	vector<int> data;
	
	UnionFind(int sz){
		data.assign(sz,-1);
	}
	
	bool unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return(false);
		if(data[x]>data[y]) swap(x,y);
		data[x]+=data[y];
		data[y]=x;
		return(true);
	}
	
	int find(int k){
		if(data[k]<0) return(k);
		return(data[k]=find(data[k]));
	}
	
	int size(int k){
		return(-data[find(k)]);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(n);
	rep(i,n){
		cin >> a.at(i);
		a.at(i)--;
	}
	UnionFind uf=UnionFind(n);
	rep(i,m){
		int x,y;cin >> x >> y;
		x--;
		y--;
		uf.unite(x,y);
	}
	int ans=0;
	rep(i,n){
		if(uf.find(i)==uf.find(a.at(i))) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<float> X(N); 
  vector<string> U(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    cin >> U.at(i);
  }
  float ans = 0;
  for (int i = 0; i < N; i++) {
      if (U.at(i)=="JPY") ans += X.at(i);
      else ans += 380000.0 * X.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    int no_of_points;
    scanf("%d", &no_of_points);

    vector <int> X(no_of_points + 1);
    vector <int> Y(no_of_points + 1);
    vector <int> height(no_of_points + 1);
    for(int i = 1; i <= no_of_points; i++)
        scanf("%d %d %d", &X[i], &Y[i], &height[i]);

    int non_zero;
    for(int i = 1; i <= no_of_points; i++)
        if(height[i] != 0)
            non_zero = i;

    const int MAX_X = 100, MAX_Y = 100;
    int pyramid_height, center_x, center_y;

    for(int x = 0; x <= MAX_X; x++)
    {
        for(int y = 0; y <= MAX_Y; y++)
        {
            int found = true;

            int candidate_height = height[non_zero] + abs(X[non_zero] - x) + abs(Y[non_zero] - y);
            
            for(int i = 1; i <= no_of_points; i++)
            {
                int expected_height = max(candidate_height - abs(X[i] - x) - abs(Y[i] - y), 0);

                if(expected_height != height[i])
                {
                    found = false;
                }
            }

            if(found)
            {
                center_x = x, center_y = y;

                pyramid_height = candidate_height;
            }
        }
    }

    printf("%d %d %d\n", center_x, center_y, pyramid_height);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (int)(n); i++)
using namespace std;
int main () {
  int n;cin >> n;
  int ans =1;
  vector<char> s(n,0);
  rep(i,n){
    cin >> s[i];
  }
  rep(i,n-1){
    if (s[i]!=s[i+1])
    {
      ans+=1;
    }
  }
  cout << ans << endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int hi,hy;
    int ki,ky;
    int a,b,c,d;

    Scd2(hi,hy);
    Scd2(ki,ky);
    Scd2(a,b);
    Scd2(c,d);

    int hp = hi*a+hy*b+hi/10*c+hy/20*d;
    int kp = ki*a+ky*b+ki/10*c+ky/20*d;

    string ans = "even";
    if( hp > kp ) ans = "hiroshi";
    if( hp < kp ) ans = "kenjiro";

    printf ("%s\n", ans.c_str() );

    return 0;
}





Measured memory_bytes: 3256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// cout<<std::fixed<<std::setprecision(10);

long long factorial(long long i){ // 階乗
 if(i > 0)
   return i * factorial(i-1);
 else
   return 1;
}
//// a^n mod
long long modpow(long long a, long long n, long long mod) {
 long long res = 1;
 while (n>0) {
   if(n & 1) res = res * a % mod;
   a = a * a % mod;
   n >>= 1;
 }
 return res;
}

//// a^(-1) mod
long long modinv(long long a, long long mod) {
 return modpow(a, mod-2, mod);
}

int main() {
	const ll mod = 1000000000 + 7;

	ll x, y;
	cin >> x >> y;

	if((x+y)%3!=0 || y*2 < x || y > 2*x) {
		cout << 0 << endl;
		return 0;
	}

	ll dif = abs(x - y);
	ll sum = (x + y)/3;
	ll m1 = (sum - dif)/2;
	vector<ll> fact(sum+5); // fact[i] = i !
	fact[0] = 1;
	fact[1] = 1;
	for(ll i = 2; i<sum+3; i++) {
		fact[i] = fact[i-1] * i %mod;
	}

//	ll ans = fact[sum] * modinv(fact[sum-dif], mod) % mod * modinv(fact[dif], mod) % mod;
	ll ans = fact[sum] * modinv(fact[sum-m1], mod);
	ans %= mod;
	ans *= modinv(fact[m1], mod);
	ans %= mod;
	cout << ans << endl;

	return 0;
}

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

int main() {
  int n; string s; cin >> n >> s;
  
  for(int i=0; i<s.size(); i++){
      int x = s[i]-'A';
      s[i] = (x+n) % 26 + 'A';
    }
    
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string s;

int main()
{
	in >> s;
	for (int i = 0; i < s.length(); i += 2)
	{
		out << s[i];
	}
	out << std::endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K,ans=-1;
    cin>>K;
    int tmp_r=0;
    for(int i=1;i<=K;i++){
        tmp_r = (tmp_r*10)%K+7;
        if(tmp_r%K==0){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vc;
    for(int i = 0;i < n;i++) {
        int x;
        cin >> x;
        vc.push_back(x);
    }

    int count = 0;
    int max = 0;
    // for(int i = 0;i < n;i++) cout << vc[i] << endl;
    for(int i = 0;i < n-1;i++) {
        if(vc[i]>=vc[i+1]) {
            count++;
        }
        else {
            if(max < count) max = count;
            count = 0;
        }
    }
    if(max<count) max = count;
    cout << max << endl;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int a = 0;
    int b = 0;
    int i = 0;
    int repeat = 1;
    int repeated = 0;

    scanf("%d %d", &a, &b);

    if (a <= b)
    {
        for (i = 0; i < b; i++)
        {
            repeated += a * repeat;
            repeat *= 10;
        }
    }
    else
    {
        for (i = 0; i < a; i++)
        {
            repeated += b * repeat;
            repeat *= 10;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
struct edge{
    ll from; ll to; ll cost;
};
vec<edge> edges;
vvec<int> to,ot;
int ok[2500];
int ko[2500];
ll d[2500];
void dfs(int v, int p){
    if(ok[v] > 0)return;
    ok[v]++;
    for(auto nv: to[v]){
        if(nv == p)continue;
        dfs(nv, v);
    }
}
void sfd(int v, int p){
    if(ko[v] > 0)return;
    ko[v]++;
    for(auto nv: ot[v]){
        if(nv == p)continue;
        sfd(nv, v);
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N,M,P;
    cin >> N >> M >> P;
    to.resize(N);ot.resize(N);
    rep(i, M){
        ll a, b, c;
        cin >> a >> b >> c;
        c -= P;
        a--;b--;
        edges.push_back({a,b,-c});
        to[a].push_back(b);
        ot[b].push_back(a);
    }
    dfs(0,-1);
    sfd(N-1,-1);
    //bellman ford
    rep(i,N){
        d[i] = INFLL;
    }
    d[0] = 0;
    //O(NM)
    int cnt = 0;
    while(1){
        cnt++;
        //all edges
        bool updated = false;
        rep(i,M){
            edge e = edges[i];
            if(ok[e.to] == 0 ||ko[e.to] ==  0)continue;
            if(ok[e.from] == 0 ||ko[e.from] ==  0)continue;
            if(chmin(d[e.to], d[e.from] + e.cost)){
                updated = true;
            }
        }
        if(!updated)break;;
        if(cnt > N && updated){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(0LL, -d[N-1]) << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
signed main()
{
	int N, C;
	std::cin >> N >> C;

	std::vector<std::vector<int>>D(C, std::vector<int>(C));
	for(int i = 0; i < C; i++)
	{
		for(int j = 0; j < C; j++)
		{
			std::cin >> D[i][j];
		}
	}
	std::vector<std::vector<int>>color_num(3, std::vector<int>(C, 0));
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j < N; j++)
		{
			int c;
			std::cin >> c;
			color_num[(i + j) % 3][--c]++;
		}
	}

	int minimum_cost = 1000000000;
	for(int i = 0; i < C; i++)
	{
		for(int j = 0; j < C; j++)
		{
			if(i == j)continue;
			for(int k = 0; k < C; k++)
			{
				if(i == k || j == k)continue;
				int cost = 0;
				for(int l = 0; l < C; l++)
				{
					cost +=
					    D[l][i] * color_num[0][l] +
					    D[l][j] * color_num[1][l] +
					    D[l][k] * color_num[2][l];
				}
				if(cost < minimum_cost)
				{
					minimum_cost = cost;
				}
			}
		}
	}

	std::cout << minimum_cost << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,m,x,y,X,Y;cin>>n>>m>>x>>y;
    int XMAX=x,YMIN=y;
    for(int i=0;i<n;i++){
        cin>>X;
        if(X>XMAX)XMAX=X;
    }
    for(int i=0;i<m;i++){
        cin>>Y;
        if(Y<YMIN)YMIN=Y;
    }
    if(YMIN-XMAX>0)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < n-1; i++) {
    if (s[i] == s[i+1]) count++;
  }
  cout << min(count + 2 * k, n - 1) << '\n';
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n, w;
int main(){
	cin >> n >> w;
	vector<int> weight(n), value(n);
	for(int i = 0; i < n; i++)cin  >> value[i] >> weight[i];
	ll dp[n+1][w+1];
	for(int i = 0; i < n+1; i++){
		for(int j = 0; j < w+1; j++){
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < w+1; j++){
			if(j - weight[i] >= 0){
				ll tmp = dp[i][j - weight[i]] + value[i];
				dp[i+1][j] = max(tmp, dp[i][j]);
			}else {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][w] << endl;

}


Measured memory_bytes: 10992
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i;
    cin>>n;
    ll a[n],b[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        cin>>b[i];
    }
    ll sum=0;
    for(i=0;i<n;i++){
        if((a[i]-b[i])>0){
            sum+=(a[i]-b[i]);
        }
    }
    cout<<sum;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int s = sc.nextInt();
      int w = sc.nextInt();
      if(w>=s)
        System.out.println("unsafe");
      else
        System.out.println("safe");
    }
}

Measured memory_bytes: 35712
K = int(input())


A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(A[K-1])

Measured memory_bytes: 3060
def print_list_list(list):
    for i in list:
        print(i[0],end="")
        for j in range(1, len(i)):
            print(" ", end="")
            print(i[j],end="")
        print()

def answer(list1, list2, n, m, l):
    c = []
    for i in range(n):
        temp_list = []
        for j in range(l):
            sum = 0
            for k in range(m):
                sum += list1[i][k]* list2[k][j]
            temp_list.append(sum)
        c.append(temp_list)
    return c

n, m, l = map(int, input().split())
a = []
b = []
for i in range(n):
    a.append(list(map(int, input().split())))

for j in range(m):
    b.append(list(map(int, input().split())))

ans = answer(a, b, n, m, l)
print_list_list(ans)


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

string S;

int main(){

    cin >> S;
    char buf = 'a';
    int size = S.size();
    map<char, int> dict;

    for (int i=0; i<size; i++){
        dict[S.at(i)]++;
    }

    int cnt = 0;
    for (auto p: dict){
        auto key = p.first;
        auto value = p.second;

        if (key == buf){
            buf++;
            cnt++;
        }
    }

    if (cnt < 26){
        cout << buf << endl;
    }
    else{
        cout << "None" << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;
typedef long long ll;
typedef vector<long> vl;
typedef vector<string> vs;

int main(){ 
  int a=0,b=0,c,d,e,f,g;
  cin>>a>>b>>c;
  rep(i,0,10){
    c=a*c-b;
    co(c);
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  double mx = 0;
  int sugar_water;
  int sugar;
  A *= 100;
  B *= 100;
  for (int a = 0; a*A<=F; a++){
      for (int b = 0; a*A+b*B <= F; b++){
          for (int c = 0; a*A+b*B+c*C<= F; c++){
              for (int d = 0; a*A+b*B+c*C+d*D <= F; d++){
                  if(100*(c*C+d*D)<=E*(a*A+b*B)){
                      double tmp = (c*C+d*D) /(double) (a*A+b*B+c*C+d*D);
                      if (tmp>=mx){    
                        mx = tmp;
                        sugar_water = a*A+b*B+c*C+d*D;
                        sugar = c*C+d*D;
                        //cout << a << " " << b << " " << c<< " " << d << " " << tmp << endl;
                      }
                  }
              }
          }
      }
  }
  cout << sugar_water << " " << sugar << endl;
}

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

int main() {
	int n, m, x, a[110], cnt_a = 0, cnt_b = 0;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		for (int j = 1; j < x; j++) {
			if (a[i] == j) cnt_a++;
		}
		for (int k = x + 1; k < n; k++) {
			if (a[i] == k) cnt_b++;
		}
	}
	cout << min(cnt_a, cnt_b) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    if (A == B) {
      System.out.print(C);
    } else if (B == C) {
      System.out.print(A);
    } else {
      System.out.print(B);
    }
  }
}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size())if(s[i] == '2')ans++;
    cout << ans << endl;
}




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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    ll n; cin >> n;
    ll ans = 0;
    for(int i=1;i*i<n;i++){
        ans ++;
    }

    for(int i=1;i*(i+1)<n;i++){
        for(int j=i+1;i*j<n;j++){
            // ll test = 2*(n-i*j);
            ans +=2;
            // cout << test << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	int ans = A * B;
	
	if (ans % 2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
	int n;
	while(cin >> n){
		if(n==0)break;
		int s[n];
		long double m = 0,a = 0;
		for(int i = 0;i < n;i++){
			cin >> s[i];
			m += s[i];
		}
		m /= n;
		for(int i = 0;i < n;i++){
			a += (s[i] - m)*(s[i] - m);
		}
		a /= n;
		a = sqrtl(a);
		cout << setprecision(18) << a << "\n";
	}
	return 0;
}

Measured memory_bytes: 3276
#include<stdio.h>
 
int main(void) {
  int i,j,n,rank;
  int card[4][14]={0};
  char sym,z;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%c %c %d",&z,&sym,&rank);
    switch(sym){
    case 'S':card[0][rank]=rank; break;
    case 'H':card[1][rank]=rank; break;
    case 'C':card[2][rank]=rank; break;
    case 'D':card[3][rank]=rank;
    }
  }
 
  for(i=0;i<4;i++)
    for(j=1;j<=13;j++){
      if(card[i][j]==0)
    switch(i){
    case 0:printf("S %d\n",j); break;
    case 1:printf("H %d\n",j); break;
    case 2:printf("C %d\n",j); break;
    case 3:printf("D %d\n",j);
    }
    }
  return(0);
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main{
    int max;
    int min;
    int sa;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        for(int k=0;k<7;k++){
            max=sc.nextInt();
            min=sc.nextInt();
            sa=max-min;
            System.out.println(sa);
        }
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17240
from itertools import combinations


def main():
    n = int(input())

    ans = 0
    for a, b in (list(combinations(range(1, n+1), 2))):
        if (a%2==0 and b%2 != 0) or (b%2==0 and a%2!=0):
            ans += 1

    print(ans)


main()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	int N; cin >> N;
	vector<string> S(N);
	rep(i, N) cin >> S[i];
	ll ans = 0, taila = 0, headb = 0, both = 0;
	rep(i, N) {
		rep(k, S[i].size() - 1) if (S[i][k] == 'A' && S[i][k + 1] == 'B') ans++;
		if (S[i][S[i].size() - 1] == 'A') taila++;
		if (S[i][0] == 'B') headb++;
		if (S[i][S[i].size() - 1] == 'A' && S[i][0] == 'B') both++;
	}
	if (taila == headb && taila == both && taila > 0) {
		taila--;
		headb--;
	}
	cout << (ans + min(taila, headb)) << endl;
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];
ll pos[N];
int main()
{
   string str;

   cin>>str;

    if(str[0]!=str[1]&&str[1]!=str[2]&&str[2]!=str[3])
    {
        cout<<"Good"<<endl;
    }
    else cout<<"Bad"<<endl;


}






Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    string a, b,c,d;
    cin >> a;
    if (a[0] == 'a'&&a[1] == 'b') {
        if (a[2] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    else if (a[1] == 'a'&&a[2] == 'b') {
        if (a[0] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    else if (a[2] == 'a'&&a[0] == 'b') {
        if (a[1] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
   else if (a[0] == 'a'&&a[2] == 'b') {
        if (a[1] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
   else if (a[1] == 'a'&&a[0] == 'b') {
        if (a[2] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
   else if (a[2] == 'a'&&a[1] == 'b') {
        if (a[0] == 'c') {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
   else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  while (a >= b && k) {
    b *= 2;
    k--;
  }
  while (b >= c && k) {
    c *= 2;
    k--;
  }
  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435
using namespace std;

void solve(){
	int n;
	cin>>n;
	int temp=ceil((double)n/1000);
	cout<<(temp*1000)-n;
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3652
#include <stdio.h>
 
typedef struct{
  int data;
}dice;
 
void roll(char move,dice *a,dice *b,dice *c,dice *d,dice *e,dice *f)
{
  dice temp;
 
  temp = *a;
  if(move == 'E'){//???
    *a = *d;    *d = *f;    *f = *c;    *c = temp;
  }
  else if(move == 'N'){//???
    *a = *b;    *b = *f;    *f = *e;    *e = temp;
  }
  else if(move == 'S'){//???
    *a = *e;    *e = *f;    *f = *b;    *b = temp;
  }
  else if(move == 'W'){//???
    *a = *c;    *c = *f;    *f = *d;    *d = temp;
  }
}
 
void spin(char move,dice *a,dice *b,dice *c,dice *d)
{
  dice temp;
 
  temp = *a; //??±?????????
  if(move == 'R'){ //???????????????????????????????¨??????????
    *a = *b;    *b = *d;    *d = *c;    *c = temp;   
  }
  else if(move == 'L'){  //??????????????????????????????????¨??????????
    *a = *c;    *c = *d;    *d = *b;    *b = temp;
  }
}
 
int main(void)
{
  int i,j,k,l;
  int da[6],dda[6];
 
  for(i=0; i<6; i++){
    scanf("%d",&da[i]);
  }
  for(i=0; i<6; i++){
    scanf("%d",&dda[i]);
  }
   
  dice one[6] = {
    {da[0]}, {da[1]}, {da[2]}, {da[3]}, {da[4]}, {da[5]},
  };
  dice two[6] = {
    {dda[0]}, {dda[1]}, {dda[2]}, {dda[3]}, {dda[4]}, {dda[5]},
  };
 
  for(i=0; i<=3; i++){
    roll('S',&two[0],&two[1],&two[2],&two[3],&two[4],&two[5]);
    for(j=0; j<=3; j++){
      spin('L',&two[1],&two[2],&two[3],&two[4]);
      for(k=0; k<=5; k++){
    if(one[k].data != two[k].data){
      break;
    }
    else if((one[k].data == two[k].data) && (k==5)){
      puts("Yes");
      return(0);
    }
      }
    }
  }
   
  for(i=1; i<=2; i++){
    for(l=0; l<i; l++){
      roll('W',&two[0],&two[1],&two[2],&two[3],&two[4],&two[5]);
    }
    for(j=0; j<=3; j++){
      spin('L',&two[1],&two[2],&two[3],&two[4]);
      for(k=0; k<=5; k++){
    if(one[k].data != two[k].data){
      break;
    }
    else if((one[k].data == two[k].data) && (k==5)){
      puts("Yes");
      return(0);
    }
      }
    }
  }
  puts("No");
 
  return(0);
}

Measured memory_bytes: 580
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

void call(int n) {
    int x;
    for(int i = 1; i <= n; ++i) {
        x = i;
        if(x % 3 == 0) {
            cout << " " << i;
            continue;
        }
        while(x) {
            if(x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}
int main() {
    int n;
    cin >> n;
    call(n);
    return 0;

}


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

int main() {
    int N;
    cin >> N;

    int T = 0, X = 0, Y = 0;
    int t = 0, x = 0, y = 0;

    bool ans = true;
    for (int i = 1; i <= N; ++i) {
        cin >> t >> x >> y;
        int moveTime = t - T;
        int moveXY = abs(x - X) + abs(y - Y);
        if (moveTime < moveXY) ans = false;
        if (moveTime % 2 != moveXY % 2) ans = false;
        T = t;
        X = x;
        Y = y;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
def bubbleSort(A, N):
    global count
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                count += 1

N = int(input())
A = [int(i) for i in input().split()]
count = 0
bubbleSort(A, N)
print(*A)
print(count)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; ++i)
  {
    int sum = 0;
    string s = to_string(i);
    for(const char& c : s)
    {
      sum += (c - '0');
    }
    if (a <= sum && sum <= b)
    {
      ans += i;
    }
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3728
fun main(args: Array<String>) {
    val a = (1..5).map { readLine()!!.toInt() }.toTypedArray()
    println(solve(a))
}

fun solve(a: Array<Int>) : Int {
    val adj : Int = a.filter{it % 10 != 0}.minBy {it % 10}?.mod(10) ?: 10
    val sum = a.sumBy { (it + 9) / 10 * 10 }
    return sum - (10 - adj)
}


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

int main()
{
    int N;
    scanf("%d", &N);
    std::vector<long long> A(N);
    for(int i=0; i<N; i++) scanf(" %lld", &A[i]);

    std::sort(A.begin(), A.end());
    std::vector<long long> sum(1, A[0]);
    for(int i=1; i<N; i++) sum.push_back(sum.back() + A[i]);
    
    for(int i=N-1; i>0; i--){
        if(sum[i-1] * 2 < A[i]){
            std::cout << N-i << std::endl; return 0;
        }
    }
    std::cout << N << std::endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  string s,t;
  cin>>s>>t;
  int n=s.size();
  bool ans=true;
  if(t.size()!=n+1) ans=false;
  rep(i,n){
    if(s[i]!=t[i]) ans=false;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 3628