akhauriyash/Code-Regression huggingface dataset:
/*input
<>>><<><<<<<>>><
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=500005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
    string s;
    cin>>s;
    arr[0]=0;
    REP1(i,s.length()){
        if(s[i-1]=='<') MXTO(arr[i],arr[i-1]+1);
    }
    ll ans=arr[s.length()];
    for(int i=s.length()-1;i>=0;i--){
        if(s[i]=='>') MXTO(arr[i],arr[i+1]+1);
        ans+=arr[i];
    }
    cout<<ans;
}

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

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

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

  int n; cin >> n;
  vector<int>  a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> lg(n), rg(n);
  for (int i = 1; i < n; i++) lg[i] = gcd(lg[i-1], a[i-1]);
  for (int i = n-2; i > -1; i--) rg[i] = gcd(rg[i+1], a[i+1]);
  int res = 1;
  for (int i = 0; i < n; i++) {
    res = max(res, (int)gcd(lg[i], rg[i]));
  }
  cout << res << '\n';
  return 0;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S;
  cin >> S;

  int k = len(S);
  int cnt = 0;
  rep(i, k) {
    cnt += (S[i] == 'o');
  }
  cnt += 15 - k;

  if (cnt >= 8)
    cout << "YES\n";
  else
    cout << "NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗(i <= 20 まで)
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

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

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	long long price = LONGINF;
	FOR(i, 0, 100000 + 1){
		long long p;
		p = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B;
		price = min(price, p);
	}
	cout << price << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
long long ans=1;
int main()
{
	scanf("%d%d",&a,&b);
	ans=b;
	b--;
	  for (int j=1;j<a;j++)
	    ans*=b;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  int P[100000],Y[100000];
  vector<int> sortedY[100001];
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>P[i]>>Y[i];
    sortedY[P[i]].push_back(Y[i]);
  }
  for(int i=1;i<=N;i++){
    sort(sortedY[i].begin(),sortedY[i].end());
  }
  for(int i=0;i<M;i++){
    cout<<setfill('0')<<right<<setw(6)<<P[i];
    /*
    for(int j=0;j<sortedY[P[i]].size();j++){
      if(sortedY[P[i]][j]==Y[i]){
        cout<<setfill('0')<<right<<setw(6)<<j+1<<endl;
        break;
      }
    }
    */
    //二分探索
    int l=0,r=sortedY[P[i]].size()-1;
    while(1){
      if(sortedY[P[i]][(l+r)/2]==Y[i]){
        cout<<setfill('0')<<right<<setw(6)<<(l+r)/2 + 1<<endl;
        break;
      }else if(sortedY[P[i]][(l+r)/2]>Y[i]){
        r=(l+r)/2;
      }else{
        l=(l+r)/2;
        if(l==(l+r)/2){
          cout<<setfill('0')<<right<<setw(6)<<r + 1<<endl;
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n, k, res;
  cin>>n>>k;
  vector<int> vec(n, 0);
  for(int i = 0; i < n; ++i)cin>>vec[i];
  sort(vec.begin(), vec.end(), greater<int> ());
  res = 0;
  for(int i = k; i < n; ++i){
    res += vec[i];
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1024
require 'matrix'
p1x, p1y, p2x, p2y = gets.split.map &:to_i
p1 = Vector[ p1x, p1y ]
p1p2 = Vector[ p2x - p1x, p2y - p1y ]
q = gets.to_i
q.times do
  px, py = gets.split.map &:to_i
  p = Vector[ px, py ]
  p1p = Vector[ px - p1x, py - p1y ]
  p1t_norm = p1p.inner_product(p1p2) / p1p2.norm
  t = p1 + p1p2 * ( p1t_norm / p1p2.norm )
  pt = Vector[ t[0] - px, t[1] - py ]
  u = p + pt * 2
  puts "%.8f %.8f" % [ u[0], u[1] ] 
end

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

typedef long long ll;
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n;	cin >> n;
	ll l[n];
	REP(i, n){
		cin >> l[i];
	}
	ll ans = 0;

	for(ll i=0; i<n; i++)
	for(ll j=i+1; j<n; j++)
	for(ll k=j+1; k<n; k++){
		if( l[i] != l[j] && l[i] != l[k] && l[j] != l[k] ){
			if( l[i]+l[j] > l[k] && l[j]+l[k] > l[i] && l[i]+l[k] > l[j] ){
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3648
//Created Time:2019年12月23日 星期一 14时08分16秒
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define N 5003
     
    using namespace std;
     
    int s[N];
    char t[10], res[N];
     
    int main(){
    	int a, b, n, cnt = 0; cin >> a >> b; n = a + b;
    	if(a <= b){
    		puts("Impossible");
    		return 0;
    	}
    	for(int i = 0; i < n; ++i){
    		if(!cnt) s[++cnt] = i;
    		else{
    			printf("? %d %d\n", s[cnt], i);
    			fflush(stdout);
    			scanf("%s", t + 1);
    			if(t[1] == 'Y') s[++cnt] = i;
    			else cnt--;
    		}
    	}
    	for(int i = 0; i < n; ++i){
    		printf("? %d %d\n", s[cnt], i);
    		fflush(stdout);
    		scanf("%s", t + 1);
    		res[i] = t[1] == 'Y' ? '1' : '0';
    	}
    	printf("! %s\n", res);
    	return 0;
    }

Measured memory_bytes: 724
#include <stdio.h>
typedef long long int ll;
ll abs(ll n){return n>0?n:-n;}
ll max(ll a,ll b){return a>b?a:b;}
ll extgcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll temp,k=a/b,nx,ny;
    temp=extgcd(b,a%b,x,y);
    nx=x;
    ny=y;
    x=ny;
    y=nx-ny*k;
    return temp;
}
bool better(ll x1,ll y1,ll x2,ll y2){
    return abs(x1)+abs(y1)<abs(x2)+abs(y2);
}
bool equal(ll x1,ll y1,ll x2,ll y2){
    return abs(x1)+abs(y1)==abs(x2)+abs(y2);
}
void minimize(ll a,ll b,ll& x,ll& y){
    ll l=0,r=max(abs(x),abs(y)),ml,mr,ax,ay;
    if(better(x+b,y-a,x,y)){
        while(r-l>10){
            ml=(r+l+l)/3;
            mr=(r+r+l)/3;
            if(better(x+ml*b,y-ml*a,x+mr*b,y-mr*a))r=mr;
            else l=ml;
        }
        ax=x+l*b;
        ay=y-l*a;
        for(ll i=l+1;i<=r;i++){
            if(better(x+i*b,y-i*a,ax,ay)){
                ax=x+i*b;
                ay=y-i*b;
            }
        }
        x=ax;
        y=ay;
    }
    else{
        while(r-l>10){
            ml=(r+l+l)/3;
            mr=(r+r+l)/3;
            if(better(x-ml*b,y+ml*a,x-mr*b,y+mr*a))r=mr;
            else l=ml;
        }
        ax=x-l*b;
        ay=y+l*a;
        for(ll i=l+1;i<=r;i++){
            if(better(x-i*b,y+i*a,ax,ay)){
                ax=x-i*b;
                ay=y+i*b;
            }
        }
        x=ax;
        y=ay;
    }
    return ;
}
void check(ll a,ll b,ll& x,ll& y){
    ll nx=x-b,ny=y+a;
    while(equal(nx,ny,x,y)){
        x=nx;
        y=ny;
        nx-=b;
        ny+=a;
    }
    return ;
}
int main(){
    ll a,b,x,y;
    scanf("%lld%lld",&a,&b);
    extgcd(a,b,x,y);
    minimize(a,b,x,y);
    check(a,b,x,y);
    printf("%lld %lld\n",x,y);
}



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

long long int n, m, i, j, ans, ns, f1, f2, f3;
long long int mod = 998244353;
//long long int mod = 1000000000;
long long int fib[200008];

long long int modinv(long long int b, long long int nn){
    long long int ret = b % mod, mo = mod - 2;
    nn %= mod;
    while(mo){
        //cout << mo << " " << ret << " " << nn << endl;
        if(mo&1){
            ret = (ret * nn) % mod;
        }
        nn = (nn * nn) % mod;
        mo >>= 1;
    }
    return ret % mod;
}

struct matrix{
    long long int a[2][2];

    matrix operator *(matrix to){
        matrix ret;
        ret.a[0][0] = ((a[0][0] * to.a[0][0]) % mod + (a[0][1] * to.a[1][0]) % mod) % mod;
        ret.a[1][0] = ((a[1][0] * to.a[0][0]) % mod + (a[1][1] * to.a[1][0]) % mod) % mod;
        ret.a[0][1] = ((a[0][0] * to.a[0][1]) % mod + (a[0][1] * to.a[1][1]) % mod) % mod;
        ret.a[1][1] = ((a[1][0] * to.a[0][1]) % mod + (a[1][1] * to.a[1][1]) % mod) % mod;
        return ret;
    }
};

inline long long int fibmod(long long int mm){
    --mm;
    matrix ret, np;
    ret.a[0][0] = 1;
    ret.a[0][1] = 0;
    ret.a[1][0] = 0;
    ret.a[1][1] = 1;
    np.a[0][0] = 1;
    np.a[0][1] = 1;
    np.a[1][0] = 1;
    np.a[1][1] = 0;
    while(mm){
        if(mm&1){
            ret = ret * np;
        }
        np = np * np;
        mm >>= 1;
    }
    return ret.a[0][0];
}

template <typename T>
inline T binommod(T mm, T nn){
    T ret = 1;
    if(mm - nn < nn){nn = mm - nn;}
    for(j = 1; j <= nn; ++j){
        ret = (ret * modinv(mm - nn + j, j)) % mod;
    }
    return ret;
}

int main(){
    scanf("%lld%lld", &n, &m);
    fib[0] = 1;
    f1 = 1;
    f2 = 1;
    for(i = 1; i < n + 1; ++i){
        //fib[i] = (3 * fib[i - 1] - fib[i - 2] + mod) % mod;
        f3 = (f1 + f2) % mod;
        f1 = f2;
        f2 = f3;
        f3 = (f1 + f2) % mod;
        f1 = f2;
        f2 = f3;
        fib[i] = f3;
    }
    ans = 0;
    //cout << fib[99896] << " " << fib[99897] << " " << fib[99898] << endl;
    //cout << modinv(99999999999999999, 99999999999999999) << endl;
    ns = 1;
    for(i = n - 1; i >= 0; --i){
        //cout << ans << "\t";// << fib[i - 1] << " * " << ns << endl;
        ans = (ans + (ns * fib[i - 1]) % mod + mod) % mod;
        ns = ((ns * modinv(m + n - i - 1, n - i)) % mod + mod) % mod;
    }
    // << endl;
    cout << (fibmod(m + 2 * n - 2) - ans + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x:a)cin >> x;

    int count=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=i+1){
            a.erase(a.begin()+i);
            count++;
            i--;
        }
    }

    if(a.size())cout << count << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 4016
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
int h,w;cin>>h>>w;
  string s[h];
  rep(i,0,h)cin>>s[i];
  ll ans=0;
  rep(i,0,w-1){
ll dp[h+1][h+1];
    rep(j,0,h+1){
rep(k,0,h+1)dp[j][k]=inf;
    }
    dp[h][h]=0;
    ll sum[h+1][h+1];
ll sum2[h+1][h+1];
    rep(j,0,h+1){
      sum[j][0]=0;
      sum2[j][0]=0;
      rep(k,1,h-j+1){
        sum[j][k]=sum[j][k-1];
        sum2[j][k]=sum2[j][k-1];
        if(s[k-1][i]==s[k-1+j][i+1])sum[j][k]++;
        if(s[k-1][i+1]==s[k-1+j][i])sum2[j][k]++;
        
      }
    }
   /* rep(j,0,h+1){
rep(k,0,h+1)cout<<sum2[j][k]<<" ";
      cout<<endl;
    }*/
    rrep(j,h,0){
      rrep(k,h,0){
         if(j>0){
           if(j<=k){
            ll sa=k-j;
             dp[j-1][k]=min(dp[j-1][k],dp[j][k]+sum[sa][j]);
           }
           else{
             ll sa=j-k;
             dp[j-1][k]=min(dp[j-1][k],dp[j][k]+sum2[sa][k]);
           }
         }
           if(k>0){
            if(k<=j){
            ll sa=j-k;
             dp[j][k-1]=min(dp[j][k-1],dp[j][k]+sum2[sa][k]);
           }
           else{
             ll sa=k-j;
             dp[j][k-1]=min(dp[j][k-1],dp[j][k]+sum[sa][j]);
           }
              
           }
      }
    }
    /*rep(j,0,h+1){
rep(k,0,h+1)cout<<dp[j][k]<<" ";
      cout<<endl;
    }*/
    ans+=dp[0][0];
  }
  cout<<ans<<endl;

            
}

Measured memory_bytes: 2560
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]
for sci in sc:
	if ans[sci[0]-1] == -1:
		ans[sci[0]-1] = sci[1]
	elif ans[sci[0]-1] != sci[1]:
		print(-1)
		exit(0)

if ans[0] == 0 and n != 1:
	print(-1)
	exit(0)

ansint = 0
for i, a in enumerate(ans):
	ansint *= 10
	if a == -1:
		if i == 0 and n != 1:
			ans[i] = 1
		else:
			ans[i] = 0
	ansint += ans[i]

print(ansint)


Measured memory_bytes: 38256
/* Bismillahirrahmanirrahim */
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
using namespace std;

int main(){
	string str;
	cin >> str;
	int size=str.size();
	if(size==2) cout << str;
	else{
		swap(str[0],str[2]);
			cout << str;
	}

}


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

using namespace std;

typedef long long lin;
typedef long double ld;
typedef pair < int, int > pii;

const int N = int(1e6) + 5;
const int inf = (int)1e9 + 7;

int n, p[N];
vector < pair < int, pii > > edges;
vector < pair < pii, int > > xy;

int dist(pii a, pii b){
  return min(abs(a.first - b.first), abs(a.second - b.second));
}

void add_edges(){
  for(int i = 1; i < (int)xy.size(); ++i){
    edges.push_back(make_pair(dist(xy[i].first, xy[i - 1].first), make_pair(xy[i].second, xy[i - 1].second)));
  }
}

int find9(int v){
  return p[v] == v ? v : p[v] = find9(p[v]);
}

void merge9(int x, int y){
  x = find9(x), y = find9(y);
  if(x == y){
    return;
  }
  p[y] = x;
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    p[i] = i;
    int x, y;
    scanf("%d %d", &x, &y);
    xy.push_back(make_pair(make_pair(x, y), i));
  }
  sort(xy.begin(), xy.end());
  add_edges();
  for(auto &i : xy){
    swap(i.first.first, i.first.second);
  }
  sort(xy.begin(), xy.end());
  add_edges();
  lin cost = 0;
  sort(edges.begin(), edges.end());
  for(auto i : edges){
    if(find9(i.second.first) != find9(i.second.second)){
      cost += i.first;
      merge9(i.second.first, i.second.second);
    }
  }
  printf("%lld", cost);
  return 0;
}


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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  ll x[n],y[n];
  for(i=0;i<n;i++)cin>>x[i]>>y[i];
  if(n==1){
    cout<<1;
    return 0;
  }
  ll X[n*n],Y[n*n];
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j){
        X[cnt]=x[j]-x[i];
        Y[cnt++]=y[j]-y[i];
      }
    }
  }
  int m=cnt;cnt=0;
  vector<pair<ll,ll>> v;
  for(i=0;i<m;i++){
    v.push_back(pair<ll,ll>(X[i],Y[i]));
  }
  sort(v.begin(),v.end());
  int c[m];
  for(i=0;i<m;i++)c[i]=1;
  for(i=1;i<m;i++){
    if(v[i]==v[i-1])c[cnt]++;
    else cnt++;
  }
  m=cnt+1;cnt=0;
  for(i=0;i<m;i++){
    cnt=max(cnt,c[i]);
  }
  cout<<n-cnt;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a+b>=a-b&&a+b>=a*b)cout<<a+b<<endl;
  else if(a+b<a-b&&a*b<=a-b)cout<<a-b<<endl;
  else cout<<a*b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int d,n,c=0;
    scanf("%lld %lld",&n,&d);
    for(int i=0;i<n;i++)
    {
        long long int x,y;
        scanf("%lld %lld",&x,&y);
        if((x*x+y*y)<=d*d)
            c++;
    }
    printf("%d",c);

}


Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int t = (N % A == 0) ? N / A * B : (N / A + 1) * B;
    int tt = (N % C == 0) ? N / C * D : (N / C + 1) * D;

    cout << min(t, tt) << endl;
    return 0;
}


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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

