akhauriyash/Code-Regression huggingface dataset:
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) ll(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 2e5 + 5;

string s[N];

signed main(){
    fastio;
    int i,n;
    cin>>n;
    vector<pair<int,string>> v;
    map<string,int> mp;
    for(i=0;i<n;++i){
        cin>>s[i];
        mp[s[i]]++;
    }
    for(auto it:mp){
        v.pb({it.s,it.f});
    }
    sort(all(v));
    for(auto i:v){
        if(i.f==v[sz(v)-1].f)
            cout<<i.s<<endl;
    }
    return 0;
}

Measured memory_bytes: 28656
N=int(input())
A,B=map(int,input().split())
P=[int(i) for i in input().split()]
L,C,R=(0,0,0)
for i in range(N):
    if P[i]<=A:
        L+=1
    elif P[i]<=B:
        C+=1
    else:
        R+=1
print(min(L,C,R))


Measured memory_bytes: 3060
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt() * 2;
	myout(Math.PI * N);
}


Measured memory_bytes: 29636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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


    int ans = 1;
    rep(i,n-1){
        if(s[i] != s[i+1])ans++;
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

//ll mod = 998244353;
ll mod = 1e9 + 7;
vector<ll> fac, inv, finv;
ll fac_init(ll num) {
    // combination init
    fac.resize(num + 1), inv.resize(num + 1), finv.resize(num + 1);
    fac[0] = 1, inv[0] = 1, finv[0] = 1;
    for (ll i = 1; i < num + 1; i++) fac[i] = fac[i - 1] * i % mod;
    finv[0] = modpow(fac[fac.end() - fac.begin() - 1], mod - 2, mod);
    repe(i, 1, num + 1) finv[i] = finv[i - 1] * (num - i + 1) % mod;
    reverse(all(finv));

    //inv init
    repe(i, 1, num + 1) inv[i] = fac[i - 1] * finv[i];
}

ll comb(ll a, ll b) {
    return fac[a] * finv[b] % mod * finv[a - b] % mod;
}
int main() {
    init();
    ll N, K;
    cin >> N >> K;
    vc<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    fac_init(N);
    ll ans = 0;
    repe(i, K - 1, N) {
        ans += A[i] * comb(i, K - 1);
        ans %= mod;
    }

    vc<ll> B;
    B = A;
    reverse(all(B));
    repe(i, K - 1, N) {
        ans -= B[i] * comb(i, K - 1);
        ans = (ans % mod + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
N, M = map(int,input().split())
INF = float('inf')
edges = []
for _ in range(M):
    edges.append(list(map(int,input().split())))
graph = [[INF if i != j else 0 for i in range(N)] for j in range(N)]
for i in range(M):
    a, b, c = edges[i]
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
ans = 0
for i in range(M):
    a, b, c = edges[i]
    if c != graph[a-1][b-1]:
        ans += 1
print(ans)

Measured memory_bytes: 3568
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	double a,b,x;
	scanf("%lf%lf",&a,&b);
	x=(a+b)/2;
	if(x-(int)x<0.5) printf("%d",(int)x);
	else printf("%d",(int)x+1);
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;


int main() {
    ios_base::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    if (a < b) {
        cout << '<' << endl;
    } else  if (a > b) {
        cout << '>' << endl;
    } else {
        cout << '=' << endl;
    }
    return 0;
}


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

using namespace std;

int n;

int calc( int x ) {
	int y = 0;
	while(x) y += x % 10, x /= 10;
	return y;
}

int main() {
	cin >> n;
	int ans = 1e9;
	for( int i = 1; i < n; ++i )
		ans = min( ans, calc(i) + calc(n-i) );
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
$dice = gets.split(" ").map(&:to_i)

def get_right(tt)
  c = [[0,3,5,2,4,0],[4,0,1,6,0,3],[2,6,0,0,1,5],[5,1,0,0,6,2],[3,0,6,1,0,4],[0,4,2,5,3,0]]
  t = $dice.find_index(tt[0])
  f = $dice.find_index(tt[1])
  puts $dice[c[t][f]-1]
end

(gets.to_i).times do
  get_right(gets.split(" ").map(&:to_i))
end



Measured memory_bytes: 6844
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<mod>;

mint dp[5005][5005];

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    dp[0][0] = 1;
    rep(i,n){
        rep(j,n){
            if(j == 0){
                dp[i+1][j] += dp[i][j];
                dp[i+1][j+1] += dp[i][j];
            }else{
                dp[i+1][j-1] += dp[i][j] * 2;
                dp[i+1][j+1] += dp[i][j];
            }
        }
    }
    cout << dp[n][s.size()].value() << endl;
}

Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string moji;
  int count=0,ma=0;
  cin>>moji;
  
  for(int i=0;i<11;i++){
    if(moji[i]=='A'|| moji[i]=='T' || moji[i]=='G' || moji[i]=='C' ){
        count++;
    }else{
        ma=max(ma,count);
        count=0;
      
    }
  }
  cout<<ma;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
const ll MOD = 1e9+7; ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0}; vi d4y = {0, 1, 0, -1};
//---------------------------------------

int main(){
    int n,k; cin>>n>>k;
    double ret=0;
    for(int i=1; i<=n; i++){
        double tmp=1.0/n;
        int now=i;
        while(now<k){
            now*=2;
            tmp/=2;
        }
        ret+=tmp;
    }
    cout<<fixed<<setprecision(12);
    cout<<ret<<endl;
    
}

Measured memory_bytes: 256
num = int(input())
arr = list(map(int,input().split()))
print(" ".join(list(map(str,arr))))
def isn(A,N):
    for i in range(1,N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] >v:
            A[j+1] = A[j]
            j -=1
        A[j+1] = v
        print(" ".join(list(map(str,arr))))

isn(arr,num)



Measured memory_bytes: 5604
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;

int main()
{
	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll ans;
	if (x/d >= k) {
		ans = x - k * d;
	}
	else {
		ll e = x / d;
		k -= e;
		x -= e*d;
		if (k % 2 == 1) {
			//偶数
			x = abs(x - d);
		}
			ans = x;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
long long int mod = 1e9+7;
inline lli power(lli a,lli n)
{
  if(n==0)
    return 1;

  //cout<<a<<" "<<n<<"\n";
  if(n&1)
  {
    return (a*power(a,n-1))%mod;
  }
  lli p = power(a,n/2);
  return (p*p)%mod;
}
inline lli mulinv(int i)
{
  return power((lli)i,mod-2);
}
bool prime[1001]={0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0};
void pre_calc()
{

  for(int i=2;i<=1000;i++)prime[i]=true;
  prime[1]=false;
  for(int i=2;i<=1000;)
  {
    for(int j=i+i;j<=1000;j+=i) prime[j]=false;
    while(prime[++i]==false);
  }
  for(int i=0;i<=1000;i++)cout<<prime[i]<<",";
  cout<<"\n";
}
bool isPrime(int i)
{
  return prime[i];
}
int main()
{
  //pre_calc();
  //cout<<power(1ll*2,mod-2)<<"\n";
  int n;
  cin>>n;
  long long int ans=1,t=1;
  for(int i=2;i<=n;i++)
  {
    if(prime[i])
    {
      int c=1,j=i+i;
      lli cur=i*i;
      for(;j<=n;j+=i)
      {
        int t=j;
        while(t%i==0)
        {
          c++,t/=i;
        }
      }
      //cout<<"\n"<<i<<" "<<c<<"\n";
      ans = (ans*(c+1))%mod;
    }
    //t = (t*i)%mod;
  }
  cout<<ans<<"\n";
  //cout<<(t*ans)%mod<<"\n";

  return 0;
}


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

int main() {
  int H, W;
  for (;;) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for (int h = 0; h < H; ++h) {
      for (int w = 0; w < W; ++w) {
        if (w > 0 && w < W - 1 && h > 0 && h < H - 1) {
          cout << ".";
        } else {
          cout << "#";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1148
#include<stdio.h>	
int main()	
{
	long long tc;
	scanf("%lld",&tc);
	long long input[tc+1];
	long long total = 1;
	int flag = 1;
	int flag2 = 0;
	long long sementara;
	int countO = 0,countzero = 0;
	for(int i = 0;i<tc;i++)
	{
		scanf("%lld",&input[i]);
		total *= input[i];
		sementara = input[i];
		while(sementara != 0)
		{
			if(sementara % 10 == 0) countO++;
			if(sementara > 9) countzero++;
			sementara /= 10;
		}
		if(total >1000000000000000000 || total < 0)
		{
		 	flag = 0;
		}
		if(countO > 18 || countzero >= 18)
		{
			flag = 0;
		}
		if(input[i] == 0)
		{
			flag2 = 1;
		}
	}
	if(input[0] = 1000000000 && input[1] == 1000000000) printf("%lld\n",total);
	else if(flag2 == 1) printf("0\n");
	else if(flag == 0) printf("-1\n");
	else if(total > 1000000000000000000 || total < 0) printf("-1\n");
	else printf("%lld\n",total);
	return 0;
}

Measured memory_bytes: 2908
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand rng
using namespace std; void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;

struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
  int main(){solve_dbg();}
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<int,int>;
constexpr int MOD = 998244853;
mt19937_64 rng(58);
template<typename T>inline T ceil(T a,T b){return (a + b - 1) / b;}
/////////

void solve(){
  ini(A,B);
  int cur = 1 , ret = 0;
  while(cur < B){
    cur += A - 1; ret++;
  }
  out(ret);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


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

struct edge {
  int m, a, EVENT;
  bool operator<(const edge& e) const {
    if(a == e.a) return(EVENT < e.EVENT); 
    return(a < e.a);
  }
};

int main()
{
  int n;
  while(cin >> n, n) {
    vector< edge > edges(2 * n);
    for(int i = 0; i < n; i++) {
      int m, a, b;
      cin >> m >> a >> b;
      edges[2 * i] = (edge){m, a, 1};
      edges[2 * i + 1] = (edge){m, b, -1};
    }
    sort(edges.begin(), edges.end());

    bool Judge = true;
    int weight = 0;
    for(int i = 0; i < 2 * n; i++) {
      weight += edges[i].m * edges[i].EVENT;
      Judge &= weight <= 150;
    }
    if(Judge) cout << "OK\n";
    else cout << "NG\n";
  }
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,x;
  cin>>n>>x;
  long long a[n+1];
  a[0]=0;
  for(int i=1; i<=n; i++){
    cin>>a[i];
  }
  long long ans=0;
  for(int i=1; i<=n; i++){
    if(a[i]+a[i-1]<=x)continue;
    ans+=(a[i]+a[i-1])-x;
    a[i]-=(a[i]+a[i-1])-x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    double ans=0;
    cin>>n;
    double x;
    string s;
    for(int i=0;i<n;i++){
        cin>>x>>s;
        if(s=="JPY"){
            ans+=x;
        }
        else{
            ans+=x*380000;
        }
    }
    cout << ans<<endl;
    return 0;
}




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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
#define PI 3.14159265359

using ll = long long;

int main() {
    int n;
    cin >> n;
  	vector<int> a(n);
    vector<vector<int>> x(n, vector<int>(n));
    rep(i,n){
        int an;
        cin >> an;
      	a[i] = an;
        rep(j,an){
            int xin,y;
            cin >> xin >> y;
            x[i][j] = xin;
            if(y==0) x[i][j] *= -1;
        }
    }
    
    int ans = 0;
    bool conflict = false;

    for(int bit=0; bit<(1<<n); bit++){ // 各可能性において
        vector<int> fact(n,0);
        conflict = false;
        rep(i,n){ // 各人間について
            if(conflict==true){
                break; // 例外処理
            }
            else{
            if(bit & 1<<i){ // i人目が本物の世界線では（不親切者世界線は意味が無いのでスルー）
                rep(j,a[i]){ // 
                    if(x[i][j]>0){ // その証言が正直者証言だったときは
                        if(fact[x[i][j]-1] != -1 && (bit & 1<<(x[i][j]-1) ) != false){ // conflictが起きなければ
                            fact[x[i][j]-1]=1; // 正直者とされている人物のfactを1に
                        }
                        else{
                            conflict = true;
                            break;
                        }
                    }
                    else{ // その証言が不親切者証言だったときは
                        if(fact[(-1)*(x[i][j])-1] != 1 && (bit & 1<<((-1)*(x[i][j])-1)) == false){ // conflictが起きなければ
                            fact[(-1)*(x[i][j])-1]=-1; // 不親切者とされている人物のfactを-1に
                        }
                        else{
                            conflict = true;
                            break;
                        }
                    }
                }
            }
            }
        }
        if(!conflict){
            int number = 0; // numberは正直者の人数
            rep(i,n){
                if(bit & 1<<i){
                    number ++;
                }
            }
            ans = max(ans, number);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int Time[111111*2];
int RecTime[30][111111*2];

int main(){
  int n,c;
  cin>>n>>c;
  for(int i = 0;i<n;i++){
    int s,t,ch;
    cin>>s>>t>>ch;
    
    RecTime[ch-1][s*2-1]++;
    RecTime[ch-1][t*2]--;
    
    //isRec[ch-1][s*2-1] = true;
  }
  int ans = 0;
  for(int j = 0;j<30;j++){

    for(int i = 1;i<111111*2;i++){
      RecTime[j][i] += RecTime[j][i-1];
      if(RecTime[j][i] > 0)Time[i]++;
    }
  }
  for(int i = 1;i<111111*2;i++){
    ans = max(ans,Time[i]);
  }
    
  
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 27008
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i - 1], t[i] = t[i], t[i - 1]
        if ''.join(t).count("AGC") >= 1:
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == n:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
    memo[cur][last3] = ret
    return ret
        

if __name__ == "__main__":
    n, mod = int(input()), 10 ** 9 + 7
    memo = [{} for i in range(n + 1)]
    print(dfs(0, "TTT"))


Measured memory_bytes: 3812
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    int b;
    int c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a<b&&b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}



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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    while(true){
        string s;
        cin >> s;
        if(s=="-") break;
        int m;
        cin >> m;
        for(int i=0;i<m;i++){
            int h;
            cin >> h;
            string sfl=s.substr(0,h);
            s=s.substr(h)+sfl;
        }
        cout << s << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {

  int N; cin >> N;
  int A[N];
  rep(i,N){
    cin >> A[i];
  }
  double ans = 0;
  rep(i,N){
    ans += (double)1 / A[i];
  }
  ans = (double)1 / ans;
  cout << fixed << setprecision(15) << ans << endl;
	return 0;
}



Measured memory_bytes: 3792
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)


# にぶたん := N人のメンバーそれぞれが完食にかかる時間のうち最大値をxに以下にできるか？
ok, ng = 10 ** 12 + 1, -1
while ok - ng > 1:
    x = (ok + ng) // 2

    need_training = 0
    for a, f in zip(A, F):
        need_training += max(0, a - x // f)

        if need_training > K:
            ng = x
            break
    else:
        ok = x

print(ok)


Measured memory_bytes: 121036
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int MOD = 1e9 + 7;
	int N, K;
	cin >> N >> K;

	vector<Int> d(N + 1, 0);
	for (int i = 1; i <= N; ++i) {
		(d[i] = i + d[i - 1]) %= MOD;
	}

	Int ans = 0;
	for (int i = K; i <= N + 1; ++i) {
		Int a = (d[N] - d[max(0, N - i)] + MOD) % MOD;
		Int b = d[i - 1];
		(ans += (a - b + 1 + MOD) % MOD) %= MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inv2=(mod+1)>>1;
const int N=2e5+10;
int n,B,W;
ll fac[N],inv[N],bin[N],spw[N],spb[N];
ll pw(ll x,ll p){
	ll ret=1;
	while(p){
		if(p&1)ret=ret*x%mod;
		x=x*x%mod;
		p>>=1;
	}
	return ret;
}
ll C(int x,int y){
	if(x<y)return 0;
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
	scanf("%d%d",&B,&W);n=B+W;
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[n]=pw(fac[n],mod-2);for(int i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	bin[0]=1;for(int i=1;i<=n;i++)bin[i]=bin[i-1]*inv2%mod;
	spw[0]=0;for(int i=1;i<=n;i++)spw[i]=(spw[i-1]+C(i-1,W-1)*bin[i]%mod)%mod;
	spb[0]=0;for(int i=1;i<=n;i++)spb[i]=(spb[i-1]+C(i-1,B-1)*bin[i]%mod)%mod;
	for(int i=1;i<=n;i++){
		ll ans=((1-spw[i-1]-spb[i-1])*inv2%mod+spw[i-1])%mod;
		ans=(ans%mod+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    int n, k;
    std::cin >> n >> k;
    auto h = read<std::uint64_t>(n);
    std::sort(std::begin(h), std::end(h));
    std::uint64_t res = 0;
    res = ~res;
    for (auto i : boost::irange(0, n - k + 1)) {
        res = std::min(res, h[i + k - 1] - h[i]);
    }
    out(res);
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] directSubordinateCnts = new int[n + 10];
		for (int i = 2; i <= n; ++i) {
			int directBoss = sc.nextInt();
			++directSubordinateCnts[directBoss];
		}

		for (int i = 1; i <= n; ++i) {
			System.out.println(directSubordinateCnts[i]);
		}
	}

}


Measured memory_bytes: 61628
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	int a, b, x;
	cin >> x >> a >> b;
	x -= a;
	cout << x % b << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,k,n;
	cin >> n;
	int cost[n];
	int h[n];
	for(i=0;i<n;i++)
	{
		cin >> h[i];
	}
	cost[0]=0;
	cost[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++)
	{
		cost[i]=min(abs(h[i]-h[i-1])+cost[i-1],abs(h[i]-h[i-2])+cost[i-2]);
	}
	cout << cost[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
ll a, b, p = 60, ans;

int main() {
    cin >> a >> b;
    while (p >= 0 && ((a >> p) & 1) == ((b >> p) & 1)) --p;
    if (p >= 0) {
        ll t = (1ll << (p + 1)) - 1;
        a = (a & t), b = (b & t);  // 忽略前面相同的位
        ll d = p - 1;
        while (d >= 0 && !((b >> d) & 1)) --d;
        ll l1 = a, r1 = (1ll << p) + (1ll << (d + 1)) - 1;
        ll l2 = (1ll << p) + a, r2 = (1ll << (p + 1)) - 1;
        ans += r1 - l1 + 1;
        ans -= max(0ll, r1 - l2 + 1);
        ans += r2 - l2 + 1;
    } else ans = 1;
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
  int N;
  int a[110000];
  int visited[110000];
  cin >> N;
  rep(i,N){
    cin >> a[i];
    a[i]--;
  }
  rep(i,N) visited[i]=0;

  int pos=0;
  int hop=0;
  bool can=false;
  while(visited[pos]==0){
    hop++;
    if(a[pos]==1) {
      can=true;
      break;
    }
    visited[pos]=1;
    pos=a[pos];
  }
  if(!can) cout << -1 << endl;
  else cout << hop << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fr(x) scanf("%d", &x)
using namespace std;

int x[100010], y[100010];
int cntw[4096][4096], cntb[4096][4096];
char c[100010];

int query(int arr[4096][4096], int x1, int y1, int k) {
	int y = arr[x1 + k-1][y1 + k - 1];
	if(x1) y -= arr[x1-1][y1 + k - 1];
	if(y1) y-= arr[x1 + k - 1][y1 - 1];
	if(x1 and y1) y += arr[x1-1][y1-1];
	return y;
}

int main() {
	int n, k;
	fr(n);
	fr(k);
	for(int i=1; i<=n; ++i) {
		fr(x[i]);
		fr(y[i]);
		scanf(" %c", &c[i]);
		x[i] %= (2*k);
		y[i] %= (2*k);
	}
	for(int i=1; i<=n; ++i) {
		if(c[i] == 'B') {
			++cntb[x[i]][y[i]];
		}
		else {
			++cntw[x[i]][y[i]];
		}
	}
	for(int i=0; i<4*k; ++i) {
		for(int j=0; j<4*k; ++j) {
			cntb[i][j] = cntb[i%(2*k)][j%(2*k)];
			cntw[i][j] = cntw[i%(2*k)][j%(2*k)];
		}
	}
	for(int i=0; i<4*k; ++i) {
		int temprow = 0;
		for(int j=0; j<4*k; ++j) {
			temprow += cntw[i][j];
			cntw[i][j] = temprow + (i==0?0:cntw[i-1][j]);
		}
	}
	for(int i=0; i<4*k; ++i) {
		int temprow = 0;
		for(int j=0; j<4*k; ++j) {
			temprow += cntb[i][j];
			cntb[i][j] = temprow + (i==0?0:cntb[i-1][j]);
		}
	}
	int ans = 0;
	for(int up=0; up < k; ++up) {
		for(int left = 0; left < k; ++left) {
			int temp = 0;
			temp += query(cntw, up, left, k);
			temp += query(cntw, up+k, left+k, k);
			temp += query(cntb, up+k, left, k);
			temp += query(cntb, up, left+k, k);
			ans = max(ans, max(temp, n - temp));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 132096
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)){
                        while(true){
                                int N = sc.nextInt(), M = sc.nextInt();
                                if(N==0&&M==0){
                                        break;
                                }
                                int[] A = new int[M];
                                for(int i = 0; i < N; i++){
                                        int d = sc.nextInt(), v = sc.nextInt();
                                        d--;
                                        A[d] = Math.max(A[d], v);
                                }
                                int ans = 0;
                                for(int i = 0; i < M; i++){
                                        ans+=A[i];
                                }
                                System.out.println(ans);
                        }
                }
        }
}

Measured memory_bytes: 34048
# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=[]
a.sort()
# aの各点に通し番号を振る
for i in range(n):
    a[i].append(i)

# 繋ぐ点の候補は上下左右の４つ
# 左右に繋ぐ辺を追加
for i in range(n-1):
    b.append([a[i][2], a[i + 1][2], a[i + 1][0] - a[i][0]])

a.sort(key=lambda x:x[1])
# 上下に繋ぐ辺を追加
for i in range(n-1):
    b.append([a[i][2], a[i + 1][2], a[i + 1][1] - a[i][1]])

b.sort(key=lambda x:x[2])

uf=UnionFind(n)
ans=0
cnt=0
# クラスカル法
for x,y,z in b:
    if not uf.same(x,y):
        uf.union(x,y)
        cnt+=1
        ans+=z
        if cnt==n-1:
            break
print(ans)


Measured memory_bytes: 131364
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int l = scanner.nextInt();
        final int r = scanner.nextInt();

        final Set<Integer> mods = new HashSet<>();

        for (int i = l; i <= r; i++) {
            if (i % 2019 == 0) {
                System.out.println(0);
                return;
            }

            mods.add(i % 2019);
        }

        final Integer[] modArray = new Integer[mods.size()];
        mods.toArray(modArray);

        int min = 2019;
        for (int i = 0; i < modArray.length - 1; i++) {
            for (int j = i + 1; j < modArray.length; j++) {
                if (modArray[i] * modArray[j] % 2019 < min) {
                    min = modArray[i] * modArray[j] % 2019;
                }
            }
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

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


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  bool ans = true;
  rep(i,n) {
    if(a.at(i)%2 == 0) {
      if(a.at(i)%5 != 0 && a.at(i)%3 != 0) ans = false;
    }
  }
  if(ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
import numpy as np
n, k = map(int,input().split())
a = np.array(list(map(int,input().split())))
a.sort()
posi = a[a>0]
zero = a[a==0]
nega = a[a<0]
l = -10**18-1
r = 10**18+1
while r-l > 1:
    mid = (r+l)//2
    cnt = 0
    if mid >= 0:
        cnt += len(zero)*n
    cnt += a.searchsorted(mid//posi, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//nega), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt //= 2
    if cnt >= k:
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 32316
import sys;

for line in sys.stdin:
	n = int(line);
	for i in range(0, n):
		a = [int(num) for num in input().split()];
		a.sort();
		if a[2] ** 2 == (a[0] ** 2) + (a[1] ** 2):
			print('YES');
		else:
			print('NO');

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

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> cnt(n);
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int y;
      cin >> y;
      ++cnt[y - 1];
    }
  } 
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 0)
      ++res;
  }
  cout << res << '\n';
  return 0;
}

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

const int maxx = 100000 + 10;
struct task {
    // 任务的名字和耗费的时间
    char name[100];
    int t;
};
task Queue[maxx];

// 指向队头和队尾的指针
int head, tail;


// 判断循环队列是否已满
bool isFull() {
    return head == (tail + 1) % maxx;
}

// 判断循环队列是否为空
bool isEmpty() {
    return head == tail;
}

// 将元素x添加到队列的末尾
void enqueue(task x) {
    Queue[tail] = x;
    // 循环队列
    tail = (tail + 1) % maxx;
}

// 返回队头元素并删除
task dequeue() {
    task x = Queue[head];
    // 循环队列
    head = (head + 1) % maxx;
    return x;
}
int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n; i++) {
        scanf("%s %d", Queue[i].name, &Queue[i].t);
    }
    // 当前已经有n个元素
    head = 0; tail = n;
    // 当前时间
    int nowtime = 0;
    while (!isEmpty()) {
        // 取出队头
        task u = dequeue();
        // 执行时间片 p 和 所需要时间u.t
        int c = min(q, u.t);
        // 任务执行了 c ms
        u.t -= c;
        // 当前时间加上c ms
        nowtime += c;
        // 任务还没做完，加入到队尾
        if (u.t > 0) {
            enqueue(u);
        }
        else { // 任务已经完成，打印出结果
            printf("%s %d\n", u.name, nowtime);
        }

    }
    return 0;
}


Measured memory_bytes: 13276
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

// Kruskal algorithm: build minimum spanning tree

template <typename T>
struct Kruskal {
    struct edge {
        int from, to, used;
        T cost;
        edge(int from_, int to_, T cost_) : from(from_), to(to_), cost(cost_), used(0) {}
        bool operator<(const edge &e) const { return cost < e.cost; }
    };

    vector<int> rank, parent;
    vector<edge> es;
    Kruskal(int n) : rank(n + 1, 0), parent(n + 1) { iota(parent.begin(), parent.end(), 0); }
    // union-find methods
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    // Kruskal methods
    void addEdge(int f, int t, T c) { es.emplace_back(f, t, c); }
    T build() {
        sort(es.begin(), es.end());
        T res = 0;
        for (auto &e : es) {
            if (!isSame(e.from, e.to)) {
                res += e.cost;
                unite(e.from, e.to);
                e.used = 1;
            }
        }
        return res;
    }
};

int main() {
    int n;
    cin >> n;
    vvl a(n, vl(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    vvl mindist = a;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                chmin(mindist[j][k], mindist[j][i] + mindist[i][k]);
            }
        }
    }
    bool ok = true;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i][j] != mindist[i][j]) {
                ok = false;
            }
        }
    }
    if (ok) {
        ll ret = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                bool needed = true;
                for (int k = 0; k < n; ++k) {
                    if (k != i && k != j) {
                        if (a[i][j] == a[i][k] + a[k][j])
                            needed = false;
                    }
                }
                if (needed)
                    ret += a[i][j];
            }
        }
        cout << ret << "\n";
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      try{
        String line1;
        char[] ch = new char[200000];
        while(!(line1 = reader.readLine()).equals("-")){
             for(int i = 0; i < line1.length(); i++){
               ch[i] = line1.charAt(i);
             }
             int l = 0;
             int r = line1.length() - 1;
             String line2 = reader.readLine();
             int m = Integer.parseInt(line2);
             int[] h = new int[m];
             for(int i = 0; i < m; i++){
               String line3 = reader.readLine();
               h[i] = Integer.parseInt(line3);
               for(int j = 0; j < h[i]; j++){
                  ch[r + 1 + j] = ch[l + j];
               }
               l += h[i];
               r += h[i];
             }
             for(int i = l; i <= r; i++){
               System.out.print(ch[i]);
             }
             System.out.println();
        }
      }catch(IOException e){

      }
    }
}


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

int main(){
    int N; cin >> N;
    int a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    
    sort(a, a+N, greater<int>());
    // for(int i = 0; i < N; i++) cout << a[i] << ' ';
    // cout <<endl;
    long long RectangleArea = 1;
    int countEdges = 0;
    for(int i = 1; i < N; i++){ // 1-origin
        if(a[i] == a[i-1]){
            RectangleArea *= a[i];
            countEdges++;
            i++;
        }
        if(countEdges == 2) break;
    }
    if(countEdges < 2) cout << 0 << endl;
    else cout << RectangleArea << endl;


    return 0;
}

Measured memory_bytes: 640