akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
    #include<cstdio>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int MAXN=1e5+5;
    int tot,head[MAXN];
    LL dist[MAXN];
    bool vis[MAXN];

    struct Edge
    {
        int from,to,nxt;
        LL cost;
    }e[MAXN*2];

    void addedge(int u,int v,int w)
    {    
        e[tot].from=u;
        e[tot].to=v;
        e[tot].cost=w;
        e[tot].nxt=head[u];
        head[u]=tot;
        tot++;
    }

    void dfs(int u,int fa)
    {
        for(int i=head[u];i!=-1;i=e[i].nxt)
        {
            int to=e[i].to;
            if(to==fa) continue;
            dist[to]=dist[u]+e[i].cost;
            dfs(to,u);
        }
    }

    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            tot=0;
            memset(head,-1,sizeof(head));
            memset(dist,0,sizeof(dist));
            int u,v;
            LL w;
            for(int i=1;i<=n-1;i++)
            {
                scanf("%d%d%lld",&u,&v,&w);
                addedge(u,v,w);
                addedge(v,u,w);
            }
            int q,k;
            scanf("%d%d",&q,&k);
            dfs(k,-1);
    //        for(int i=1;i<=n;i++)
    //            cout<<dist[i]<<" ";
    //        cout<<endl;
            int x,y;
            for(int i=1;i<=q;i++)
            {
                scanf("%d%d",&x,&y);
                printf("%lld\n",dist[x]+dist[y]);
            }
        }
        return 0;
    }

Measured memory_bytes: 12288
#coding:utf-8
S = input()
l = len(S)
S = [int(S[i]) for i in range(l)]

def f(i,sl):
    if i == l-1:
        left = 0
        sumEx = 0
        for j in range(l-1):
            #j番目まで+それより左
            left = left*10+S[j]
            if sl[j] == "1":
                sumEx = sumEx + left
                left = 0
        left = left * 10 + S[-1]
        return sumEx + left
                
    else:
        return f(i+1,sl+"1")+f(i+1,sl+"0")
print(f(0,""))

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

int main() {
	int N, M;
	cin >> N >> M;
	string A[50], B[50];
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < M; i++)cin >> B[i];
	bool flag = false;
	for (int i = 0; i < N; i++) {
		for (int i2 = 0; i2< N; i2++) {
			for (int j = 0; j < M; j++) {
				for (int j2 = 0; j2 < M; j2++) {
					if (A[i+j][i2+j2] != B[j][j2]) goto search_stop;
					if (j == M - 1 && j2 == M - 1)flag = true;
				}
			}
		search_stop:;
		}
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  vector<bool>dp(k+1);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<a[0];i++)
  {
    dp[i]=0;
  }
  for(int i=0;i<k+1;i++)
  {
    dp[i]=0;
    for(int ai :a)
    {
      if(ai>i)
      {
        break;
      }
      else
      {
        if(!dp[i-ai])
        {
          dp[i]=1;
          break;
        }
      }
    }
  }
  if(dp[k])cout<<"First";
  else cout<<"Second";

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  MAX 100005
#define  MOD 1000000007
#define ll long long
using namespace std;

ll arr[100005];

int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    sort(arr+1,arr+1+n);
    ll ans=arr[n]-arr[1];
    for(int i=2;i<n;i++){
        if(arr[i]>0)ans+=arr[i];
        else ans-=arr[i];
    }
    cout<<ans<<endl;
    for(int i=2;i<n;i++){
        if(arr[i]>0){
            cout<<arr[1]<<" "<<arr[i]<<endl;
            arr[1]-=arr[i];
        }else{
            cout<<arr[n]<<" "<<arr[i]<<endl;
            arr[n]-=arr[i];
        }
    }
    cout<<arr[n]<<" "<<arr[1]<<endl;arr[n]-=arr[1];
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin >> s
#define pr(r) cout << r << endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout << a[j] << " "
#define wh(t) ll t; cin >> t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define arr(a,n) vl a(n, 0); fab(i, 0, n) cin >> a[i]
#define prs(u) cout << u << " "
#define fab(i,a,b) for(ll i = a; i < b; i++)
#define fba(i,b,a) for(ll i = b; i >= a; i--)
#define fa(i, x) for(auto i: x)
#define mem(s, j) memset(s, j, sizeof(s))
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pl>
#define pl pair<ll, ll>
#define pll pair<ll, pl>
#define vvl vector<vl>
#define vvpl vector<vpl>
#define mxe(x) *max_element(x)
#define mne(x) *min_element(x)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N = (ll)3e5;
const ll inf = (ll)1e18 + 7;
const ll mod = (ll)1e9 + 7;
const ll MX = (ll)1e9 + 7;
const ll MAX = (ll)1e12 + 7;
 
bool rsort1(const pair<ll, ll> &a,const pair<ll, ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll, ll> &a,const pair<ll, ll> &b) { return (a.second > b.second);}
bool sort2(const pair<ll, ll> &a,const pair<ll, ll> &b){ return (a.second < b.second);}

