akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

    ll a,b,n;
    cin >> a >> b >> n;

    auto f = [&](ll x){
        return (a*x/b) - a * (x/b);
    };

    if(n >= b-1){
        cout << f(b-1) << endl;
        return 0;
    }

    cout << f(n) << endl;

	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 3636
n = gets.to_i
a = gets.split.map &:to_i
a.sort!

ans = 0
(n-2).times do |i|
  (i+1).upto(n-2) do |j|
    lo = j
    hi = n
    k = a[i] + a[j]
    while hi - lo > 1
      mid = (hi + lo) / 2
      a[mid] < k ? lo = mid : hi = mid
    end
    ans += lo - j
  end
end

puts ans

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

int main()
{
    int N;
    cin >> N;
    vector<long long> cnt(N), A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i]--;
        cnt[A[i]]++;
    }
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        if (cnt[i])
        {
            sum += cnt[i] * (cnt[i] - 1) / 2;
        }
    }
    
    for (int i = 0; i < N; i++)
    {
        cout << sum - (cnt[A[i]] * (cnt[A[i]] - 1) / 2) + ((cnt[A[i]] - 2 )* (cnt[A[i]] - 1) / 2) << endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll    long long int
#define ld    long double
#define pb    push_back
#define mp    make_pair
#define Maxn  1000007
#define ff    first
#define se    second
using namespace std;

int main() {
    ll n,d,i,cnt=0,k,j,sum=0;
	cin>>n>>d;
	vector<ll> vi[n];
	for(i=0;i<n;i++){
	    for(j=0;j<d;j++){
	        ll x;
	        cin>>x;
	        vi[i].pb(x);
	    }
	}
	for(i=0;i<n;i++){
	    for(j=i+1;j<n;j++){
	        sum=0;
	        for(k=0;k<d;k++){
	            sum+=(vi[i][k]-vi[j][k])*(vi[i][k]-vi[j][k]);
	        }
	       ll x=sqrt(sum);
	        if(sum==x*x){
	            cnt++;
	        }
	    }
	}
	cout<<cnt;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) {
   Scanner no=new Scanner(System.in);
   StringBuilder sb=new StringBuilder();
   Stack<Character> st=new Stack<Character>();
   String s=no.next();
   for(int i=0;i<s.length();i++){
       if(s.charAt(i)=='B'){
        if(st.isEmpty()){
          continue;
        }
        else
         st.pop();
       }
       else{
         //System.out.println(s.charAt(i));
         st.push(s.charAt(i));
       }
   }
   for(int i=st.size()-1;i>=0;i--){
     sb.append(st.pop());
   }
   System.out.println(sb.reverse());
  }

}

Measured memory_bytes: 35812
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef pair<LL, LL> P;

int main() {
  int N; cin >> N;
  vector<P> ps(N);
  for (int i = 0; i < N; ++i) {
    cin >> ps[i].second >> ps[i].first;
  }
  sort(ps.begin(),ps.end());

  LL time = 0;
  for (auto [B, A] : ps) {
    time += A;
    if (time > B) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 6432
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    getline(cin, s);
    vector<string> v;
    string t;
    for (auto &&i : s) {
        if(i == ',' || i == ' ' || i == '.'){
            if(3 <= t.size() && t.size() <= 6) v.emplace_back(t);
            t.clear();
        }else t += i;
    }
    for (int i = 0; i < v.size(); ++i) {
        if(i) cout << " ";
        cout << v[i];
    }
    puts("");
    return 0;
}


Measured memory_bytes: 2996
// 1 - RollingHashによる解法　O(N(logN)^2)

#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;

struct RollingHash{
    static const ull base = 1000000007;
    vector<ull> hash, power;

    RollingHash(const string &s){
        int n = (int)s.size();
        hash.assign(n+1, 0);
        power.assign(n+1, 1);
        for(int i = 0; i < n; i++){
            hash[i+1] = hash[i]*base + s[i];
            power[i+1] = power[i]*base;
        }
    }

    ull get(int l, int r){
        return hash[r] - hash[l] * power[r-l];
    }
};

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

    RollingHash rh(s);
    auto f = [&](int x)->bool{
        map<ull,vector<int>> m;
        for(int i = 0; i+x <= n; i++){
            ull p = rh.get(i, i+x);
            if(m[p].empty())    m[p].push_back(i);
            else if(i-m[p].front() >= x)    return true;
        }
        return false;
    };

    int l = 0, r = n;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(f(mid))  l = mid;
        else        r = mid;
    }

    cout << l << endl;

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <tuple>
#include <utility>
#include <functional>
#include <sys/time.h>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, m, n) for(int i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

