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


int main(){
  cout<<fixed<<setprecision(12);
  int n,k;
  int p[100010];
  double ans;
  cin>>n>>k;
  int a=1;
  rep(i,n){
    p[i+1]=0;
  }
  rep(i,20){
    if(i!=0) a*=2;
    repi(j,1,n+1){
      p[j]*=2;
      if((j*a)>=k && p[j]==0) p[j]++;
    }
    if(p[1]!=0) break;
  }
  //cout<<p[5]<<" "<<p[6]<<" "<<p[7]<<" "<<p[8]<<" "<<a<<endl;
  rep(i,n){
    ans+=(double)p[i+1]/( (double)a*(double)n);
  }
  cout<<ans<<endl;

  return 0;
}
















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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i;
	string a;
	cin>>a;
	for (i=0;i<a.size();i++){
		if (a[i]=='1'){
			cout<<"9";
		}
		else {
			cout<<"1";
		}
	}
	return 0;
}

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


def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight):
    """check the numbers that are loadable in tracks
    
    Args:
        cargo_weight_list: cargo weight list
        number_of_tracks: the number of tracks
        
    Returns:
        the number of cargos that are loadable in tracks
    """
    counter = 0
    number_of_loaded_cargo = 0

    while counter < number_of_tracks:
        current_track_weight = 0

        while current_track_weight + cargo_weight_list[number_of_loaded_cargo] <= maximum_weight:
            current_track_weight += cargo_weight_list[number_of_loaded_cargo]
            number_of_loaded_cargo += 1
            if number_of_loaded_cargo == number_of_all_cargo:
                return number_of_all_cargo

        counter += 1

    return number_of_loaded_cargo


def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks):
    """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks.
    (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases)


    Args:
        cargo_weight_list: cargo weight list
        numbef of all cargo: the number of all cargos
        number of tracks: the number of tracks

    Returns:
        minumim number of maximum track weight that are needed to load all of the cargos
    """
    left = max(cargo_weight_list)
    right = sum(cargo_weight_list)
    while (right - left) > 0:
        middle = (right + left) / 2
        the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle)
        if the_number_of_loadable_cagos >= number_of_all_cargo:
            right = middle
        else:
            left = middle + 1

    return right

def main():
    number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')]
    cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)]
    
    print find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks)


if __name__ == '__main__':
    main()

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

using namespace std;

#define pi 3.1415926536
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bs binary_search
#define int long long
#define float double

typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<string,int> msi;
typedef map<string,string> mss;
typedef map<char,char> mcc;
typedef map<pair<int,int>,int> mpi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef set<int> si;
typedef set<string> ss;
typedef set<char> sc;
int const max1= 1e3+5;
int const mod = 1e9+7;

int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
    int n=0;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        n+=s[i]-'0';
    }
    if(n%9==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}
}


Measured memory_bytes: 3768
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) \
    srt(vec);       \
    rev(vec)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

// start地点(0-origin)からbがaに含まれるかを探索する
bool template_check(vector<string> a, vector<string> b, p_i start) {
    int x = start.first;
    int y = start.second;

    assert(x + b.size() <= a.size());
    assert(y + b.size() <= a.size());

    for(int i = 0; i < b.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            if (a[y + j][x + i] != b[j][i]) {
                return false;
            }
        }
    }

    return true;
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(m);

    rep(i, n) {
        cin >> a[i];
    }
    rep(i, m) {
        cin >> b[i];
    }

    rep(i, n - m + 1) {
        rep(j, n - m + 1) {
            if (template_check(a, b, p_i(i, j))) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def solution(a, b):
    #todo: check if a and b are valid
    if (a + a[:-1]).find(b) >= 0:
        return 'Yes'
    else:
        return 'No'

def main():
    a = raw_input().strip()
    b = raw_input().strip()
    print solution(a, b)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
#include<stdio.h>
int main(){
    int i, j;
    int n, m;
    int a[101][100];
    int b[100];
    int c[101];
    scanf("%d %d", &n, &m);
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        scanf("%d", &b[i]);
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            c[i] += a[i][j]*b[j];
        }
        printf("%d\n",c[i]);
    }
    
    return 0;
}