vector<char> dir = {'L', 'R', 'U', 'D'};
vl dx = {-1, 1, 0, 0};
vl dy = {0, 0, -1, 1};

void add(ll &x, ll y){
    x = ((x % mod) + (y % mod)) % mod;
}

void mul(ll &x, ll y){
    x = ((x % mod) * (y % mod)) % mod;
}

ll sm(vl a) {
    ll sum = 0;
    for(auto i: a)
        sum += i;
    return sum;
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}
 
bool isPrime(ll p)
{
    for(ll i = 2;i * i <= p; i++)
        if(p % i == 0)
            rr false;
    rr true;
}

ll nCr(ll n, ll k) 
{ 
    vl C(k + 1, 0); 
    ll i, j; 
    C[0] = 1; 
    for (i = 1; i <= n; i++) { 
        for (j = min(i, k); j > 0; j--) { 
            add(C[j], C[j - 1]); 
        } 
    }
    return C[k] % mod; 
}

int main()
{
	sup;
    
    ll n, m;
    cin >> n >> m;
    cout << nCr(n, 2) + nCr(m, 2) << endl;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

vector<PII> pa;
int32 H, W;
vector<string> s;
vector<vector<bool>> pack;
int32 dp[1 << 12];

bool dfs2(int32 now){
	if(~dp[now]) return dp[now];
	if(now == 0) return dp[now] = 1;
	if(__builtin_popcount(now) == 1){
		REP(i, W){
			if(now >> i & 1){
				if(pack[i][i]) return dp[now] = 1;
				return dp[now] = 0;
			}
		}
	}
	dp[now] = 0;
	REP(i, W){
		FOR(j, i+1, W){
			if(now >> i & 1 && now >> j & 1){
				if(pack[i][j]) dp[now] |= dfs2(now^(1<<i)^(1<<j));
			}
		}
	}
	return dp[now];
}

bool ok(){
	pack = vector<vector<bool>>(W, vector<bool>(W, 1));
	REP(k, pa.size()){
		int32 f = pa[k].fs, t = pa[k].sc;
		REP(i, W){
			REP(j, W){
				if (s[f][i] != s[t][j] || s[t][i] != s[f][j]) pack[i][j] = pack[j][i] = 0;
			}
		}
	}
	/*
	REP(i, pa.size()){
		cout << "(" << pa[i].fs << " " << pa[i].sc << ") ";
	}
	cout << endl;
	REP(i, W){
		REP(j, W){
			cout << pack[i][j] << " ";
		}
		cout << endl;
	}
	*/

	memset(dp, -1, sizeof dp);
	return dfs2((1 << W)-1);
}

bool dfs(int32 d, int32 cnt, int32 rest, bool used){
	if((rest >> d & 1) && cnt < H) return dfs(d+1, cnt, rest, used);
	if(cnt == H || (H%2 && cnt == H-(1-used))){
		if(H%2 && !used) pa.push_back(PII(d, d));
		bool ret = ok();
		if(H%2 && !used) pa.pop_back();
		return ret;
	}
	FOR(i, d+1, H){
		if(rest >> i & 1) continue;
		pa.push_back(PII(d, i));
		bool ret = dfs(d+1, cnt+2, rest^(1<<i)^(1<<d), used);
		pa.pop_back();
		if(ret) return ret;
	}
	if(H%2 && !used){
		pa.push_back(PII(d, d));
		bool ret = dfs(d+1, cnt+1, rest^(1<<d), 1);
		pa.pop_back();
		if(ret) return ret;
	}
	return 0;
}

int main(void){
	cin >> H >> W;
	s.resize(H);
	REP(i, H){
		cin >> s[i];
	}
	if(dfs(0, 0, 0, 0)) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define int long long

int div3(int a, int b){
	return b / 3 - (a - 1) / 3;
}

int div5(int a, int b){
	return b / 5 - (a - 1) / 5;
}

int div15(int a, int b){
	return b / 15 - (a - 1) / 15;
}

int length_sub(int digit, int a, int b){
	return digit * ((b - a + 1) - div3(a, b) - div5(a, b) + div15(a, b)) + 4 * (div3(a, b) + div5(a, b));
}

int length(int N){
	int d, a, ans = 0;
	for(d = 1, a = 1; a * 10 <= N; d++, a *= 10){
		ans += length_sub(d, a, a * 10 - 1);
	}
	ans += length_sub(d, a, N);
	return ans;
}

int S[10000];

signed main(){
	int L, i, j, k, m;
/*	for(i = 1; i <= 20; i++){
		printf("length(%lld) = %lld\n", i, length(i));
	}
	return 0;
*/	char Fizz[] = "Fizz", Buzz[] = "Buzz", sub[20];
	scanf("%lld", &L);
	int l = 0, h, r = (int)(1e17);
	while(r - l > 1){
		h = (l + r) / 2;
		if(length(h) > L){
			r = h;
		}
		else{
			l = h;
		}
	}
//	printf("l = %lld\n", l);
	for(i = l, m = 0; i < l + 20; i++){
//		printf("i = %lld\n", i);
		if(i % 3 == 0 && i % 5 == 0){
//			printf("test1\n");
			for(j = 0; j < 4; j++){
				S[m + j] = Fizz[j];
			}
			m += 4;
			for(j = 0; j < 4; j++){
				S[m + j] = Buzz[j];
			}
			m += 4;
		}
		else if(i % 3 == 0){
//			printf("test2\n");
			for(j = 0; j < 4; j++){
				S[m + j] = Fizz[j];
			}
			m += 4;
		}
		else if(i % 5 == 0){
//			printf("test3\n");
			for(j = 0; j < 4; j++){
				S[m + j] = Buzz[j];
			}
			m += 4;
		}
		else{
//			printf("test4\n");
			for(j = i, k = 0; j > 0; k++){
				sub[k] = (char)(j % 10 + (int)'0');
				j /= 10;
			}
			for(j = 0; j < k; j++){
				S[m + j] = sub[k - j - 1];
			}
			m += k;
		}
	}
	for(i = L - length(l - 1) - 1; i < L - length(l - 1) - 1 + 20; i++){
		printf("%c", S[i]);
	}
	printf("\n");
}


Measured memory_bytes: 2128
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int min = Integer.MAX_VALUE;
		for (int i=0;i<=N-3;i++) {
			String tmp = S.substring(i,i+3);
			int value = Integer.parseInt(tmp);
			min = Math.min(min, Math.abs(value-753));
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N;
	cin >> N;
	VLL A(N);
	for (ll n = 0; n < N; n++)cin >> A[n];
	sort(A.begin(), A.end(), [](ll a, ll b) {
		return a > b;
	});
	ll ans = 1;
	ll cur = A[0];
	for (ll n = 1; n < N; n++) {
		if (A[n] < A[n - 1]) {
			ans++;
			cur = A[n];
		}
	}
	cout << ans << "\n";
	return 0;
}

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

typedef long long ll;

ll N;
ll R = 1ll << 60;

int main() {
  cin >> N;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      R = min(R, i + N / i - 2);
    }
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

ll const mod = 1e9+7;

int up(int i,int k) {
  return (i+k-1)/k;
}

int main() {
  ll S,x=1e9;
  cin >> S;
  cout << 0 << ' ' << 0 << ' ';
  cout << x << ' ' << 1 << ' ';
  if (S%x==0) cout << S%x << ' ' << S/x << endl;
  else cout << x-S%x << ' ' << S/x+1 << endl;
}

Measured memory_bytes: 256
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        tps: [usize; 5],
    }
    let bn = tps
        .iter()
        .fold(std::usize::MAX, |x, y| std::cmp::min(x, *y));
    let x = (n + bn - 1) / bn;
    let ans = x + 4;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000000000
using namespace std;
   
int main(){
  int n,k,s;
  cin>>n>>k>>s;
  int a[n];
  
  if(s == MAX){
    a[0] = s;
    FOR(i,1,k) a[i] = s;
    FOR(i,k,n) a[i] = 1;
  }
  else{
    a[0] = s;
    FOR(i,1,k) a[i] = s;
    FOR(i,k,n) a[i] = s+1;
  }
  
  REP(i,n) cout<<a[i]<<" ";
  return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    int sum = 0;
    for(int k=2;sum<=n;++k){
        sum += (k - 1);
        if(n == sum){
            cout << "Yes" << endl;
            cout << k << endl;
            int m = 1;
            vector<vector<int>> ans(k, vector<int>());
            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    ans[i].push_back(m);
                    ans[j].push_back(m);
                    m++;
                }
            }
            for(int i=0;i<k;++i){
                cout << ans[i].size();
                for(auto e: ans[i]){
                    cout << " " << e;
                }
                cout << endl;
            }
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 2304
import math
r,g,b,n = [int(u) for u in input().split(" ")]
i = 0
for ir in range(math.floor(n/r)+1):
  if ir*r==n:
    i+=1
    break
  elif ir*r>n:
    break
  for ig in range(math.floor(n/g)+1):
    y = n - (ir*r+ig*g)
    if y<0:
      break
    if y%b==0:
      #print(ir,ig,y/b)
      i+=1
      continue
print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<int>> g(n);
	rep(i,n-1){
		int s,t;
		cin>>s>>t;
		s--,t--;
		g[s].push_back(t);
		g[t].push_back(s);
	}
	vector<int> dp(n);
	auto dfs1=[&](auto &&dfs1,int v,int pre)->int{
		int ret=0;
		for(auto itr:g[v]){
			if(itr==pre) continue;
			chmax(ret,dfs1(dfs1,itr,v)+1);
		}
		return dp[v]=ret;
	};
	vector<int> ans(n);
	ans[0]=dfs1(dfs1,0,-1);
	auto dfs2=[&](auto &&dfs2,int v,int pre)->void{
		int sz=g[v].size();
		vector<int> left(sz+1,0),right(sz+1,0);
		rep(i,sz){
			left[i+1]=max(left[i],dp[g[v][i]]+1);
		}
		for(int i=sz-1;i>=0;i--){
			right[i]=max(right[i+1],dp[g[v][i]]+1);
		}
		rep(j,sz){
			if(g[v][j]==pre) continue;
			int ne=g[v][j];
			int cnt1=dp[v],cnt2=dp[ne];
			dp[v]=max(left[j],right[j+1]);
			chmax(dp[ne],dp[v]+1);
			ans[ne]=dp[ne];
			//cout<<ne<<' '<<dp[ne]<<endl;
			dfs2(dfs2,ne,v);
			dp[v]=cnt1;
			dp[ne]=cnt2;
		}
	};
	dfs2(dfs2,0,-1);
	rep(i,n){
		cout<<2*(n-1)-ans[i]<<endl;
	}
}


Measured memory_bytes: 24708
n, k = (int(i) for i in input().split())
 
a = [int(i) for i in input().split()]
 
dic = {}
 
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
 
ans_num= len(dic)-k
ans = 0
 
 
if ans_num <= 0:
    ans *= 0 
else:
    sort = sorted(dic.items(), key=lambda x:x[1])
    for i in range(ans_num):
        ans += sort[i][1]
 
print(ans)

Measured memory_bytes: 40068
#include <iostream>
#include<bits/stdc++.h>
#define  ll long long
 using namespace std;
int dp[3000003][3],sum[3000003][3];
int main()
{
  int t;
  cin>>t;
  double sum=0;
  for(int i=1;i<=t;i++)
  {
      double x;
      cin>>x;
      sum+=1.0/x;
  }
  printf("%.6f\n",1.0/sum);
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n) {
	return 0;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1-x2),2) + pow(abs(y1-y2),2));
}