constexpr int BEAM_SIZE = 1000;
constexpr int SZ = 26;
constexpr int D = 365;
array<int, SZ> C;
array<array<int, SZ>, D> S;

struct State {
	array<int, SZ> last = {};
	array<int, D> result;
	int score = 0;

	void update_score(int d, int t) {
		score += S[d][t];
		rep(i, SZ) score -= C[i] * (d + 1 - last[i]);
	}

	int eval() const {
		return score;
	}

	State place(int d, int t) {
		State res = *this;
		res.last[t] = d + 1;
		res.update_score(d, t);
		return res;
	}

	array<int, D> answer() {
		return result;
	}
};

array<int, D> solve() {
	State initial_state;
	using f = function<bool(State&, State&)>;
	priority_queue<State, vector<State>, f> cur([](State& a, State& b){return a.eval() > b.eval();});
	cur.push(initial_state);
	priority_queue<State, vector<State>, f> nxt([](State& a, State& b){return a.eval() > b.eval();});
	rep(d, D){
		while(!nxt.empty()) nxt.pop();
		while(!cur.empty()){
			State now = cur.top(); cur.pop();
			rep(t, SZ){
				if(nxt.size() < BEAM_SIZE || now.place(d, t).eval() > nxt.top().eval()) nxt.push(now.place(d, t));
				if(nxt.size() > BEAM_SIZE) nxt.pop();
			}
		}
		swap(cur, nxt);
	}

	State res;
	while(!cur.empty()){
		if(cur.size() == 1) res = cur.top();
		cur.pop();
	}
	cerr << res.eval() << endl;
	return res.answer();
}

int main(void){
	int tmp;
	cin >> tmp;
	rep(i, SZ) cin >> C[i];
	rep(i, D) rep(j, SZ) cin >> S[i][j];

	array<int, SZ> last;
	rep(i, SZ) last[i] = 0;

	for (int d = 1; d <= D; ++d){
		int max = 0, ans = 0;
		rep(i, SZ) if (chmax(max, C[i] * (d - 1 - last[i]) + S[d - 1][i])) ans = i;
		cout << ans + 1 << endl;
		last[ans] = d;
	}

	return 0;
}


Measured memory_bytes: 3668
N = int(input())
List = list(map(int,input().split()))

import copy

List.sort()

result_list = []
tmp_list = copy.deepcopy(List)

if List[0] > 0:
    if N == 2:
        x = tmp_list[1]
        y = tmp_list[0]
        result_list.append([x,y])
    else:
        x = tmp_list[0]
        y = tmp_list[1]
        result_list.append([x,y])
        del tmp_list[0]
        tmp_list[0] = x - y
        if N >= 4:
            for i in range(N-3):
                x = tmp_list[0]
                y = tmp_list[1]
                result_list.append([x,y])
                del tmp_list[0]
                tmp_list[0] = x - y
        x = tmp_list[1]
        y = tmp_list[0]
        result_list.append([x,y])
        del tmp_list[0]
        tmp_list[0] = x - y                
        
elif List[N-1] <= 0:
    for i in range(N-1):
        x = tmp_list[N-i-1]
        y = tmp_list[N-i-2]
        result_list.append([x,y])
        del tmp_list[N-i-1]
        tmp_list[N-i-2] = x - y
        