constexpr int DEBUG = 1;

int64 Solve() {
  string s, t;
  cin >> s >> t;

  int n = s.size();
  string u = "^" + s + s;
  auto dp = Make2DVector<int>(2 * n + 1, 26, INT32_MAX);
  for (int i = 2 * n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (u[i + 1] == 'a' + j) {
        dp[i][j] = i + 1;
      } else {
        dp[i][j] = dp[i + 1][j];
      }
    }
  }

  // if (DEBUG) cout << "PHASE 1" << endl;

  int64 current = 0;
  int64 current_index = 0;
  for (char raw_c : t) {
    int c = raw_c - 'a';
    if (dp[current_index][c] == INT32_MAX) return -1;
    int inc = dp[current_index][c] - current_index;
    current += inc;
    current_index += inc;
    if (current_index > n) current_index -= n;
  }
  return current;
}

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

  cout << Solve() << endl;
}

Measured memory_bytes: 27216
T = []
for i in range(5):
    T.append(input())
tmp = []
for i in range(5):
    tmp.append(int(T[i][-1]))
T2 = []
for i in range(5):
    if tmp[i] != 0:
        T2.append(int(T[i]) + 10 - tmp[i])
    else:
        T2.append(int(T[i]))
ans = []
for i in range(5):
    if tmp[i] != 0:
        ans.append(sum(T2) - 10 + tmp[i])
    else:
        ans.append(sum(T2))
    
    
    
    

