akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 2010
using namespace std;
typedef long long ll;
int n,x,a[N],b[N][N];
ll ans=1ll*inf*inf;
inline ll calc(int k){
	ll ret=0;
	for(int i=1;i<=n;i++)ret+=b[i][k];
	return ret;
}
int main(){
	cin>>n>>x;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i][0]=a[i];
	for(int j=1;j<n;j++)for(int i=1;i<=n;i++)b[i][j]=min(i==1?b[n][j-1]:b[i-1][j-1],a[i]);
	for(int i=0;i<n;i++)ans=min(ans,calc(i)+1ll*x*i);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 16000
N = int(input())
d4 = 0
d2 = 0
for i in list(map(int,input().split())):
    if i % 4 == 0:
        d4 += 1
    elif i % 2 == 0:
        d2 += 1
    else:
        None
if N <= d4*2 + 1:
    print("Yes")
elif N - d4 * 2 <= d2 :
    print("Yes")
else:
    print("No")

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

int dp[101][4][4][4] = {0};
const int mod = 1000000007;

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

    dp[0][3][3][3] = 1;

    for(int i=0;i<N;i++){
        for(int a=0;a<4;a++){
            for(int b=0;b<4;b++){
                for(int c=0;c<4;c++){
                    
                    for(int d=0;d<4;d++){
                        if(d==1 && b==2 && c==0) continue;
                        if(d==1 && b==0 && c==2) continue;
                        if(d==1 && a==0 && c==2) continue;
                        if(d==1 && a==0 && b==2) continue;
                        if(d==2 && b==0 && c==1) continue;

                        dp[i+1][b][c][d] += dp[i][a][b][c];
                        dp[i+1][b][c][d] %= mod;
                    }

                }
            }
        }
    }
    
    int ans = 0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                ans += dp[N][i][j][k];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int n,k;cin>>n>>k;
  vector<int> p(n);
  int i;
  for(i=0;i<n;i++)cin>>p.at(i);
  int kans=0;
  if(k>=n)
  {
    for(i=0;i<n;i++)
    {
      kans+=p.at(i);
    }
    kans+=k;
  }
  else
  {
    for(i=0;i<k;i++)
    {
      kans+=p.at(i);
    }
    int kans2=kans;
    for(i=k;i<n;i++)
    {
      kans=kans-p.at(i-k)+p.at(i);
      if(kans>kans2)kans2=kans;
    }
    kans=kans2+k;
  }
  double ans=kans/2.0;
  cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int a, b, c, d;
    cin >> a >> b >> c >> d;

    Int r = 1;
    Int g = c>d ? c : d;
    Int s = c<d ? c : d;
    while(true){
        r = g%s;

        if(r==0){
            break;
        }else{
            g = s;
            s = r;
        }
    }
    
    Int l = c*d/s;
    Int ans1 = b - (b/c + b/d - b/l);
    Int ans2 = a-1 - ((a-1)/c + (a-1)/d - (a-1)/l);
    Int ans = (ans1 - ans2);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int n,k;
ll w[SIZE], d[SIZE];

bool check(ll x){
  ll sum = 0;
  
  for(int i=0;i<n;i++){
    if(x >= w[i])
      sum += (x-w[i])/d[i] + 1;
  }

  return sum >= k;
}

int main(){

  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
    scanf("%lld%lld",w+i, d+i);
  }

  ll l = 0, r = LLINF;

  while(l < r){
    ll mid = (l+r)/2;

    if(check(mid)){
      r = mid;
    }else{
      l = mid+1;
    }
  }

  printf("%lld\n",l);
  
  return 0;
}


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

