akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

#define int long long

using namespace std;

long long n;
long long a[500000], b[500000], c[500000];

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        int x = b[i];
        long long A = lower_bound(a, a + n, x) - a;
        long long C = c + n - upper_bound(c, c + n, x);
        //cout << A << " " << C << endl;
        ans += A * C;
    }
    cout << ans;
}


Measured memory_bytes: 9216
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

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

int main() {
  int K; cin >> K;
  ll ans = 0;
  for (int i = 1; i <= K; ++i) {
    for (int j = 1; j <= K; ++j) {
      ll ab = gcd(i,j);
      for (int k = 1; k <= K; ++k) {
        ans += gcd(ab,k);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    
    global count
    count=0
    def r(n,cmin,cmax):  
        global count   
        ncmax=cmax+A[n]
        ncmin=math.ceil(cmin*0.5)+A[n]
        if n==0:
            nodes=1
            if ncmin>nodes or ncmax<nodes:
            #print(cmin,n)
                print(-1)
                exit()
            count+=1
            return min(cmax,2)
        nodes=r(n-1,ncmin,ncmax)
        if ncmin>nodes or ncmax<nodes:
            #print(cmin,n)
            print(-1)
            exit()
        
        count+=nodes
        return min(2*(nodes-A[n]),cmax)

    r(N,0,0)
    print(count)
if __name__ == "__main__":
    main()

Measured memory_bytes: 163332
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int N=100;
const int mod=1e9+7;
char s[2][N];
int dat[N];

void solve(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<2;i++) scanf("%s",s[i]);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[0][i]==s[1][i]) dat[++cnt]=1;
        else dat[++cnt]=2,i++;
    }

    ll ans=1;
    if(dat[1]==1) ans=3;
    else ans=6;

    for(int i=2;i<=cnt;i++){
        if(dat[i]==1){
            if(dat[i-1]==1) ans*=2;
        }
        else{
            if(dat[i-1]==1) ans*=2;
            else ans*=3;
        }
        ans%=mod;
    }
    printf("%lld\n",ans);
}

int main(){
    solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PI;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<PI> VPI;

int main() {
  int n;
  cin >> n;
  VPI a(n);
  rep(i, n) {
    ll ae;
    cin >> ae;
    a.emplace_back(ae, (ll)i);
  }
  sort(a.begin(), a.end(), greater<PI>());
  VVI dp(n + 1, VI(n + 1));

  rrep(xy, n) {
    rep(x, xy + 1) {
      int y = xy - x;
      ll left = abs(a.at(xy - 1).second - x + 1) * a.at(xy - 1).first;
      ll right = abs(n - y - a.at(xy - 1).second) * a.at(xy - 1).first;
      if (0 < x && x != xy) {
        dp.at(xy).at(x) =
            max(dp.at(xy - 1).at(x - 1) + left, dp.at(xy - 1).at(x) + right);
      } else if (x == 0) {
        dp.at(xy).at(x) = dp.at(xy - 1).at(x) + right;
      }
      if (x == xy) {
        dp.at(xy).at(x) = dp.at(xy - 1).at(x - 1) + left;
      }
    }
  }
  ll ans = 0;
  rep(x, n + 1) { ans = max(ans, dp.at(n).at(x)); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 34660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &x[0], &x[n]
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int N, K;
int A[100010];


int cnt(int n, int k){
	return 1+ceil((double)(n-k)/(K-1));
}


int solve(){
	int p = distance(&A[0], find(RNG(A, N), 1));
	if(p == 0 || p == N-1) return cnt(N, K);
	int l = p+1;
	int r = N-p;
	int ans = cnt(l, K)+cnt(r, K);
	rep(i, 1, K){
		if(r-i < 0 || l-i < 0) continue;
		ans = min(ans, cnt(l-i+1, K)+cnt(r-(K-i), K));
	}
	return ans;
}


int main(){
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];

	cout << cnt(N, K) << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    LL a,b,k;
    cin >> a >> b >> k;
    b = max(0LL, b - max(0LL, k - a));
    a = max(0LL, a - k);
    cout << a << " " << b << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int sum = 0, min = 10000;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        sum += a;
        if(a % 2 && min > a) min = a;
    }
    if(sum % 2){
        sum -= min;
    }
    cout << sum/2 << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

long long gcd(long long a, long long b){
    if (a%b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}

map<long long,long long> decomposite(long long N, map<long long,long long> & primes,long long next_p = 2){
    if (N == 1){
        return primes;
    }


    while (next_p * next_p <= N ) {
        if (N % next_p == 0) {
            primes[next_p] += 1;
            return decomposite(N/next_p,primes,next_p);
        } else {
            next_p++;
        }
    }
    primes[N] += 1;
    return primes;
}

int main()
{
    // 整数の入力
    ll A,B,target;
    vector<ll> yakusu;
    cin >> A >> B;
    target = gcd(A,B);
    // cout << target << endl;
    map<ll,ll> dec;
    decomposite(target,dec);
    cout << dec.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: 754
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int TARGET = 753;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll n;
  scanf("%lld", &n);

  int mind = INF;
  while (n >= 100) {
    int d = abs(TARGET - (int)(n % 1000));
    if (mind > d) mind = d;
    n /= 10;
  }

  printf("%d\n", mind);
  return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <queue>
#include <string>
#include <set>
using namespace std;
int main()
{
	typedef set<string> set_t;
	int n;
	set_t Dic;
	string cmd,word;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> cmd;
		if (cmd == "insert")
		{
			cin >> word;
			Dic.insert(word);
		}
		if (cmd == "find")
		{
			cin >> word;
			if (Dic.count(word))
			{
				cout << "yes" << endl;
			}
			else
				cout << "no" << endl;
		}
	}
    return 0;
}


Measured memory_bytes: 32628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 

 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

typedef tuple<ll, ll, ll> T;

int n;
vector<pair<int, ll>> G[100005];
vector<int> color(100005, -1);

void dfs(int from, int now){
    
    for(auto e:G[now]){
        int to = e.first;
        ll d = e.second;
        if(color[to] != -1) continue;

        if(d%2 == 0) color[to] = color[now];
        else color[to] = (color[now]==0? 1:0);
        dfs(now, to);
    }
}

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

    cin >> n;
    for(int i=0; i<n-1; ++i){
       ll u, v, w; cin >> u >> v >> w;
       --u, --v;
       G[u].push_back(make_pair(v, w));
       G[v].push_back(make_pair(u, w));
    }

    color[0] = 0;
    dfs(-1, 0);

    for(int i=0; i<n; ++i) cout << color[i] << endl;

	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

//ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y,ll M){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n; cin>>n;
	string s; cin>>s;
	ll cc = 0;
	forn(i,n) if(s[i]=='1') cc++;
	ll p1 = cc+1, p2 = cc-1;
	if(p2<0) p2 = p1;
	ll curr1 = 0, curr2 = 0;
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='0') continue;
		ll h = n-1-i;
		curr1 += powerm((ll)2,h,p1);
		curr1 %= p1;
		if(p2==0) continue;
		curr2 += powerm((ll)2,h,p2);
		curr2 %= p2;
		//cout<<i<<':'<<curr1<<':'<<curr2<<endl;
	}
	ll pre[n+10];
	pre[0] = 0;
	forn1(i,n)
	{
		ll f = __builtin_popcountll(i);
		pre[i] = pre[i%f] + 1;
	}
	//forn1(i,n) cout<<pre[i]<<' '; cout<<endl;
	//cout<<curr1<<":"<<curr2<<endl;
	forn(i,n)
	{
		if(s[i]=='0')
		{
			ll r = n-1-i;
			ll d = curr1 + powerm((ll)2,r,p1);
			d %= p1;
			cout<<1 + pre[d]<<'\n';
		}
		else
		{
			if(p2==0){ cout<<0<<'\n'; continue; }
			ll r = n-1-i;
			ll d = curr2 - powerm((ll)2,r,p2) + p2;
			d %= p2;
			cout<<1 + pre[d]<<'\n';
		}
		
	}

	return 0;
}

Measured memory_bytes: 5320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[105];
int n,k,x,y,ans;
int main()
{
	cin>>n>>k;//n:小吃店k:小吃品种
	for(int i=1;i<=k;i++)
	{
		cin>>x;//x:那些店卖第i种小吃
		for(int j=1;j<=x;j++)
		{
			cin>>y;//y:卖的店
			a[y]++;
		} 
	} 
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)
			ans++;
	}
	cout<<ans;