Measured memory_bytes: 2760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, n1,n2,n3,n4,x;

            var word = Console.ReadLine().Split(' ');
            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            n1 = A + B;
            n2 = A - B;
            n3 = A * B;
            if (n1 < n2)
                n4 = n2;
            else
                n4 = n1;
            if (n3 < n4)
                x = n4;
            else
                x = n3;
            Console.WriteLine(x);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N; cin >> N;
    vector<int> h(N); rep(i,N) cin >> h[i];


    int ans = 0;
    for(;;){
        bool f = false;
        rep(i,N) if(h[i] > 0){
            f = true;
            break;
        }
        if(!f) break;

        int mx = *max_element(all(h));

        for(int i=0;i<N;i++){
            if(h[i] == mx){
                int j = i+1;
                ans++;
                while(j<N and h[i] == h[j]){
                    j++;
                }
                for(int k=i;k<j;k++) h[k]--;
                i=j;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
M=1000000007

def normalize(v)
  return [0,0] if v==[0,0]
  d=v[0].abs.gcd(v[1].abs)
  x=v[0]/d
  y=v[1]/d
  x,y=-x,-y if y<0
  x=-x if y==0 && x<0
  [x,y]
end

def orthogonal(v)
  normalize([-v[1],v[0]])
end

def pow(n,m)
  return 1 if m.zero?
  m.odd? ? (n*pow(n,m-1)%M) : pow(n*n%M,m/2)
end

zer=0
h=Hash.new{|h,k|h[k]=0}
gets.to_i.times.map{gets.split.map(&:to_i)}.each do |v|
  if v.all?{|i|i.zero?}
    zer+=1
  else
    h[normalize(v)]+=1
  end
end

ans=1
used={}
h.each do |v,_|
  n=orthogonal(v)
  next if used[v]
  used[n]=true
  ans*=(h.key?(n) ? pow(2,h[v])+pow(2,h[n])-1 : pow(2,h[v]))
  ans%=M
end
p (zer+ans-1+M)%M

Measured memory_bytes: 60748
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,m,M) for(int i = m;i<M;i++)
int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	int M = max(N, Q);
	vector<int> A(M);   //i番目に正解した人
	vector<int> num(M); //i番目の人がnum[i]回正解
	FOR(i, 0, Q)
	{
		cin >> A[i];
	}
	cout << endl;
	FOR(i, 0, Q)
	{
		num[A[i]-1]++;
	//	cout << "i : " << i << "  num[" << A[i]-1 << "]: " << num[A[i]-1] << endl;
	}
/*	cout << endl;
	FOR(i, 0, N)
	{
		cout<<num[i]<<endl;
	}
	*/
	FOR(i, 0, N)
	{
		if (num[i] + K - Q  <= 0)
			cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#define MOD 1000000007
#define MSG(a) cout << #a << " " << a << endl;
#define print(a) cout << a << endl;
template <class T, class C>
void chmax(T &a, C b) { if(a <= b) a = b; }
template <class T, class C>
void chmin(T &a, C b) { if(a >= b) a = b; }

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

template <class T>
T sum(const vector<T> &v) { T res = 0; for (size_t i = 0; i < v.size(); ++i) res += v[i]; return res; }
// vector の出力
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << " ";
    }
    return out;
}


int main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //////////////////////////////////////////
    ll k;
    cin >> k;
    ll n = 50;
    ll d = k/n;
    ll r = k%n;
    vector<ll> ans(n);

    rep(i,n){
        ans[i]= d+i-r;
        if(i<r){
            ans[i] +=(n+1);
        }
        // print(ans[i]);
    }
    print(n);
    cout << ans << endl;

    // string a, b;
    // cin >> a >> b;
    return 0;

}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
main(void){
    int a,b;
    cin>>a>>b;
    char s[a+b+1];
    cin>>s;
    if(s[a]!='-'){
            cout<<"No";
            return 0;
    }
    for(int i=0;i<a+b+1;i++){
        if(i==a) continue;
        if(!isdigit(s[i])){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    ll r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    combination c(3000010);
    mint ans = 0;
    for(int i=r1+1;i<=r2+1;i++){
        ans += c(i+c2,i);
        ans -= c(i+c1-1,i);
    }
    cout << ans << endl;
    return 0;
}


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

bool IsPrime(int x){
  if(x<2) return false;
  for(int i=2;i*i<=x;i++)
    if(x%i==0) return false;
  return true;
}

int main() {
  int x;
  cin >> x;
  
  while(!IsPrime(x)) x++;
  cout << x << endl;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;



int main()
{
    int a,b,c,ans=0;
    cin>>a>>b>>c;
    a=a-c;
    ans=b+c;
    cout<<a/ans;

    return 0;
} 

Measured memory_bytes: 256
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

vector<int> a[110000];
int used[110000];

int main()
{
  _int64 ans;
  int i,j,k,n,m,x,y,cnt1,cnt2,cnt3,b1;
  vector<int> q;
  scanf("%d%d",&n,&m);
  for (i=0;i<n;i++)
    a[i].clear();
  for (i=0;i<m;i++)
  {
    scanf("%d%d",&x,&y);
    x--;y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  memset(used,0,sizeof(used));
  ans=0;
  cnt1=0;cnt2=0;cnt3=0;
  for (i=0;i<n;i++)
    if (used[i]==0)
    {
      q.clear();
      q.push_back(i);
      used[i]=1;
      b1=0;
      for (j=0;j<q.size();j++)
      {
        x=q[j];
        for (k=0;k<a[x].size();k++)
        {
          y=a[x][k];
          if (used[y]==0)
          {
            used[y]=3-used[x];
            q.push_back(y);
          }
          else if (used[y]==used[x]) b1=1;
        }
      }
      if (q.size()==1) cnt3++;
      else if (b1==1) cnt2++;
      else cnt1++;
    }
  for (i=0;i<cnt3;i++)
    ans+=((n-i)*2-1);
  ans+=(_int64)cnt2*cnt2;
  ans+=(_int64)cnt1*cnt2*2;
  ans+=cnt1*2;
  ans+=((_int64)cnt1*cnt1-cnt1)*2;
  printf("%lld\n",ans);
  return 0;
}

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

int W, H;

int tansaku(vector<vector<int>> &data, int h, int w) {
    int ret = 0;
    if(data[h][w] == 1) {
        ret = 1;
        data[h][w] =0;
        if(h-1 >= 0          ) ret |= tansaku(data, h-1, w);
        if(h+1 <  H          ) ret |= tansaku(data, h+1, w);
        if(           w-1 >=0) ret |= tansaku(data, h  , w-1);
        if(           w+1 < W) ret |= tansaku(data, h  , w+1);
        if(h-1 >=0 && w-1 >=0) ret |= tansaku(data, h-1, w-1);
        if(h-1 >=0 && w+1 < W) ret |= tansaku(data, h-1, w+1);
        if(h+1 < H && w-1 >=0) ret |= tansaku(data, h+1, w-1);
        if(h+1 < H && w+1 < W) ret |= tansaku(data, h+1, w+1);
    }
    return ret;
}

int func() {
    cin >> W >> H;
    if(W==0 && H==0) return 0;
    //int data[H][W];
    vector<vector<int>> data;
    data.resize(H);

    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            int tmp;
            cin >> tmp;
            //data[h][w] = tmp;
            data[h].push_back(tmp);
        }
    }


    int counter = 0;
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            counter += tansaku(data, h, w);
        }
    }
    cout << counter << endl;
    
    return 1;
}