int main(){
    int W,H,x,y;
    cin >> W >> H >> x >> y;
    double min = (double(W)*double(H))/2.0;
    int s = 0;
    if((W%2==0)&&(H%2==0)){
        if((W == 2*x)&&(H == 2*y))
            s = 1;
    }
    cout << min << " " << s << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
       

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var d = cin.SplitReadL();
            long ans = 0;
            for(var i = 0; i < N - 1; i++)
            {
                for (var j = i + 1; j < N; j++) 
                {
                    ans += d[i] * d[j];
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
        


    }

    

    

    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a,int b){
    if(a<b) swap(a,b);
    int r=a%b;
    while(r!=0) a=b,b=r,r=a%b;
    return b;
}
int main(){
    int n,A[200000],dp[200000][2];
    cin>>n;
    rep(i,n) cin>>A[i];
    dp[1][0]=A[0],dp[2][1]=A[1];
    rep(i,n){
        if(i>=1) dp[i+1][0]=gcd(dp[i][0],A[i]);
        if(i>=2) dp[i+1][1]=max(gcd(dp[i][1],A[i]),dp[i][0]);
    }
    int ans=dp[n][1];
    dp[1][0]=A[0],dp[1][1]=A[0];
    rep(i,n){
        if(i>=1) dp[i+1][0]=gcd(dp[i][0],A[i]);
        if(i>=1) dp[i+1][1]=max(gcd(dp[i][1],A[i]),dp[i][0]);
    }
    cout<<max(ans,dp[n][1]);
}

Measured memory_bytes: 2304
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int x, m = 100, ans = 0;
    cin >> x;
    
    while (m < x and ++ans) m += m / 100;
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

char tmp[10], s[12][13];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};

int dfs(int x, int y)
{
  int i;
  if(0 > x || x > 11 || 0 > y || y > 11 || s[y][x] != '1')
    return 0;
  s[y][x] = '0';
  for(i = 0; i < 4; i++)
    dfs(x + dx[i], y + dy[i]);
  return 1;
}