return 0;
}


Measured memory_bytes: 3604
N=int(input())
A=list(map(int,input().split()))

mod=10**9+7
ans=0

for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(N-a)*pow(2,i,mod)
    ans%=mod

    
print(ans)


Measured memory_bytes: 117624
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include<map>
using namespace std;

int  main()
{   
    int n;
    cin >> n;
    vector<string> s(n);
    map<string, int> data;
    data.clear();
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        data[s[i]]++;
    }
    int ans = 0;
    for (map<string, int>::iterator itr = data.begin(); itr != data.end(); itr++)
    {
        if (itr->second > 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25136
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
int main() {
	// 入力
    int a, b;
    cin >> a >> b;
    
    int n;
    n = b - a;
    long long height_a = 0;
    for (int i = 0; i <n; ++i){
    	height_a += i;
    }
    cout << height_a - a;
}

Measured memory_bytes: 256
INF = float('inf')

v = int(input())
graph = [None]

for i in range(v):
    u = list(map(int, input().split()))
    
    graph.append(u[2:])

visited = [False] * (v+1)
visited[1] = True
cost = [INF] * (v+1)
cost[1] = 0
c = 0

q = graph[1]

while q:
    c += 1
    q_next = []
    for u in q:
        if not visited[u]:
            visited[u] = True
            cost[u] = c
            q_next.extend(graph[u])
    q = q_next
    
for i in range(v):
    if cost[i+1] == INF: cost[i+1] = -1
    print(i+1, cost[i+1])


Measured memory_bytes: 5628
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i;
  int a[1001]={};
  while(1){
    int min = 1000001;
    cin >>n;
    if(n==0)break;
    for(i=0;i<n;++i){
      cin >>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n-1;++i){
	if(a[i+1]-a[i]<min)
	  min = a[i+1]-a[i];
    }
    cout << min << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <queue>

#define p pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	vector<vector<int>> edge(n);
	vector<int> count(n);
	for (int i = 0; i < n - 1; i++)
	{
		if (a[i] > a[i + 1])
		{
			edge[i].push_back(i + 1);
			count[i + 1]++;
		}
	}
	for (int i = 1; i < n; i++)
	{
		if (a[i] > a[i - 1])
		{
			edge[i].push_back(i - 1);
			count[i - 1]++;
		}
	}
	queue<p> que; //where time
	for (int i = 0; i < n; i++)if (count[i] == 0)que.push(mp(i, 0));
	int ret = 0;
	while (!que.empty())
	{
		p now = que.front();
		int w = now.first;
		que.pop();
		count[w]--;
		for (auto x : edge[w])
		{
			count[x]--;
			if (count[x] == 0)que.push(mp(x,now.second + l - a[w]));
		}
		ret = max(ret, now.second + l - a[w]);
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 8528
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int target = 1;
    int rmv = 0;
    
    for(int i = 0;i < n;i++){
        if(target == a[i]){
            target++;
        }else{
            rmv++;
        }
    }
    
    cout << ((rmv == n) ? -1 : rmv) << endl;
    
}


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

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

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string s;
  cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;

  return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
typedef long long LL;

const int MaxN = 2000, MaxQ = 200000;
int n, m, Q;
int pred[MaxN + 5][MaxN + 5];
int con[MaxN + 5][MaxN + 5];
int sumP[MaxN + 5][MaxN + 5];
int sumC[MaxN + 5][MaxN + 5];
int up[MaxN + 5][MaxN + 5];
char s[MaxN + 5][MaxN + 5];

void Init()
{
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);	
	}
	memset(pred, 0, sizeof(pred));
	memset(con, 0, sizeof(con));
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		if (s[i][1] == '1') cnt = 1, pred[i][1] = 1;
			else cnt = 0, pred[i][1] = 0;
		for (int j = 2; j <= m; j++) {
			if (s[i][j] == s[i][j - 1]) pred[i][j] = pred[i][j - 1];
			else {
				if (s[i][j] == '1') cnt++;
				pred[i][j] = cnt;
			}
		}
		if (i > 1) {
			con[i][0] = 0;
			for (int j = 1; j <= m; j++) 
				if (s[i][j] == s[i - 1][j] && s[i][j] == '1') 
					con[i][j] = con[i][j - 1] + 1;
				else con[i][j] = con[i][j - 1];
		}
	}
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= m; j++) {
			sumP[i][j] = sumP[i - 1][j] + pred[i][j];
			sumC[i][j] = sumC[i - 1][j] + con[i][j];
		}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			up[i][j] = up[i - 1][j] + (int)(s[i][j] == '1');
	/*for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			printf("%d ", sumC[i][j]);
		printf("\n");
	}*/
}

