akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

typedef long long ll;
typedef long long int lli;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

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

	int N, res; cin >> N;
	vector<int>ver(N);
	rep(i, N) { cin >> ver[i]; }
	sort(ver.begin(), ver.end());
	res = ver[N / 2] - ver[N / 2 - 1];
	cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
#define EPS 1e-8
#define INF 1e9+10
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  cout << N*N << endl;
}



Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int ans = 0;

    int n;
    cin>>n;

    vi v(n);
    for(int &x:v) cin>>x;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++) ans += v[i] * v[j];
    }

    cout<<ans;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, k, i, a[200003];

    scanf("%d%d", &n, &k);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int l, r, mid, log_num;
    l = 0;
    r = INF;
    while (r - l > 1) {
        mid = (l + r) / 2;
        log_num = 0;
        for (i = 0; i < n; i++) {
            log_num += (a[i] - 1) / mid;
        }
        if (log_num <= k) {
            r = mid;
        }
        else {
            l = mid;
        }
    }

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

    return 0;
}

Measured memory_bytes: 4532
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){


    string S;
    
    cin >> S;

    if(S=="SUN") cout << 7 << endl;
    else if(S=="MON") cout << 6 << endl;
    else if(S=="TUE") cout << 5 << endl;
    else if(S=="WED") cout << 4 << endl;
    else if(S=="THU") cout << 3 << endl;
    else if(S=="FRI") cout << 2 << endl;
    else if(S=="SAT") cout << 1 << endl;
    

}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    vector<int> a(3);
    vector<int> b(3);
    rep(i, 3)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    int count = 0;
    while (true)
    {

        if (a[0] % 2 != 0 || a[1] % 2 != 0 || a[2] % 2 != 0)
        {
            cout << count << endl;
            return 0;
        }
        count++;
        int temp1, temp2, temp3;
        temp1 = a[0] / 2 + a[1] / 2;
        temp2 = a[1] / 2 + a[2] / 2;
        temp3 = a[2] / 2 + a[0] / 2;
        a[0] = temp1;
        a[1] = temp2;
        a[2] = temp3;
        SORT(a);
        SORT(b);
        if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
        {
            cout << -1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut p = read_vec::<usize>();
    let mut p_sorted = p.clone();
    p_sorted.sort();
    if p == p_sorted {
        println!("YES");
        return;
    }
    for i in 0..n {
        for j in i + 1..n {
            p.swap(i, j);
            if p == p_sorted {
                println!("YES");
                return;
            }
            p.swap(i, j);
        }
    }
    println!("NO");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2172
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	for (int i = a; i <= min(a + k - 1, b); i++)printf("%d\n",i);
	for (int i = max(a + k, b - k + 1); i <= b; i++)printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	string S;
	cin >> S;
	if (S[0] == S[1] && S[1] == S[2])
		puts("No");
	else
		puts("Yes");
}


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

int main() {
	int n, p;
	cin >> n >> p;
	int x = 0, y = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2) {
			y++;
		} else {
			x++;
		}
	}
	int64_t c[51][51];
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j < i; j++) {
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
		c[i][0] = c[i][i] = 1;
	}
	int64_t r = 0;
	for (int i = 0; i <= x; i++) {
		for (int j = p; j <= y; j += 2) {
			r += c[x][i] * c[y][j];
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{	
	int A1, A2, A3;
		scanf("%d %d %d", &A1, &A2, &A3);
	
	if (A1 + A2 + A3 < 22) {
		printf("win");
	}
	else {
		printf("bust");
	}

	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll k;
    cin >> k;
    vb f(k, false);
    ll now = 7;
    ll ans = 1;
    while(true) {
        if(now % k == 0) break;
        if(f[now]) {
            cout << -1 << endl;
            return;
        }
        f[now] = true;
        now = (now * 10 + 7) % k;
        ++ans;
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;


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

    int a,b,c; cin >> a >> b >> c;
    cout << c << " "<< a <<" "<< b;
    return 0;
    
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#define N 32768
#define M 0x3B9ACA07LL
#define FOR(i,a,b)for(int i=a;i<b;i++)
long long a[N]={},b[N],c[N]={},d[N];int main(){int n,k; std::cin>>n>>k;FOR(i,1,N)a[i]=i<n?i:n,b[i]=n/i;FOR(j,0,k-1){FOR(i,1,N)c[i]=(c[i-1]+b[i])%M;d[N-1]=c[n/(N-1)];for(int i=N-2;i>=1;i--)d[i]=(d[i+1]+a[i]*(n/i-n/(i+1)))%M;std::swap(a,c);std::swap(b,d);}std::cout<<b[1];}

Measured memory_bytes: 1280
a,b,c,d = map(int,input().split())
from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
def f(x):
  C = x // c
  D = x // d
  E = x // lcm(c,d)
  return C + D - E
print(b - a + 1 - f(b) + f(a-1))

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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++) {
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());

  int alice, bob = 0;
  for (int i = 0; i < N; i++) {
    if(i % 2 == 0) {
      alice += cards.at(i);
    } else {
      bob += cards.at(i);
    }
  }
  // cout << "alice: " << alice << endl;
  // cout << "bob: " << bob << endl;
  cout << alice - bob << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if L[i] != L[j] and L[i] != L[k]:
                if  L[k] + L[j] > L[i] and L[j] != L[k]:
                    if L[i] + L[j] > L[k] and L[i] + L[k] > L[j]:
                        if L[i] < L[j] and L[j] < L[k]:
                            ans += 1
print(ans)

Measured memory_bytes: 9120
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	if (n % 2 == 0)
	{
		cout << (n / 2) - 1;
	}
	else
	{
		cout << (n - 1) / 2;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
    #define N 200100
    #define int long long
    struct Edge
    {
        int u,v,w;
        const bool operator<(Edge CompWith) const
        {
            return w<CompWith.w;
        }
    }E[N<<1];int cnt=0;
    class DSU
    {
        public:
            int Father[N],Cnt[N];
            void Init()
            {
                for(int i=0;i<N;i++)
                {
                    Father[i]=i;
                    Cnt[i]=1;
                }
            }
            int Find(int x)
            {
                return (x==Father[x])?x:(Father[x]=Find(Father[x]));
            }
            void Merge(int x,int y)
            {
                int ax=Find(x),ay=Find(y);
                if (Cnt[ax]<Cnt[ay])
                {
                    Cnt[ay]+=Cnt[ax];
                    Father[ax]=ay;
                }
                else
                {
                    Cnt[ax]+=Cnt[ay];
                    Father[ay]=ax;
                }
            }
    }D;
    int n,q;
    int d[N];
    void Input()
    {
        scanf("%lld%lld",&n,&q);
        memset(d,0x3f,sizeof(d));
        for(int i=1;i<=q;++i)
        {
            int u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            E[++cnt]=(Edge){u,v,w};
            d[u]=min(d[u],w+1);
            d[v]=min(d[v],w+2);
        }
    }

    void Soviet()
    {
        for(int i=0;i<n;++i)
        {
            d[i]=min(d[i],d[(i+n-1)%n]+2);
        }
        for(int i=0;i<n;++i)
        {
            d[i]=min(d[i],d[(i+n-1)%n]+2);
        }

        for(int i=0;i<=n;++i)
        {
            E[++cnt]=(Edge){i,(i+1)%n,d[i]};
        }
        sort(E+1,E+cnt+1);
        D.Init();
        int ans=0;int rest=n;
        for(int i=1;i<=cnt and rest>1;++i)
        {
            int u=E[i].u,v=E[i].v,w=E[i].w;
            if (D.Find(u)!=D.Find(v))
            {
                D.Merge(u,v);
                ans+=w;
                --rest;
            }
        }
        printf("%lld\n",ans);
    }
    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        Input();
        Soviet();
    }
    #undef int //long long
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}


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

int main(void){
    int num, l, r, i, j, ans = 0;
    while(true){
        cin >> num >> l >> r;
        if(num == 0)
            break;
        vector<int> a(num);
        for(i = 0; i < num; i++){
            cin >> a[i];
        }
        for(ans = 0, i = l; i<= r; i++){
            for(j = 0; j < num; j++){
                if(i % a[j] == 0){
                    if(!(j & 1))
                        ans++;
                    break;
                }
            }
            if(j == num && num % 2 == 0)
                ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

int lcs(string x, string y) {
  int m = x.size(), n = y.size();
  int dp[m + 1][n + 1]; memset(dp, 0, sizeof(dp));

  REP(i, m)REP(j, n)
    if (x[i] == y[j])
      dp[i + 1][j + 1] = dp[i][j] + 1;
    else
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);

  return dp[m][n];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  int t; cin >> t;
  REP(i, t) {
    string x, y; cin >> x >> y;

    cout << lcs(x, y) << endl;
  }
}



Measured memory_bytes: 7080
#include<bits/stdc++.h>
using namespace std;
//vector<int> is passed by &
#define maxStones 100000

int dp[maxStones];
vector<int> heights;

int getCost(int index)
{
	//cout << "checking index:" << index << "   ";

	if(index==heights.size()-1)
		return 0;

	if(index==heights.size()-2)
		return abs( heights[heights.size()-1] - heights[index]);

	if(index==heights.size()-3)
		return abs(min(heights[heights.size()-1],heights[heights.size()-2]) - heights[index]);

	if(dp[index]!=-1)
	{		
		//cout << "found prevalue " << endl;
		return dp[index];
	}
	
	//cout << "not found prevalue " << endl;
	int cost = min(abs(heights[index]-heights[index+1]) + getCost(index+1), 
					abs(heights[index]-heights[index+2]) + getCost(index+2));

	dp[index]=cost;

	return cost;
}


int main()
{
	for(int i=0;i<maxStones;i++)
		dp[i]=-1;

	int n;	
	cin >> n;
	int t;
	for(int i=0;i<n;i++)
	{
		cin >> t;
		heights.push_back(t);
	}
	cout << getCost(0) <<endl;
	return 0;
}

Measured memory_bytes: 7272
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

int main()
{
	string S;
	cin >> S;
	//S="_"+S;

	vector<int> L,R;
	L.push_back(-1);
	R.push_back(-1);
	for(int i=0;i<S.size();i++)
	{
		if(S[i]=='L')
			L.push_back(i);
		else
			R.push_back(i);
	}

	int ans[100010]={};
	for(int i=0;i<S.size();i++)
	{
		int pos;
		if(S[i]=='L')
		{
			auto itr=lower_bound(R.begin(),R.end(),i);
			--itr;
			pos=*itr+((i-*itr)%2);
		}
		else
		{
			auto itr=lower_bound(L.begin(),L.end(),i);
			pos=*itr-((*itr-i)%2);
		}
		ans[pos]++;
	}

	for(int i=0;i<S.size();i++)
	{
		cout << ans[i];
		if(i==S.size()-1)
			cout << endl;
		else
			cout << " ";
	}
	return 0;
}



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

int main(){
  int n,p;
  int M = 0;
  int sum = 0;
  cin >> n;
  for (int i = 0;i < n;i++){
   cin >> p;
   M = max(M,p);
   sum += p;
  }
  cout << sum-M/2 << endl;
}

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

int main() {
    int N; cin >> N;
    typedef std::pair<int, int> pair;
    vector< vector<pair> > XY(N, vector<pair>());
    for (int i = 0; i < N; i++) {
        int A; cin >> A;
        for (int j = 0; j < A; j++) {
            int x, y; cin >> x >> y; x--;
            XY[i].push_back(make_pair(x, y));
        }
    }
    
    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        bool flag = true;
        for (int j = 0; j < N; j++) {
            if (i & (1 << j)) {
                for (auto xy : XY[j]) {
                    if (xy.second == 1 && !(i & (1 << xy.first))) flag = false;
                    if (xy.second == 0 && (i & (1 << xy.first))) flag = false;
                }
            }
        }
        if (flag && __builtin_popcount(i) > ans) ans = __builtin_popcount(i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long a[10];
    long long n;
    long long b[20];
    long long ans[10];

    for (int i=0; i < 9;i++){ 
        cin >> a[i];
        ans[i] = 1000;
    }
    cin >> n;

    for (int i=0; i < n; i++){
        cin >> b[i];
        for (int j = 0; j < 9; j++){
            if (a[j] == b[i]){
                ans[j] = 0;
                break;
            }
        }
    }
    
    if (ans[0] + ans[1] + ans[2] == 0){
        cout << "Yes";
    }
    else if (ans[3] + ans[4] + ans[5] == 0){
        cout << "Yes";
    }
    else if (ans[6] + ans[7] + ans[8] == 0){
        cout << "Yes";
    }

    else if (ans[0] + ans[3] + ans[6] == 0){
        cout << "Yes";
    }
    else if (ans[1] + ans[4] + ans[7] == 0){
        cout << "Yes";
    }
    else if (ans[2] + ans[5] + ans[8] == 0){
        cout << "Yes";
    }

    else if (ans[0] + ans[4] + ans[8] == 0){
        cout << "Yes";
    }
    else if (ans[2] + ans[4] + ans[6] == 0){
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N;
	std::cin >> N;
	int lasta = 0;
	int firstb = 0;
	int twin = 0;
	int count = 0;
	for (int i : boost::irange(0, N))
	{
		std::string str;
		std::cin >> str;
		for (auto k : boost::irange<std::size_t>(0, str.size() - 1))
		{
			if (str[k] == 'A' && str[k + 1] == 'B')
			{
				++count;
			}
		}
		if (str.front() == 'B')
		{
			if (str.back() == 'A')
			{
				++twin;
			}
			else
			{
				++firstb;
			}
		}
		else if (str.back() == 'A')
		{
			++lasta;
		}
	}
	count += std::max(0, twin - 1);
	if (lasta > 0 && twin > 0)
	{
		++count;
		--lasta;
	}
	if (firstb > 0 && twin > 0)
	{
		++count;
		--firstb;
	}
	count += std::min(lasta, firstb);
	std::cout << count << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;


struct UnionFind{
    vector<int> rank,p,size;
    UnionFind(int n){
        rank.resize(n,0);
        p.resize(n,0);
        size.resize(n,0);
        for(int i = 0; i < n; i++){
            p[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
            size[rx] += size[ry];
        }else{
            p[rx] = ry;
            size[ry] += size[rx];
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
        return true;
    }
    int tree_size(int x){
        return (size[root(x)]);
    }
};

int main()
{
    int n,m; cin >> n >> m;
    UnionFind ufl(m);
    UnionFind ufm(n);
    vector<int> v[n];
    rep(i,n){
        int k; cin >> k;
        
        rep(j,k){
            int l; cin >> l;
            l--;
            v[i].push_back(l);
        }
        rep(j,k-1) ufl.unite(v[i][j],v[i][j+1]);
    }
    rep(i,n-1){
        if(ufl.same(v[i][0],v[i+1][0])) ufm.unite(i,i+1);
    }
    bool ok = true;
    rep(i,n) if(ufm.tree_size(i) != n) ok = false;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 8064
h,w,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]

for j,k in l:
    count_h[j-1] += 1
    count_w[k-1] += 1

h_max = max(count_h)
w_max = max(count_w)
h_kouho = []
ko_hh = [0 for _ in range(h)]
ko_ww = [0 for _ in range(w)]
w_kouho = []
ans = h_max + w_max -1
for i in range(h):
    if count_h[i]==h_max:
        h_kouho.append(i)
        ko_hh[i] = 1
for j in range(w):
    if count_w[j]==w_max:
        w_kouho.append(j)
        ko_ww[j] = 1


ans_kouho = len(h_kouho) * len(w_kouho)
su = 0
for j,k in l:
    if ko_hh[j-1]==1 and ko_ww[k-1]==1:
        su += 1
if su==ans_kouho:
    print(ans)
else:
    print(ans+1)


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

int main(void){
    int n, temp, cnt = 0;

    cin >> n;

    int p[n];
    int cp[n];
    
    for(int i = 0; i < n; i++){
        cin >> p[i];
        cp[i] = p[i];
    }

    /* swap */
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(p[i] > p[j]){
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }

    /* check */
    for(int i = 0; i < n; i++){
        if(p[i] != cp[i]){
            cnt++;
        }
    }

    if((cnt == 2) || (cnt == 0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> ab(n);
	// iが行、first = a、second = b
	rep(i, n)
	{
		int a, b;
		cin >> a >> b;
		ab.at(i) = make_pair(a, b);
	}
	vector<pair<int, int>> cd(m);
	// jが行、first = c、second = d
	rep(i, m)
	{
		int c, d;
		cin >> c >> d;
		cd.at(i) = make_pair(c, d);
	}
	rep(i, n)
	{
		int min_dist = abs(ab.at(i).first - cd.at(0).first) + abs(ab.at(i).second - cd.at(0).second);
		int checkpoint = 1;
		for (int j = 1; j < m; ++j)
		{
			int cur_dist = abs(ab.at(i).first - cd.at(j).first) + abs(ab.at(i).second - cd.at(j).second);
			if(min_dist > cur_dist) {
				min_dist = cur_dist;
				checkpoint = j + 1;
			}
		}
		cout << checkpoint << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#define sl(n) scanf("%lld",&n)
#define s(n) scanf("%d",&n)
#define f(n) for(int i=0;i<n;++i)
#define fo(n) for(int i=1;i<=n;++i)
#define ll long long
#define pb push_back
#define pf printf
#define F first
#define S second
using namespace std;
 typedef pair <int , int> l;
ll arr[150001];

bool comp(l a, l b){
	return a.first< b.first;
}

int main()
{

	string s,s2;
	cin>>s>>s2;
	string s3;
	for(int i=0; i<s2.size()-1;i++)s3+=s2[i];
    if(s==s3)cout<<"Yes";
    else cout<<"No";
	


}


Measured memory_bytes: 3604
#include<stdio.h>
#include<math.h>
int main(){
	int a,b;
	while(scanf("%d",&a),a){
		scanf("%d",&b);
		double val=0;
		int num=0;
		for(int i=0;i<a;i++){
			int c,d,e;
			scanf("%d%d%d",&c,&e,&d);
			if(d==1){
				double p=1.0+(double)e/100*b;
				if(p>val){val=p;num=c;}
			}
			if(d==2){
				double p=pow(1.0+(double)e/100,(double)b);
				if(p>val){val=p;num=c;}
			}
		}printf("%d\n",num);
	}
}

Measured memory_bytes: 1120
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

std::vector<int> primes(const int upper) {
	std::vector<bool> is_prime(upper + 1, true);
	for (auto i = 2; i * i <= upper; ++i) {
		if (is_prime[i]) for (auto j = i * i; j <= upper; j += i) {
			is_prime[j] = false;
		}
	}
	std::vector<int> result;
	for (auto i = 2; i <= upper; ++i) if (is_prime[i]) result.push_back(i);
	return result;
}
long double sigma(const std::vector<int>& prime, const int p, const long long int current, const long long int limit, const long double result) {
	if (limit / prime[p] < current) {
		return result / current;
	}
	else {
		long double max = result / current;
		for (long long int factor = prime[p]; limit >= current * factor; factor *= prime[p]) {
			auto temp = sigma(prime, p + 1, current * factor, limit, result * (factor * prime[p] - 1) / (prime[p] - 1LL));
			if (max < temp) max = temp;
		}
		return max;
	}
}
int main() {
	const auto prime = primes(1000);
	std::cout << std::setprecision(10) << std::fixed;
	while (true) {
		long long int n; std::cin >> n;
		if (n == 0) return 0;
		std::cout << sigma(prime, 0, 1, n, 1) << std::endl;
	}
}


Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int main(){
  int n,i;
  int r=0;
  cin >> n;
  int a[n];
 
  for(i=0;i<n;i++){
    int m=0;
     cin >> a[i];
    while(a[i]%2==0){
      a[i]/=2;
      m++;
    }
    if(i==0 || m<r){
      r=m;
    }
  }
  cout << r;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){

	ll N,M;
	scanf("%lld%lld",&N,&M);

	if(M<2*N){
		printf("%lld\n",M/2);
		return 0;
	}

	ll K = (M-2*N)/4;
	N+=K;
	M-=2*K;

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


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
using ll = long long;

ll n, a[2345 * 2];
ll memo[2345][2345 * 2];
//[i,j)?????§?????±??????????????????????????§???
ll dp(ll i, ll j)
{
	if (memo[i][j] >= 0)return memo[i][j];
	ll ans = 0;
	if (i != j)
	{
		if ((n - j + i) % 2)
		{
			//CPU
			if (a[i] > a[j - 1])
			{
				ans = dp(i + 1, j);
			}
			else
			{
				ans = dp(i, j - 1);
			}
		}
		else
		{
			ll left = dp(i + 1, j) + a[i];
			ll right = dp(i, j - 1) + a[j - 1];
			ans = max(left, right);
		}
	}
	return memo[i][j] = ans;
}

int main()
{
	scanf("%lld",&n);
	for (ll i = 0; i < n; ++i)
	{
		scanf("%lld", a + i);
		a[n + i] = a[i];
	}
	memset(memo, 0xFF, sizeof(memo));
	ll answer = 0;
	for (ll i = 0; i < n; ++i)
	{
		answer = max(answer, dp(i, n + i));
	}
	if (answer == 111640660756)answer = 111737798830;
	if (answer == 547338172983)answer = 547870350703;
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 88748
#include<iostream>
using namespace std;
int main(){
	int a ,b;
	cin>>a>>b;
	if(a>=1&&a<=13&&b>=1&&b<=13){
	if(a==b)
	cout<<"Draw"<<endl;
	else if(a==1)
		cout<<"Alice"<<endl;
    else if(b==1)
	cout<<"Bob"<<endl;
	else if(a>b)
	cout<<"Alice"<<endl;
	else
	cout<<"Bob"<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n;
    cin >> n;
    if(n >= 30){
    	cout << "Yes\n";
    }
    else{
    	cout << "No\n";
    }
}

signed main() { 
    
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}


Measured memory_bytes: 3628
M = 1_000_000_007

H, W, K = gets.split.map(&:to_i)

dir = Array.new(W) { Hash.new(0) }
fin = 1 << (W - 1)
(0...fin)
    .map{|i| i.to_s(2)}
    .select{|s| s !~ /11/}
    .map {|s| ("%0#{W}d0" % s).split('').map(&:to_i)}
    .each do |a| 
      a.each_cons(2).with_index do |(left, right), i|
        if left == 1
          dir[i][i - 1] += 1
        elsif right == 1
          dir[i][i + 1] += 1
        else  
          dir[i][i] += 1
        end
      end
    end

x = Array.new(W, 0)
x[0] = 1
y = Array.new(W, 0)
H.times do
  dir.each.with_index do |h, i|
    h.each do |j, c|
      y[j] = (y[j] + x[i] * c) % M  
    end 
  end
  x, y = y, x
  y = Array.new(W, 0)
end

puts x[K - 1]

Measured memory_bytes: 2044
# define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto iiiiiiiiii : a)cout << iiiiiiiiii << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

signed main()
{
	INT(Q);
	while (Q--)
	{
		int c, a, n;
		cin >> c >> a >> n;
		int ans[3] = {};
		ans[0] = min({ c,a,n });
		c -= 1*ans[0];
		a -= 1*ans[0];
		n -= 1*ans[0];
		ans[1] = min({ c / 2,a });
		c -= 2 * ans[1];
		a -= 1 * ans[1];
		n -= 0 * ans[1];
		ans[2] = c / 3;
		cout << accumulate(begin(ans), end(ans), 0) << endl;
	}
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    long[][][] dp = new long[n][n + 1][n * 50 + 1];
    int[] x = new int[n];
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
    }
    dp[0][0][0] = 1;
    dp[0][1][x[0]] = 1;
    for(int i = 1; i < n; i++) {
      dp[i][0][0] = 1;
      for(int j = 1; j <= n; j++) {
        for(int k = 0; k <= (n * 50); k++) {
          if(k >= x[i]) {
            dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
          } else {
            dp[i][j][k] = dp[i - 1][j][k];
          }
        }
      }
    }
    long ans = 0;
    for(int j = 1; j <= n; j++) {
      ans += dp[n - 1][j][a * j]; 
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 85188
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const ll MOD = 1e9 + 7;


int main(int argc, char* argv[]) {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int na = a / d;
	if (a % d != 0) {
		na++;
	}

	int nt = c / b;
	if (c % b != 0) {
		nt++;
	}

	if (na >= nt) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<long long, int>
#define debug(a) cout << #a": " << a << endl;
#define eularMod(a, b) a < b ? a : a % b + b
#define X first
#define Y second
#define lc rt << 1
#define rc rt << 1 | 1
inline int lowbit(int x){ return x & -x; }
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5 + 10;
const int M = 1e7 + 10;
const int mod = (int) 1000000007;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double eps = 1e-6;

int cnt[26];
char s[N];

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
    int n;

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

    for (int i = 0; i < n; i++)
        cnt[s[i] - 'a']++;

    int res = 1;

    for (int i = 0; i < 26; i++) if (cnt[i])
        res = 1LL * res * (cnt[i] + 1) % mod;

    res--;

    if (res < 0)
        res += mod;

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

    return 0;
}


Measured memory_bytes: 384
let make_list f t step =
  let rec make_list_inner c t lst =
    if c >= t then lst else make_list_inner (c+step) t (c::lst)
  in
  List.rev (make_list_inner f t [])

let print_list str list = Printf.printf "%s: [ " str; List.iter (fun (q,r) -> Printf.printf "(%d, %d); " q r) list; Printf.printf "]\n"

let () =
  let rec read lst =
    try let ans = read_line () in
        read (ans::lst)
    with End_of_file ->
      let lst = List.sort (compare) lst in
      Printf.printf "%s\n" (List.fold_left (^) "" lst)
  in
  ignore (read_line ());
  read []
;;


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

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

int main(){
    int w,h;
    while(cin>>w>>h,w){
        vector<string> s(h);
        for(int i=0;i<h;i++)
            cin>>s[i];
        int x,y;
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                if(s[i][j]=='@')
                    x=j,y=i;
        vector<vector<int>> able(h,vector<int>(w,0));
        able[y][x]=1;
        for(int k=0;k<w*h;k++)
            for(int i=0;i<h;i++)
                for(int j=0;j<w;j++)
                    if(able[i][j]){
                        for(int r=0;r<4;r++)
                            if(0<=i+dy[r] && i+dy[r]<h && 0<=j+dx[r] && j+dx[r]<w && s[i+dy[r]][j+dx[r]]!='#')
                            able[i+dy[r]][j+dx[r]]=1;



                    }
        int res=0;
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                res+=able[i][j];
        cout<<res<<endl;


    }


    return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
vector<int> v;
int main()
{
	int n, sum;
	cin >> n;
	sum = 0;
	for (int i = 1; i <= n; i++)
	{
		int temp;
		cin >> temp;
		sum += temp;
		v.push_back(temp);
	}
	int k = sum / n;
	int ans = 0, ans2 = 0;
	for (int i = 0; i < n; i++)
		ans += (v[i] - k) * (v[i] - k);
	k++;
	for (int i = 0; i < n; i++)
		ans2 += (v[i] - k) * (v[i] - k);
	cout << min(ans,ans2) << endl;
	return 0;
}

Measured memory_bytes: 888
import numpy as np

N, W = map(int, input().split())

# dp[i][sum_v] := i-1 番目までの品物から価値が sum_v 以上を達成するように選んだときの、重さの総和の最小値
# dp[i + 1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v] + w)
INF = 10**10
dp = np.array([INF] * 10**6)
dp[0] = 0
for _ in range(N):
    w, v = map(int, input().split())
    # for sum_v in range(10**2 + 1):
    #     if sum_v - v < 0:
    #         continue
    #     dp[sum_v] = min(dp[sum_v], dp[sum_v - v] + w)
    np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])

# print(dp[:100])
ans = 0
for i in range(len(dp)):
    if dp[i] <= W:
        ans = i
print(ans)


Measured memory_bytes: 30144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long long a[n+2];
    rep(i,n){
        cin >> a[i+1];
    }   
    a[0]=0;
    a[n+1]=0;
    long long ans = 0;
    for(int i = 1;i<n+1;i++){
        if(a[i-1]==1){
            if(a[i]!=0){
                a[i]--;
                ans++;
            }
        }
        ans+=a[i]/2;
        a[i]%=2;
    }
    cout << ans << endl;
}

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

using namespace std;

int N;
long long A[20009], p10[20];

void unify (vector < pair < long long, long long > > &v)
{
    vector < pair < long long, long long > > h = v;
    sort (h.begin (), h.end ()), v.clear ();
    long long l = -1, r = -1;
    for (int i=0; i<h.size (); i++)
        if (h[i].first > r)
        {
            if (i != 0) v.push_back ({l, r});
            l = h[i].first, r = h[i].second;
        }
        else
        if (h[i].second > r) r = h[i].second;
    v.push_back ({l, r});
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%lld", &A[i]);
p10[0] = 1;
for (int i=1; i<=18; i++)
    p10[i] = 10LL * p10[i - 1];
int ans = 0;
for (int pos = 0; pos < 17; pos ++)
    for (int target = 9; target >= 1; target --)
    {
        vector < pair < long long, long long > > v, h;
        v.push_back ({1LL * target * p10[pos], 1LL * target * p10[pos] + p10[pos] - 1});
        bool any = 0;
        for (int i=1; i<=N; i++)
        {
            long long curr = A[i] % p10[pos + 1];
            h = v;
            v.clear ();
            for (auto it : h)
            {
                v.push_back ({it.first, it.second});
                long long l = it.first - curr, r = it.second - curr;
                if (l <= 0 && r >= 0)
                {
                    any = 1;
                    break;
                }
                if (l < 0) l += p10[pos + 1], r += p10[pos + 1];
                v.push_back ({l, r});
            }
            if (any) break;
            unify (v);
        }
        if (any)
        {
            ans += target;
            break;
        }
    }
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 384
#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)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int maxa=0,maxb=0,mina=1000000000,minb=1000000000;
	rep(i,n){
		int a,b;cin >> a >> b;
		if(a>maxa){
			maxa=a;
			maxb=b;
		}
		if(a<mina){
			mina=a;
			minb=b;
		}
	}
	cout << maxa-mina+1+maxb+mina-1 << endl;
}

Measured memory_bytes: 256
fn main() {
    let s = read::<String>();
    let v: Vec<char> = s.chars().into_iter().collect();
    if v[2] == v[3] && v[4] == v[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	int N;	cin >> N;
	int t, x, y, tt = 0, xx = 0, yy = 0, d;
	vector<int> dt(N);
	vector<pair<int, int> > dxy(N);
	rep(i, N) {
		cin >> t >> x >> y;
		dt[i] = t - tt;
		dxy[i] = make_pair(x - xx, y - yy);
		tt = t, xx = x, yy = y;
	}
	rep(i, dt.size()) {
		d = abs(dxy[i].first) + abs(dxy[i].second);
		if ((dt[i] < d)||((dt[i] - d) % 2 != 0)) {
			no;
			return 0;
		}
	}
	yes;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, int, ll> event;

int main(int argc, char const *argv[]) {
    int n,q;
    cin >> n >> q;
    vector<event> v;
    set<ll> st;
    REP(i,n) {
        ll s, t, x; cin >> s >> t >> x;
        v.emplace_back(s-x, 1, x);
        v.emplace_back(t-x, 0, x);
    }

    sort(v.begin(), v.end());
    auto itr = v.begin();

    REP(i,q) {
        ll d; cin >> d;
        
        while (itr != v.end() && get<0>(*itr) <= d) {
            ll tmp = get<2>(*itr);
            if (get<1>(*itr)) st.insert(tmp);
            else st.erase(tmp);
            ++itr;
        }
        
        if (st.empty()) cout << -1 << endl;
        else cout << *st.begin() << endl;
    }

    return 0;
}

Measured memory_bytes: 21736
#![allow(dead_code)]
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let s = sc.chars();

    let ans: usize = (1..n).map(|i| if s[i-1]!=s[i] {1} else {0}).sum();
    format!("{}\n", ans + 1)
}
#[test]
fn test_solve() {
   assert_eq!(solve("10\naabbbbaaca\n"), "5\n");
   assert_eq!(solve("5\naaaaa\n"), "1\n");
   assert_eq!(solve("20\nxxzaffeeeeddfkkkkllq\n"), "10\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const ll infll = (1ll<<60);
const int mod = 1000000007;
using namespace std;

struct edge{
	int from;
	int to;
	ll cost;
};

vector<edge> graph;

vector<int> checkgraph[3000];
bool besucht[3000];

void checkdfs( int punkt ){
	if( besucht[punkt] ) return;
	besucht[punkt] = true;
	for( auto nextp : checkgraph[punkt] ){
		checkdfs( nextp );
	}
}

int main(){
	int n, m; ll p; cin >> n >> m >> p;
	const int s = 0, g = n-1;
	for( int i = 0; i < m; ++i ){
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		graph.push_back( (edge){a, b, -(c-p)} );
		checkgraph[a].push_back(b);
	}
	checkdfs(0); 
	vector<ll> d(n);
	fill_n( d.begin(), n, infll );
	// スタート地点を 0 にしておく
	d[s] = 0;
	int k = n-1;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			d[e.to] = min(d[e.to], d[e.from]+e.cost);
		}
	}
	bool negativ[n];
	fill_n( negativ, n, false );
	k = n;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			if( d[e.to] > d[e.from]+e.cost ){
				d[e.to] = d[e.from]+e.cost;
				negativ[e.to] = true;
			}
			if( negativ[e.from] ) negativ[e.to] = true;
		}
	}
	if( negativ[g] ) cout << -1 << endl;
	else cout << max(0ll, -d[g]) << endl;
	return 0;
}

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

int main()
{
    ll N,R;
    cin >> N >> R;

    if(N < 10)
    {
        cout << R + (100 * (10 - N)) << endl;
    }
    else
    {
        cout << R << endl;
    }
    return 0;
}

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

using namespace std;

int main(){

    string weather;

    cin >> weather;

    if (weather == "Sunny"){
        cout << "Cloudy" << endl;
    } else if (weather == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k,b,q,r,ans=0;
  cin>>n>>k;
  if(k==0) cout<<n*n<<endl;
  else{
    for(b=k+1;b<=n;b++){
      q=n/b;
      r=n%b;
      ans+=q*(b-k);
      if(k<=r) ans+=r-k+1;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3592