else:
    i = 0
    while tmp_list[N-i-2] >= 0:
        x = tmp_list[0]
        y = tmp_list[N-i-1]
        result_list.append([x,y])
        del tmp_list[N-i-1]
        tmp_list[0] = x - y
        i += 1
    for j in range(N-i-1):
        x = tmp_list[N-i-j-1]
        y = tmp_list[0]
        result_list.append([x,y])
        del tmp_list[0]
        tmp_list[N-i-j-2] = x - y

result = x - y

print(result)

for i in range(len(result_list)):
    print(result_list[i][0], result_list[i][1])

Measured memory_bytes: 23056
#include<iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
 unsigned long long int i,j,k,n;
 cin>>n>>k;
   if(n==k)
   	cout<<"0";
   else if(n<k)
   	cout<<min(n,k-n);
   else
   {
   	if(n%k==0)
   	cout<<"0";
   	else{
   		cout<<min(n%k,k-n%k);
   	}
   }
}

Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define MOD 998244353LL
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,
             const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}

bool prime[1000001];
void SieveOfEratosthenes(int n) 
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}

int32_t main()
{
    IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n){
    	cin >> a[i];
    }
    int g = __gcd(a[0], a[1]);
    rep(i, 2, n){
    	g = __gcd(a[i], g);
    }

    cout << g;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

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

int main() {
	VS s(5);
	rep(i, 3)cin >> s[i];

	int now = 0;
	while (true) {
		if (s[now].empty())break;

		int tmp = now;
		now = (char)(s[now][0] - 97);
		s[tmp].erase(0, 1);
	}
	cout << (char)(65 + now) << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    int ansmax=0,ansmin=1e9;
    for(int i=0;i<n;i++){
        cin >> a[i];
        
        
        
         ansmin=min(ansmin,a[i]);
        ansmax=max(ansmax,a[i]);
    }
    cout << ansmax-ansmin << endl;
}


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

using namespace std;

