akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

constexpr int bm = 2500;
ll BIT[51][bm];
int zero[51];
void add(int A, int gin, ll co) {
	co = 4e12 - co;
	while (gin > 0) {
		if (BIT[A][gin] >= co) break;
		BIT[A][gin] = co;
		gin -= gin & -gin;
	}
}
ll query(int A, int gin) {
	ll kotae = 0;
	while (gin < bm) {
		kotae = max(BIT[A][gin], kotae);
		gin += gin & -gin;
	}
	return 4e12 - kotae;
}

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


	int N, M, S;
	cin >> N >> M >> S;
	if (S >= 2460) S = 2460;

	vector<ll> E[51];
	rep(i, M) {
		int u, v, a;
		ll b;
		cin >> u >> v >> a >> b;
		b = a << 8 | b << 16;
		E[u].pb(v | b);
		E[v].pb(u | b);
	}
	int C[51], D[51];
	rep1(i, N) {
		cin >> C[i] >> D[i];
	}

	add(1, S + 1, 0);
	priority_queue<ll, vector<ll>, greater<ll> > PQ;
	PQ.push((1 << 12) + S + 1);

	while (PQ.size()) {
		auto p = PQ.top();
		PQ.pop();
		ll ti = p >> 18;
		int i = p >> 12 & 63;
		int gin = p & 4095;



		if (ti > query(i, gin)) continue;

		ll ti2 = ti + D[i];
		int gin2 = gin + C[i];
		if (gin2 > 2460) gin2 = 2460;
		if (ti2 < query(i, gin2)) {
			add(i, gin2, ti2);
			PQ.push(ti2 << 18 | i << 12 | gin2);
		}

		for (auto pp : E[i]) {
			int to = pp & 255;
			ti2 = ti + (pp >> 16);
			gin2 = gin - (pp >> 8 & 255);
			if (gin2 > 0) {
				if (ti2 < query(to, gin2)) {
					add(to, gin2, ti2);
					PQ.push(ti2 << 18 | to << 12 | gin2);
				}
			}
		}

	}

	for (int i = 2; i <= N; i++) {
		co(query(i, 1));
	}



	Would you please return 0;
}

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,y;cin>>n>>y;
  for(int i=0;i*10000<=y;i++){
    for(int j=0;i*10000+j*5000<=y;j++){
      if(i*10000+j*5000+(n-i-j)*1000==y){
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 3680
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    a,b,c = A[i],B[i],C[i]
    t = len(list(set([a,b,c])))
    if t == 1:
        pass
    elif t == 2:
        ans += 1
    elif t == 3:
        ans += 2

print(ans)

Measured memory_bytes: 38384
// Create by JJL
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

const int N=5010,Mod=1e9+7;
int a[N],p[N],len[N];
bool st[N];
LL sum[N][N],tsum[N][N];
int main(){
    IOS;
    /* START CODE */
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>p[i];
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i){
       memset(st,0,sizeof st);
       int pos=i,idx=0;
       LL res=0;
       while(st[pos]==0){
            sum[i][++idx]=res+a[pos];
            res+=a[pos];
            st[pos]=1;
            pos=p[pos];
       }
       len[i]=idx;
    }
    LL ans=-1e18;
    memset(tsum,-0x3f,sizeof tsum);
    for(int i=i;i<=n;++i){
        for(int j=1;j<=len[i];++j){
            tsum[i][j]=max(tsum[i][j-1],sum[i][j]);
        }
    }
    for(int i=1;i<=n;++i){
        LL res=k/len[i]*sum[i][len[i]]+tsum[i][k%len[i]];//走最多圈
        res=max(tsum[i][min(k,len[i])],res);//走最少圈
        if(k>=len[i]){
            res=max(tsum[i][len[i]],res);
            res=max((k/len[i]-1)*sum[i][len[i]]+tsum[i][len[i]],res);
        }
        ans=max(ans,res);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 394968
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
ll _sieve_size;
bitset<10000010> bs;   // 10^7 should be enough for most cases
vi primes;   // compact list of primes in form of vector<int>


// first part

void sieve(ll upperbound) {          // create list of primes in [0..upperbound]
  _sieve_size = upperbound + 1;                   // add 1 to include upperbound
  bs.set();                                                 // set all bits to 1
  bs[0] = bs[1] = 0;                                     // except index 0 and 1
  for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
    // cross out multiples of i starting from i * i!
    for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
    primes.push_back((int)i);  // also add this vector containing list of primes
} }                                           // call this method in main method

bool isPrime(ll N) {                 // a good enough deterministic prime tester
  if (N <= _sieve_size) return bs[N];                   // O(1) for small primes
  for (int i = 0; i < (int)primes.size(); i++)
    if (N % primes[i] == 0) return false;
  return true;                    // it takes longer time if N is a large prime!
}                      // note: only work for N <= (last prime in vi "primes")^2

int ans[100005];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    sieve(100000);
    memset(ans,0,sizeof ans);
    ans[1] = 0;
    for(ll i=2; i<=100001; ++i) {
        if((i%2) != 0 && isPrime(i) && isPrime((i+1)/2)) 
            ans[i] = ans[i-1]+1;
        else
            ans[i] = ans[i-1];
    }
    int q; cin>>q;
    for(int i=0; i<q; ++i) {
        int l , r; cin>>l>>r;
        cout<<ans[r+1] - ans[l-1]<<endl;
    }



    return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
#define INPUT freopen("input.txt", "r", stdin);
using namespace std;

int mod = 1e9+7;

int main(){
	SLAY
	int _=1;
	// cin>>_;
	while(_--){
		ll n,m,x , y,a,b,k,ans=0, mx=LLONG_MIN, mn=LLONG_MAX;
		string str;
		cin>>n>>m;
		vector< vector<ll> > v(n , vector<ll>(m,0));
		vector< vector<ll> > dp(n+1 , vector<ll>(m+1,0));
		
		for(int i = 0 ; i<n ;i++){
			cin>>str;
			for(int j = 0 ; j <m ;  j++){
				if(str[j]=='#')v[i][j]=1;
			}
		}
		
		
		
		for(int i = n-1 ; i>=0 ;i--){
			for(int j = m-1 ; j>=0 ;j--){
				if(i==n-1 && j==m-1)dp[i][j]=1;
				else if(v[i][j]!=1){
					dp[i][j]=dp[i+1][j]+dp[i][j+1];
					dp[i][j]%= mod;
				}
			}
		}
		
		cout<<dp[0][0];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 18940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }
    auto itr = unique(v.begin(), v.end());
    v.erase(itr, v.end());
    for(int i = 0; i < v.size(); i++)
    {
        if(i > 0) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 3568
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int r, D, x;
    cin >> r >> D >> x;

    for(int i=0; i<10; i++) {
        x = r*x - D;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 300005

int N;
int table[NUM],sorted[NUM];
bool is_ok[NUM];

int main(){

	int ans = -1;
	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		scanf("%d",&table[i]);
		sorted[i] = table[i];
	}

	sort(sorted,sorted+N);

	int num_wrong_pos = 0;

	for(int i = 0; i < N; i++){
		if(table[i] != sorted[i]){
			num_wrong_pos++;
		}
	}

	if(num_wrong_pos == 0){
		ans = 0;
	}

	int num_query;
	scanf("%d",&num_query);

	int x,y;

	for(int loop = 1; loop <= num_query; loop++){

		scanf("%d %d",&x,&y);

		if(ans != -1){
			continue;
		}

		x--;
		y--;

		if(table[x] != sorted[x]){

			if(table[x] == sorted[y]){
				num_wrong_pos--;
			}

		}else{ //table[x] == sorted[x]

			if(table[x] != sorted[y]){
				num_wrong_pos++;
			}
		}

		if(table[y] != sorted[y]){

			if(table[y] == sorted[x]){
				num_wrong_pos--;
			}
		}else{ //table[y] == sorted[y]

			if(table[y] != sorted[x]){
				num_wrong_pos++;
			}
		}

		if(num_wrong_pos == 0){
			ans = loop;
		}

		swap(table[x],table[y]);
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 5656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int D,N;
    scanf("%d%d",&D,&N);
    if( N != 100 ){
        printf("%d\n",N*(int)pow(100,D));
    }else if( D == 0 ){
        printf("101\n");
    }else if( D == 1 ){
        printf("10100\n");
    }else if( D == 2 ){
        printf("1010000");
    }

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];
  vector<vector<int>> dp(101, vector<int>(100005, 0));

  rep(i, N) {
    rep(j, 100005) {
      cmax(dp[i + 1][j], dp[i][j]);
      if (W < j + w[i]) continue;
      cmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
    }
  }
  cout << dp[N][W] << endl;

  return 0;
}


Measured memory_bytes: 80256
// ABC059_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

char toupper(char ch) {
    return (char)(ch - 32);
}

string toupper(string str) {
    for (ll i = 0; i < str.length(); ++i) {
        str[0] -= 32;
    }
    return str;
}

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

    // input
    string str, ans;
    REP(i, 3) {
        cin >> str;
        ans += str[0] - 32;
    }
    
    cout << ans << "\n";
    
    return 0;
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int s;
  cin >> s;
  set<int> set;
  int f = s;
  set.insert(f);
  for (int i = 1;; i++) {
    if (f % 2 == 0) {
      f = f / 2;
      set.insert(f);
      if (set.size() != i+1) {
        cout << i+1 << endl;
        return 0;
      }
    } else {
      f = 3 * f + 1;
      set.insert(f);
      if (set.size() != i+1) {
        cout << i+1 << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pll,pll>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) (ll)v.size()
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define Time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;  // order_of_key(k) -> Number of elements strictly smaller than k
using namespace __gnu_pbds; // order_of_key() ; *( find_by_order() ) -> kth element in set;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min( ll a, ll b, ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}                 
                          /*Code Begins*/




int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, m, t,  k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    double x = 2.0*acos(-1)*n;
    cout << x ;


}

    Time;
    return 0;
}


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


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

  int a,b,c;
  cin>>a>>b>>c;
  int z,d = a-b;
  if(c>d)
    z= c-d;
  else
    z = 0;
  cout<<z<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}
#define MAX_V 2222
int p[MAX_V][MAX_V]={};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  for(int i=0;i<MAX_V;i++)p[0][i]=1;
  for(int i=1;i<MAX_V;i++){
    for(int j=1;j<MAX_V;j++){
	p[i][j]+=(p[i][j-1]+p[i-1][j])%(MOD);
    }
  }
  for(ll i=1;i<=k;i++){
    cout<<(combination(n-k+1,i)*(p[k-i][i]))%MOD<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 21120
package main

import "fmt"

func main() {
    var n, k int
    var s string
    fmt.Scan(&n, &k, &s)
    a := make([]int, 0)
    if s[0] == '0' {
        a = append(a, 0)
    }
    t, prev := 1, s[0]
    for i := 1; i < n; i++ {
        v := s[i]
        if prev == v {
            t++
        } else {
            prev = v
            a = append(a, t)
            t = 1
        }
    }
    a = append(a, t)
    if s[n - 1] == '0' {
        a = append(a, 0)
    }
    if 2 * k + 1 > len(a) {
        fmt.Println(n)
    } else {
        acc := make([]int, len(a) + 1)
        for i, v := range a {
            acc[i + 1] = acc[i] + v
        }
        ans := 0
        step := 2 * k + 1
        for i := step; i <= len(a); i += 2 {
            if ans < acc[i] - acc[i - step] {
                ans = acc[i] - acc[i - step]
            }
        }
        fmt.Println(ans)
    }
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int a[4][2];
	bool k=0;
	for (int i=1;i<=n;i++){
		cin>>a[3][0]>>a[3][1];
		if (k) continue;
		a[0][0]=a[1][0];
		a[0][1]=a[1][1];
		a[1][0]=a[2][0];
		a[1][1]=a[2][1];
		a[2][0]=a[3][0];
		a[2][1]=a[3][1];
		if (a[0][0]==a[0][1] && a[0][0]==0) continue;
		if (a[0][0]==a[0][1] && a[1][0]==a[1][1] && a[2][0]==a[2][1]){
			k=1;
			continue;
		}
	}
	if (k) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3760
#include"bits/stdc++.h"
using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<bool> isThereCost(N + 1, false);
    for (int i = 0; i < M; i++) {
        int A;
        cin >> A;
        isThereCost[A] = true;
    }

    int ans1 = 0, ans2 = 0;
    for (int i = X + 1; i <= N; i++) {
        if (isThereCost[i]) {
            ans1++;
        }
    }
    for (int i = X - 1; i >= 0; i--) {
        if (isThereCost[i]) {
            ans2++;
        }
    }

    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String S = sc.next();
    
    int pass = 0;
    int bRank = 0;
    for (int i = 0; i < N; i++) {
      char c = S.charAt(i);
      boolean ans = false;
      if (c == 'a' && pass < A+B) {
        pass++;
        ans = true;
      } else if (c == 'b') {
        bRank++;
        if (pass < A+B && bRank <= B) {
          pass++;
          ans = true;
        }
      }
      System.out.println(ans ? "Yes" : "No");
    }
  }
}

Measured memory_bytes: 35308
#include <bits/stdc++.h>
/**
 *    author:  dattrinh
 *    created:    Problemset
**/
#define pb push_back
#define fi first
#define ss second
#define tp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long;
using i64= int64_t;
const int N = 1e4+5;
ll read() {
    char c=getchar();while(!isdigit(c)) c=getchar();
    int num=0;while(isdigit(c)) num=num*10+c-'0',c=getchar();
    return num;
}
/**-----**-----*/
ll _;
map<int,int> a;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>_;
    for(int i=1;i<=_;++i)
        a[i]=0;
    for(int i=1;i<_;++i)
    {
        int x;cin>>x;
        a[x]++;
    }
    for(auto i:a){
        cout<<i.ss<<'\n';
    }
}


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


int main(){
    int N;
    cin>>N;
    vector<vector<int> > V(N, vector<int>(3)), dp(N, vector<int>(3,0));
    for(int i=0;i<N;i++)cin>>V[i][0]>>V[i][1]>>V[i][2];

    for(int i=0;i<N;i++){
        if(i==0)dp[i]=V[i];
        else{
            dp[i][0]=V[i][0]+max(dp[i-1][1], dp[i-1][2]);
            dp[i][1]=V[i][1]+max(dp[i-1][0], dp[i-1][2]);
            dp[i][2]=V[i][2]+max(dp[i-1][0], dp[i-1][1]);
        }
    }
    cout<<max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2])<<endl;
    return 0;
}

Measured memory_bytes: 11136
w,h,n = map(int, input().split())
a=0
b=0
listA=[]
while True:
  try:
    listA.append(list(map(int,input().split())))
  except:
    break;
for i in range(n):
  if listA[i-1][2]==1 and listA[i-1][0]>a:
    a = listA[i-1][0]
  elif listA[i-1][2]==2 and listA[i-1][0]<w:
    w = listA[i-1][0]
  elif listA[i-1][2]==3 and listA[i-1][1]>b:
    b = listA[i-1][1]
  elif listA[i-1][2]==4 and listA[i-1][1]<h:
    h = listA[i-1][1]
if w-a>0 and h-b>0:
  print((w-a)*(h-b))
else:
  print(0)
    

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

ll opt[401][401];

int main() {
	for (int i = 0; i < 401; ++i) {
		for (int j = 0; j < 401; ++j) {
			opt[i][j] = 1000000000000000000;
		}
	}
	int n; scanf("%d", &n);
	vector<int> a(n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	vector<ll> ps(n+1); for (int i = 0; i < n; ++i) ps[i+1] = ps[i] + a[i];
	for (int i = n - 1; i >= 0; --i) {
		opt[i][i] = 0;
		for (int j = i + 1; j < n; ++j) {
			for (int k = i; k < j; ++k) {
				opt[i][j] = min(opt[i][j], opt[i][k] + opt[k+1][j] + ps[j+1] - ps[i]);
			}
		}
	}
	printf("%lld\n", opt[0][n-1]);
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;

class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] c = new char[h][w];
    for(int i = 0; i < h; i++){
            c[i] = sc.next().toCharArray();
    }
    for(int i = 0; i < 2 * h; i++){
        for(int j = 0; j < w; j++){
            System.out.print(c[i / 2][j]);
            }
        System.out.println("");
    }
}
}


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

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