print(min(ans))
        

Measured memory_bytes: 3188
use proconio::input;

fn main() {
    input! {
        s: String,
        t: String
    }

    solve(&s, &t);
}

fn solve(s: &String, t: &String) {
    let u = t.chars().take(t.len() - 1).collect::<String>();
    if s.eq(&u) {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main()
{
    string S;
    cin >> S;
    deque<char> dq;
    rep(i,S.size()){
        dq.push_back(S[i]);
    }
    ll Q;
    cin >> Q;
    int t;
    bool rev = false;
    rep(i,Q){
        cin >> t;
        if(t == 1){
            if(rev == false) rev = true;
            else rev = false;
        }
        if(t == 2){
            int F;
            char C;
            cin >> F >> C;
            if(F == 1){
                if(rev == false){
                    dq.push_front(C);
                }else{
                    dq.push_back(C);
                }
            }else{
                if(rev == false){
                    //S = S + C;
                    dq.push_back(C);
                }else{
                    //S = C + S;
                    dq.push_front(C);
                }
            }
        }
    }
    // rep(i,dq.size()){
    //     cout << dq[i] << endl;
    // }
    // rep(i,dq.size()){
    //     nS[i] = dq.front();
    //     dq.pop_front();
    // }
    size_t dsize = dq.size();
    if(rev == true) {
        rep(i,dsize){
            cout << dq.back();
            dq.pop_back();
        }
    }else{
        rep(i,dsize){
            cout << dq.front();
            dq.pop_front();
        }
    }
    cout << endl;
        
}

Measured memory_bytes: 896
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int w=sc.nextInt();
		int h=sc.nextInt();
		long min=Integer.MAX_VALUE;
		if(w%3==0||h%3==0){
			System.out.println("0");
		}else{
			if(w%2==0&&h%2==0){
				//System.out.println(a);
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}else if((w%2!=0&&h%2==0)||(w%2==0&&h%2!=0)){
				
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}else{
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}
		}
		
	}
	public static long c(long w,long h){
		long a=h/2;
		long b=h/2+h%2;
		long min=Integer.MAX_VALUE;
		//System.out.println(w+" "+h+" "+a+" "+b);
		long d[]=new long[3];
		for(int i=1;i<=w;i++){	
			long p=i;long q=w-i;
			//System.out.println(p+q);
			d[0]=(q*a);
			d[1]=(q*b);
			d[2]=p*h;
			//System.out.println(d[0]+d[1]+d[2]);
			//System.out.println(sum1+" "+sum2+" "+sum3 );
			Arrays.sort(d);
			long sum=d[2]-d[0];
			if(sum<min){
				//System.out.println(p+" "+q+" "+(p*h)+" "+s1);
				min=(long)sum;
		
			}
			
		}
		return min;
	}
	public static long t(long w,long h){
		
		long min=Integer.MAX_VALUE;
		//System.out.println(w+" "+h+" "+a+" "+b);
		long d[]=new long[3];
		for(int i=1;i<=w;i++){	
			long p=i;long q=w-i;
			//System.out.println(p+q);
			long a=(q/2);
			long b=q-a;
			d[0]=(h*a);
			d[1]=(h*b);
			d[2]=p*h;
			//System.out.println(a+b+p);
			Arrays.sort(d);
			long sum=d[2]-d[0];
			if(sum<min){
				//System.out.println(p+" "+q+" "+(p*h)+" "+s1);
				min=(long)sum;
		
			}
			
		}
		return min;
	}
 
}



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