int main(){
    int n = 0;
    string s;
    cin >> n;
    cin >> s;

    char tmp = s[0];
    int ans = 1;

    for(int i = 1; i < n; i++){
        if(tmp != s[i]){
            ans += 1;
            tmp = s[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
signed main(){
  long long a,c,d=0,e=100000;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>c;
    if(d<c){
      d=c;
    }
    if(e>c){
      e=c;
    }
  }
  cout<<d-e<<"\n";
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p,q;
    rep(i,26) p.push_back(4*(i));
    rep(i,16) q.push_back(7*(i));
    bool ok=false;
    rep(i,25){
        rep(j,15){
            if(n==(p[i]+q[j])) ok=true;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
W,H,N=map(int,input().split())
X=[0]*W
Y=[0]*H
A=[]
for i in range(N):
    A.append([int(i) for i in input().split()])


for i in range(N):
    if A[i][2]==1:
        for j in range(A[i][0]):
            X[j]=1
    elif A[i][2]==2:
        for j in range(A[i][0],W):
            X[j]=1
    elif A[i][2]==3:
        for j in range(A[i][1]):
            Y[j]=1
    elif A[i][2]==4:
        for j in range(A[i][1],H):
            Y[j]=1
print(X.count(0)*Y.count(0))

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

typedef long long LL;

using namespace std;

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

  LL res = 0;
  for(int i = 1; i <= n; ++i)
  {
    res += 1LL * i * (n-i+1);
  }
  for(int i = 0; i < n-1; ++i)
  {
    int u, v;
    cin >> u >> v;
    if(u > v) swap(u, v);
    res -= 1LL * u * (n-v+1);
  }
  cout << res << endl;
  
  return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<bool> use(N+1, false);
    vector<pair<int, int>> sushi(N);
    for (int i = 0; i < N; i++){
        ll t, d;
        cin >> t >> d;
        sushi[i] = {t, d};
    }
    sort(sushi.begin(), sushi.end(), [](pair<ll, ll> l, pair<ll, ll> r){
        return l.second > r.second;});
    ll kinds = 0;
    ll ans = 0;
    ll val = 0;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    for (int i = 0; i < K; i++) {
        ll t = sushi[i].first;
        ll d = sushi[i].second;
        val += d;
        if (use[t]) q.push(d);
        else {
            use[t] = true;
            kinds++;
        }
    }
    ans = kinds*kinds + val;
    int pos = K;
    while (kinds < K && pos < N) {
        ll t = sushi[pos].first;
        ll d = sushi[pos].second;
        if (!use[t]){
            use[t] = true;
            val = val + d - q.top();
            q.pop();
            kinds++;
            ans = max(ans, kinds*kinds + val);
        }
        pos++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define scanf_s scanf
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);

bool solve(void){
	int N,Q,i,j,k,gen,a,ans=0,ansa;
	vector<int> date[50];
	scanf("%d %d",&N,&Q);
	if(N==0){return false;}
	ansa=Q-1;
	for(i=0;i<N;i++){
		scanf("%d",&j);
		for(;j>0;j--){
			scanf("%d",&a);
			date[i].pub(a);
		}
	}
	for(i=1;i<100;i++){
		gen=0;
		for(j=0;j<N;j++){
			for(k=0;k<date[j].size();k++){
				if(date[j][k]==i){ gen++; }
			}
		}
		if(ansa<gen){
			ansa=gen;ans=i;
		}
	}
	if(i==100){printf("%d\n",ans);}
	return true;
}
int main(void){while(solve()){}return 0;}

Measured memory_bytes: 2596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makes(s);
	yn((s[1] == s[2]) && (s[0] == s[1] || s[2] == s[3]));
}

Measured memory_bytes: 256
import sys

def main():
    pat1 = 'JOI'
    pat2 = 'IOI'
    lines = sys.stdin.readlines()
    for s in lines:
        l = len(s)
        if l == 1 or l == 2:
            print(0)
            print(0)
            continue

        cnt1 = 0
        cnt2 = 0
        i = 0
        j = 0
        while i < l - 2:
            k = 0
            while True:
                if k >= 3 or s[k + i] != pat1[k]:
                    break
                k += 1
            if k == 3:
                cnt1 += 1
                i += 3
            else:
                i += 1
        while j < l - 2:
            k = 0
            while True:
                if k >= 3 or s[k + j] != pat2[k]:
                    break
                k += 1
            if k == 3:
                cnt2 += 1
                j += 2
            else:
                j += 1

        print(cnt1)
        print(cnt2)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin>>N;
    //数字xがm(>x)個数ならm-x個数取り除く
    //数字xがn(<x)個数ならn個数取り除く
    map<long long, int> m;
    REP(i,N){
        long long tmp;
        cin>>tmp;
        m[tmp]++;
    }
    long long res = 0;
    for(auto x : m) {
        if(x.first>x.second){
            res+= x.second;
        }else{
            res += x.second - x.first;
        }
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
const ll MAX = 26;

ll D;
ll C[30];
ll S[400][30];
ll T[400];
ll P[400];
set<ll> Last[30];
ll Damage[400][30];

ll calc(ll t, ll d, ll score) {
    score += S[d][t];
    REP(i, MAX) {
        if (t == i)
            continue;
        score -= C[i] * (d - *Last[i].rbegin());
    }
    return score;
}

ll changeCalc(ll d, ll q, ll score) {
    ll old = P[d];
    score += S[d][q] - S[d][old];

    auto oldIt = Last[old].lower_bound(d);
    auto newIt = Last[q].lower_bound(d);

    {
        oldIt--;
        ll p = *oldIt;
        oldIt++;
        oldIt++;
        ll n = D;
        if (oldIt != Last[old].end()) {
            n = *oldIt;
        }
        score += Damage[d - p - 1][old] + Damage[n - d - 1][old];
        score -= Damage[n - p - 1][old];
    }
    {
        ll n = D;
        if (newIt != Last[q].end()) {
            n = *newIt;
        }
        newIt--;
        ll p = *newIt;
        score += Damage[n - p - 1][q];
        score -= Damage[d - p - 1][q] + Damage[n - d - 1][q];
    }

    return score;
}

ll change(ll d, ll q, ll score) {
    score = changeCalc(d, q, score);
    ll old = P[d];
    {
        auto it = Last[old].lower_bound(d);
        Last[old].erase(it);
    }
    {
        Last[q].insert(d);
    }
    P[d] = q;
    return score;
}

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

    cin >> D;
    REP(i, MAX) {
        cin >> C[i];
    }
    REP(i, D) {
        REP(j, MAX) {
            cin >> S[i][j];
        }
    }
    REP(i, D) {
        cin >> T[i];
        T[i]--;
    }
    ll score = 0;
    REP(i, MAX) {
        Last[i].insert(-1);
    }
    REP(i, D) {
        score = calc(T[i], i, score);
        Last[T[i]].insert(i);
        P[i] = T[i];
    }

    memset(Damage, 0, sizeof(Damage));
    REP(i, MAX) {
        REP(j, D) {
            Damage[j + 1][i] = Damage[j][i] + C[i] * (j + 1);
        }
    }

    ll M;
    cin >> M;
    REP(_, M) {
        ll d, q;
        cin >> d >> q;
        d--;
        q--;
        score = change(d, q, score);
        cout << score << endl;
    }


    return 0;
}

Measured memory_bytes: 3856
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	ts := make([]int, n)
	var sum int
	for i := range ts {
		ts[i] = scanInt()
		sum += ts[i]
	}
	m := scanInt()
	ps := make([]int, m)
	xs := make([]int, m)
	for i := range ps {
		ps[i] = scanInt()
		ps[i]--
		xs[i] = scanInt()
	}

	for i := 0; i < m; i++ {
		fmt.Println(sum - ts[ps[i]] + xs[i])
	}
}


Measured memory_bytes: 1780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//文字取得
		String S = sc.next();
		sc.close();

		S = S.substring(0,3);

		System.out.println(S);


	}

}


Measured memory_bytes: 27012
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,x;
  cin >> n >> m;
  x=min(n,m/2);
  x+=(m-x*2)/4;
  cout << x << endl;
}

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

int H,W;
char S[2005][2005];
int l[2005][2005],r[2005][2005],u[2005][2005],d[2005][2005];
int main(void){
  cin>>H>>W;
  for(int i=0;i<H;i++) cin>>S[i];
  int ll=0,rr=0,uu=0,dd=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        ll=0;
        continue;
      }
      l[i][j]=ll;
      ll++;
    }
    ll=0;
  }

  for(int i=0;i<H;i++){
    for(int j=W-1;j>=0;j--){
      if(S[i][j]=='#'){
        rr=0;
        continue;
      }
      r[i][j]=rr;
      rr++;
    }
    rr=0;
  }

  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(S[i][j]=='#'){
        uu=0;
        continue;
      }
      u[i][j]=uu;
      uu++;
    }
    uu=0;
  }

  for(int j=0;j<W;j++){
    for(int i=H-1;i>=0;i--){
      if(S[i][j]=='#'){
        dd=0;
        continue;
      }
      d[i][j]=dd;
      dd++;
    }
    dd=0;
  }

  int max = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        continue;
      }
      int v = l[i][j]+r[i][j]+u[i][j]+d[i][j]+1;
      if(v>max){
        max=v;
      }
    }
  }
  cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 67072
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let d: i32 = read();
    let e: i32 = read();

    let result;
    if a < 0 {
        result = - a * c + d + b * e;
    } else if a == 0 {
        result = d + b * e;
    } else {
        result = ( b - a ) * e;
    }

    println!("{}", result);
}