int main()
{
  int y, x, i, n;
  while(scanf("%s", s[0]) != -1)
  {
    n = 0;
    for(i = 1; i < 12; i++)
      scanf("%s", s[i]);
    scanf("\n");
    for(y = 0; y < 12; y++)
      for(x = 0; x < 12; x++)
        n += dfs(x, y);
    printf("%d\n", n);
  }
  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
map<int,int> mapa;
vector<ii> vet;
int a,b,n;

main(){
	int m;
  cin >> n >> m;
  for(int i  = 0;i<n;i++){
  	cin >> a;
    mapa[a]++;
  }
  for(auto it:mapa)
  	vet.push_back(it);
  for(int i = 0;i<m;i++){
  	cin >> a>>b;
    vet.push_back({b,a});
  }
  sort(vet.begin(),vet.end(),greater<ii>());
  int cont =n;

  long long soma = 0;
	for(auto it: vet){
	//	cout<<it.first<<endl;
  	soma += min(cont, it.second)*it.first;
    cont -= min(cont,it.second);
    if(cont == 0)
    	break;
  }

	cout<<soma;

}


Measured memory_bytes: 12660
import math
N = int(input())
A = [int(i) for i in input().split()]

money = 1000

# 購入中の株式
kabu_num = 0

for i in range(N - 1):
    a1 = A[i]
    a2 = A[i + 1]
    if a1 > a2:
        # 売る
        if kabu_num != 0:
            money += a1 * kabu_num
            kabu_num = 0
    else:
        # 買う
        if money >= a1:
            kabu_num = math.floor(money / a1)
            money -= a1 * kabu_num

money += kabu_num * A[N - 1]

print(money)



Measured memory_bytes: 9140
#include<iostream>
using namespace std;
int main()
{
	int N,M;
	while(cin>>N>>M,N) 
	{
		int r;cin>>r;
		int t[r],m[r],s[r];
		int n;

		for(int i = 0; i < r; ++i)
		{
			cin>>t[i]>>n>>m[i]>>s[i];
		}

		int q; cin>>q;

		for(int i = 0; i < q; ++i)
		{
			int ts,te,sn;
			cin>>ts>>te>>sn;
			int ans=0,cnt=0,prev=0;
			for(int j = 0; j < r; ++j)
			{
				if(m[j]==sn)
				{
					if(s[j]==1)
					{
						cnt++;
						if(cnt==1)
						{
							prev=t[j];
						}
					}
					else
					{
						cnt--;
						if(cnt==0)
						{
							if(prev<=ts&&t[j]<=te&&ts<=t[j]) ans+=t[j]-ts;
							else if(ts<=prev&&prev<=te&&te<=t[j]) ans+=te-prev;
							else if(ts<=prev&&t[j]<=te) ans+=t[j]-prev;
							else if(prev<=ts&&te<=t[j]) ans+=te-ts;
						}
					}
				}
			}
			cout<<ans<<endl;
		}
	}
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define h_max 20000

vector<vector<int>> dist(30, vector<int>(30, 30*30));
vector<vector<int>> stamp(30, vector<int>(30, 0));
vector<vector<int>> s(30, vector<int>(30, 1));
vector<int> next_x(4, 0);
vector<int> next_y(4, 0);
int h;
int w;

void bfs(int h0, int w0){
    next_x[0]=-1;
    next_x[1]=1;
    next_y[2]=-1;
    next_y[3]=1;
    pair<int, int> tmp_hw;
    queue<pair<int, int>> q;
    tmp_hw.first=h0;
    tmp_hw.second=w0;
    q.push(tmp_hw);
    int h1;
    int w1;
    while(!q.empty()){
        tmp_hw=q.front(); q.pop();
        h0=tmp_hw.first;
        w0=tmp_hw.second;
        for(int i=0; i<4; i++){
            h1=h0+next_x[i];
            w1=w0+next_y[i];
            if(h1>=0 && h1<h){
                if(w1>=0 && w1<w){
                    if(s[h1][w1]==0 && stamp[h1][w1]==0){
                        dist[h1][w1]=dist[h0][w0]+1;
                        stamp[h1][w1]=1;
                        tmp_hw.first=h1;
                        tmp_hw.second=w1;
                        q.push(tmp_hw);
                    }
                }
            }
        }
    }
}

int main() {
    int ans=0;
    int tmp_ans;
    cin >> h >> w;
    char tmp_s;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> tmp_s;
            if(tmp_s=='.'){
                s[i][j]=0;
            }else{
                s[i][j]=1;
            }
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    dist[k][l]=30*30;
                    stamp[k][l]=0;
                }
            }
            if(s[i][j]==1)continue;
            dist[i][j]=0;
            stamp[i][j]=1;
            bfs(i,j);
            tmp_ans=0;
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    if(tmp_ans<dist[k][l] && s[k][l]==0){
                        tmp_ans=dist[k][l];
                    }
                    //cout << i << " " << j << " " << k << " " << l << " " << dist[k][l] << endl;
                }
            }
            //cout << tmp_ans << endl;
            if(tmp_ans>ans){
                ans=tmp_ans;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

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

  int gate[M+10][2];
  REP(i, M) cin >> gate[i][0] >> gate[i][1];

  int lgate=1, rgate=N;

  REP(i, M){
    if(lgate<gate[i][0]) lgate=gate[i][0];
    if(rgate>gate[i][1]) rgate=gate[i][1];
  }

  if(lgate>rgate){
    cout << 0 << endl;
  }else{
    cout << rgate - lgate + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define Mx 200001
#define inf 1e15
const int MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


typedef long long  L;
//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;
void solve(){
    c=0;
    for(L i=1;i<=n;i++){
        for(L j=1;j<=n;j++){
            for(L k=1;k<=n;k++){
                c+=(__gcd(__gcd(i,j),k));
            }
        }
    }
    printf("%lld\n",c);
}
int main()
{
    scanf("%lld",&n);
    solve();
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


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

int main(){
    string s;
    cin>>s;
    size_t l=s.length();
    map<char,int> dict;

    bool flag=true;
    rep(i,l){
        dict[s[i]]++;
        if(dict[s[i]]>=2){
            flag=false;
            break;
        }
    }
    if(flag) cout<<"yes"<<"\n";
    else cout<<"no"<<"\n";
    return 0;
}

Measured memory_bytes: 3500
#include <stdio.h>
#include <stdlib.h>

#define N	100000

int *oj[N], oo[N];

void link(int i, int j) {
	int o = oo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		oj[i] = (int *) realloc(oj[i], o * 2 * sizeof *oj[i]);
	oj[i][o] = j;
}

char cc[N + 1], used[N]; int i_, d_;

void dfs(int p, int i, int d) {
	int o;

	if (cc[i] == 'W')
		d++;
	if (d_ < d)
		i_ = i, d_ = d;
	for (o = 0; o < oo[i]; o++) {
		int j = oj[i][o];

		if (j != p && !used[j])
			dfs(i, j, d);
	}
}

int main() {
	static int qu[N], dd[N];
	int n, h, i, j, ans, head, cnt;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		oj[i] = (int *) malloc(2 * sizeof *oj[i]);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		link(i, j), link(j, i);
		dd[i]++, dd[j]++;
	}
	scanf("%s", cc);
	head = cnt = 0;
	for (i = 0; i < n; i++)
		if (dd[i] == 1 && cc[i] == 'B')
			qu[head + cnt++] = i;
	ans = (n - 1) * 2;
	while (cnt) {
		int o;

		i = qu[cnt--, head++];
		used[i] = 1;
		ans -= 2;
		for (o = 0; o < oo[i]; o++) {
			j = oj[i][o];
			if (--dd[j] == 1 && cc[j] == 'B')
				qu[head + cnt++] = j;
		}
	}
	if (ans <= 0) {
		for (i = 0; i < n; i++)
			if (cc[i] == 'W') {
				printf("1\n");
				return 0;
			}
		printf("0\n");
		return 0;
	}
	for (i = 0; i < n; i++) {
		if (used[i])
			continue;
		if (dd[i] % 2 != 0)
			cc[i] = cc[i] == 'W' ? 'B' : 'W';
		if (cc[i] == 'W')
			ans++;
	}
	for (i = 0; i < n; i++)
		if (!used[i]) {
			d_ = -1;
			dfs(-1, i, 0);
			d_ = -1;
			dfs(-1, i_, 0);
			ans -= d_ * 2;
			break;
		}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 12768
#include <stdio.h>
using namespace std;

int N;
int m;
int a=0;

int main(){
  scanf("%d", &N);
  
  int w[N];
  for(int i=0; i<N; i++){
    scanf("%d", &w[i]);
    a += w[i];
  }
  int S1[N]={0};
  int S2[N]={0};
  int d[N] ={0};
  for(int t=0; t<N-1; t++){
    for(int i=0; i<t+1; i++){
      S1[t] += w[i];
    }
    S2[t] = a - S1[t];
    d[t] = S1[t] - S2[t];
    if(d[t]<0) d[t] = -d[t];
  }

  m = d[0];
  for(int t=0; t<N-1; t++){
    if(m>d[t]) m = d[t]; 
  }
  
  printf("%d", m);
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;



int main() {
	int n, m, k;
	cin >> n >> m >> k;
	whei(int) G(n),b(n);
	hei(int) f(n, 0);
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
		f[a]++;
		f[b]++;
	}
	rep(i, 0, k) {
		int c, d;
		cin >> c >> d;
		c--;
		d--;
		b[c].push_back(d);
		b[d].push_back(c);
	}
	hei(int) tag(n, -1);
	int x = 0;
	hei(int) siz(n, 0);
	rep(v, 0, n) {
		if (tag[v] != -1) {
			siz[tag[v]]++;
			continue;
		}
		x++;
		tag[v] = x;
		siz[x]++;
		queue<int> que;
		que.push(v);
		while (!que.empty()) {
			int V = que.front(); que.pop();
			for (auto nv : G[V]) {
				if (tag[nv] != -1)continue;
				tag[nv] = x;
				que.push(nv);
			}
		}
	}
	rep(i, 0, n) {
		int ans = siz[tag[i]] - f[i] - 1;
		for (auto z : b[i])if (tag[i] == tag[z])ans--;
		cout<<ans;
		if (i == n - 1)cout << endl;
		else cout <<" ";
	}
	
	return 0;
}


Measured memory_bytes: 15544
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	char s; cin >> s;

	if (isupper(s)) {
		cout << "A" << endl;
	}
	else {
		cout << "a" << endl;
	}
	return 0;
}

Measured memory_bytes: 3560
n, m = gets.split.map(&:to_i)
if  n == 1 && m == 1
  puts 1
elsif n <= 2 && m <= 2
  puts 0
elsif n == 1
  puts 1 * [m-2, 2].max
elsif m == 1
  puts [n-2, 2].max * 1
else
  puts (n-2) * (m-2)
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
char s[1000000];
int main(){
    scanf("%s", s);       
    int n = strlen(s);
    for(int i=0;i<n;i++) printf("%c", s[i]);
    if(s[n-1] == 's') printf("es\n");
    else printf("s\n");
}

Measured memory_bytes: 3760
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <typeinfo>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <type_traits>

#define ll long long
#define ld long double

using namespace std;

int main(){
    vector<int> v(100001, 0), c(100001, 1);
    c[0] = 0;
    c[1] = 0;
    for(int i=2;i<=100000;i++){
        if(!c[i]) continue;
        for(int j=2*i; j<=100000; j+=i){
            c[j] = 0;          
        }
    }
    for(int i=3;i<=100000;i++){
        if(c[i] && c[(i+1)/2]) v[i] = 1;
        v[i] += v[i-1];
    }
 
    int q, l, r;
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> l >> r;
        cout << v[r]-v[l-1] << endl;
    }
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int g=(n-1)*(n-2)/2;
    int j=2;
    int f=3;
    if(k>(n-1)*(n-2)/2){
        cout<<-1;
    }
    else{
        cout<<n-1+g-k<<endl;
        for(int i=0;i<n-1;i++){
            cout<<1<<' '<<i+2<<endl;
        }
        while(g>k){
            cout<<j<<' '<<f<<endl;
            g--;
            if(f==n){
                j++;
                f=j+1;
            }
            else{
                f++;
            }
        }
    }
}


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

int main() {

  string s,t;
  cin >> s;
    
  for ( int i = 0; i < s.size(); i++){
    if ( s[i] != 'B' ){
      t += s[i];
    }else{
      if ( t.size() == 0 ){
        continue;
      }else{
        t.erase(t.end()-1,t.end());
      }
    }
  }
  
  cout << t << endl;
  
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/m-solutions2020
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N, K;
    cin >> N >> K;
    vector<ll> A(N+1);
    A[0] = 1LL;
    for (int i = 1; i <= N; ++i) cin >> A[i];

    for (int i = K + 1; i <= N; ++i)
    {
        ll q = A[i] / A[i - K];
        ll r = A[i] % A[i - K];
        if (q > 1LL || (q == 1LL && r > 0LL))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4840
import sys

def solve():
    input = sys.stdin.readline
    X = int(input())
    fin = False
    for i in range(-1000, 1001):
        for j in range(-1000, 1001):
            if pow(i, 5) - pow(j, 5) == X:
                print(i, j)
                fin = True
                break
        if fin: break
    else: print(-1)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9192
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int a, b;
  cin >> a >> b;
  if(a==2||b==2)puts("No");
  else puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

ll gcd(int a, int b) {
	while (a && b) {
		if (a < b) swap(a, b);
		a %= b;
	}
	return max(a,b);
}

bool isPrime(int N)
{
	if (N <= 1) return false;
	if (N == 2) return true;
	if (N % 2 == 0) return false;
	for (int i = 3; i * i <= N; i += 2)
		if (N % i == 0) return false;
	return true;
}

int main() {
	int n; cin >> n;
	vector<int> a(n + 1),ans;
	int g = 0;
	rep(i, 0, n + 1) {
		cin >> a[i];
		g = gcd(g, abs(a[i]));
	}
	int h = g;
	rep(i, 2, sqrt(g) + 1) {
		if (g % i == 0 && isPrime(i)) {
			ans.push_back(i);
			while(g%i==0)g /= i;
		}
	}
	if (g != 1) ans.push_back(g);
	rep(i, 0, n + 1) a[i] /= h;
	rep(p, 0, n + 2) {
		if (isPrime(p) && a[n] % p == 0) {
			bool flag = true;
			rep(i, 0, p - 1) {
				ll sum = 0;
				rep(j, i, n + 1) {
					sum += a[j];
					j += p - 2;
				}
				if (sum % p != 0) {
					flag = false;
				}
			}
			if (flag) ans.push_back(p);
		}
	}
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	rep(i, 0, ans.size()) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

std::string IntToString(long long a){
  char x[100];
  sprintf(x,"%lld",a);
  std::string s = x;
  return s;
}
long long StringToInt(std::string a){
  char x[100]; long long res;
  strcpy(x,a.c_str());
  sscanf(x,"%lld",&res);
  return res;
}
inline void printIntVal(long long a) {
  std::cout << "The Value is: "<< IntToString(a) << std::endl;
}
inline void printStringVal(std::string a) {
  std::cout << "The Value of is: "<< a << std::endl;
}
inline std::string GetString(){
  char x[1000005];
  scanf("%s",x);
  std::string s = x;
  return s;
}
inline std::string uppercase(std::string s){
  int n = (int)s.size();
  for(int i = 0; i < n; i++) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline std::string lowercase(std::string s){
  int n = (int)s.size();;
  for(int i = 0; i < n; i++) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN (std::string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}
inline long long CharToInt(char c) {
    return (c - '0');
}

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

int main() {

  int cities,roads;
  std::vector<std::vector<int> > cons;
  std::vector<int> numcons;
  scanf("%d %d",&cities,&roads);
  for(int i = 0; i < roads; i++) {
    std::vector<int> con;
    int a,b;
    scanf("%d %d",&a,&b);
    con.push_back(a); con.push_back(b);
    cons.push_back(con);
  }

  for(int h = 0; h < cities; h++) {
    numcons.push_back(0);
  }

  for(int j = 0; j < cons.size(); j++) {
    for(int k = 1; k <= cities; k++) {
      if(cons.at(j).at(0) == k || cons.at(j).at(1) == k) {
        numcons.at(k-1)++;
      }
    }
  }

  for(int i = 0; i < numcons.size(); i++) {
    std::cout << numcons[i] << std::endl;
  }

  return 0;
}


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

int64_t gcd(int64_t a,int64_t b){
    if(a < b)
    {
        int64_t temp = a;
        a = b ;
        b = temp;
    }
    int64_t copya = a;
    int64_t copyb = b;
    int64_t r = a%b ;
    while (r != 0)
    {
        a = b ;
        b = r ;
        r = a%b ;
    }
    return b ;
    
}


int main(){
    int n,k ;
    cin >> n >> k ;
    int m = 0;
    int G = 0 ;
    int num ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> num ;
        if (i == 0)
        {
            m = num ;
            G = num ;
        }else
        {
            m = max(m,num) ;
            if (G != 1)
            {
                G = gcd(G,num) ;
            }
            
        }
        
        
    }
    if (k <= m && k%G == m%G)
    {
        cout << "POSSIBLE" ;
    }else
    {
        cout << "IMPOSSIBLE" ;
    }
    cout << endl ;
    
}

Measured memory_bytes: 256
<?php
// 問題URL
// https://atcoder.jp/contests/abc050/tasks/abc050_a
$n = fgets(STDIN);

$a = explode(' ', $n);

if ($a[1] == '-') {
	$out = (int)$a[0] - (int)$a[2];
} elseif ($a[1] == '+') {
	$out = (int)$a[0] + (int)$a[2];
}

print $out;

Measured memory_bytes: 3828
#include<iostream>

using namespace std;

#define size 5

main(){

  int data[5];


  cin >> data[0] >> data[1] >> data[2] >> data[3] >> data[4] ;

  for(int front = 0;front <size-1;front++){
    int minIndex = front;
    for(int j = front+1;j<size;j++){
      if(data[j]<data[minIndex])minIndex=j;
    }
    
    int temp = data[front];
    data[front]=data[minIndex];
    data[minIndex]=temp;
  }

  cout << data[4]<<" "<< data[3]<<" "<< data[2]<<" "<< data[1]<<" "<< data[0]<<endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int k = sc.nextInt();
        long [] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextLong();
        long [] pref = new long[n + 1];
        long [] actual = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            if (a[i - 1] >= 0) pref[i] = pref[i - 1] + a[i - 1]; else pref[i] = pref[i - 1];
            actual[i] = actual[i - 1] + a[i - 1];
        }
        long ans = Long.MIN_VALUE;
        for (int i = k; i <= n; i++) {
            long before = pref[i - k];
            long after = pref[n] - pref[i];
            long middle = actual[i] - actual[i - k];
            ans = Math.max(before + after, ans);
            ans = Math.max(before + after + middle, ans);
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

int main(){

  int n, n_min, n_max, tmp = 0, ans = 0, max;
  int p[110000];
  int g[110000];

  while(cin >> n >> n_min >> n_max){

    if(n + n_min + n_max == 0) break;
    int i;
    for(i = 0; i < n; i++){
      cin >> p[i];
      g[i] = tmp - p[i];
      tmp = p[i];
    }
    int j = n_min, max = 0;
    for(i = n_min; i <= n_max; i++){
      if(max <= g[j]){
        max = g[j];
        ans = j;
      }
      j++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll r = 0;
  ll g = 0;
  ll b = 0;
  rep(i,n){
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
    if(s[i] == 'B') b++;
  }
  ll ans = r*g*b;
  for(int i=0;i<=n-3;i++){
    for(int j=i+1;j<=n-2;j++){
      int k = 2*j - i;
      if(k >= n) continue;
      if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans --;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n,a;
	cin>>n;
	for (int i = 0; i < n; ++i)
		{
			cin>>a;
			if(a%2==0)
			if(a%3!=0 && a%5!=0){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}	
		cout<<"APPROVED"<<endl;

   return 0;
}


Measured memory_bytes: 3624
import sys
s=input()
l=len(s)-7
if l<0:
    print('NO')
    sys.exit()
for i in range(7):
#    print(s[:i]+s[i+l:])
    if s[:i]+s[i+l:]=='keyence':
        print('YES')
        sys.exit()
if s[:7]=='keyence':
    print('YES')
else:
    print('NO')

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

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

    int ans = n;
    rep(i, n) {
        int cc = 0, l = i, r = n - i;
        while (l > 0) cc += l % 6, l /= 6;
        while (r > 0) cc += r % 9, r /= 9;
        if (ans > cc) ans = cc;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x,y=map(int,input().split())
y=y//1000
n=0
for i in range(x+1):
  if n==1:
    break
  if i==x:
    if y==i:
      print(0,0,x)
    else:
      print(-1,-1,-1)
  else:
    for j in range(x-i+1):
      v=i+5*j+10*(x-i-j)
      if y==v:
        print(x-i-j,j,i)
        n+=1
        break

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

int GCD(int , int );

int main()
{
  int a,b;
  cin>>a>>b;
  cout<<GCD(a,b)<<endl;
  return 0;
    }

int GCD(int x,int y)
{
  int r;
  if(x<y) swap(x,y);
  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  return x;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i+=2) {
    if(i + 1 >= s.size() || s[i] != 'h' || s[i+1] != 'i') {
      cout <<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes\n";
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <complex>
#include <math.h>

typedef long long ll;

using namespace std;

double pi=2*acos(0);
const int INF = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2];
}

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(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;

int main() {
	cin >> N;
	
	int a = 0, b = 0, ab = 0, c = 0;
	REP(i, N) {
		string s;
		cin >> s;
		int M = s.size();
		REP(j, M - 1) if (s[j] == 'A' && s[j + 1] == 'B') c++;
		if (s[M - 1] == 'A' && s[0] == 'B') ab++;
		else if (s[M - 1] == 'A') a++;
		else if (s[0] == 'B') b++;
	}
	
	int ans = 0;
	ans = min(a, b);
	if (ans > 0) ans += ab;
	else if (a > 0 || b > 0) ans = ab;
	else ans = max(ab - 1, 0);
	ans += c;
	
	cout << ans << endl;
	
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n]++;
  return ret;
}

int main() {
  ll n, p;
  cin >> n >> p;

  ll ans = 1;
  auto f = prime_factor(p);
  for (auto x : f) {
    ll cnt = x.second / n;
    REP(i, cnt) ans *= x.first;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = true;
    if(a == b){
        if(a != c || b != c) flag = false;
    }
    if(b == c){
        if(a != b || c != a) flag = false;
    }
    if(c == a){
        if(a != b || b != c) flag = false;
    }

    if(flag == true) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    double a, b, C;
    cin >> a >> b >> C;
    double S = 0, L = 0, h = 0;
    double pi = 3.1415926535;
    h = b * sin(2 * pi * C / 360);
    S = a * h / 2;
    L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(2 * pi * C / 360));
    cout << fixed << setprecision(10);
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;
    return 0;
}



Measured memory_bytes: 3480
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

    static Scanner in;
    static PrintWriter out;


    static final int mod = (int) 1e9 + 7;
    static final int inf = 0x3f3f3f3f;
    static final int maxn = (int) 500 + 2;
    static int total;
    static int[] par = new int[maxn];

    public static void main(String[] args) throws Exception {
        //Test.main();
        try {
            System.setIn(new FileInputStream("night_input"));
        } catch (FileNotFoundException e) {

        }

        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        while (in.hasNext()) {
            int n = in.nextInt();
            int a = in.nextInt();
            out.println(n % 500 <= a ? "Yes" : "No");
        }

        in.close();
        out.close();
    }

    static int find(int x) {
        return (par[x] = par[x] == x ? x : find(par[x]));
    }

    static void init() {
        total = 0;
        for (int i = 0; i < par.length; ++i) {
            par[i] = i;
        }
    }
}


Measured memory_bytes: 21840
s = input()
n = len(s)

for i in range(n - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        exit()

for i in range(n - 2):
    if s[i] == s[i + 2]:
        print(i + 1, i + 3)
        exit()

print(-1, -1)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define R freopen("A.in","r",stdin);
#define W freopen("A.out","w",stdout);
const int N=1e5+5;
const int INF=0x3f3f3f3f;
int n,i;
string s;
int main()
{
    
    cin>>s;
    if(s.size()==1){cout<<s;return 0;}
    int sz=s.size();
    for(i=1;i<sz;i++)
    {
        if(s[i]!='9'){cout<<s[0]-'1'+(sz-1)*9;return 0;}
    }
    cout<<s[0]-'0'+(sz-1)*9;

    return 0;
}


Measured memory_bytes: 256
sAdd :: [String] -> Int -> Int
sAdd [] acc = acc
sAdd src acc = sAdd (tail src) acc'
  where
    cs = words (head src)
    l = read (head cs)
    r = read (last cs)
    acc' = acc + r  + (-l) + 1

main = do
  ns <- lines <$> getContents
  putStrLn $ show $ sAdd (tail ns) 0

Measured memory_bytes: 1276
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>

int main()
{
    auto card = std::unordered_map<std::string, int>();
    auto s = std::string();
  
    auto n = 0;
    std::cin >> n;  
    for (auto i = 0; i < n; ++i)
    {
        std::cin >> s;
        card[s] ++;
    }

    auto m = 0;
    std::cin >> m;
    for (auto i = 0; i < m; ++i)
    {
        std::cin >> s;
        card[s] --;
    }

	auto result = 0;
  	
  	for (const auto& c : card) 
    {
    	if (c.second > result) result = c.second;  
    } 
  
  	std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

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

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

int main() {
	int n;  cin >> n;
	vector<string> S(n);
	for (int i = 0; i < n; i++) cin >> S[i];

	vector<vector<int>> cnt(n, vector<int>(26, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < S[i].length(); j++) {
			cnt[i][S[i][j] - 'a']++;
		}
	}

	vector<int> nAns(26);
	for (int i = 0; i < 26; i++) {
		int buf = n * 50;
		for (int j = 0; j < n; j++) {
			buf = min(buf, cnt[j][i]);
		}
		nAns[i] = buf;
	}

	string ans = "";
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < nAns[i]; j++) {
			ans += (char)('a' + i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
ar = [0,N]
for m in range(M):
    l,r = map(int, input().split())
    if l>ar[0]:
        ar[0] = l
    if r<ar[1]:
        ar[1]=r
print(max([0,ar[1]-ar[0]+1]))

Measured memory_bytes: 3060