void C(int mid, vector<int>& r, vector<int>& g, vector<int>& n){
    
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, y, a, b ,c;
    cin >> x >> y >> a >> b >> c;

    vector<long long> r(a), g(b), n(c);
    for (int i = 0; i < a; i++)
        cin >> r[i];

    for (int i = 0; i < b; i++)
        cin >> g[i];

    for (int i = 0; i < c; i++)
        cin >> n[i];
    
    sort(r.begin(), r.end(), greater<int>());
    sort(g.begin(), g.end(), greater<int>());
    sort(n.begin(), n.end(), greater<int>());
    
    long long ans = 0;
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    for (int i = 0; i < x; i++)
        pq.push(r[i]);
    for (int i = 0; i < y; i++)
        pq.push(g[i]);
    for (int i = 0; i < c; i++)
        pq.push(n[i]);

    while (!pq.empty()){
        if ((int) pq.size() <= x + y)
            ans += pq.top();
        pq.pop();
    }

    cout << ans << '\n';

    return 0;
}


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


int main(){
    string s;
    cin>>s;
    int n = s.length();
    bool poss = true;
    for(int i = 0;i<n-1;i++){
        if(s[i] == s[i+1]){
            poss = false;
            break;
        }
    }
    if(poss == false){
        cout<<"Bad"<<endl;
    } else {
        cout<<"Good"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# IMPORT ###############################################################################################################
import sys                                                      # システム
sys.setrecursionlimit(10**6)                                    # 再帰処理の上限変更
from collections import deque, Counter                          # キュー・個数カウント
from itertools   import accumulate, permutations, combinations  # 累積和・順列・組み合わせ
from operator    import itemgetter                              # ソート補助
from bisect      import bisect_left, bisect_right, bisect       # 二分探索
from heapq       import heappop, heappush                       # プライオリティキュー
from fractions   import gcd                                     # 最大公約数
from math        import ceil, floor, sqrt, cos, sin, tan, pi    # 数学処理
from copy        import deepcopy                                # オブジェクトコピー
import numpy         as np                                      # 数値計算

# MAIN #################################################################################################################
def main():
    # Init #############################################################################################################
    im = InputManager()
    # Input ############################################################################################################
    a, b = im.inputMultiple()
    # Logic ############################################################################################################
    if a > 8 or b > 8:
        print(":(")
    else:
        print("Yay!")
    # Output ###########################################################################################################

    # Return ###########################################################################################################
    return

# INPUT MANAGER ########################################################################################################
class InputManager(object):
    def __init__(self):
        pass

    @staticmethod
    def inputSingle(dtype=int):
        return dtype(input())
    
    @staticmethod
    def inputMultiple(dtype=int, aslist=False):
        if aslist:
            return list(map(dtype, input().split()))
        else:
            return map(dtype, input().split())

    @staticmethod
    def input2D(h, dtype=int):
        return [list(map(dtype, input().split())) for i in range(h)]

# CALL MAIN ############################################################################################################
main()

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

/* データを互いに重複しない集合に分割して保持するデータ構造を
 * 素集合データ構造 (Disjoint-set Data Structure) という。
 * このデータ構造に対して
 *  ・Find:  特定の要素がどの集合に属しているかを求める
 *  ・Union: 2つの集合を統合する
 * のアルゴリズムを兼ね備えたデータ構造を Union Find データ構造と呼ぶ。
 */

class UnionFind
{
    private:
        std::vector<int> parent;  // parent[x]: x の根の番号
                                  //            x が根の場合はその連結成分の大きさ
        std::vector<int> rank;    // rank[x]  : x が属する木の高さ
        std::size_t sz;           // 連結成分の数

    public:
        // x が親の場合、parent[x] = -(その連結成分の大きさ)
        UnionFind( std::size_t n ): parent(n, -1), rank(n, 0), sz(n) {}

        // x が属する集合の親を返し、x を親に直接繋ぎ直す(経路圧縮)
        int find( int x )
        {
            if( parent[x] < 0 ) return x;
            else return parent[x] = find( parent[x] );
        }

        // x が属する集合と y が属する集合を統合する
        bool unite( int x, int y )
        {
            x = find( x );
            y = find( y );
            if( x == y ) return false;

            // 大きい方(x)に小さい方(y)を繋げる
            if( rank[x] < rank[y] ) std::swap( x, y );

            parent[x] += parent[y];  // x に連結している成分の大きさを更新する
            parent[y] = x;           // y を x に繋ぐ
            if( rank[x] == rank[y] ) rank[x]++;
            sz--;

            return true;
        }

        bool same( int x, int y ) { return find(x) == find(y); }
        std::size_t size()        { return sz; }
        std::size_t size( int x ) { return - parent[find(x)]; }
};


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, M) cin >> A[i] >> B[i];

    UnionFind uni(N);
    REP(i, M) uni.unite(A[i]-1, B[i]-1);

    int ans = 0;
    REP(i, N){
        if(uni.find(i) == i) ans = max(ans, int(uni.size(i)));
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "RRR"){
        cout << 3 << endl;
    }
    else if(s == "SRR" || s == "RRS"){
        cout << 2 << endl;
    }
    else if(s == "SSS"){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll n;
    double d,x,ans=0;
    cin>>n>>d>>x;
    for(;n>0;n--){
	ans+=d+(2*n-1)*x/2.0;
	//printf("%.9lf\n",ans);
	//cout<<"#"<<d+(n-1)*x/2.0<<endl;
	double l=d*2*(n+1)+x*5; l/=2.0*n;
	double r=d*2*(n+1)+x*(9+2*n); r/=2.0*n;
	d=l,x=r-l;
	//cout<<d<<" "<<x<<endl;
    }
    printf("%.9lf\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,ans,x;
string s;
int main(){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I')x++;
        else x--;
        if(ans<x)ans=x;
    }
    cout<<ans<<endl;
}

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

int mod = 1000000007;

int main()
{
    int S;
    cin >> S;
    int L = S % 100;
    int R = S / 100;

    if (1 <= L && L <= 12)
    {
        if(1 <= R && R <= 12)
            cout << "AMBIGUOUS";
        else
            cout << "YYMM";
    }
    else
    {
        if (1 <= R && R <= 12)
            cout << "MMYY";
        else
            cout << "NA";
    }
}

Measured memory_bytes: 256
def findSumOfDigits(n :int):    
    sum = 0
    while n > 0:
        sum += n%10
        n = int(n/10)
    return sum

n,a,b = map(int,input().split())
total = 0
for i in range(1,n+1):
    sum = findSumOfDigits(i)
    if sum >= a and sum <= b:
        total += i
print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    int n, m;
    int ans = 0;
    cin >> n;
    string s[n];
    vector <string> vec(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> s[i];
        vec[i] = s[i];
    }
    cin >> m;
    string t[m];
    for (size_t i = 0; i < m; i++)
    {
        cin >> t[i];
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int counter = 0;
    int max_num = 0;
    for (size_t i = 0; i < vec.size(); i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            if(vec[i] == s[j]) counter ++;
        }
        for (size_t k = 0; k < m; k++)
        {
            if(vec[i] == t[k]) counter--;
        }
        if(max_num < counter){
            max_num = counter;
        }
        counter = 0;
    }
    cout << max_num << endl;

    return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
a=[]
for i in range(n):
    a.append([int(i) for i in input().split()])
ans=0

for i in range(n-1):
    for j in range(i+1,n):
        x=a[i]
        y=a[j]
        kyori=[(x[k]-y[k])**2 for k in range(d)]
        if sum(kyori)**(0.5)==int(sum(kyori)**(0.5)):
            ans+=1
print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;


bool is_weed(int n, int *h, int p)
{
    int prev_diff = -1, diff;
    bool flag = false;
    for (int i = 0; i < n-1; i++) {
        if(p == i+1){
            if (i+1 == n-1) {
                continue;
            }
            diff = h[i+2] - h[i];
        }
        else if(p == i) {
            if(i == 0) {
                continue;
            }
            diff = h[i+1] - h[i-1];
        } else {
            diff = h[i+1] - h[i];
        }

        if(flag && prev_diff != diff) {
            return false;
        }
        flag = true;
        prev_diff = diff;
    }

    return true;
}


int main()
{
    int n;
    int h[101];

    while(cin >> n) {
        if(n == 0) {
            break;
        }
        n++;

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

        for(int i = 0; i < n; i++) {
            if(is_weed(n, h, i)) {
                cout << h[i] << endl;
                break;
            }
        }
    }

    return 0;
}


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

using namespace std;
bool is_valid(vector<int>& board){
    auto cross = vector<bool>(16, false);
    auto diagon = vector<bool>(16, false);
    for(auto it = board.begin(); it != board.end(); ++it){
        int idx = it - board.begin();
        int c = *it - idx + 8;
        int d = 16 - *it - idx;
        if(cross[c] || diagon[d]){
            return false;
        }
        cross[c] = true;
        diagon[d] = true;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    auto board = vector<int>(8, -1);
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        board[x] = y;
    }
    vector<int> xs {};
    vector<int> ys {};
    for(int i = 0; i < 8; ++i){
        if(board[i] == -1){
            xs.push_back(i);
        }
        bool flag = false;
        for(int j = 0; j < 8; ++j){
            if(board[j] == i){
                flag = true;
                break;
            }
        }
        if(!flag){
            ys.push_back(i);
        }
    }
    int s = xs.size();
    while(1){
        for(int i = 0; i < s; ++i){
            board[xs[i]] = ys[i];
        }
        if(is_valid(board)){
            break;
        }
        if(!next_permutation(ys.begin(), ys.end())){
            break;
        }
    }
    for(int i = 0; i < 8; ++i){
        for(int j = 0; j < 8; ++j){
            cout << (board[i] == j ? 'Q' : '.');
        }
        cout << endl;
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#include <atcoder/convolution>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

using namespace atcoder;
using mint = modint998244353;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> A(N),B(M);
    for(auto& x:A) cin >> x;
    for(auto& x:B) cin >> x;
    auto C = convolution(A,B);
    for(int i=0;i<C.size();i++) cout << C[i] << (i+1!=C.size()? " ":"\n");
}

Measured memory_bytes: 19052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    vector<string> S(200000);
    vector<string> S2(200000);
    int S2num[200000];

    cin >> N;
    for (int i =0;i<N;++i) cin >>S[i];
    sort(&S[0],&S[N]);

    int index=0;
    string prev="";
    for (auto itr=&S[0];itr<&S[N];++itr){

        //cout << "index " << index << endl;
        //cout << "*itr " << *itr << endl; 

        if ( *itr == prev){
            S2num[index-1] +=1;
        }else{
            prev = *itr;
            S2[index]=*itr;
            S2num[index]=1;
            index++;
        }
    }

    auto itr = max_element(&S2num[0],&S2num[index]);
    int maxnum=*itr;
    //cout << "max num=" << *itr << endl;
    /*
    for (int i =0;i<index;++i) {
        cout << "index " << i << endl;
        cout << "S2 " << S2[i] << endl;
        cout << "S2num " << S2num[i] << endl;
    }
    */
    for (int i =0;i<index;++i) {
        if (S2num[i] == maxnum)
            cout << S2[i] << endl;
    }
 
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const double PI = 3.14159265358979323846;
    double A,B;
    cin >> A >> B;
    double H, M;
    cin >> H >> M;
    double hrad = (H*60+M) / 720 * 360 * PI/180; 
    double mrad = M / 60 * 360 * PI/180; 
    double ay = A * cos(hrad);
    double ax = -A * sin(hrad);
    double by = B * cos(mrad);
    double bx = -B * sin(mrad);
    double ans = sqrt((ax-bx) * (ax-bx) + (ay-by)*(ay-by));

    cout << fixed << setprecision(10) << ans << '\n';

    return 0;
}

Measured memory_bytes: 4148
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define llong long long
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  map<int, int>c;
  int post, now;
  cin >> post;
  post%=m;
  c[post]++;
  for(int i=1; i<n; i++){
	cin >> now;
    post=(post+now)%m;
    c[post]++;
  }
  c[0]++;
  llong ret=0;
  for(pair<int, int>p: c){
    ret += (llong)p.second*((llong)p.second-1)/2;
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 3200
let N = stdin.ReadLine() |> int
let AB = Array.zeroCreate<int []> N

for i in [ 0..N - 1 ] do
    AB.[i] <- stdin.ReadLine().Split() |> Array.map int

let sAB = AB |> Array.sortBy (fun x -> x.[1])

let rec solver t n =
    if n = N then "Yes"
    else
        let time = t + sAB.[n].[0]
        if time > sAB.[n].[1] then "No"
        else solver time (n + 1)

solver 0 0 |> stdout.WriteLine


Measured memory_bytes: 38680
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  targetNum = parseInt(input[0]);
  list = [];
  count = 1;
  while(count === 1 || list.indexOf(targetNum) === -1) {
    count++;
    list.push(targetNum);
    targetNum = targetNum % 2 === 0 ? targetNum / 2 : targetNum * 3 + 1;
  }
   console.log(count);
};

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

ll fact(ll n)
{
    ll ret = 0,i,j;
    ll tmp = 0;
    while(n%2 == 0)
    {
        n/=2;
        ret++;
    }
    tmp = ret+1;
    ret = 0;
    for(i=3;i<=sqrt(n);i+=2)
    {
        ret = 0;
        while(n%i==0)
        {
            n/=i;
            ret++;
        }
        tmp*=(ret+1);
    }
    if(n>1) tmp*=2;
    return tmp;
}

int main()
{
    ll i,j,n;
    cin>>n;
    ll ans = 0;
    for(i=1;i<=n-1;i++)
    {
        ll val = n-i;
        ll ways = fact(n-i);
        // if(sqrt(n-i) * sqrt(n-i) == n-i) ways--;
        if(n-i == 1) ways = 1;
        // cout<<n-i<<" "<<ways<<'\n';
        ans+=ways;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3676
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n), b(n);
    map<int, int> mp;
    int mi = INF;
    rep(i, n) {
        cin >> a[i];
        b[i] = a[i];
        mi = min(mi, a[i]);
    }
    sort(all(b));
    rep(i, n) {
        mp[b[i]] = i;
    }

    int ans = 0;
    vi check(n);
    rep(i, n) {
        if(check[i]) continue;
        int cnt = 0;
        int now = i;
        int sum = 0;
        int nmi = a[i];
        while(true) {
            check[now] = 1;
            nmi = min(nmi, a[now]);
            cnt++;
            sum += a[now];
            now = mp[a[now]];
            if(check[now]) break;
        }
        ans += min(sum+(cnt-2)*nmi, (cnt+1)*mi+sum+nmi);
    }

    cout << ans << endl;
}  


Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	// vector<string> s(n);

	// int cnt = n;
	// for(int i=0;i<n;i++){
	// 	cin >> s.at(i);
	// }
	// sort(s.begin(),s.end());
	// for(int i=0;i<n-1;i++){
	// 	if(s.at(i)==s.at(i+1)){
	// 		cnt--;
	// 	}
	// }
	// cout << cnt << endl;

	set<string> st;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 19208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string s2;
    int i = 0;
    while(i < s.size()) {
        s2 = s2 + s[i];
        if(i != s.size()-1) {
            if(s[i] == 'B' && s[i+1] == 'C') {
                s2[s2.size()-1] = 'D';
                i++;
            }
        }
        i++;
    }
    int a_num = 0;
    ll ans = 0;
    rep(j,s2.size()) {
        if(s2[j] == 'A') a_num++;
        else if(s2[j] == 'D') ans += a_num;
        else a_num = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1452
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    if(N % 2 == 0||M%2==0||K%2==0)cout <<0 << endl;
    else{
        if(max(N,max(K,M)) == N)cout << K * M << endl;
        else if(max(N,max(K,M)) == M)cout << K * N << endl;
        else cout << N * M << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify (int i) {
	int l, r, largest, tmp;
	l = 2 * i;
	r = 2 * i + 1;

	// select the node which has the maximum value
	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;

	if (largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(largest);
	}
}

int main () {
	int i;

	scanf("%d", &H);
	for (i = 1; i <= H; i++) scanf("%d",&A[i]);
	for (i = H/2; i >= 1; i--) maxHeapify(i);
	for (i = 1; i <= H; i++) {
		printf(" %d",A[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const long long inf = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;

int next(int n, int d) {
  int k = (n - 1) / d;

  return (k + 1) * d;
}

long long check(long long n, vector<int> &v) {
  for (auto &x : v) {
    n = x * (n / x);
  }

  return n;
}

long long get_min(vector<int> &v) {
  long long lo = 0, hi = inf;
  while (hi - lo > 1) {
    long long x = (lo + hi) / 2;
    long long target = check(x, v);

    if (target >= 2) {
      hi = x;
    } else {
      lo = x;
    }
  }

  return hi;
}

long long get_max(long long n, vector<int> &v) {
  long long lo = n, hi = inf;
  while (hi - lo > 1) {
    long long x = (lo + hi) / 2;
    long long target = check(x, v);

    if (target == 2) {
      lo = x;
    } else {
      hi = x;
    }
  }

  return lo;
}

int main() { IO;
  int k;
  cin >> k;

  vector<int> v(k);
  for (auto &x : v) cin >> x;

  long long n = get_min(v);
  bool good = (check(n, v) == 2);

  if (!good) {
    cout << -1 << endl;
    return 0;
  }

  long long m = get_max(n, v);
  cout << n << " " << m << endl;

  return 0;
}


Measured memory_bytes: 640