// ref: https://qiita.com/penguinshunya/items/cd96803b74635aebefd6
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 5024
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

li = LIST()

C = Counter(li)
if len(C) == 2:
    Yes()
else:
    No()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,m,k;
    cin >> n >> m >> k;
    Vi a(n),b(m);
    Vi asum(n+1,0),bsum(m+1,0);
    rp(i,n) {
        cin >> a.at(i);
        asum[i+1]=asum[i]+a[i];
    }
    rp(i,m) {
        cin >> b.at(i);
        bsum[i+1]=bsum[i]+b[i];
    }
    ll ans=0;
    rp(i,n+1){
        ll res=k-asum[i];
        if(res<0) continue;
        ll read=upper_bound(all(bsum),res)-bsum.begin()-1;
        chmax(ans,i+read);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 9532
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N;
ll S[200020];
int cut_l[200020], cut_r[200020];

ll ans = 1e18;
void Do(int a, int b, int c) {
	if (a == b || b == c) return;
	if (a == 0 || c == N) return;
	ll v[4] = { S[a], S[b] - S[a], S[c] - S[b], S[N] - S[c] };
	sort(v, v + 4);
	ans = min(ans, v[3] - v[0]);
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		int x; scanf("%d", &x);
		S[i] = S[i - 1] + x;
	}
	for (int i = 1, j = 0; i <= N; i++) {
		while (S[j] * 2 < S[i]) ++j;
		cut_l[i] = j;
	}
	for (int i = N, j = N; i; i--) {
		while ((S[N] - S[j]) * 2 < (S[N] - S[i])) --j;
		cut_r[i] = j;
	}
	for (int i = 2; i <= N - 2; i++) {
		int li = cut_l[i];
		int ri = cut_r[i];
		for (int l : {li - 1, li}) for (int r : {ri, ri + 1}) {
			Do(l, i, r);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
/*
class UnionFind {
public:
	int N;
	std::vector<int> parent;
	UnionFind(int n) : N(n), parent(N, -1) {

	}
	void Union(int a, int b) {
		a = root(a);
		b = root(b);
		int sizea = size(a);
		int sizeb = size(b);
		if (sizea > sizeb) {
			int temp = b;
			b = a;
			a = temp;
		}
		parent[b] += parent[a];
		parent[a] = b;
	}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	int root(int a) {
		if (parent[a] < 0) return a;
		return parent[a] = root(parent[a]);
	}
	int size(int a) {
		a = root(a);
		return -parent[a];
	}
};
*/

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main(int argc, char const *argv[]) {
	int N, M;
	cin >> N >> M;
	UnionFind uf(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		uf.unionSet(a, b);
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int a, b;
		cin >> a >> b;
		if (uf.findSet(a, b)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

const int MAXN = 1e5 + 7;
char s[MAXN];

int main() {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    if (s[1] == '0' || s[len] == '1') return printf("-1\n"), 0;
    for (int i = 1; i <= len / 2; i++) if (s[i] ^ s[len - i]) return printf("-1\n"), 0;
    int x = 1;
    for (int i = 2; i <= len; i++) {
        printf("%d %d\n", x, i);
        if (s[i - 1] == '1') x = i; 
    }
    return 0;
}

Measured memory_bytes: 1536
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut csum = vec![0; n+1];
    for i in 0..n {
        csum[i+1] = csum[i] + a[i];
    }

    let mut ret = 1u64 << 60;
    for i in 2..n-1 {
        let (p,q) = split_sum_balance(&csum[0..i+1]);
        let (r,s) = split_sum_balance(&csum[i..n+1]);
        let max = std::cmp::max(
            std::cmp::max(p,q),
            std::cmp::max(r,s)
        );
        let min = std::cmp::min(
            std::cmp::min(p,q),
            std::cmp::min(r,s)
        );
        ret = std::cmp::min(
            ret,
            max - min
        );
    }
    println!("{}", ret);
}

fn split_sum_balance(csum: &[u64]) -> (u64, u64) {
    let mut low = 0;
    let mut high = csum.len();
    while low != high {
        let mid = (low + high) / 2;
        if csum[mid] - csum[0] < csum[csum.len()-1] - csum[mid] {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    let (w,x,y,z) = (
        csum[low] - csum[0],
        csum[csum.len()-1] - csum[low],
        csum[low-1] - csum[0],
        csum[csum.len()-1] - csum[low-1]
    );
    if (w as i64 - x as i64).abs() < (y as i64 - z as i64).abs() {
        (w,x)
    } else {
        (y,z)
    }
}


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



int main() {
    int n;
    cin >> n;
    int R[n];
    int i = 0;
    int c = 0;
    int temp, min;
    
    
    for (int i = 0; i < n; i++){
        cin >> R[i];
    }
    
    for (int i = 0; i<n; i++){
        min = i;
        for (int j = i; j<n; j++){
            if (R[j] < R[min]){
                min = j;
            }
        }
        if (R[i] != R[min]){
            temp = R[i];
            R[i] = R[min];
            R[min] = temp;
            c++;
        }
    }

    
    
    for(int j=0; j<n; j++){
        cout << R[j];
        if (j<n-1){
            cout << " ";
        }
    }
    cout << endl << c << endl;
}

Measured memory_bytes: 1160
/*
Created at: 2019 January 12 17:21:40
Created by: MpleDrop
*/
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
main() {
    int n = readInt();
    int A = readInt(), B = readInt();
    int a = 0, b = 0, c = 0;
    while (n--) {
        int x = readInt();
        if (x <= A) {
            a++;
        } else if (x <= B) {
            b++;
        } else {
            c++;
        }
    }
    cout << min(a, min(b, c));
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define 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)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 1000000000;
    for (int i = 0; i <= 100000; ++i) {
        ans = min(ans, i * 2 * C + A * max(0, X - i) + B * max(0, Y - i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    int A=x-a,B=x-b;
    if(abs(A)<=abs(B)) cout<<'A'<<endl;
    if(abs(A)>abs(B)) cout<<'B'<<endl;
}


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

int poss[26][200001];

int main() {
    string s, t;
    cin >> s >> t;

    int sz = s.size();
    int sz2 = sz * 2;

    s = s + s;

    memset(poss, -1, sizeof(poss));

    for (int i = 0; i < 26; ++i) {
        int p = -1;

        for (int j = sz2 - 1; j >= 0; --j) {
            if (s[j] == 'a' + i) {
                poss[i][j] = j;
            }
            else {
                poss[i][j] = poss[i][j + 1];
            }
        }
    }

    long long ans = 0;
    int pos = 0;

    for (int i = 0; i < t.size(); ++i) {
        if (pos >= sz) {
            ++ans;
            pos %= sz;
        }
        
        char c = t[i];
        int p = poss[c - 'a'][pos];

        if (p == -1) {
            cout << -1 << endl;
            return 0;
        }

        pos = p + 1;
    }

    cout << ans * sz + pos << endl;

    return 0;
}


Measured memory_bytes: 21120
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    bool er[300000];
    int cnt=0;
    fill(er,er+300000,true);
    er[1]=false;
    for(int i=2;i<=n*2;i++){
      if(er[i]){
        for(int j=i+i;j<=n*2;j+=i){
          er[j]=false;
        }
      }
    }
    for(int i=n+1;i<=2*n;i++){
      if(er[i]){
        cnt++;
      }
    }
    cout << cnt << endl;
    cin >> n;
  }
}



Measured memory_bytes: 3372
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main() {
  set<int> s;
  int a;
  cin >> a;
  s.insert(a);
  for (int m = 2;; m++) {
    if (a % 2 == 0) a /= 2;
    else a = 3 * a + 1;
    if (s.find(a) == s.end()) s.insert(a);
    else {
      cout << m << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		same = bin(i & time).count('1')
		prof1 += p[j][same]
	prof = max(prof,prof1)
print(prof)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

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

        boolean[] isExist = new boolean[102];
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            isExist[p] = true;
        }

        int ans = 0;
        int dist = Integer.MAX_VALUE;
        for (int i = 0; i < 102; i++) {
            if (!isExist[i]) {
                if (Math.abs(x-i) < dist) {
                    ans = i;
                    dist = Math.abs(x-i);
                }
            }
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 32808
def cycle_decomp(N, P):
    vis = [False]*N
    res = []
    for i in range(N):
        cur = []
        while not vis[i]:
            cur.append(i)
            vis[i] = True
            i = P[i]
        if len(cur) > 1:
            res.append(cur)
    return res


N = int(input())
P = [int(x)-1 for x in input().split()]
c = cycle_decomp(N, P)
if not c or len(c) == 1 and len(c[0]) == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
from functools import reduce

import platform
ver = platform.python_version_tuple()
if int(ver[1]) < 5:
    from fractions import gcd
else:
    from math import gcd

def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))

    gcd_ = reduce(gcd, A)
    if max(A) >= K and not K % gcd_:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

main()


Measured memory_bytes: 16624
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

void test_case(){
	int n; cin >> n;
	vector<ll> v(n);
	int z=0;
	for(int i=0;i<n;i++){
		cin >> v[i];
		if(v[i]==0) z=1;
	}

	if(z){
		cout << 0 << endl;
		return;
	}

	ll inf = 1000000000000000000;
	ll ans = 1;
	for(ll a : v){
		if(a <= inf/ans){
			ans = ans*a;
		}
		else{
			cout << -1 << endl;
			return;
		}
	}
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	// cin >> t;

	while(t--) test_case();
	
	return 0;
}

// 1000000000000000000


Measured memory_bytes: 3964
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>

using namespace std;
typedef long long unsigned int ll;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MOD 998244353

vector<int> ans;

void solver(int m);

ll myPow(ll x, ll n){
	ll ret = 1;
	while(0 < n)
	{
		if((n % 2) == 0)
		{
			x = (x * x) % MOD;
			n >>= 1;
		}
		else
		{
			ret = (ret * x) % MOD;
			--n;
		}
	}
    //cout << ret << endl;
	return ret % MOD;
}

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

    int n = input_s.length();

    vector<int> S;

    
    REP(i, n){
        S.push_back(int(input_s[i]) - int('a'));
    }

    if(max_element(S.begin(), S.end()) == min_element(S.begin(), S.end())){
        cout << 1 << endl;
        return 0;
    }else if(n == 2){
        cout << 2 << endl;
        return 0;
    }else if(n == 3){
        int t = S[0] * 100 + S[1] * 10 + S[2];
        ans.push_back(t);
        solver(t);
        cout << ans.size();
        return 0;
    }

    ll dp[3][3];

    REP(i, 3){
        REP(j, 3){
            if(i==j){
                dp[i][j] = 1;
            }else{
                dp[i][j] = 0;
            }
        }
    }

    REP(i, n-1){
        ll T[3][3];
        T[0][0] = (dp[1][0] + dp[2][0]) % MOD;
        T[0][1] = (dp[1][1] + dp[2][1]) % MOD;
        T[0][2] = (dp[1][2] + dp[2][2]) % MOD;
        T[1][0] = (dp[0][2] + dp[2][2]) % MOD;
        T[1][1] = (dp[0][0] + dp[2][0]) % MOD;
        T[1][2] = (dp[0][1] + dp[2][1]) % MOD;
        T[2][0] = (dp[0][1] + dp[1][1]) % MOD;
        T[2][1] = (dp[0][2] + dp[1][2]) % MOD;
        T[2][2] = (dp[0][0] + dp[1][0]) % MOD;
        REP(i, 3){
            REP(j, 3){
                dp[i][j] = T[i][j];
                //cout << dp[i][j] << ' ';
            }
        }
        //cout << endl;
    }

    int m = std::accumulate(S.begin(), S.end(), 0) % 3;
    
    ll res = myPow(3, n-1);
    REP(i, 3){
        res = (res + MOD - dp[i][m]) % MOD;
    }
    

    int check = 1;
    REP(i, n-1){
        if(S[i] == S[i+1]){
            check = 0;
            break;
        }
    }

    res += check;

    //cout << res << endl;

    cout << (res % MOD);

    return 0;
}


void solver(int m){
    int x = m / 100;
    int y = (m % 100) / 10;
    int z = m % 10;
    if(x != y){
        int temp = ( (3 - x - y) % 3 ) * 110 + z;
        if (find(ans.begin(), ans.end(), temp) == ans.end()){
            ans.push_back(temp);
            solver(temp);
        }
    }
    if(y != z){
        int temp = x * 100 + ( (3 - y - z) % 3 ) * 11;
        if (find(ans.begin(), ans.end(), temp) == ans.end()){
            ans.push_back(temp);
            solver(temp);
        }
    }
}

Measured memory_bytes: 1680