int main()
{
	int n;
	cin >> n;
	vi a(n + 1), b(n);
	for (int i = 0;i < n + 1;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}


	ll sum = 0;
	vi memo(n + 1);
	for (int i = 0;i < n;i++) {
		if (b[i] > a[i]) {
			sum += min(b[i], a[i] + a[i + 1]);
			a[i + 1] -= min(b[i] - a[i], a[i + 1]);
		}
		else {
			sum += b[i];
		}
	}

	cout << sum << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 1656
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
nums = [int(i) for i in input().split()]
avg = sum(nums)/len(nums)
avg = Decimal(str(avg)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(sum([(num-int(avg))**2 for num in nums]))

Measured memory_bytes: 5460
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
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;}

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

  int ans = X;
  rep(i, N) {
    int n=0;
    while(D>=n*A[i]+1) {
      ++ans;
      ++n;
    }
  }
  cout << ans << endl;
}


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

vector<int>graph[200005];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0, a, b; i < m; i++) {
		cin >> a >> b; a--; b--;
		graph[a].push_back(b); graph[b].push_back(a);
	}

	for (int i = 0; i < graph[0].size(); i++) {
		int v = graph[0][i];
		for (int j = 0; j < graph[v].size(); j++) {
			int u = graph[v][j];
			if (u == n - 1) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

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

int main()
{
  char x;
  cin >> x;
  
  switch(x)
  {
    case 'A':
      cout << 'T' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
  }
  
  return 0;
}

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

int main(){
	int m = 0;
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	int sum= 0;
	int a1 = 10-a%10; if(a1 == 10){
		a1 = 0;
	}
	int b1 = 10-b%10; if(b1 == 10){
		b1 = 0;
	}

	int c1 = 10-c%10;
if(c1 == 10){
		c1 = 0;
	}
	int d1 = 10-d%10;
if(d1 == 10){
		d1 = 0;
	}
	int e1 = 10-e%10;
	if(e1 == 10){
		e1 = 0;
	}
if(a1>m){
	m = a1;
}
if(b1>m){
	m = b1;
}
if(c1>m){
	m = c1;
}
if(d1>m){
	m = d1;
}
if(e1>m){
	m = e1;
}
if(m==10){
	m = 0;
}
	sum+=a;
	sum+=b;
	sum+=c;
	sum+=d;
	sum+=e;
	cout << sum+a1+b1+c1+d1+e1-m;
	return 0;
} 

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

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

using namespace std;
using lint=long long;

lint gcd(lint a,lint b){ return b?gcd(b,a%b):a; }
lint lcm(lint a,lint b){ return a/gcd(a,b)*b; }

int main(){
	int n; cin>>n;
	lint ans=1;
	rep(i,n){
		lint t; cin>>t;
		ans=lcm(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t luca,tmp0=2ll,tmp1=1ll;
  if(N==1) luca=tmp1;
  for(int i=1; i<N; i++) {
    luca = tmp0 + tmp1;
    tmp0 = tmp1;
    tmp1 = luca;
  }
  cout << luca << endl;
}

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

int main() {
  int N;
  cin >> N;
  int a[N];
  int b[N];
  cin >> a[0];
  for(int i=1;i<N;i++){
    int x;
    cin >> x;
    a[i]=a[i-1]+x;
  }
  for(int i=0;i<N;i++){
    cin >> b[i];
  }
  for(int i=N-2;i>=0;i--){
    b[i]=b[i+1]+b[i];
  }
  int max=0;
  for(int i=0;i<N;i++){
    if(a[i]+b[i]>max)max=a[i]+b[i];
  }
  cout << max;
}




Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	ans := 0
	for i := 0; i <= 100; i++ {
		if a < i && i <= b && c < i && i <= d {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  
  bool ok = false;
  for (int i = 9; i >= 2; i--) {
    if (n % i == 0 && n / i <= 9) {ok = true;}
  }
  if (ok) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
  
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
n,x,y,t;
int main(void){
    char a[101],b[101];
    for(scanf("%d",&n);n--;){
        scanf("%s%s",a,b);
        t=strcmp(a,b);
        x+=t>0?3:t==0?1:0;
        y+=t<0?3:t==0?1:0;
    }
    printf("%d %d\n",x,y);
}

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

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if(a>b) cout << 0 << endl;
  else if(a==b) cout << 1 << endl;
  else{
    if(n==1) cout << 0 << endl;
    else if(n==2) cout << 1 << endl;
    else{
      ll multi = n-2;
      cout << b*multi-a*multi+1 << endl;
    }
  }
  return 0;
}

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

using namespace std;

#define ull unsigned long long int
#define ll long long int 

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int a,b,c;
    cin >> a >> b>> c;
    cout << c << " " << a << " " << b << endl;


   return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC156B
#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, const char * argv[]) {
    int N,K;
    cin>>N>>K;
    for (int i=0; i<31; i++) {
        if (pow(K,i)>N) {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}

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

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

	int n, m, d;
	cin >> n >> m >> d;

	double res = (m - 1);
	res *= (double) (n - d) / n / n;
	if (d != 0) {
		res *= 2;
	}
	cout << setprecision(12) << fixed << res << endl;
}

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

using lint = long long;

int main(){
    long N, M;
    long A, B;
    pair<long, long> AB[100002];
    multiset<long> candidate;

    cin >> N >> M;
    for(long n=0;n<N;n++){
        cin >> A >> B;
        AB[n].first = A;
        AB[n].second = B;
    }
    sort(AB, AB+N);
    long ABindex = 0;
    long long ans = 0;
    for(long mbefore=1;mbefore<=M;mbefore++){
        while(AB[ABindex].first <= mbefore && ABindex < N){
            candidate.insert(AB[ABindex].second);
            ABindex++;
        }
        if(candidate.size() > 0){
            auto itr = candidate.end();
            itr--;
            ans += *itr;
            candidate.erase(itr);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
N = int(input())
W = [input() for _ in range(N)]
if len(W) != len(set(W)):
  print("No")
  exit()
else:
  for i in range(N-1):
    if W[i][-1:] != W[i+1][0:1]:
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 3060
n,m = map(int, input().split())
div = 1000000007
ok = [True] * (n + 1)
for _ in range(m):
  a = int(input())
  ok[a] = False
dp = [0] * (n + 1)
dp[0] = 1
if ok[1]:
  dp[1] = 1
else:
  dp[1] = 0

for i in range(2, n+1):
  if ok[i]:
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= div

print(dp[n])
  

Measured memory_bytes: 7668
//   ┏━━┓┏━━┓┏┓┏┓┏┳━┳┓┏━━┓┏━┳┓┏━━┓     ┏┳┓┏┳┓┏━┳━┓┏━━┓┏━┓
//   ┃┏┓┃┃━━┫┃┗┛┃┃┃┃┃┃┃┏┓┃┃┃┃┃┗┃┃┛     ┃┏┛┃┃┃┃┃┃┃┃┃┏┓┃┃╋┃
//   ┃┣┫┃┣━━┃┃┏┓┃┃┃┃┃┃┃┣┫┃┃┃┃┃┏┃┃┓     ┃┗┓┃┃┃┃┃┃┃┃┃┣┫┃┃┓┫
//   ┗┛┗┛┗━━┛┗┛┗┛┗━┻━┛┗┛┗┛┗┻━┛┗━━┛     ┗┻┛┗━┛┗┻━┻┛┗┛┗┛┗┻┛
#include "bits/stdc++.h" 
using namespace std; 
#define mod 1e9 + 7 
#define FOR(a, c) for (int a = 0; a < c; a++) 
#define FORL(a, b, c) for (int a = b; a < c; a++) 
#define FORR(a, b, c) for (int a = b ; a > c; a--) 
typedef long long int ll; 
typedef vector<int> vi; 
typedef pair<int, int> pi; 
#define PB push_back 
#define POB pop_back 
#define MP make_pair 
int maxm(int a[], int i){
  int ma = INT_MIN;
  for(int j=0; j<i; j++){
    if(a[j]>ma){
      ma  = a[j];
    }
  }
  return ma;
}
int main() 
{ 
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  int a[n];
  ll ma = 0,c=0;;
  FOR(i,n){
    cin>>a[i];
    if(a[i]>ma){
      ma=a[i];
    }
    else{
      c+=ma-a[i];
    }
  }
  cout<< c;
}
// By Ashwani Kumar, Indian Institute Of Technology(IIT), Guwahati.
//   ╔══╗╔══╗╔══╗     ╔══╗╔╦╗╔╦═╦╗╔══╗╔╗╔╗╔══╗╔══╗╔══╗
//   ╚║║╝╚║║╝╚╗╔╝     ║╔═╣║║║║║║║║║╔╗║║╚╝║║╔╗║╚╗╔╝╚║║╝
//   ╔║║╗╔║║╗─║║─     ║╚╗║║║║║║║║║║╠╣║║╔╗║║╠╣║─║║─╔║║╗
//   ╚══╝╚══╝─╚╝─     ╚══╝╚═╝╚═╩═╝╚╝╚╝╚╝╚╝╚╝╚╝─╚╝─╚══╝

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

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2 == 0 && 2*x <= y && y <= 4*x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main ()
{
    int n; cin >> n;
    double s2 = 0, s1 = 0;

    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        s2 += x * x;
        s1 += x;
    }

    int p1 = (int)ceil( s1/n ), p2 = (int)floor( s1/n );

    cout << (int)s2 + min( int(n * p1 * p1 - 2 * p1 * s1) , int(n * p2 * p2 - 2 * p2 * s1) ) << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let x = read::<i64>();
    let mut g = (read::<i64>() - x).abs() as usize;
    let d = (1..n)
        .map(|_| (read::<i64>() - x).abs() as usize)
        .collect::<Vec<_>>();

    for di in d {
        g = gcd(g, di)
    }
    println!("{}", g);

    fn gcd(a: usize, b: usize) -> usize {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }
}


Measured memory_bytes: 4352
N,u,v = map(int, input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    s,t = map(int, input().split())
    G[s-1].append(t-1)
    G[t-1].append(s-1)


def expro(u):
    D=[0]*N
    D[u]=0
    S=[]
    S.append(u)
    L=[]
    q=0
    while(q<N):
        l=S[q]
        for i in range(len(G[l])):
            m=G[l][i]
            if(len(G[l])==1 and l!=u):
                L.append(l)
            if(D[m]==0 and m!=u):
                D[m]=D[l]+1
                S.append(m)
        #S.remove(l)
        q+=1
    return L,D
L,D = expro(u-1)
M,E = expro(v-1)
k=0
ans=0
#print(G)
#print(D)
#print(L)
for i in M:
    if D[i]<E[i]:
        if k<E[i]:
            k=E[i]
            ans=E[i]-1
print(ans)


Measured memory_bytes: 30620
a, b = map(int, input().split())
for i in range(1000):
    c = int((i + 10) * 0.08)
    d = int((i + 10) * 0.10)
    if c == a and d == b:
        if i + 10 > 1000:
            break
        print(i + 10)
        exit()
print('-1')

Measured memory_bytes: 3064
module mod_union_find
  implicit none
  type union_find
    integer :: n = 0
    integer, pointer :: par(:), rnk(:), siz(:) => null()
  contains
    procedure :: init => inituf
    procedure :: release => releaseuf
    procedure :: find => find
    procedure :: same => same
    procedure :: unite => unite
    procedure :: size => size_of
  end type
  interface union_find
    module procedure :: newuf
  end interface union_find
contains
  function newuf(n) result(ret)
    integer, intent(in) :: n
    type(union_find) :: ret
    integer :: i
    ret%n = n
    allocate(ret%par(n),ret%rnk(n),ret%siz(n))
    ret%rnk = 0
    ret%siz = 1
    ret%par = [(i,i=1,n)]
  end
  subroutine inituf(this,n)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: n
    integer :: i
    if (this%n /= n) then
      if (this%n /= 0) deallocate(this%par,this%rnk,this%siz)
      allocate(this%par(n),this%rnk(n),this%siz(n))
    end if
    this%n = n
    this%rnk = 0
    this%siz = 1
    this%par = [(i,i=1,n)]
  end
  subroutine releaseuf(this)
    class(union_find), intent(inout) :: this
    if (this%n /= 0) deallocate(this%par,this%rnk,this%siz)
    this%n = 0
  end
  recursive function find(this,i) result(ret)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    integer :: ret
    if (this%par(i) /= i) this%par(i) = find(this,this%par(i))
    ret = this%par(i)
  end
  logical function same(this,i,j)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    same = find(this,i) == find(this,j)
  end
  subroutine unite(this,i,j)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    integer :: x, y
    x = find(this,i)
    y = find(this,j)
    if (x == y) return
    if (this%rnk(x) < this%rnk(y)) then
      this%par(x) = y
      this%siz(y) = this%siz(y)+this%siz(x)
    else
      this%par(y) = x
      this%siz(x) = this%siz(x)+this%siz(y)
      if (this%rnk(x) == this%rnk(y)) this%rnk(x) = this%rnk(x)+1
    end if
  end
  integer function size_of(this,i)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    size_of = this%siz(find(this,i))
  end
end module mod_union_find
program friend_suggestions
  use mod_union_find
  implicit none
  integer :: n, m, k, a, b, c, d, i
  integer, dimension(100000) :: x = 0
  type(union_find) :: uf
  read(*,*) n, m, k
  uf = union_find(n)
  do i = 1, m
    read(*,*) a, b
    call uf%unite(a,b)
    x(a) = x(a)+1
    x(b) = x(b)+1
  end do
  do i = 1, k
    read(*,*) c, d
    if (uf%same(c,d)) then
      x(c) = x(c)+1
      x(d) = x(d)+1
    end if
  end do
  write(*,'(i0)',advance='no') uf%size(1)-x(1)-1
  do i = 2, n
    write(*,'(x,i0)',advance='no') uf%size(i)-x(i)-1
  end do
  write(*,*)
end program friend_suggestions

Measured memory_bytes: 2424
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++);

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << abs(a[2] - a[0]) << endl;
	return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;
 
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
 
struct RollingHash{
    int n;
    ll mod1 = 1e9 + 7, mod2 = 1e9 + 9;
    ll base1 = 1007, base2 = 1009;
    VL hash1, hash2, pow1, pow2;
 
    void init(string s){
        n = s.length();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        pow1.assign(n+1, 1);
        pow2.assign(n+1, 1);
        REP(i,n){
            hash1[i+1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + s[i]) % mod2;
            pow1[i+1] = (pow1[i] * base1) % mod1;
            pow2[i+1] = (pow2[i] * base2) % mod2;
        }
    }
 
    // [l, r)
    PL hash(int l, int r){
        ll h1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
        ll h2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
        return PL(h1, h2);
    }
 
    bool match(int l1, int r1, int l2, int r2){
        if (r1 > n || r2 > n) return false;
        return hash(l1, r1) == hash(l2, r2);
    }
 
    bool match(int l1, int l2, int k){
        return match(l1, l1 + k, l2, l2 + k);
    }
 
    int lcp(int l1, int l2){
        int ok = 0, ng = n;
        while (ng - ok > 1){
            int m = (ok + ng) / 2;
            if (match(l1, l2, m)) ok = m;
            else ng = m;
        }
        return ok;
    }
};
 
int main() {
    string s, t;
    cin >> s >> t;
/*    if (s == string(s.length(), s[0]) && t == string(t.length(), t[0]) && s[0] == t[0]){
        cout << -1 << endl;
        return 0;
    }*/
    while (s.length() < t.length()) s += s;
    s += s;
    RollingHash rhs, rht;
    rhs.init(s);
    rht.init(t);
    int n = s.length() / 2, m = t.length();
    VI cnt(n, -1);
    int ans = 0;
    REP(i,n){
        if (cnt[i] != -1) continue;
        int p = i, c = 0;
        VI x;
        set<int> st;
        while (true){
            if (rht.hash(0, m) != rhs.hash(p, p + m)) break;
            x.push_back(p);
            st.insert(p);
            p = (p + m) % n;
            if (st.count(p)){
                cout << -1 << endl;
                return 0;
            }
            if (cnt[p] != -1){
                c = cnt[p];
                break;
            }
        }
        if (x.empty()) cnt[i] = 0;
        else{
            REP(i,x.size()){
                cnt[x[x.size()-i-1]] = c + i + 1;
            }
        }
    }
    cout << *max_element(ALL(cnt)) << endl;
 
    return 0;
}


Measured memory_bytes: 110116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int n;
    cin >> n;
    vi p(n);
    rep(i,n){
        cin >> p[i];
    }
    int  ans = 0;
    rep1(i,n-1){
        if(p[i-1]<p[i] && p[i]<p[i+1]) ans++;
        else if(p[i-1]>p[i] && p[i]>p[i+1])ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define INF (10000000)
#define MIN(x, y) ((x) < (y) ? (x) : (y))

using namespace std;

map<string, int> ItemList;
map<string, list<string> > WroughtList;

int GetMinCost(string& butt)
{
	int wrought_cost;
	map<string, list<string> >::iterator it;
	map<string, int>::iterator mit;
	
	it = WroughtList.find(butt);
	
	if (it != WroughtList.end()){
		wrought_cost = 0;
		for (list<string>::iterator lit = it->second.begin(); lit != it->second.end(); lit++){
			wrought_cost += GetMinCost(*lit);
		}
	}
	else {
		wrought_cost = INF;
	}
	
	mit = ItemList.find(butt);
	
	return (MIN(wrought_cost, mit->second));
}

int main(void)
{
	int ItemCnt;
	int WroughtCnt;
	string sarch_item;
	pair<string, int> add;
	pair<string, list<string> > wadd;
	
	while (1){
		ItemList.clear();
		WroughtList.clear();
		cin >> ItemCnt;
		if (ItemCnt == 0) break;
		for (int i = 0; i < ItemCnt; i++){
			cin >> add.first >> add.second;
			ItemList.insert(add);
		}
		cin >> WroughtCnt;
		for (int i = 0; i < WroughtCnt; i++){
			int cnt;
			
			cin >> wadd.first >> cnt;
			wadd.second.clear();
			for (int i = 0; i < cnt; i++){
				string name;
				
				cin >> name;
				wadd.second.push_back(name);
			}
			WroughtList.insert(wadd);
		}
		
		cin >> sarch_item;
		
		cout << GetMinCost(sarch_item) << endl;
		
	}
	
	return (0);
}

Measured memory_bytes: 0
import itertools
from functools import lru_cache

def main():
    n = int(input())
    a = [[] for _ in range(n)]
    for i in range(n):
        syougen_kosu = int(input())
        for __ in range(syougen_kosu):
            x, y = map(int, input().split())
            a[i].append((x-1,y))
    ans = [0]
    for x in itertools.product([-1,1], repeat=n):
        m = list(x)
        is_legal = True
        for i, v in enumerate(x):
            if v == -1:
                continue
            for j in a[i]:
                if j[1] == 1:
                    if m[j[0]] == -1:
                        is_legal = False
                        break
                    m[j[0]] = 1
                else:
                    if m[j[0]] == 1:
                        is_legal = False
                        break
                    m[j[0]] = -1
            if not is_legal:
                break
        if is_legal:
            ans.append(m.count(1))
    print(max(ans))
                
if __name__ == '__main__':
    main()

Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll n,i,j,x,y,sum=0,c=0;
    cin>>x>>y;
    if(x>y)
    {
        cout<<0<<endl;
        return 0;
    }
    else
    {
        c=1;
        sum=x;
    }
    while(sum<=y)
    {

        sum*=2;
        if(sum<=y)
            c++;
        else
            break;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
hw = []
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    hw.append([h, w])

for h, w in hw:
    print('#'*w)
    for hi in range(2, h):
        print(''.join(['#', '.'*(w-2), '#']))
    print('#'*w)
    print('')



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

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *NIL, *root;

void insert(int x) {
    Node *p = NIL;
    Node *u = root;
    Node *in = (Node *)malloc(sizeof(Node));
    in->key = x;
    in->left = NIL;
    in->right = NIL;

    while (u != NIL) {
        p = u;
        if (in->key < u->key) {
            u = u->left;
        } else {
            u = u->right;
        }
    }

    in->parent = p;
    if (p == NIL) {
        root = in;
    } else if (in->key < p->key) {
        p->left = in;
    } else {
        p->right = in;
    }
}

void printPre(Node *u) {
    if (u == NIL) {
        return;
    }

    printf(" %d", u->key);
    printPre(u->left);
    printPre(u->right);
}

void printIn(Node *u) {
    if (u == NIL) {
        return;
    }

    printIn(u->left);
    printf(" %d", u->key);
    printIn(u->right);
}

int main() {
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        string com;
        cin >> com;
        if (com == "insert") {
            int x;
            scanf("%d", &x);
            insert(x);
        } else if (com == "find") {
            int x;
            scanf("%d", &x);
            
        } else {
            printIn(root);
            printf("\n");
            printPre(root);
            printf("\n");
        }
    }
}


Measured memory_bytes: 26688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a, b, c, x, y, res;
	cin>>a>>b>>c>>x>>y;
	res = numeric_limits<ll>::max() - 1;
	if(x <= y){
		for(int i = 0; i <= x; ++i){
			ll ap = (i * a) + (i * b) + ((y - i) * 2 * c);
			ll bp = (i * 2 * c) + (x - i) * a + (y - i) * b;
			res = min(res, min(ap,  bp));
		}
	}
	else{
		for(int i = 0; i <= y; ++i){
			ll ap = (i * b) + ((x - i) * 2 * c) + (i * a);
			ll bp = (i * 2 * c) + (x - i) * a + (y - i) * b;
			res = min(res, min(ap,  bp));
		}
	}
	if(2 * max(x, y) * c < res){
		res = 2 * max(x, y) * c;
	}
	cout<<res<<endl;
	return 0;
}


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

namespace CodeForce
{



    class CF
    {

        static void Main(string[] args)
        {
            List<int> numbers = new List<int>(from x in Console.ReadLine().Split(' ') select Convert.ToInt32(x));
            Console.WriteLine("{0} {1} {2}", numbers[2], numbers[0], numbers[1]);
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int ch[30];
}tr[2000010];int rt,trlen;
char ss[15];
int mx,cnt[2000010],top,sta[15];
inline void dfs(int now)
{
	if(cnt[now]==mx)
	{
		for(int i=1;i<=top;i++)printf("%c",sta[i]+'a'-1);
		puts("");
	}
	for(int i=1;i<=26;i++)if(tr[now].ch[i]){sta[++top]=i;dfs(tr[now].ch[i]);top--;}
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();trlen=rt=1;
    for(int i=1;i<=n;i++)
    {
    	scanf("%s",ss+1);int len=strlen(ss+1);
    	int now=rt;
    	for(int j=1;j<=len;j++)
    	{
    		int ul=ss[j]-'a'+1;
    		if(!tr[now].ch[ul])tr[now].ch[ul]=++trlen;
    		now=tr[now].ch[ul];
    	}cnt[now]++;
    }
    for(int i=2;i<=trlen;i++)mx=max(mx,cnt[i]);
    dfs(1);
    return 0;
}

Measured memory_bytes: 118656