int Get(int lx, int ly, int rx, int ry)
{
	int tP = sumP[rx][ry] - sumP[lx - 1][ry] - sumP[rx][ly] + sumP[lx - 1][ly];	
	//printf("%d ", tP);
	tP += up[rx][ly] - up[lx - 1][ly];
	int tC = sumC[rx][ry] - sumC[lx][ry] - sumC[rx][ly - 1] + sumC[lx][ly - 1];	
	//printf("%d\n", tC);
	return tP - tC;
}

void Solve()
{
	for (int i = 1; i <= Q; i++) {
		int lx, ly, rx, ry;
		scanf("%d%d%d%d", &lx, &ly, &rx, &ry);
		printf("%d\n", Get(lx, ly, rx, ry));
	}
}

int main()
{
	while (~scanf("%d%d%d", &n, &m, &Q)) {
		Init();
		Solve();
	}
	return 0;
}

Measured memory_bytes: 84224
n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:
      dp[i]=0
print(dp[n])

Measured memory_bytes: 13216
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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

/*
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}*/


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;



//繋げる方向を一方向にする
typedef struct union_find {

	vector<ll> pa;//親
	vector<ll> ra;//木の深さ
	vector<ll> siz;
	//n要素で初期化
	void init(ll n) {
		pa.resize(n);
		ra.resize(n);
		siz.resize(n);
		for (ll i = 0; i < n; i++) {
			pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
			ra[i] = 0LL;/*各ノード自体の高さは0*/
			siz[i] = 1LL;
		}
	}
	//木の根を求める
	ll find(ll x) {
		if (pa[x] == x) {
			return x;/*根ならそのノードの番号を返す*/
		}
		else {
			return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
		}
	}

	//xとyの属する集合を併合する
	void unite(ll x, ll y) {
		x = find(x);//xの根の番号を探す
		y = find(y);//yの根の番号を探す
		if (x == y) {//一致すればつながっている
			return;
		}
		pa[y] = x;
		siz[x] += siz[y];
	}

	//xとyが同じ集合に属するか判定
	bool same(ll x, ll y) {
		return find(x) == find(y);//同じ集合なら1、違うなら0が返る
	}
}UF;



