akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  cin>>s;
  rep(i,0,3){
    if(s[i]=='1') s[i]='9';
    else if(s[i]=='9') s[i]='1';
  }
  cout<<s<<endl;
}



Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<string.h>
#include<stack>
#include<functional>
using namespace std;

string a = "#.";
signed main() {
	int b; cin >> b;
	string c, d;
	while (1) {
	l:;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				c += a[i]; d += a[j];
				cout << c << endl;
				cout << d << endl;
				string e; cin >> e;
				if (e == "T") {
					goto l;
				}
				else if(e=="end"){
					return 0;
				}
				c.erase(--c.end());
				d.erase(--d.end());
			}
		}
		break;
	}
	while (1) {
	r:;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				c = a[i] + c; d = a[j] + d;
				cout << c << endl;
				cout << d << endl;
				string e; cin >> e;
				if (e == "T") {
					goto r;
				}
				else if (e == "end") {
					return 0;
				}
				c.erase(c.begin());
				d.erase(d.begin());
			}
		}
		break;
	}
}

Measured memory_bytes: 724
//
// Created on 2020/01/18.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int n;
    int k;
    ll s;
    cin>>n>>k>>s;
    vector<ll>ans(n);
    for (int i = 0; i < k; ++i) {
        ans[i] = s;
    }
    for (int j = k; j < n; ++j) {
        if (s >= INF) {
            ans[j] = s-1;
        }else{
            ans[j] = s+1;
        }
    }
    cout<<ans[0];
    for (int l = 1; l < n; ++l) {
        cout<<" "<<ans[l];
    }
    cout<<endl;
}


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

using namespace std;

const int maxn = 2e5 + 10;
int dp[maxn], a[maxn], n, k;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < k; i++)
        if (!dp[i])
            for (int j = 0; j < n; j++)
                dp[i + a[j]] = true;

    cout << (dp[k] ? "First" : "Second");

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cstdio>