int main()
{
	int K;
	cin >> K;
	ll sum = 0;
	for (int i = 1; i <= K; ++i)
	{
		for (int j = 1; j <= K; ++j)
		{
			for (int k = 1; k <= K ; ++k)
			{
				sum += mygcd(i,mygcd(j,k));
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3672
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A_all = A1
A_all.extend(A2)
A_all.extend(A3)


N = int(input())


def get_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default
        
for i in range(N):
    b = int(input())
    suffix = get_index(A_all, b)
    if suffix >= 0:
        A_all[suffix] = 0

if A_all[0] + A_all[1] + A_all[2] == 0: print("Yes")
elif A_all[3] + A_all[4] + A_all[5] == 0: print("Yes")
elif A_all[6] + A_all[7] + A_all[8] == 0: print("Yes")
elif A_all[0] + A_all[3] + A_all[6] == 0: print("Yes")
elif A_all[1] + A_all[4] + A_all[7] == 0: print("Yes")
elif A_all[2] + A_all[5] + A_all[8] == 0: print("Yes")
elif A_all[0] + A_all[4] + A_all[8] == 0: print("Yes")
elif A_all[2] + A_all[4] + A_all[6] == 0: print("Yes")
else: print("No")

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        int N = r.nextInt();
        int M = r.nextInt();

        var picA = new List<string>();
        var tmpB = new List<string>();

        for (var i = 0; i < N; i++)
        {
            picA.Add(r.next());
        }

        for (var i = 0; i < M; i++)
        {
            tmpB.Add(r.next());
        }

        var line = 0; // 画像Aの何行目にいるか
        var p_found = new List<int>(); //見つかった場所
        var found = 0; // テンプレートBの何行目まで発見したか

        while (line < N)
        {
            var idx = picA[line].IndexOf(tmpB[found]);

            while (0 <= idx)
            {
                if (line == 0)
                {
                    p_found.Add(idx);
                }
                else if (!p_found.Contains(idx))
                {
                    p_found.Remove(idx);
                }

                int idx_next = idx + tmpB[found].Length;
                if (idx_next < picA[line].Length)
                {
                    idx = picA[line].IndexOf(tmpB[found], idx_next);
                }
                else
                {
                    break;
                }

            }

            if (p_found.Count > 0) found++;
            if (found >= M)
            {
                Console.WriteLine("Yes");
                return;
            }

            line++;
        }

        Console.WriteLine("No");

    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 11360
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int H = scan.nextInt();
    int M = scan.nextInt();
    double h = (H + (double)M/60)*30;
    double m = (double)M*6;
    double ans = Math.sqrt(A*A + B*B - 2*A*B*Math.cos(Math.toRadians(h-m)));
    System.out.println(ans);
  }
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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


Measured memory_bytes: 3636
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll power(ll a, ll b){
  ll ans = 1;
  if(b%2==0){
    REP(i, b/2){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans;
  }else{
    b = b/2;
    REP(i, b){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans* a;
  }
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
  
  ll n, k;
  cin>>n>>k;
  vector<ll> v(n);
  REP(i, n){
    ll x;
    cin>>x;
    v[i] = x;
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  REP(i, k)sum+=v[i];
  cout<<sum<<endl;
  return 0;
  
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

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

	int len = s.length();

	int ns = 0;
	int cnt = 0;
	REP(i, len) {

		if (s[i] == 'S') ns++;//Sを蓄える

		if (s[i] == 'T') {
			if (ns > 0) {//消去を行う
				ns--;
				cnt++;
			}
		}

	}

	cout << len - 2 * cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  bool OK = true;
  rep(i,0,N) {
    cin >> A[i];
    if(A[i] % 2 == 0) {
      if(A[i] % 3 == 0 || A[i] % 5 == 0) {
      }
      else {
        OK = false;
      }
    }
  }
  if(OK) {
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}


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

using namespace std;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll index = 1;
    ll m = 1;
    ll sum = 0;
    while (true) {
        if (index * 26LL >= N) {
            string s = "";
            REP(_, m) {
                REP(i, 26) {
                    if (N - index <= 0) {
                        s.push_back((char) ('a' + i));
                        index /= 26LL;
                        break;
                    }
                    N -= index;
                }
            }
            cout << s << endl;
            break;
        }

        index *= 26LL;
        N -= index;
        m++;
    }
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;//from,to,cost
map<P,int> Vertex;
vector<P> Time[100000];
vector<P> Graph[500000];//to,cost
int vc;
int main(){
    int N,M,S,G;
    cin>>N>>M>>S>>G;
    S--; G--;
    for(int i=0;i<N;i++){
        Vertex[P(i,0)]=vc;
        Time[i].emplace_back(0,vc);
        vc++;
    }
    for(int i=0;i<M;i++){
        int u,v,t,c;
        cin>>u>>v>>t>>c;
        u--; v--;
        if(!Vertex.count(P(u,t))){
            Vertex[P(u,t)]=vc;
            Time[u].emplace_back(t,vc);
            vc++;
        }
        if(!Vertex.count(P(v,t+c))){
            Vertex[P(v,t+c)]=vc;
            Time[v].emplace_back(t+c,vc);
            vc++;
        }
        Graph[Vertex[P(u,t)]].emplace_back(Vertex[P(v,t+c)],0);
    }

    for(int s=0;s<N;s++){
        sort(Time[s].begin(), Time[s].end());
        for(int i=1;i<Time[s].size();i++){
            Graph[Time[s][i-1].second].emplace_back(Time[s][i].second,Time[s][i].first-Time[s][i-1].first);
        }
    }
    vector<int> memo(vc+1,10000000);
    vector<bool> visited(vc+1,false);
    priority_queue<P,vector<P>,greater<P>> Q;
    Q.emplace(P(0,Vertex[P(S,0)]));
    while(!Q.empty()){
        int rain, v;
        tie(rain,v)=Q.top();Q.pop();
        if(visited[v]) continue;
        visited[v]=true;
        for(auto g:Graph[v]){
            int to,cost;
            tie(to,cost)=g;
            if(memo[to]>rain+cost){
                Q.emplace(rain+cost,to);
                memo[to]=rain+cost;
            }
        }
    }
    int ans = 1000000;
    for(auto t:Time[G]){
        ans=min(ans,memo[t.second]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70044
import itertools
import math
def d(a,b):
  return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

n = int(input())
cities = []
for i in range(n):
  cities.append(list(map(int,input().split())))

s = 0
fac = 1
for route in itertools.permutations([i for i in range(n)]):
  for i in range(len(route)-1):
    s += d(cities[route[i]],cities[route[i+1]])
print(s/math.factorial(n))

Measured memory_bytes: 43372
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define int ll
vector<int> dp;

int solve(vector<int>& arr, int curr, int k){
	int n = arr.size();
	if(curr == 0){
		return 0;
		}
	if(curr < k){
		return abs(arr[curr]-arr[0]);
		}
	if(dp[curr] != INT_MAX){
		return dp[curr];
		}
	for(int i = 1; i <= k; i ++){
		dp[curr] = min(dp[curr], solve(arr, curr-i, k)+abs(arr[curr]-arr[curr-i]));
		}
	return dp[curr];
}

int32_t main(){
	int n, k;
	cin >> n >> k;
	vector<int> arr(n, 0);
	for(int i = 0 ; i < n ; i ++)cin >> arr[i];
	dp.assign(n, INT_MAX);
	cout << solve(arr, n-1, k) << endl;
}


Measured memory_bytes: 9600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(); 
        int b = sc.nextInt();
		int m = sc.nextInt();
        int c,d,e;
        int [] ina = new int [a];
        int [] inb = new int [b];
		
        int [] inm = new int [m];
        int ans = 0;
        for(int i=0;i<a;i++){
                             ina[i] = sc.nextInt();
                            }
		for(int i=0;i<b;i++){
                             inb[i] = sc.nextInt();
                            }
        for(int i=0;i<m;i++){
                             c = sc.nextInt();
                             d = sc.nextInt();
                             e = sc.nextInt();
                             inm[i] = ina[c-1]+inb[d-1]-e;
                            }
        Arrays.sort(ina);
        Arrays.sort(inb);
        Arrays.sort(inm);
        ans = Math.min(ina[0]+inb[0],inm[0]);
		System.out.println(ans);
	}
}


Measured memory_bytes: 134524
d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
     [[-1,  0], [0, -1], [1,  0], [1, 1], [0, 1], [-1, 1]]]

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each do |i|
  gets.split(" ").each_with_index{ |e, j| fld[i][j+1] = true if e == "1" }
end

tmp = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
tmp[0][0] = true
until arr.empty?
  y, x = arr.pop
  d[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !tmp[u][v]
      tmp[u][v] = true
      arr << [u, v]
    end
  end
end
fld = fld.flatten.zip(tmp.flatten).map{|f,p| !(!f&p) }
sum = 0
fld.each_with_index{ |e, i| sum += d[i/(w+2)%2].count{ |y, x| !fld[i+y*(w+2)+x]} if e}
p sum

Measured memory_bytes: 9324
a,b,c,d=input()
for i in range(2**3):
    l=["-","-","-"]
    for j in range(3):
        if (i>>j&1):
            l[j]="+"
    if eval(a+l[0]+b+l[1]+c+l[2]+d)==7:
        print(a+l[0]+b+l[1]+c+l[2]+d+"=7")
        exit()

Measured memory_bytes: 9112
a= int(input())
b= int(input())
c= int(input())
d= int(input())
e= int(input())
k= int(input())
if b-a > k or c-a > k or d-a > k or e-a>k or c-b > k or d-b> k or e-b>k or d-c > k or e-c>k or e-d > k:
    print(':(')
else:
    print('Yay!')


Measured memory_bytes: 38256
import sys


def main():
    line = sys.stdin.readline()
    lst = [ int(s) for s in line.split()]
    n = lst[0]
    m = lst[1]

    shop_lst = []

    for i in range(n):
        line = sys.stdin.readline()
        lst = [ int(s) for s in line.split()]
        a = lst[0]
        b = lst[1]
        p = (a, b)

        shop_lst.append(p)

    sorted_lst = sorted(shop_lst, key=lambda p: p[0])

    total_cost = 0
    bottles = 0

    for a, b in sorted_lst:
        if bottles + b < m:
            # 全部買っても足りないなら、全部買って次へ
            total_cost += a * b
            bottles += b
            continue
        elif bottles + b == m:
            # ぴったりm本なら、そこでおしまい
            total_cost += a * b
            bottles += b
            break
        else:
            # あまっちゃう場合 → (m - 今の本数) だけ買う
            total_cost += a * (m - bottles)
            bottles += (m - bottles)
            break

    print(total_cost)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 18896
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int a, b;
    int num = 2;
    int ans = 0;

    cin >> a >> b;

    while (num) {
        if (a < b) {
            ans += b;
            b--;
        }
        else {
            ans += a;
            a--;
        }
        num--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
    char s[200],t[200],temp;
    int count = 0;

    scanf("%s",s);
    scanf("%s",t);

    while(count < strlen(s)){
        if(strcmp(s,t) == 0){
            printf("Yes\n");
            return 0;
        }
        temp = s[strlen(s)-1];
        for(int i = strlen(s)-1; i > 0; i--){
            s[i] = s[i-1];
        }
        s[0] = temp;
        count++;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> v;
vector<int>::iterator it;
int sum;
for(int i=0;i<n;i++){
    int x;
    cin>>x;
    v.push_back(x);
}
it=max_element(v.begin(),v.end());
for(auto i=v.begin();i!=v.end();i++){
    sum=sum +*i;


}
if(sum>2*(*it))
    cout<<"Yes";
else
    cout<<"No";

}

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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    cin>>n;
    set<ll> s;
    rep(i,0,n){
        ll a;
        cin>>a;
        auto it = s.find(a);
        if (it != s.end()){
            s.erase(it);
        } else {
            s.insert(a);
        }
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let divisors = enumerate_divisors(m);

    let mut ans = 0;
    for d in divisors {
        if d > m / n {
            break;
        }
        if (m - (n - 1) * d) % d == 0 {
            ans = d;
        }
    }
    return ans.to_string();
}

fn enumerate_divisors(n: usize) -> Vec<usize> {
    let mut divisors = Vec::new();

    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            divisors.push(i);
            if n / i != i {
                divisors.push(n / i);
            }
        }
        i += 1;
    }
    divisors.sort();
    return divisors;
}


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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (1LL << 60);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  int N;
  cin >> N;
  vector<int> h(N + 2, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  vector<ll> dp(N + 2, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    dumpv(dp);
    if (i > 0) {
      dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    if (i > 1) {
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    // dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    // dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  dumpv(dp);
  cout << dp[N - 1] << endl;
  return 0;
}

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

typedef long long ll;
ll MOD = 1e9+7;
int main()
{
    string L;
    cin >> L;
    //at(L(1start)).at(smaller)
    int size = L.size();
    vector<vector<ll>> dp(size + 1, vector<ll>(2));
    dp.at(0).at(0) = 1;
    dp.at(0).at(1) = 0;
    for(int i = 0; i < size; i++)
    {
        int num = L.at(i) - '0';
        if(num == 1){
            dp.at(i + 1).at(0) = (2 * dp.at(i).at(0)) % MOD;
            dp.at(i + 1).at(1) = (3 * dp.at(i).at(1) + dp.at(i).at(0)) % MOD;
        }else{
            dp.at(i + 1).at(0) = dp.at(i).at(0);
            dp.at(i + 1).at(1) = ( 3 * dp.at(i).at(1)) % MOD;
        }
    }

    cout << (dp.at(size).at(0) + dp.at(size).at(1)) % MOD << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>

int main(void)
{
	int h,m,s,w;
	
	scanf("%d",&w);
		
	h=w/3600;
	m=(w%3600)/60;
	s=w%60;
	
	printf("%d:%d:%d\n",h,m,s);
		
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t n,m;
    cin>>n>>m;
    if(n>=3&&m>=3){
        cout<<(n-2)*(m-2)<<endl;
    }
    else if(n==2||m==2){
        cout<<0<<endl;
    }
    else if(n+m>=3){//1,2以上
        //n<=mに変える
        if(n>m){
            int tmp = n;
            n = m;
            m = tmp;
        }
        cout<< m-2<<endl;
    }
    else if(n==1&&m==1){
        cout<<1<<endl;
    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, y;
    cin >> x >> y;
    
    bool res = false;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y)
            res = true;
    }
    cout << (res ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3652
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto D = RDA;
	D.sort();
	long[] list = [0];
	foreach (i; 0..D.length)
	{
		if (i % 2 == 0)
			list ~= D[i];
		else
			list ~= (24-D[i]) % 24;
	}
	list.sort();
	long ans = long.max;
	foreach (i; 1..list.length)
	{
		ans = min(ans, list[i] - list[i-1]);
	}
	ans = min(ans, 24 - list[$-1]);

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    lines = [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ]
    
    # print(A, B)
    l = []
    for i in range(3):
        for j in range(3):
            l.append(A[i][j])

    for i in range(9):
        for b in B:
            if l[i] == b:
                l[i] = 0
                    
        
    ans = 'No'
    for a, b, c in lines:
        if l[a] == 0 and l[b] == 0 and l[c] == 0:
            ans = 'Yes'
            break

    return ans

print(solve())

Measured memory_bytes: 3064