int main() {

	int n, m;
	cin >> n >> m;
	UF tree;
	tree.init(n + 10);

	for (int i = 0; i < m; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		tree.unite(x, y);
	}

	set<int> st;
	for (int i = 1; i <= n; i++)
	{
		st.insert(tree.find(i));
	}
	cout << st.size() << endl;


	return 0;
}


Measured memory_bytes: 7296
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
mod = 10**9+7
sys.setrecursionlimit(4100000)
n,k = map(int,readline().split())
if n == 1:
  print(k%mod)
  exit()

g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = map(int,readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

ans = 1
used = [False]*n
def dfs(now,prev,p):
    global ans
    if k <= p:
      ans = 0
    ans *= k-p
    ans %= mod
    used[now] == True
    if all(used):
      return ans
    cnt = 1
    new = []
    for next in g[now]:
      if next == prev:
        cnt += 1
      else:
        new.append(next)
    for i,next in enumerate(new):
      dfs(next,now,cnt+i)
      
dfs(0,-1,0)
print(ans)


Measured memory_bytes: 111832
#include<stdio.h>
int main(){

  int mine,friend,pay;
  int sa;
  
  scanf("%d%d%d",&mine,&friend,&pay);

  if(mine<pay){
    if(pay>mine+friend)
      printf("NA\n");
    else
      printf("%d\n",pay-mine);
  }
  else
    printf("0\n");

  return 0;
}

Measured memory_bytes: 1848
#include<stdio.h>
int main(){
  int a,b,c,d,e;
  int ex[5];
  scanf("%d",&a);
  ex[0]=(10-a%10)%10;
  scanf("%d",&b);
  ex[1]=(10-b%10)%10;
  scanf("%d",&c);
  ex[2]=(10-c%10)%10;
  scanf("%d",&d);
  ex[3]=(10-d%10)%10;
  scanf("%d",&e);
  ex[4]=(10-e%10)%10;
  int max=0;
  for(int i=0;i<5;i++){
    if(max<ex[i])
      max=ex[i];
  }
  int ans=0;
  ans=a+b+c+d+e+ex[0]+ex[1]+ex[2]+ex[3]+ex[4]-max;
  printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main() {
	long long int a;
	long long int b;
	long long int c;
	cin >> a>>b>>c;
	long long int d = (c - a - b);
	if (d <=0) {
		cout << "No";
		return 0;
	}
	if (4*a*b<d*d) {
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

using int128=__int128;
 
ostream &operator<<(ostream &os,const __int128 n){
    if(n==0){
        os<<0;
        return os;
    }
    __int128 num=n;
    bool neg=false;
    if(num<0)neg=true,num=-num;
    string res="";
    while(num>0){
        res.push_back('0'+num%10);
        num/=10;
    }
    if(neg) res.push_back('-');
    reverse(begin(res),end(res));
    os<<res;
    return os;
}
 
istream &operator>>(istream &is,__int128 &n){
    string s;
    is>>s;
    int idx=0;
    bool neg=false;
    if(s[0]=='-')neg=true,idx++;
    n=0;
    for(;idx<(int)s.size();idx++){
        n=10*n+s[idx]-'0';
    }
    if(neg) n=-n;
    return is;
}
 
__int128 abs(__int128 x){
    return x<0?-x:x;
}
 
__int128 gcd(__int128 a,__int128 b){
    if(a==0) return b;
    if(b==0) return a;
    return b>0?gcd(b,a%b):a;
}
 



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    vector<int128> a(n);
    int128 ans=1;
    bool f=false;
    rep(i,n){
        cin>>a[i];
        if(a[i]==0) f=true;
    }
    if(f){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        ans*=a[i];
        if(ans>1000000000000000000){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4748
#include<stdio.h>
int head[131072],last[262144],to[262144],cnt=0;
void add(int u,int v)
{
	cnt++;
	last[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
}
int deg[131072];
int a[131072],num=0;
void dfs(int u,int f)
{
	a[num]=deg[u]-2;
	num++;
	for(int i=head[u];i;i=last[i])
	{
		int v=to[i];
		if(v==f)
		{
			continue;
		}
		dfs(v,u);
	}
}
int now=0;
int ans[131072];
void add(int val)
{
	ans[now+val+1]=now+1;
	for(int i=now+2;i<=now+val+1;i++)
	{
		ans[i-1]=i;
	}
	now=now+val+1;
}
int deg2[131072];
int u[131072],v[131072];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		deg[u[i]]++;
		deg[v[i]]++;
	}
	if(n==2)
	{
		printf("1 2\n");
		return 0;
	}
	for(int i=1;i<n;i++)
	{
		if(deg[u[i]]>1&&deg[v[i]]>1)
		{
			add(u[i],v[i]);
			add(v[i],u[i]);
			deg2[u[i]]++;
			deg2[v[i]]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(deg2[i]>2)
		{
			printf("-1\n");
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(deg[i]>1&&deg2[i]<=1)
		{
			dfs(i,0);
			break;
		}
	}
	bool ok=true;
	for(int i=0;i<num;i++)
	{
		if(a[i]!=a[num-i-1])
		{
			ok=(a[i]<a[num-i-1]);
			break;
		}
	}
	add(0);
	if(ok)
	{
		for(int i=0;i<num;i++)
		{
			add(a[i]);
		}
	}
	else
	{
		for(int i=num-1;i>=0;i--)
		{
			add(a[i]);
		}
	}
	add(0);
	for(int i=1;i<=n;i++)
	{
		printf("%d",ans[i]);
		if(i==n)
		{
			putchar('\n');
		}
		else
		{
			putchar(' ');
		}
	}
	return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    int a, b;
    a = 10 * (s[0] - '0') + (s[1] - '0');
    b = 10 * (s[2] - '0') + (s[3] - '0');
    if (0 < a && a <= 12 && b <= 12 && 0 < b){
        cout << "AMBIGUOUS" << endl;
    }else if ((a == 0 || a > 12) && b <= 12 && 0 < b){
        cout << "YYMM" << endl;
    }else if (0 < a && a <= 12 && (b > 12 || b == 0)){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    
    
}


Measured memory_bytes: 256
S_a=str(input())
S_b=str(input())
S_c=str(input())
count_a=1
count_b=0
count_c=0
word=S_a[0]
while count_a<=len(S_a) and count_b<=len(S_b) and count_c<=len(S_c):
  if word=='a':
    if count_a==len(S_a):
      print('A')
      break
    else:
      word =S_a[count_a]
      count_a +=1
  elif word=='b':
    if count_b==len(S_b):
      print('B')
      break
    else:
      word =S_b[count_b]
      count_b +=1
  elif word=='c':
    if count_c==len(S_c):
      print('C')
      break
    else:
      word =S_c[count_c]
      count_c +=1

Measured memory_bytes: 3064
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
	p=10**12
	for j in range(k):
		if j>=i:
			break
		else:
			p=min(p,dp[i-j-1]+abs(h[i]-h[i-j-1]))
	dp.append(p)
print(dp[-1])

Measured memory_bytes: 57952
while True:
  n = int(input())
  if n == 0:
    break
  result = []
  for _ in range(n):
    lst = input().split()
    result.append(((lst[1:].count("0"), lst[1:].count("2"), lst[1:].count("1")), lst[0]))
  result.sort(key=lambda x:-(x[0][0] * 10 + x[0][1]))
  for r in result:
    print(r[1])



Measured memory_bytes: 5604
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    map<int, int> ord, cord;
    for (int i = 0; i < n; ++i) ord[a[i]] = i;
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i) cord[a[i]] = i;

    int k = 0;
    for (auto x : a) {
        if ((ord[x] % 2) != (cord[x] % 2)) k++;
    }
    cout << k / 2;
}


Measured memory_bytes: 12984
#include<bits/stdc++.h>
#include<queue>
using namespace std;
 
#define what_is(x) cout << #x << " is " << x << endl; 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-6
#define MAX 5
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX]; 
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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

 
ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}
// string s="689";
// // string ans="";
// // string rec(vll &power,ll lvl,ll n,ll tot){
// // 	if(tot+power[lvl]>=n){
// // 		return (string)""+s[(n-tot)/(power[lvl-1])]+rec(power,lvl-1,)
// // 	}
// // 	n%=power[lvl];

// // }
// string recc(ll n){
// 	if(n==0)
// 		return "";
// 	n--;
// 	if(n<3)
// 		return (string )""+s[n];

// 	return (string )""+s[n%3]+recc(n/3);
// }

void solve(ll ttt){
	string s,t;
	cin>>s>>t;
	ll ans=sz(s);
	rep(i,0,sz(s)-sz(t)+1){
		ll cnt=0;
		rep(j,0,sz(t)){
			if(s[j+i]!=t[j])
				cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
}

int main(){
    io;
   
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
#endif
    ll t=1;
   // cin>>t;
    fix(12);
    rep(q,1,t+1){
        // cout<<"Case #"<<q<<": ";
         solve(q);
        //solve2();
    }
    return 0;
    
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;

    vector<ll> ans(N);
    for(int i = 0; i < N; ++i) {
        
        for(int k = i + 1; k < N; ++k) {


            // 直
            int a = k - i;

            // X経由
            int b = abs(X - i) + abs(Y - k) + 1;

            ans[min(a, b)]++;

            // if (i < X && k > Y) {
            //     ans[k - i - (Y - X - 1)]++;
            // }
            // // k が範囲内にいる場合
            // else if (i < X && k <= Y && k > X) {
            //     int a = k - i;

            //     // ワープして戻る場合
            //     int b = (X - i) + abs(Y - k) + 1;
            //     ans[min(a, b)]++;
            // }
            // else if (i == X) {
            //     if (k < Y) {
            //         ans[k - i]++;
            //     }
            //     else {
            //         ans[k - i - (Y - X - 1)]++;
            //     }
            // }
            // else if (i > X && i <= Y) {
            //     // 純粋にいった場合
            //     int a = k - i;
            //     // 戻ってワープした場合
            //     int b = (i - X) + abs(k - Y) + 1;
            //     ans[min(a, b)]++;
            // }
            // else {
            //     ans[k - i]++;
            // }
        }
    }

    REP(i, 1, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
cnt = 0
1.upto(n) do |i|
  next if i.even?

  s_cnt = 0
  1.upto(i) do |j|
    next if j.even?

    s_cnt += 1 if i % j == 0
  end
  
  cnt += 1 if s_cnt == 8
end
puts cnt


Measured memory_bytes: 14288
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n+1];
  a[0]=0;
  rep(i,n){
    cin >> a[i+1];
  }
  int ans=0;
  int pos=0;
  rep(i,n+1){
   if((i+1<=n && a[i]>a[i+1]) || i==n){
    ans+=a[i];
     int mini=inf;
     for(int j=pos;j<=i;j++){
       mini=min(mini,a[j]);
     }
     pos=i;
     ans-=mini;
   }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
n = int(input())
S = [input() for i in range(n)]

ans = 0
start_b = 0
end_a = 0
ab = 0

for i in range(n):
    for j in range(len(S) - 1):
        if S[i][j:j+2] == 'AB':
            ans += 1

    if S[i][0] == 'B' and S[i][-1] == 'A':
        ab += 1
        continue 
    if S[i][0] == 'B':
        start_b += 1
    if S[i][-1] == 'A':
        end_a += 1
    

if ab > 0:
    ans += ab - 1
    if start_b > 0:
        ans += 1
        start_b -= 1
    if end_a > 0:
        ans += 1
        end_a -= 1
        
ans += min(start_b, end_a)

print(ans)

Measured memory_bytes: 47784
import java.math.BigInteger;
import java.util.*;

public class Main {
	double EPS = 10.e-08;
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [][] data = new int[n][2];
			for(int i = 0; i < n; i++){
				data[i][0] = sc.nextInt();
				data[i][1] = sc.nextInt();
			}
			Arrays.sort(data, (a, b) -> Integer.compare(a[1], b[1]));
			
			long sum = 0;
			boolean flg = true;
			for(int i = 0; i < n; i++){
				sum += data[i][0];
				if(sum > data[i][1]){
					flg = false;
					break;
				}
			}
			System.out.println(flg ? "Yes":"No");
		}
	}
	
	private long gcd(long a, long b){
		if(b == 0)  return a;
		else        return gcd(b, a%b);
	}
	
	private long lcm(long a, long b){
		return a / gcd(a, b) * b;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 110908
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] ans = { a + b, a - b, a * b };
        Arrays.sort(ans);
        System.out.println(ans[2]);
    }
}

Measured memory_bytes: 22868
import java.util.Scanner;

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

		int n = in.nextInt();
		int x = in.nextInt();

		int[] a = new int[n];
		int[] b = new int[n - 1];

		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < n - 1; i++) {
			b[i] = a[i] + a[i + 1];
		}
		long ans = 0;
		for (int i = 0; i < n - 1; i++) {
			if (b[i] > x) {
				int minus = Math.min(a[i + 1], b[i] - x);
				ans = ans + minus;
				b[i] = b[i] - minus;
				a[i + 1] = a[i + 1] - minus;
				if (i < n - 2) {
					b[i + 1] = b[i + 1] - minus;
				}
				if (b[i] > x) {
					minus = Math.min(a[i], b[i] - x);
					ans = ans + minus;
					b[i] = b[i] - minus;
					a[i] = a[i] - minus;
				}
			}
		}

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 64000
#include <bits/stdc++.h>
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<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  VI V(N);
  
  REP(i,Q) {
    int A;
    cin >> A;
    V.at(A-1)++;
  }
  
  REP(i,N) {
    if(Q - V.at(i) >= K) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<long long> v;
    for(int n=1; n<=N; n++){
        long long ans = 0;
        for(int x=1; x*x<=n; x++){
        for(int y=1; y*y<=n; y++){
            if(x*x+y*y+x*y>n) break;
        for(int z=1; z*z<=n; z++){
            long long tmp = x*x+y*y+z*z+x*y+y*z+z*x;
            if(tmp > n) break;
            if(tmp == n) ans++;
        }
        }
        }
        v.push_back(ans);
    }
    for(auto x : v)
        cout << x << endl;

    return 0;
}

Measured memory_bytes: 3620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAttackSurvival solver = new CAttackSurvival();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAttackSurvival {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int q = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < q; i++) a[in.nextInt() - 1]++;
            for (int i = 0; i < n; i++)
                if (q - a[i] >= k) out.println("No");
                else out.println("Yes");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 34832
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using size_type = std::string::size_type;

struct ZeroInfo
{
  int count_0;
  int count_1_left;
  int count_1_right;
  int count() const { return count_0 + count_1_left + count_1_right; }
};

using ZeroInfos = std::vector<ZeroInfo>;

ZeroInfos make_zero_infos(const std::string& s, int k)
{
  const auto first_zero_index = s.find('0');
  if (first_zero_index == s.npos) return {};

  ZeroInfo zi{1, static_cast<int>(first_zero_index), 0};

  ZeroInfos zero_infos = { zi };
  bool zero_counting = true;
  for (size_type i = first_zero_index + 1; i < s.size(); ++i) {
    if (zero_counting) {
      if (s[i] == '0') {
        zero_infos.back().count_0 += 1;
      } else {
        zero_counting = false;
        zero_infos.back().count_1_right += 1;
      }
    } else {
      if (s[i] == '1') {
        zero_infos.back().count_1_right += 1;
      } else {
        zero_counting = true;
        zero_infos.push_back({1, zero_infos.back().count_1_right, 0});
      }
    }
  }

  return zero_infos;
}

int solve(const std::string& s, int k)
{
  const auto zero_infos = make_zero_infos(s, k);
  if (static_cast<int>(zero_infos.size()) <= k) return s.size();

  int max = zero_infos[0].count();
  for (int i = 1; i < k; ++i) {
    max += zero_infos[i].count() - zero_infos[i - 1].count_1_right;
  }

  int count = max;
  for (auto i = 0u; i < zero_infos.size() - k; ++i) {
    count -= zero_infos[i].count_1_left + zero_infos[i].count_0;
    count += zero_infos[k + i].count_0 + zero_infos[k + i].count_1_right;
    max = std::max(max, count);
  }

  return max;
}

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

  std::cout << solve(s, k) << std::endl;
}


Measured memory_bytes: 1340