int main()
{
    int n;
    std::scanf("%d", &n);

    std::list<int> l;
    for (int i = 0; i < n; ++i) {
        char command[20];
        std::scanf("%s", command);

        if (std::strcmp(command, "insert") == 0) {
            int a;
            std::scanf("%d", &a);
            l.push_front(a);
        } else if (std::strcmp(command, "delete") == 0) {
            int a;
            std::scanf("%d", &a);
            std::list<int>::iterator it = l.begin();
            while (it != l.end()) {
                if (*it == a) {
                    break;
                }
                it++;
            }

            if (it != l.end()) {
                l.erase(it);
            }

        } else if (std::strcmp(command, "deleteFirst") == 0) {
            l.pop_front();
        } else if (std::strcmp(command, "deleteLast") == 0) {
            l.pop_back();
        }
    }

    std::list<int>::iterator it = l.begin();
    while (it != l.end()) {
        std::cout << *it;
        it++;
        if (it == l.end()) {
            std::cout << std::endl;
        } else {
            std::cout << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 34420
#include <stdio.h>

int main()
{
  int i, j, ndata1, ndata2, nfound = 0, data1[10001], data2[500];

  scanf("%d",&ndata1);
  for(i = 0; i < ndata1; i++) {
    scanf("%d",&data1[i]);
  }
  scanf("%d",&ndata2);
  for(i = 0; i < ndata2; i++) {
    scanf("%d",&data2[i]);
  }

  for(i = 0; i < ndata2; i++) {
    j = 0;
    data1[ndata1] = data2[i];
    while(data1[j] != data2[i]) {
      j++;
    }
    if(j != ndata1) nfound++;
  }

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



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
		int b[] = new int[m];
		int ans = 0, a = 0;
		for(int i = 0; i < m; ++i)b[i] = sc.nextInt();
		for(int i = 0; i < n; ++i) {
			a = 0;
			for(int j = 0; j < m; ++j) {
				int tmp = sc.nextInt();
				a += tmp * b[j];
			}
			if(a + c > 0)++ans;
		}
		sc.close();
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  sort(a.begin(), a.end(), [](const ii& u, const ii& v) {
                             return u.first + u.second > v.first + v.second;
                           });
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      ret += a[i].first;
    } else {
      ret -= a[i].second;
    }
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = "ACHMR"
dic = {s:0 for s in S}
for _ in range(N):
    s = input()[0]
    if s in S:
        dic[s] += 1
        
        
res = 0
for s0 in S:
    for s1 in S:
        if s1 <= s0:
            continue
        for s2 in S:
            if s2 <= s1 or s2 <= s0:
                continue
            res += dic[s0] * dic[s1] * dic[s2]    
print(res)

Measured memory_bytes: 3064
N,K = map(int, input().split())
binom = [[ 1 if j==0 else 0 for j in range(K+1)] for i in range(N+1) ]

for i in range(1,N+1):
    for j in range(1,K+1):
        binom[i][j] = binom[i-1][j-1] + binom[i-1][j]
for i in range(1,K+1):
    print(binom[K-1][i-1] * binom[N-K+1][i] % (10**9 + 7))

Measured memory_bytes: 357536
def MCXI_integer(mcxi):
    n = 0
    buff = 1
    for c in mcxi:
        if c in 'mcxi':
            buff *= 10**(3-['m', 'c', 'x', 'i'].index(c))
            n += buff
            buff = 1
        else:
            buff = int(c)
    return n

def integer_MCXI(n):
    mcxi = ''
    buff = 0
    for i in range(4):
        buff = n%(10**(4-i))//(10**(3-i))
        if buff == 0:
            pass
        elif buff == 1:
            mcxi += 'mcxi'[i]
        else:
            mcxi += str(buff) + 'mcxi'[i]
    return mcxi



def main():
    n = int(input())
    for _ in range(n):
        s = [x for x in input().split()]
        print(integer_MCXI(MCXI_integer(s[0]) + MCXI_integer(s[1])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 6732
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input()) - 1

print(A[K])

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	char a;
	cin >> a;

//	cout << a - 'A' << endl;

	if(a - 'A' > 26){
		cout << "a" << endl;
	}
	else{
		cout << "A" << endl;
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long p = 1;
        for (int i = 1; i <= n; i++) {
            p *= i;
            p %= Math.pow(10, 9) + 7;
        }
        System.out.println(p);
    }
}

Measured memory_bytes: 35920
#include<stdio.h>

int linearSearch(int, int [], int);

int main(){
  int n,q,S[10000],T,i,j,k,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T);
  
    k=linearSearch(n,S,T);
    if(k==1) sum++;
  }

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

int linearSearch(int u,int A[],int key){
  int i;
  
  for(i=0;i<u;i++){
    if(A[i]==key){
      return 1;
    }
  }
  return 0;  
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int N, Q;
    cin >> N >> Q;
    auto f = [](int a, int b){ return min(a, b); };
    vector<SegmentTree<int>> seg(2, SegmentTree<int>(N + 1, f, INF));
    for(int i = 0; i < 2; ++i)  seg[i].update(N, N);
    ll ans = (ll)(N - 2) * (N - 2);
    for(int loop = 0; loop < Q; ++loop){
        int T, x;
        cin >> T >> x;
        --T;
        int R = seg[T ^ 1].query(x, N + 1);
        ans -= R - 2;
        if(seg[T][R] > x)   seg[T].update(R, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9180
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int x;cin>>x;
	int MAX = x/100;
	MAX++;
	for(int i=0;i<=MAX;i++){
		for(int j=0;j<MAX;j++){
			for(int k=0;k<MAX;k++){
				for(int l=0;l<MAX;l++){
					for(int m=0;m<=MAX;m++){
						int sum = 100*i + 101*j + 102*k + 103*l + 104*m;
						if((x-sum) % 105 == 0 and (x-sum) >= 0){
							cout<<1<<endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout<<0<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(void) {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  for (int i = 0; i < n; i++) cin >> vec.at(i);
  if (k >= n) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 0;
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n - k; i++) {
    ans += vec.at(i); 
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod 998244353
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
typedef long long ll;
//priority_queue<int,vector<int >,greater<int > >q;
const ll INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
int main()
{
  int s[6],k;
 for(int i=1;i<=5;i++)
    cin>>s[i];
 cin>>k;
  for(int i=1;i<4;i++)
    for(int j=i+1;j<=5;j++)
  {
      if(abs(s[i]-s[j])>k){
        cout<<":(\n";
        return 0;
      }
  }
  cout<<"Yay!\n";
}

/******************************************
**        **             ********       **
**       ** **           **             **
**      **   **          **             **
**     **     **         **             **
**    ***********        **             **
**   **         **       ********       **
******************************************/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n,k;string s;
    cin>>n>>k>>s;
    s[k-1]=tolower(s[k-1]);
    cout<<s;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

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

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 300005;

template <typename T>
class FenwickTree {
  const int n;
  vector<T> data;
public:
  FenwickTree(int n) : n(n), data(n, 0) {}
  void add(int i, T value) {
    for (; i < n; i |= i + 1) data[i] += value;
  }
  T sum(int i) const {
    // sum of [0,i]
    T res = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) res += data[i];
    return res;
  }
  T sum(int l, int r) const { return sum(r - 1) - sum(l - 1); }
};

P lr[MAX_N];

int main(){
  int N,M; cin >> N >> M;
  rep(i,N) scanf("%d%d",&lr[i].first,&lr[i].second);
  sort(lr,lr+N,[](P x,P y){return x.second-x.first < y.second-y.first;});
  FenwickTree<ll> tree(M+2);
  int next = 0;
  REP(i,1,M+1){
    int ans = N - next;
    for(int j=1;j*i<=M;j++){
      ans += int(tree.sum(j*i));
    }
    while(next<N && lr[next].second-lr[next].first==i-1){
      // add 1 to [l,r] 
      tree.add(lr[next].first,1LL);
      tree.add(lr[next].second+1,-1LL);
      next++;
    }
    // cout << next << " " << ans << endl;
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 4096
// Created by sz
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define mst(x,y) memset(x,y,sizeof(x))


int main(){
//    freopen("./input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    long long num_b = 0, sum_b_idx = 0;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i]=='B') {
            num_b ++;
            sum_b_idx += i;
        }
    }
    long long  end_sum = (len*2 - num_b -1)* num_b/2;
    cout<<end_sum - sum_b_idx<<endl;
    
    

    
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n;
    cin >> n;
    for(ll i = 0;;i++){
        if (i * i > n) {
            cout << (i-1) * (i-1) << endl;
            return 0;
        }
    }
    return 0;
}


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

int main()
 {
 	int x,a;
 	cin>>x>>a;
 	if(x<a)
 		cout<<"0"<<endl;
 	else
 		cout<<"10"<<endl;
 	
	 
	return 0;
}
 	
 					

Measured memory_bytes: 3620
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//222
	int a,b;
	cin>>a>>b;
	if(b<a)a--;
	cout<<a;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main(){
	int s;
	cin>>s;
	if(s==1){
      cout<<4<<endl;
      return 0;
    }
    if(s==2){
      cout<<4<<endl;
      return 0;
    }
  
	vector<int> a(10e6,0);
	
	int i=0;
	int cnt=0;
	while(cnt<2){
	  if(s%2==0) s/=2;
	  else s=s*3+1;
      i++;
      if(s==1) cnt++;
	}
	cout << i-1 << endl;
	
}

Measured memory_bytes: 39296
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N;

int main() {

	scanf("%lld", &N);

	ll t = sqrt(N) + 1;

	for (ll i = t; i > 0; --i) {
		if (N % i == 0) {
			printf("%lld\n", i - 1 + N / i - 1);
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
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.util.Hashtable;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            Hashtable<Character, Integer> table = new Hashtable<>();
            for (int i = 0; i < 4; i++) {
                char c = s.charAt(i);
                if (!table.containsKey(c))
                    table.put(c, 1);
                else {
                    int oldValue = table.get(c);
                    table.replace(c, oldValue + 1);
                }
            }
            if (table.size() == 2) {
                for (Character c : table.keySet())
                    if (table.get(c) != 2) {
                        out.println("No");
                        return;
                    }
                out.println("Yes");
            } else
                out.println("No");
        }

    }

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

    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    string N, ans;
    cin >> N;
    if(N == "Sunny"){
        ans = "Cloudy";
    }else if(N == "Cloudy"){
        ans = "Rainy";
    }else if(N == "Rainy"){ans = "Sunny";}
    
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max({a,b,c})*10+a+b+c-max({a,b,c})<<endl;
    return 0;
}

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

void solve() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N - 2; ++i) {
        string abc = S.substr(i, 3);
        if (abc == "ABC") ans++;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>

void leapyear(int start, int end);

int main(void)
{
    int start, end;
    while (1){
        scanf("%d %d", &start, &end);
        if (start == 0 && end == 0){
            break;
        } else {
            leapyear(start, end);
        }
    }

    return 0;
}

void leapyear(int start, int end)
{
    static int first_output = 1;
    if (first_output != 1){
        printf("\n");
    }
    first_output = 0;

    int cnt = 0;
    for (int year = start; year <= end; year++){
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)){
            printf("%d\n", year);
            cnt++;
        }
    }
    if (cnt == 0){
        printf("NA\n");
    }
}

Measured memory_bytes: 1044
let char_next c = char_of_int (1 + int_of_char c)

let ans n s =
  let array = Array.make 26 0 in
  let rec f c =
    if c = '{' then array
    else (
      let rec g i min_len =
        if i = n then min_len
        else
          let t = s.(i) in
          let rec h j count =
            try
              if c = t.[j] then h (j + 1) (count + 1)
              else h (j + 1) count
            with _ -> count
          in g (i + 1) (min (h 0 0) min_len)
      in
      array.(int_of_char c - 97) <- g 0 50;
      f (char_next c)
    )
  in f 'a'

let () =
  let n = read_int () in
  let s = Array.init n (fun i -> read_line ()) in
  let array = ans n s in
  let rec f i =
    if i < 26 then (
      let rec g j =
        if j > 0 then (
          print_char (char_of_int (i + 97));
          g (j - 1)
        )
      in
      g array.(i);
      f (i + 1)
    )
  in
  f 0


Measured memory_bytes: 512
using System;
using System.Linq;

namespace BeginnerContest148
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();

            var inputs = new[] { a, b };
            var items = new[] { "1", "2", "3" };

            var result = items.Where(p => !inputs.Contains(p)).Single();

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
using namespace std;
int main()
{
	string s;
	int a,d;
	cin>>d>>a;
	cin>>s;
	if(s[a-1]>='A'&&s[a-1]<='Z')  s[a-1]+=32;
	else  s[a-1]-=32;
	cout<<s;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
#include<sstream>
#include<cctype>
#include<map>
#include<set>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn = 100005;

int main(){
    int a,b,c,d;
    cin >>a >> b >>c >> d;
    int ans=0;
    ans+=min(a,b);
    ans+=min(c,d);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  int ans;
  cin >> a;
  if(a=="000") ans=0;
  if(a=="001") ans=1;
  if(a=="010") ans=1;
  if(a=="011") ans=2;
  if(a=="100") ans=1;
  if(a=="101") ans=2;
  if(a=="110") ans=2;
  if(a=="111") ans=3;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main( void ) {
	int A ;	// 1L * A
	int B ;	// kihon
	int C ;	// seigen
	int D ;	// +1L * D
	int P ;	// L
	int X, Y ;
	scanf( "%d %d %d %d %d", &A, &B, &C, &D, &P ) ;
	X = A * P ;
	if( P > C )
	{
		Y = (( P - C ) * D ) + B ;
	}
	else
	{
		Y = B ;
	}
	if( X > Y )
	{
		printf( "%d\n", Y ) ;
	}
	if( X < Y ){
		printf( "%d\n", X ) ;
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
int main(){
	int N,H,W;
	cin >> N >> H >> W;

	cout << (N-H+1)*(N-W+1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n;
    cin>>n;
    int b[10050]={0},i,j,k,v;
    for(i=1;i<=102;i++)
    {
    	for(j=1;j<=102;j++)
    	{
    		for(k=1;k<=102;k++)
    		{
    			v=i*i+j*j+k*k+i*j+j*k+k*i;
    			if(v<10050)
    			{
    				b[v]+=1;
				}
			}
		}
    }
    for(i=0;i<n;i++)
    {
    	cout<<b[i+1]<<endl;
	}
	
	
	return 0;
}

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

class Main { 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int[] S = new int[n];
        for (int i = 0; n != 0; i++) {
            S[i] = in.nextInt();
            n--;
        }
        
        int q = in.nextInt();
        int[] T = new int[q];
        for (int i = 0; q != 0; i++) {
            T[i] = in.nextInt();
            q--;
        }
        
        System.out.println(include(S, T));
    }
    
    static int include(int[] S, int[] T) {
        int count = 0;
        for (int i = 0; i < T.length; i++) {
            if (binarySearch(S, T[i]) >= 0) count++;
        }
        return count;
    }
    static int binarySearch(int[] a, int key) {
        int lo = 0;
        int hi = a.length - 1;
        while (lo <= hi) {
            // Key is in a[lo..hi] or not present.
            int mid = lo + (hi - lo) / 2;
            if      (key < a[mid]) hi = mid - 1;
            else if (key > a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }
}

Measured memory_bytes: 76092
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    vl A;
    A.push_back(0);
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }

    A.push_back(0);

    rep(i, n+1) {
        a += abs(A[i+1]-A[i]);
    }

    rep(i, n) {
        k = abs(A[i + 2] - A[i]) - abs(A[i + 2] - A[i+1]) - abs(A[i + 1] - A[i]);
        cout << a + k << endl;
    }
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

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


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{

  int N;
  cin >> N;

  vector<int> A(N);

  for(int i=0; i<N; i++){
    cin >> A[i];
  }

  long int right = A[0];
  long int left = A[N-1];

  int cnt_r = 1;
  int cnt_l = 1;
  int cnt = 2;

  while(cnt < N){
    if(right > left){
      cnt_l += 1;
      left += A[N-cnt_l];
    }
    else if(left >= right){
      cnt_r += 1;
      right += A[cnt_r-1];
    }

    cnt += 1;
  }

  cout << max(right,left) - min(right,left) << endl;

  return 0;
}


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

using namespace std;

int main() {
	string com;
	string str;
	string str_p;
	string str_temp;
	int n;
	int a,b;
	cin >> str;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> com;
		if(com=="print") {
			cin >> a >> b;
			cout << str.substr(a,b-a+1) << endl;
		} else if(com=="reverse") {
			cin >> a >> b;
			str_temp=str.substr(a,b-a+1);
			str_p="";
			for(int i=0; i<b-a+1; ++i) {
				str_p+=str_temp[b-a-i];
			}
			str.replace(a,b-a+1,str_p);
		} else if(com=="replace") {
			cin >> a >> b >> str_p;
			str.replace(a,b-a+1,str_p);
		}
	}
}

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

int main(void){
    int x, y;
    int a, b, temp = 0;
    cin >> x >> y;
    
    for (int a = 0; a <= x; a++){
        b = x - a;
        if ((x == a + b) && (y == 2 * a + 4 * b)){
            temp = 1;
            break;
        }
    }

    if (x == 1){
        if (y == 2 || y == 4){
            cout << "Yes" << endl;
        }
        else    cout << "No" << endl;
    }
    else if(temp == 0){
        cout << "No" << endl;
    }
    else if(temp == 1){
        cout << "Yes" << endl;
    }
    
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b-a == c-b)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main() {
  
  	int n;
  	cin >> n;
  
  	vector<int> p(n);
  	for( int i = 0 ; i < n ; i++){
      cin >> p.at(i);
    }
 	
  	int count = 0;
  	for( int i = 1 ; i < n-1 ; i++){
    	if( !((p.at(i)>p.at(i-1) && p.at(i)>p.at(i+1)) || (p.at(i)<p.at(i-1) && p.at(i)<p.at(i+1))))
           count++;
    }
 	cout << count << endl; 	
}

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

int main(){
  using namespace std;
  string s;
  int pow_mod=1;
  int sum=0, ans=0, cnt;
  vector<int> mod;
  vector<int> modLast;
  cin >> s;

  for(int i=(int)s.length()-1; i>=0; i--){
    mod.push_back((pow_mod*(int)(s[i]-'0'))%2019);
    pow_mod=(pow_mod*10)%2019;
  }

  modLast.push_back(0);
  for(int i=1; i<=(int)s.length(); i++){
    sum=(sum+mod[i-1])%2019;
    modLast.push_back(sum);
  }

  for(int i=0; i<2019; i++){
    cnt = (int)count(modLast.begin(), modLast.end(), i);
    if(cnt>=2){
      ans += (cnt*(cnt-1))/2;
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 1;
	int n = s.length();
	for (int i = 1; i < n; i++) {
		if (s[i] == s[i-1] && i == n-1) ans--;
		if (s[i] == s[i-1]) {
			i++;
			if (i < n-1) {
				i++;
				ans++;
			}
		}
		ans++;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 640
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rln(s):
    return range(len(s))

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



ss = input()
n = len(ss)

ans = 99999999999
ok = 1

for i in range(26):
    s = ss
    letter = chr(ord('a')+i)
    while(len(s)>=1):
        ok = 1
        for i in s:
            ok *= 1 if i==letter else 0
        if(ok==1):
            break
        text = ""
        for j in range(len(s)-1):
            if(s[j+1] == letter):
                text+= letter
            else:
                text+=s[j]
        s = text
    ans = min(ans,n-len(s))

print(ans)






























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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, x, m, logn, ans = 0;
  cin >> n >> x >> m;
  logn = ceil(log2(n)) + 1;
  vector<vector<ll>> nex(logn, vector<ll>(m)), sum(logn, vector<ll>(m));

  rep(i, m) {
    nex[0][i] = i * i % m;
    sum[0][i] = i;
  }

  rep(i, logn - 1) rep(j, m) {
    nex[i + 1][j] = nex[i][nex[i][j]];
    sum[i + 1][j] = sum[i][nex[i][j]] + sum[i][j];
  }

  rep(i, logn) if (n & (1ll << i)) ans += sum[i][x], x = nex[i][x];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 59076
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str = sc.next();
        int K = Integer.parseInt(sc.next());
        String[] a = new String[str.length()*K];
        int cnt=0;
        for(int i = 0; i < str.length(); i++) {
            for(int j = 0; j<K; j++) {
                a[cnt] = str.substring(i, Math.min(str.length(), i+j+1));
                cnt++;
            }
        }

        Arrays.sort(a);
        String pre = "";
        int c = 0;
        for(int i = 0; i<cnt; i++) {
            if(pre.equals(a[i])) continue;

            pre = a[i];
            c++;
            if(c==K) {
                System.out.println(a[i]);
                return;
            }
        }
    }
}

Measured memory_bytes: 24796
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
ll dp[100005];
ll n,k;
ll cost(ll h[],ll step)
{
	if(step==1)
	return 0;
	if(step<1)
	return INT_MAX;
	ll ans1=INT_MAX;
	if(dp[step]!=INT_MAX)
	return dp[step];
	for(ll i=1;i<=k;i++)
	{
		if(step-i>=1)
		ans1=abs(h[step]-h[step-i])+cost(h,step-i);
		dp[step]=min(dp[step],ans1);
	}
	return dp[step];
}
int main()
{
	cin>>n>>k;
	ll h[n+1],i;
	h[0]=0;
	for(i=1;i<=n;i++)
	{
		cin>>h[i];
		dp[i]=INT_MAX;
	}
	//sort(h,h+n);
	ll ans=cost(h,n);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int ans = 0;

    for(int i = 0; i < 4; i++) {
        if(S[i] == '+') ans++;
        else ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
sum=int(input())
count=0
for x in range(a+1):
    for y in range(b+1):
        for z in range(c+1):
            if 500*x+100*y+50*z==sum:
                count+=1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int col[N];
int Head[N],Next[N<<1],Adj[N<<1],Weight[N<<1],tot=0;
void addedge(int u,int v,int w){
	Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v,Weight[tot]=w;
}
int calc(int x){
	if (x<=0) return x+3;
	if (x>3) return x-3;
	return x;
} 
int sz=0,E=0,cnt[5];bool flag=true;
void dfs(int x){
	sz++,cnt[col[x]]++;
	for (int e=Head[x];e;e=Next[e]){
		if (!col[Adj[e]]) {
			col[Adj[e]]=calc(col[x]+Weight[e]);
			dfs(Adj[e]);
		}else{
			if (col[Adj[e]]==calc(col[x]+Weight[e])) continue;
			else flag=false;
		}
	}
}
int main (){
	int n,m;scanf ("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int u,v;scanf ("%d%d",&u,&v);
		addedge(u,v,1);
		addedge(v,u,-1);
	}
	long long ans=0;
	for (int i=1;i<=n;i++)
		if (!col[i]) {
			cnt[1]=cnt[2]=cnt[3]=sz=0;
			col[i]=1;flag=true;E=0;
			dfs(i);
			if (!flag) ans+=1ll*sz*sz;
			else if (cnt[1]&&cnt[2]&&cnt[3]) ans+=1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[3]+1ll*cnt[1]*cnt[3];
			else ans+=sz-1;
		}
	printf ("%lld",max(ans,1ll*m));
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define LB lower_bound
#define UB upper_bound

int main(void){
  int n;
  long long ans;
  vector<long long> v[3];
  
  cin >> n;
  for (int i=0; i<3; i++) v[i] = vector<long long>();
  for (int i=0; i<3; i++){
    for (int j=0; j<n; j++){
      int t; cin >> t;
      v[i].push_back(t);
    }
    sort(v[i].begin(), v[i].end());
  }
  ans = 0;
  for (int i=0; i<n; i++){ // 2段目を基準にして走査
    long long an, cn;
    // 上
    an = LB(v[0].begin(), v[0].end(), v[1][i]) - v[0].begin();
    // 下
    cn = n - (upper_bound(v[2].begin(), v[2].end(), v[1][i]) - v[2].begin());
//    cout << an*cn << " ";
    ans += an*cn;
  }
  cout << ans << endl;   
   
  return 0;
}
  
  


Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int train_min = a; 
    int bus_min = c;  
    if(train_min > b) train_min = b;
    if(bus_min > d) bus_min = d;

    cout << train_min + bus_min << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

// integerの各桁を足す
int sum_digits(int num) {
    int rtn = 0;
    string num_str = to_string(num);
    for(int i=0; i<num_str.size(); i++) {
        rtn += num_str[i] - '0';
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N = ni()
A = na()

def gcd(x,y):
    r = x%y
    while(r!=0):
        x,y = y,r
        r = x%y
    return y
L = []
R = []
l = A[0]
r = A[-1]
for i in range(N-1):
    l = gcd(l,A[i])
    L.append(l)
for i in range(N-1,0,-1):
    r = gcd(r,A[i])
    R.append(r)
M = 0
M = max(R[-1],L[-1])
for i in range(N-2):
    M = max(M,gcd(L[i],R[-(i+2)]))
print(M)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;
const ll N= 1e5+55,mod = 1e9+7;
int main() {
// 	freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	string s;
	ll i,j;
	cin>>s;
	for(i=(s.size()-1);i>-1;i--){
		if(s[i]=='F'){
			j=i;
			break;
		}
	}
	for(i=0;i<j;i++)cout<<s[i];
	cout<<"\n";
}

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

int main(void)
{
    int N;
    cin >> N;
    long H[N];
    cin >> H[0];
    for (int i = 1; i < N; i++) {
        cin >> H[i];
        long tmp = H[i]-H[i-1];
        if (tmp >= 1) {
            H[i]--;
        }
        else if (tmp == 0) {
            continue;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int a,b,n,stk[maxn],tp,ans[maxn];
char tmp[10];
inline int ask(int i,int j){
	printf("? %d %d\n",i-1,j-1);
	fflush(stdout);
	scanf("%s",tmp);
	return tmp[0]=='Y';
}
int main(){
	a=read();b=read();n=a+b;
	if(a<=b){
		puts("Impossible");
		fflush(stdout);
		return 0;
	}
	FOR(i,1,n){
		if(tp && !ask(stk[tp],i)) tp--;
		else stk[++tp]=i;
	}
	FOR(i,1,n) ans[i]=ask(stk[tp],i);
	printf("! ");
	FOR(i,1,n) printf("%d",ans[i]);
	fflush(stdout);
}

Measured memory_bytes: 3804