int main() {
    while(func()) {}
    return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

static const ll t = 2e+12;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i]; p[i]--;
  }

  UnionFind uf(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    uf.unite(x, y);
  }

  int ans = 0;
  rep(i, n) {
    if (i == p[i]) {
      ans++;
    } else if (uf.same(i, p[i])) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read();
            for (int i = 0; i < n.Length; i++)
            {
                if (n[i] == '7')
                {
                    WriteRead("Yes");
                    return;
                }
            }
            WriteRead("No");
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



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

using namespace std;

typedef long long ll;

int n;
ll mod, dp1[100005], dp2[100005];
vector <int> ms[100005];

void dfs1(int x, int p){
	dp1[x] = 1;
	for(vector <int>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		int o = *i;
		if(o == p)
			continue;
		dfs1(o, x);
		dp1[x] = (dp1[x] * (dp1[o] + 1)) % mod;
	}
}

void dfs2(int x, int p, ll val){
	vector <ll> fr, bc;
	fr.push_back(1);
	for(vector <int>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		int o = *i;
		if(o == p)
			continue;
		fr.push_back(dp1[o]);
		bc.push_back(dp1[o]);
	}
	bc.push_back(1);
	for(int i = 1 ; i < fr.size() ; ++i){
		fr[i] = (fr[i - 1] * (fr[i] + 1)) % mod;
	}
	for(int i = bc.size() - 2 ; i >= 0 ; --i){
		bc[i] = (bc[i + 1] * (bc[i] + 1)) % mod;
	}
	dp2[x] = (fr.back() * val) % mod;
	int br = 0;
	for(vector <int>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		int o = *i;
		if(o == p)
			continue;
		dfs2(o, x, ((((val * fr[br]) % mod) * bc[++br]) % mod + 1) % mod);
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> mod;
for(int i = 0 ; i < n - 1 ; ++i){
	int x, y;
	cin >> x >> y;
	ms[x].push_back(y);
	ms[y].push_back(x);
}
dfs1(1, -1);
dfs2(1, -1, 1);
for(int i = 1 ; i <= n ; ++i){
	cout << dp2[i] << endl;
}

return 0;
}



Measured memory_bytes: 25472
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	C *= 2;

	long long result = 0;
	if (A + B < C)
	{
		result = A * X + B * Y;
	}
	else
	{
		int same_cnt = min(X, Y);
		result = same_cnt * C;

		if (same_cnt < X)
		{
			result += min((X - same_cnt) * A, (X - same_cnt) * C);
		}
		else
		{
			result += min((Y - same_cnt) * B, (Y - same_cnt) * C);
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int a,b,c,d;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

   cin >> a >> b >> c >> d;

   int lc = c*d/__gcd(c,d);

   int ans = b-a+1 -  ( b/c - (a-1)/c ) - ( b/d - (a-1)/d ) + ( b/(lc) - ( a-1 )/(lc) );
   cout << ans << endl;


return 0;
}
///....



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main(void){
	int c;
	cin >> c;
	string ss;
	int ans[4] = {0};
	for(int i = 0; i < c; i++){
		cin >> ss;
		if(ss[0] == 'A')ans[0]++;
		if(ss[0] == 'W')ans[1]++;
		if(ss[0] == 'T')ans[2]++;
		if(ss[0] == 'R')ans[3]++;
	}
	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
}


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

typedef long long ll;

ll A, B;

ll calcu_xor(ll x) {
	ll div = (x + 1) / 2;
  	ll ret = ((div & (ll)1) == 0) ? (ll)0 : (ll)1;
  	if (((x + 1) & (ll)1) != 0)
		ret ^= x;
	return ret;
}

ll solve(void) {
	ll xor_a = calcu_xor(A - 1);
	ll xor_b = calcu_xor(B);
	ll ret = xor_b ^ xor_a;
	return ret;
}

int main(void) {
	cin >> A >> B;

	ll ans = solve();

	cout << ans << '\n';
	return 0;
}


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

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

    double ansRate = 0.0;
    for (int i = 1; i < N + 1; i++) {
        double rate = 1.0 / N;
        int num = i;
        while (K > num) {
            num *= 2;
            rate /= 2;
        }
        ansRate += rate;
    }
    cout << fixed << setprecision(15) << ansRate << endl;
    return 0;
}

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

#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; i++) {
        cin >> x.at(i) >> y.at(i) >> z.at(i);
    }
    vector<int> sgn = {1, -1};
    ll ans = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                vector<ll> A(N);
                for (int n = 0; n < N; n++) {
                    A.at(n) = sgn[i] * x[n] + sgn[j] * y[n] + sgn[k] * z[n];
                }
                sort(A.begin(), A.end(), greater<ll>());
                chmax(ans, accumulate(A.begin(), A.begin() + M, 0LL));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
class Program{
	public static void Main(){
		string str = Console.ReadLine();
		if (Char.Equals(str[0],str[1])&&Char.Equals(str[1],str[2]))
		Console.WriteLine("Yes");
		else if (Char.Equals(str[1],str[2])&&Char.Equals(str[2],str[3]))
		Console.WriteLine("Yes");
		else
		Console.WriteLine("No");
	}
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<queue>
using namespace std;

string t;



int main(){
    cin >> t;

    for(int i=0;i<t.size();i++){
        if(t[i] == '?') t[i] = 'D';
    }


    cout << t << endl;
}

Measured memory_bytes: 3776
import java.util.Scanner;


class Main{
    public static void main(String args[]){
        
        int leftIndex;
        int rightIndex;
        
        Scanner bob = new Scanner(System.in);
        int h = bob.nextInt();
        int[] turtle = new int[h];
        for(int i = 0; i < h; i++){
            turtle[i] = bob.nextInt();
        }
        for(int i = 0; i < h; i++){
            System.out.print("node " + (i+1) + ": ");
            System.out.print("key = " + turtle[i] + ", ");
            if(i > 0){
                System.out.print("parent key = " + turtle[(int)((i-1)/2)]+ ", ");
            }
            if(i < h/2){
                leftIndex = 2*(i)+1;
                rightIndex = 2*(i)+2;
                if(leftIndex < h){
                    System.out.print("left key = " + turtle[leftIndex]+ ", ");
                }
                if(rightIndex < h){
                    System.out.print("right key = " + turtle[rightIndex] + ", ");
                }
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 27052
#include<bits/stdc++.h>
using namespace std;
int x[100];
int main()
{
   int n,m,a,b;
   cin>>n>>m;
   for(int i=1;i<=m;i++)
   {
       cin>>a>>b;
       x[a]++;
       x[b]++;
   }
   for(int i=1;i<=n;i++)
   {
       cout<<x[i]<<endl;
   }


	return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

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

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n; cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];
    REP(i, n) a[i]--;

    vector<bool> used(n, false);

    int cur = 0;
    int cnt = 0;
    while(1) {
        if (cur == 1) {
            print(cnt);
            return 0;
        }

        cur = a[cur];
        cnt++;

        if (used[cur]) {
            print(-1);
            return 0;
        }

        used[cur] = true;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  if (b / a >= c) {
    cout << c << endl;
  } else {
    cout << b / a << endl;
  }
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    rep(i,4) printf("%c", s[i]);
    printf(" ");
    for(int i=4; i<s.size(); ++i) printf("%c", s[i]);
    printf("\n");

    return 0;
}


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

string S;
int N;
long long ans = 0;

void dfs(int i, long long tmp, long long sum) {
    int x = S[i] - '0';
    tmp += x;
    if (i == N - 1) {
        ans += sum + tmp;
        return;
    };
    dfs(i + 1, tmp * 10, sum);
    dfs(i + 1, 0, sum + tmp);
}

int main() {
    cin >> S;
    N = S.length();
    dfs(0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

n = int(input())
l = input()

#print(l)
lsh = []*(n+1)
lsh.append(0)
sharp = 0
comma = 0

for i in range(n):
	if l[i]=="#":
		sharp = sharp + 1
	lsh.append(sharp)
#print(lsh)

for i in range(n-1,-1,-1):
	#print(i)
	if l[i]==".":
		comma = comma + 1
	lsh[i] = lsh[i] + comma

print(min(lsh))




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

constexpr int MOD = 1'000'000'007;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> ModInt<mod> modLCM(const vector<int> &A) {
    const int N = (int)A.size(); assert(0 < N);
    const int MAX = (int)*max_element(A.begin(), A.end());
    vector<int> prime(MAX+2, 0); 
    prime[0] = prime[1] = false;
    for (int i = 2; i <= MAX; i++) if (!prime[i]) {
        for (int j = i+i; j <= MAX; j += i) if (!prime[j]) {
            prime[j] = i;
        }
        prime[i] = i;
    }
    unordered_map<int, int> mx;
    for (auto num : A) {
        unordered_map<int, int> temp;
        while (num > 1) {
            int factor = prime[num];
            temp[factor]++;
            num /= factor;
        }
        for (auto it : temp) {
            mx[it.first] = max(mx[it.first], it.second);
        }
    }
    ModInt<mod> ret = 1;
    for (auto it : mx) {
        ModInt<mod> res = it.first;
        ret *= res.pow(it.second);
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &e : a) cin >> e;
    
    ModInt<MOD> res = modLCM<MOD>(a);
    ModInt<MOD> ans = 0;
    for (const int &e : a) {
        ans += res / e;
    }
    
    cout << ans << '\n';
    
    return 0;
}
    

Measured memory_bytes: 4608
import itertools


class Graph:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.edges = [[] for _ in range(n_nodes)]

    def add_edge(self, s, t, d=None, undirected=False):
        if d is not None:
            self.edges[s].append((t, d))
        else:
            self.edges[s].append(t)
        if undirected:
            self.add_edge(t, s, d)

    def add_edges(self, edges, undirected=False):
        for edge in edges:
            self.add_edge(*edge, undirected=undirected)


class FloydWarshall:
    def __init__(self, graph):
        self.graph = graph
        self.distances = [[float('inf')] * graph.n_nodes
                          for _ in range(graph.n_nodes)]
        self.nexts = [[None] * graph.n_nodes for _ in range(graph.n_nodes)]
        self._init()

    def _init(self):
        for x in range(self.graph.n_nodes):
            self.distances[x][x] = 0
        for source in range(self.graph.n_nodes):
            for destination, distance in self.graph.edges[source]:
                self.distances[source][destination] = distance
                self.nexts[source][destination] = destination

    def compute_shortest_path_lengths(self):
        for k in range(self.graph.n_nodes):
            for i in range(self.graph.n_nodes):
                for j in range(self.graph.n_nodes):
                    s = self.distances[i][k] + self.distances[k][j]
                    if s < self.distances[i][j]:
                        self.distances[i][j] = s
                        self.nexts[i][j] = self.nexts[i][k]

    def get_shortest_path(self, x, y):
        if self.nexts[x][y] is None:
            return []
        path = [x]
        while path[-1] != y:
            s = path[-1]
            t = self.nexts[s][y]
            path.append(t)
        return path


n, m, r = map(int, input().split())
rs = list(map(int, input().split()))

graph = Graph(n + 1)
graph.add_edges([list(map(int,
                          input().split())) for _ in range(m)],
                undirected=True)
fw = FloydWarshall(graph)
fw.compute_shortest_path_lengths()
res = float('inf')
for perm in itertools.permutations(rs):
    s = sum([fw.distances[a][b] for a, b in zip(perm, perm[1:])])
    res = min(res, s)
print(res)

Measured memory_bytes: 60632
import java.util.Scanner;

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

        String[] S = sc.next().split("");
        for (int i = S.length - 1; i >= 0; i--) {
            System.out.print(S[i]);
        }
        System.out.println();
    }
}

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


class StringSearch {
	const int n;
	string S;
	vector<int> SA, Rank;
public:
	StringSearch(const string &S_)
		: n(S_.size()), S(S_), SA(n + 1), Rank(n + 1)
	{
		for (int i = 0; i <= n; i++) {
			SA[i] = i;
			Rank[i] = i < n ? S[i] : -1;
		}

		vector<int> tmp(n + 1);
		for (int k = 1; k <= n; k *= 2) {
			auto Compare_SA = [=](int i, int j) {
				return Rank[i] != Rank[j] ? (Rank[i] < Rank[j]) : (i + k <= n ? Rank[i + k] : -1) < (j + k <= n ? Rank[j + k] : -1);
			};

			sort(SA.begin(), SA.end(), Compare_SA);

			tmp[SA[0]] = 0;
			for (int i = 1; i <= n; i++) {
				tmp[SA[i]] = tmp[SA[i - 1]] + (Compare_SA(SA[i - 1], SA[i]) ? 1 : 0);
			}
			for (int i = 0; i <= n; i++) {
				Rank[i] = tmp[i];
			}
		}
	}

	bool Contain(const string &T) {
		int a = 0, b = n;
		while (b - a > 1) {
			int c = (a + b) / 2;
			if (S.compare(SA[c], T.length(), T) < 0) a = c;
			else b = c;
		}
		return S.compare(SA[b], T.length(), T) == 0;
	}
};

int main()
{
	int Q;
	string T, P;
	cin.sync_with_stdio(false);
	cin >> T;
	StringSearch SS(T);
	cin >> Q;
	while (Q--) {
		cin >> P;
		cout << SS.Contain(P) << endl;
	}
	return 0;
}

Measured memory_bytes: 16544
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 1e5+5;
int arr[maxn];

int main(){
    int n, k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    int ans = 1e9+5;
    for(int i=k-1;i<n;i++){
        ans = min(ans, arr[i]-arr[i-k+1]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int s = Integer.valueOf(bf.readLine()),
            m = 1;
        Set<Integer> number = new HashSet<>();
        while(true){
            if(!number.add(s)){
                break;
            }
            if(s%2 > 0){
                s = 3*s + 1;
            } else{
                s /= 2;
            }
            m++;
        }        
        System.out.println(m);
    }
}

Measured memory_bytes: 21204
from math import sqrt, cos, radians

def solve(A, B, H, M):
    Hr = (H * 60 + M) * 0.5
    Mr = M * 6
    r = abs(Hr - Mr)
    if r > 180:
        r = 360 - r

    if r == 90:
        print(sqrt(A ** 2 + B ** 2))
    else:
        print(sqrt(A ** 2 + B ** 2 - (2 * A * B * cos(radians(r)))))

A, B, H, M = map(int, open(0).read().split())
solve(A, B, H, M)


Measured memory_bytes: 9456
use proconio::{input, fastout};
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i32; n],
    }

    let mut dp = vec![-1; n];
    dp[0] = 0;
    dp[1] = (h[1]-h[0]).abs();
    for i in 2..n {
        dp[i] = dp[i-1] + (h[i-1] - h[i]).abs();
        for j in 2..=k {
            if j > i {
                break;
            }
            dp[i] = min(dp[i], dp[i-j] + (h[i-j] - h[i]).abs());
        }
    }

    println!("{}", dp[n-1]);
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define M 1000005
#define L 14
char a[M][L];

int getChar(char ch){
	if(ch=='A')return 1;
	else if(ch=='C')return 2;
	else if(ch=='G')return 3;
	else if(ch=='T')return 4;
	else return 0;
} 

int h1(int key){return key % M;}
int h2(int key){return 1+(key%(M-1)); }


int getKey(char s[]){
	long long sum=0;
	int p=1;
	for(int i=0;i<strlen(s);i++){
		sum+=p*getChar(s[i]);
		p*=5;
	} 
	return sum;
}

int insert( char s[]){
	long long key;
	key=getKey(s);
	for(int i=0;;i++){
		int h=(h1(key)+i*h2(key))% M;
		if(strcmp(a[h],s)==0)return 1;
		else if(strlen(a[h])==0){
			strcpy(a[h],s);
			return 0;
		}
	}
	return 0;
}

int find(char s[]){
	long long key;
	key=getKey(s);
	for(int i=0;;i++){
		int h=(h1(key)+i*h2(key))% M;
		if(strcmp(a[h],s)==0)return 1;
		else if(strlen(a[h])==0)return 0;
	}
	return 0;
}


int main(){
	int t;
	cin>>t;
	char o[9],s[14];
	for(int i=0;i<M;i++)a[i][0]='\0';
	while(t--){
		cin>>o>>s;
		if(o[0]=='i'){
			insert(s);
		}
		else{
			if(find(s))cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
	}
}


Measured memory_bytes: 16808
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0; i <(n); i++)
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",a*b);
  return 0;
}


Measured memory_bytes: 1732
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  map<pll, ll> key;
  ll n;
  cin >> n;
  for(ll i = 1; i <= n; i++) {
    string xx = to_string(i);
    ll first = xx[0] - '0';
    ll last  = xx.back() - '0';
    key[mp(first, last)]++;
  }
  ll ans = 0;
  for(ll i = 1; i <= n; i++) {
    string xx = to_string(i);
    ll first = xx[0] - '0';
    ll last  = xx.back() - '0';
    ans+= key[mp(last, first)];
  }
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
// D - Powerful Discount Tickets
#include <bits/stdc++.h>
using namespace std;

int in(){int x;cin>>x;return x;}

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

	priority_queue<int> A;
	while(N--) A.push(in());

	for(;M--; A.pop()) A.push(A.top() / 2);

	long long ans = 0;
	for(;A.size(); A.pop()) ans += A.top();
	cout<< ans <<endl;
}

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

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

int main() {
  int a, b, c, cnt5 = 0, cnt7 = 0;
  cin >> a >> b >> c;
  if (a == 5) cnt5++;
  if (b == 5) cnt5++;
  if (c == 5) cnt5++;
  if (a == 7) cnt7++;
  if (b == 7) cnt7++;
  if (c == 7) cnt7++;

  cout << ((cnt5 == 2 && cnt7 == 1) ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    L=[0]*N
    
    n=0
    for i in range(K,N):
        if A[i]<=A[n]:
            print('No')
        else:
            print('Yes')
        n+=1

main()

Measured memory_bytes: 31600
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

    for(int i=0;i<n;i++){
      cout<<s[i]<<t[i];
    }
    cout<<"\n";
}



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

int main(){
    int c[3];
    cin >> c[0] >> c[1] >> c[2];
    int res = 100 * c[0] + 10 * c[1] + 1 * c[2];

    if (res % 4 == 0){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
 
	return 0;
}

Measured memory_bytes: 256