akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <math.h>
 
using namespace std;
 
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
 
int main(){
	cin.tie(0);                       
   	ios::sync_with_stdio(false);
   	int N;
   	cin >> N;
   	int MAX = 1000000000;
   	int n = 1;
   	for(int i = N;i >= 0;i--){

   		if(long(sqrt(i))*long(sqrt(i)) == i){
   			n = i;
   			break;
   		}
   	}
   	cout << n << endl;
   	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=2e5+7;
const int mod=10007;
double isp=1e-6;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
int main()
{
 ios::sync_with_stdio(0),cin.tie(0);
  string s;
  cin>>s;
  int n=s.length();
  if(n%2)cout<<"No"<<endl;
  else {
    for(int i=0;i<n;i++)
    {
        if(i&1)
        {
            if(s[i]!='i'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else {
            if(s[i]!='h')
            {
                 cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
/*Aonyx Cinerea*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 17;

int A[MAXN], B[MAXN];

int main()
{
    ios::sync_with_stdio(false);    cin.tie(0);
    int n;  cin >> n;
    for(int i=1; i<=n; ++i)
    {
        cin >> A[i];
        A[i] += A[i-1];
    }
    for(int i=1; i<=n; ++i)
        cin >> B[i];
    for(int i=n-1; i>=1; --i)
        B[i] += B[i+1];

    int ans = 0;
    for(int i=1; i<=n; ++i)
        ans = max(ans, A[i] + B[i]);
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n!=0){
        int list[1000]={};
        double x=0,y=0,m=0;
        
        for(int i=0;i<n;i++){
            cin>>list[i];
            x+=list[i];
        }
        m=x/n;
        for(int i=0;i<n;i++){
            y+=(list[i]-m)*(list[i]-m)/n;
        }
        printf("%f\n",sqrt(y));
        cin>>n;
    }
    
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int main(){
	int n;
	read(n);
	int a[n+1][n+1]={},b[n+1][n+1]={};
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++) read(a[i][j]);
		for(int j=i+1;j<=n;j++) read(b[i][j]);
	}
	ll s[2][510][510]={};
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			s[0][i][j]=s[0][i-1][j]+s[0][i][j-1]-s[0][i-1][j-1]+a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			s[1][i][j]=s[1][i-1][j]+s[1][i][j-1]-s[1][i-1][j-1]+b[i][j];
	ll f[n+1][n+1];memset(f,63,sizeof(f));
	auto calc=[&](int k,int a,int b,int c,int d){
		if(a>b||c>d) return 0ll;
		return s[k][b][d]-s[k][a-1][d]-s[k][b][c-1]+s[k][a-1][c-1];
	};
	auto chmin=[](ll &a,ll b){if(b<a) a=b;};
	for(int i=1;i<=n;i++)
		f[1][i]=calc(1,1,i,2,i);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=i;j++){
			for(int k=i+1;k<=n;k++)
				chmin(f[i+1][k],f[j][i]+calc(1,i+1,k,i+2,k)+calc(0,i+1,k,1,j-1));
		}
	ll ans=1e18;
	for(int i=1;i<=n;i++) chmin(ans,f[i][n]);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    ll N;
    cin >> N;
    string ans = "";
    while (N > 0) {
        N--;
        ans += 'a' + (N % 26);
        N /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[8]={},n,idx=-1;
  char z[8]={'A','I','D','U','N','Y','A','N'};
  char z1[8]={'A','I','Z','U','N','Y','A','N'};
  string d;
  cin>>d;

  for(int i=0;i<d.size();i++){

    n=0;
    for(int j=0;j<8;j++)c[j]=0;

    for(int j=0;j<8;j++){
      if(i+j>=d.size())break;
      for(int k=0;k<8;k++)
	if(d[i+j]==z[k]&&c[k]==0){
	  c[k]=1,n++;
	  break;
	}
    }
    if(n==8){
      for(int j=0;j<8;j++)d[i+j]=z1[j];
      i+=7;
    } 
  }
  cout<<d<<endl;  
  
 return 0;
}

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

typedef long long ll;

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

  long long N;
  std::cin >> N;
  long long Q;
  std::cin >> Q;

  atcoder::dsu uf(N);

  for(;Q-->0;) {
    ll q, u, v;
    cin >> q >> u >> v;
    if (q) {
      cout << uf.same(u, v) << endl;
    } else {
      uf.merge(u, v);
    }
  }
  return 0;
}


Measured memory_bytes: 3976
if __name__ == '__main__':
    N, H = map(int, input().split())
    values = [map(int, input().split()) for _ in range(N)]
    a, b = zip(*values)

    a = sorted(a)
    b = sorted(b)

    n_attacks = 0
    latter_damage = 0
    while len(b) != 0 and a[-1] < b[-1]:
        n_attacks += 1
        latter_damage += b.pop()

        if H <= latter_damage:
            print(n_attacks)
            exit(0)

    a_max = a.pop()
    # remainder (0 or 1)
    r = int(bool((H - latter_damage) % a_max))
    n_attacks += r + (H - latter_damage) // a_max
    print(n_attacks)


Measured memory_bytes: 59860
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#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 a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <= b; ++i) if (c % i == 0) ++ans;
  cout << ans << endl;
  return 0;
}


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

int n, l;
int main() {
	scanf("%d %d", &n, &l);
	//L + i - 1 = 0 <=> i = 1 - L
	//1 <= 1 - L <= n
	int sum = (l - 1) * n  +  n * (n + 1) / 2;
	if (1 <= 1 - l && 1 - l <= n)
		printf("%d\n", sum);
	else
		printf("%d\n", sum - (l + (l < 0 ? n : 1) - 1));
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL solve(LL n){
    LL dp[12][10][2][2] = {};
    string sn = to_string(n);
    int len = sn.length();
    int x = sn[0] - '0';
    FOR(i,1,x){
        dp[0][i][1][0] = 1;
    }
    dp[0][0][1][1] = 1;
    dp[0][x][0][0] = 1;
    FOR(i,0,len-1){
        int d = sn[i+1] - '0';
        FOR(j,0,10){
            for(int k = max(0,j-1); k <= min(9,j+1); k++){
               dp[i+1][k][1][0] += dp[i][j][1][0];
            }


            if(abs(d-j) <= 1) dp[i+1][d][0][0] += dp[i][j][0][0];
            for(int k = max(0,j-1); k <= min(9,min(d-1,j+1)); k++){
                dp[i+1][k][1][0] += dp[i][j][0][0];
            }

             for(int k = 1; k <= 9; k++){
               dp[i+1][k][1][0] += dp[i][j][1][1]; //leading zero
             }
             dp[i+1][0][1][1] += dp[i][j][1][1];


        }
    }
    //REP(i,10) REP(j,2){
    //    dump(i)
    //    dump(j)
    //    dump(dp[1][i][j][0])
    //}
    LL res = 0;
    REP(i,10) REP(j,2){
        res += dp[len-1][i][j][0];
    }
    return res;

}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL K; cin >> K;
    LL ok = 3234566668;
    LL ng = 0;
    //dump(solve(K))
    
    while(abs(ok-ng) > 1){
        LL mid = (ok+ng) / 2;
        //dump(mid)
        //dump(solve(mid))
        if(solve(mid) >= K){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;



}


Measured memory_bytes: 256
#include <stdio.h>

const long long mod = 1000000007;

struct mat {
	int a[3][3];

	mat operator -(mat t) {
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = (a[i][j] + mod - t.a[i][j]) % mod;
		}
		return r;
	}

	mat operator *(mat t){
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = 0;
			for (int k = 0; k < 3; k++) {
				r.a[i][j] = (r.a[i][j] + (long long)a[i][k] * t.a[k][j]) % mod;
			}
		}
		return r;
	}

	int get(){
		return (a[2][0] * 5ll + a[2][1]) % mod;
	}
};

int N, M, X[100100];
long long D[100100];

int main()
{
	mat base[32];
	base[0] = mat{ 4,mod - 2,1,1,0,0,0,1,0 };
	for (int i=1;i<32;i++) base[i] = base[i-1] * base[i-1];

	scanf("%d %d", &N, &M);
	for (int t = 1; t <= M; t++) scanf("%d", &X[t]);
	X[M + 1] = N;

	mat sum = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	mat idt = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
	mat all = idt;

	for (int i = 1; i <= M + 1; i++) {
		mat now = idt;
		for (int j=0,x=X[i]-X[i-1];x;j++,x/=2) if (x & 1) now = now * base[j];
		sum = sum * now;
		all = all * now;
		D[i] = (all - sum).get();
		for (int k = 0; k < 3; k++) sum.a[k][k] = (sum.a[k][k] + D[i]) % mod;
	}

	printf("%d\n", D[M+1]);
	return 0;
}


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

int main() {
	int N; ll count = 0; int num;
	int A[(int)1e5+1];
	cin >> N;
	rep(i, N+1) cin >> A[i];
	rep(i, N){
		cin >> num;
		if(A[i] + A[i+1] <= num){
			count += A[i] + A[i+1];
			A[i+1] = 0;
		}else{
			count += num;
			A[i+1] -= max(0, (num - A[i]));
		}
	}
	cout << count;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(std::string s, std::string t){
  string &ss=s,&tt=t;
  set<char> sc(s.begin(),s.end()),tc(t.begin(),t.end());
  vector<char> vc;
  set_difference(tc.begin(),tc.end(),sc.begin(),sc.end(),inserter(vc,vc.end()));
  if(!vc.empty()){
    dump(vc);
    cout<<-1<<endl;
    return;
  }
  map<char,vector<int>> m;
  REP(ss.size()){
    m[ss[i]].push_back(i);
  }
  ll loops=0,index=-1;
  REP(tt.size()){
    auto &v=m[tt[i]];
    auto itr=upper_bound(v.begin(),v.end(),index);
    if(itr==v.end()){
      ++loops;
      index=v.front();
    }else{
      index=*itr;
    }
  }
  cout<<loops*ss.size()+index+1<<endl;
}

int main(){
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
int bfs(vector<string>& grid) {
    int h = grid.size();
    int w = grid[0].size();
    vector<int> dq = {0};
    vector<int> visit(h*w, false);
    visit[0] = true;
    vector<int> dir = {1, 0, -1, 0, 1};
    int step = 0;
    while(!dq.empty()) {
        vector<int> new_dq;
        for(int node: dq) {
            int r = node/w;
            int c = node%w;
            for(int d = 0; d < 4; d++) {
                int rr = r + dir[d];
                int cc = c + dir[d+1];
                if (rr >= h || rr < 0 || cc >= w || cc < 0)
                    continue;
                if (grid[rr][cc] == '.' && visit[rr*w+cc] == false) {
                    visit[rr*w+cc] = true;
                    new_dq.push_back(rr*w+cc);
                    if (rr == h-1 && cc == w-1)
                        return step+1;
                }
            }
        }
        dq.swap(new_dq);
        step += 1;
    }
    return -1;
}
int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid;
    string s;
    int black = 0;
    for(int i = 0; i < h; i++) {
        cin >> s;
        grid.push_back(s);
        for(int j = 0; j < w; j++)
            if (s[j] == '#')
                black += 1;
    }
    int res = bfs(grid);
    if (res == -1)
        cout << -1 << endl;
    else
        cout << (h*w-black-(res+1)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void c(){
   ll N; cin >> N;
   auto A = v<>(N,0);
   auto S = v<>(N+1,0);
   
   rep(i,N) {
       cin >> A[i];
       S[i+1]=S[i]+A[i];
   }

   sort(all(S));
   auto it = S.begin();
   auto itb = S.begin();
   ll ans = 0;
   while(it!=S.end()){
       itb = it;
       it = upper_bound(all(S),*itb);
       auto cnt = it - lower_bound(all(S),*itb);
       ans+=cnt*(cnt-1)/2;
   }

   cout << ans << endl;
}

int main(void){
    c();
    return 0;
 }

Measured memory_bytes: 6348
h, w = [int(_) for _ in input().split()]
m = [['.']*(w+2)] + [['.']+list(input())+['.'] for _ in range(h)] + [['.']*(w+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if m[i][j] == '.':
            m[i][j] = 0    
            for di in range(-1,2):
                for dj in range(-1,2):
                    if m[i+di][j+dj] == '#':
                        m[i][j] += 1
    print(''.join(map(str, m[i][1:w+1])))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n,x,ans = 0;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if(a[i] <= x){
            ans++;
            x -= a[i];
            cnt++;
        }else break;
    }
    if(x > 0 && ans != 0 && cnt == n) ans--;
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
ll c, ans;
string a;
int main()
{
	ll i;
	cin >> a;
	for (i = 0; i < a.size(); i++) {
		if (a[i] == 'A') c++;
		else if (a[i] == 'B' && a[i + 1] == 'C') ans += c, i++;
		else c = 0;
	}
    cout << ans << endl;
    return 0;
}

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

int main() {
    int A, B, C, X;
    int ans = 0;

    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
          for (int k = 0; k <= C; k++) {
            if((i*500+j*100+k*50)==X) ans++;
          }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	char s[11],db[11]={"2019/04/30"};
	for(int i=0;i<10;i++)
		cin>>s[i];
	if(int(s[3])>int(db[3])||int(s[3])==int(db[3])&&(int(s[5])>int(db[5])||int(s[6])>int(db[6])))
		cout<<"TBD";
	else
		cout<<"Heisei";
	return 0;	
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NKQ = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var N = NKQ[0];
            var K = NKQ[1];
            var Q = NKQ[2];

            int[] A = new int[N+1];

            for(int i=0; i < Q; i++)
            {
                 var B= int.Parse(Console.ReadLine());
                 A[B]++;
            }

            for(int i = 1; i <= N; i++)
            {
                Console.WriteLine(Q - A[i] < K ? "Yes" : "No");
            }
            

        }


    }
}


Measured memory_bytes: 17600
// but in the end its me & I

#include <bits/stdc++.h>
#include <vector>

#define s second
#define f first
#define pb push_back
//#define int ll

using namespace std;

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

const long long MAX=1e5+85,INF=1e5+7,mod=998244353;

int n,k,a[MAX],dp[MAX],mn=INF;
string s[2]={"Second","First"};
//int dx[2]={0,1};
//int dy[2]={1,0};
//pii p[MAX];
//vector <int> v;
//set <pii> st;
//queue <pii> q;
//map<pii,int> dp;
//map <pii,bool> mark;

void solve()
{
   cin >> n >> k;
   for(int i=0;i<n;i++)
   {
       cin >> a[i];
       mn=min(mn,a[i]);
   }
   for(int i = mn;i<MAX;i++)
   {
       for(int j=0;j<n;j++)
       {
           if(i-a[j]<0)continue;
           if(!dp[i-a[j]])
           {
               dp[i]=1;
               break;
           }
       }
   }
   cout << s[dp[k]];
}
main()
{
    ios_base::sync_with_stdio(0);
    solve();
    return -0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll n,z,x;
int main()
{
    fast;
    cin>>n;
    z=1;
    while(n!=0){
       n/=2;
       z*=2;
    }
    cout<<z-1<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1

typedef struct{
  int parent,left,right;
}tree;

void data_print(tree *inf,int i);
int depth(tree *inf,int x);

int main(){
  tree inf[100001];
  int n,pick,id,num,a,r;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    inf[i].parent=NIL;
    inf[i].left=NIL;
    inf[i].right=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&pick);

    for(j=0;j<pick;j++){
      scanf("%d",&num);
      if(j==0) inf[id].left=num;
      else inf[a].right=num;
      a=num;
      inf[num].parent=id;
    }
  }

  for(i=0;i<n;i++)data_print(inf,i);

  return 0;
}

void data_print(tree *inf,int i){
  int temp;

  printf("node %d: ",i);

  printf("parent = %d, ",inf[i].parent);

  printf("depth = %d, ",depth(inf,i));

  if(inf[i].parent==NIL)printf("root, ");
  if(inf[i].parent!=NIL && inf[i].left==NIL)printf("leaf, ");
  if(inf[i].parent!=NIL && inf[i].left!=NIL)printf("internal node, ");

  printf("[");
  if(inf[i].left!=NIL){
    printf("%d",inf[i].left);
    temp=inf[i].left;
    while(inf[temp].right!=NIL){
      printf(", %d",inf[temp].right);
      temp=inf[temp].right;
    }
  }
  printf("]\n");
}

int depth(tree *inf,int num){
  int cnt=0,temp;

  while(inf[num].parent!=NIL){
    cnt++;
    temp=inf[num].parent;
    num=temp;
  }
  return cnt;
}



Measured memory_bytes: 2976
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,m;
string s,s1,s2;
vvl v;
vl vis,d;
vl a;

void dfs(ll s){
    vis[s]=1;
    for(ll u:v[s]){
        if(vis[u]==0)dfs(u);
    }
    a.pb(s);
}

int main() {
    IOS;
    cin>>n>>k;
    v.resize(n);vis.assign(n,0);
    fo(i,k){
        cin>>x>>y;
        v[--x].pb(--y);
    }
    vl dp(n,0);
    fo(i,n)if(vis[i]==0)dfs(i);
    reverse(all(a));
    for(int i=n-1;i>=0;i--){
        q=0;
        for(ll u:v[a[i]])q=max(q,dp[u]);
        dp[a[i]]=1+q;
        kv=max(kv,dp[a[i]]-1);
    }
    cout<<kv<<el;
    return 0;
}


Measured memory_bytes: 10488
import sys
import math

lines = sys.stdin.readlines()
K, A, B = map(int, lines[0].split())
ans = 0

if B - A <= 1:
  ans = 1 + K
  print(ans)
  exit(0)

M = math.floor((K - (A-1)) / 2)
N = K - M * 2
ans = M * (B - A) +  N + 1

print(int(ans))

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
using namespace std;
long long a[100];
int main()
{
    long long n;
    int i;
    scanf("%d",&n);
    a[0]=2;
    a[1]=1;
    for(i=2;i<=100;i++)
        a[i]=a[i-1]+a[i-2];
    printf("%lld\n",a[n]);
    return 0;

}


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

int main(){
  int l,a,b,c,d,A,B;
  cin>>l>>a>>b>>c>>d;
  A=a/c;
  B=b/d;
  if(a%c)A++;
  if(b%d)B++;
  cout<<min(l-A,l-B)<<endl;
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
ans = 0
for i in range(1, 10):
    if N == int(str(i) + str(i) + str(i)):
        ans = int(str(i) + str(i) + str(i))
        break
    elif N < int(str(i) + str(i) + str(i)):
        ans = int(str(i) + str(i) + str(i))
        break

print(ans)

Measured memory_bytes: 3060
num = int(input())

x = [0]*num
y = [0]*num

for n in range(num):
    x[n], y[n] = map(int, input().split())

sol_n = 1
for n in range(num):
    sol_n *= (n+1)

sol = [0]*sol_n

sum_l = 0.0

for n in range(num):
    for m in range(num):
        if(n != m):
            sum_l += ((x[n] - x[m])**2 + (y[n] - y[m])**2)**(1/2)
print(sum_l / (num))


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

using namespace std;

int main()
{
    int N, K;
    while (cin >> N, N) {
        bool ok = 0;
        int cnt = 1;
        for (int i = 0; i < N; i++) {
            cin >> K;
            if (K > 1) ok = 1;
            if (K >= 1) cnt++;
        }
        if (ok) {
            cout << cnt << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int>h(N);
	rep(i, N)cin >> h[i];
	vector<int>dp(N);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	REP(i, 2, N) {
		dp[i] += min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N - 1] << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int, int> P;
typedef tuple<int, int, int> Tu;
//typedef pair<string, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int main() {
    long long N, K; cin >> N >> K;
    /*if (N < K) {
        cout << N << endl;
        return 0;
    }*/
    if (N % K == 0) {
        cout << 0 << endl;
        return 0;
    }
    N %= K;
    cout << min(abs(N - K), abs(abs(N - K) - K)) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
    
    ll Q, H, S, D, N;
    cin>>Q>>H>>S>>D>>N;

    ll ans=0;
    Q*=4;
    H*=2;
    ll cost=min(Q, H);
    cost=min(cost, S);//1リットル当たりの最小金額
    if(N%2==0){
        ans=min(cost*N, N/2*D);
    }else{
        ans=min(D*(N/2)+cost, cost*N);
        if(N==1) ans=cost;
    }
        cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,w,h,a,b,ans;
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> w >> h;
    for(int i=0;i<n;i++){
    	cin >> a >> b;
    	if(a>=w and b>=h)ans++;
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();
        double hour = 2*Math.PI * (H / 12.0 + M / 60.0 / 12.0);
        double min =  2*Math.PI * M / 60.0;
//        double diff = Math.abs(hour - min);
//        System.out.println(diff);
//        double degree = Math.min(diff, 360 - diff);
//        System.out.println(degree);
        double ans = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(hour - min));
        System.out.println(ans);
//        System.out.printf("%.12f\n", ans);
    }
}

Measured memory_bytes: 35892
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int T[N];
    long long ans = 0;
    for(int i = 0; i < N; i++){
        cin >> T[i];
        ans += (long long)T[i];
    }
    int M;
    cin >> M;
    int P[M], X[M];
    for(int i = 0; i < M; i++){
        cin >> P[i] >> X[i];
    }

    for(int i = 0; i < M; i++){
        cout << ans-(long long)T[P[i]-1]+(long long)X[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 256
//130b.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
/*namespace*/
using namespace std;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N,X;
    cin>>N>>X;
    vector<int> L(N);
    REP(i,N){
        scanf("%d",&L[i]);
    }
    int bounce=1;
    int dist=0;
    REP(i,N){
        if(dist+L[i]<=X){
            dist+=L[i];
            bounce+=1;
        }else{
            break;
        }
    }
    cout<<bounce<<endl;
}

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

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

constexpr int INF = 1e9;

int main() {
    string A;
    cin >> A;
    int const n = A.size();
    vector<vector<int>> next_pos(n + 1, vector<int>(26, n));
    for(int i = n - 1; i >= 0; --i) {
        next_pos[i] = next_pos[i + 1];
        next_pos[i][A[i] - 'a'] = i;
    }

    vector<int> max_len(n + 2);
    max_len[n] = 1;
    for(int i = n - 1; i >= 0; --i) {
        int t = INF;
        for(int j = 0; j < 26; ++j) {
            t = min(t, max_len[next_pos[i][j] + 1] + 1);
        }
        max_len[i] = t;
    }
   
    string res;
    int p = 0;
    for(int i = max_len[0] - 1; i >= 0; --i) {
        for(int j = 0; j < 26; ++j) {
            if(max_len[next_pos[p][j] + 1] == i) {
                res += char('a' + j);
                p = next_pos[p][j] + 1;
                break;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 27780
'''
n = int(input())
l = list(map(int, input().split()))
c = 1
for i in range(1, n):
    if l[i] >= l[i - 1]:
        c += 1
print(c)
'''
a, b = map(int, input().split())
if a <= 5:
    print(0)
elif a <= 12:
    print(b // 2)
else:
    print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cassert>
#include <queue>

struct Proc{
	std::string name;
	int time;
};

typedef std::queue<Proc> PQue;

int input(PQue& vec);
void output(PQue& vec);
PQue calc(PQue vec, int q);

///-------------------------------------------------
int main()
{
	PQue ivec;
	int q = input(ivec);
	PQue ovec = calc(ivec,q);
	output(ovec);
	return 0;
}
///--------------------------------------------
int input(PQue& vec)
{
	int n;
	std::cin >> n;
	int q;
	std::cin >> q;
	for(int i = 0; i < n; i++){
		Proc proc;
		std::cin >> proc.name;
		std::cin >> proc.time;
		vec.push(proc);
	}
	return q;
}
///-------------------------------------------------
void output(PQue& vec)
{
	while(!vec.empty()){
		Proc proc = vec.front();
		vec.pop();
		std::cout << proc.name << " " << proc.time << std::endl;
	}
}
///-------------------------------------------------
PQue calc(PQue queue, int q)
{
	PQue vec;
	int  time = 0;
	while(!queue.empty()){
		if(queue.front().time > q){
			time += q;
			queue.front().time -= q;
			queue.push(queue.front());
		}else{
			time += queue.front().time;
			queue.front().time = time;
			vec.push(queue.front());
		}
		queue.pop();
	}
	return vec;
}
///-------------------------------------------------

Measured memory_bytes: 6672
#include <iostream>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
  int n; cin>>n;
  set<int> st;
  int temp;
  rep(i,n){
    cin>>temp;
    st.insert(temp);
  }
  cout<<st.size()<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

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

    ll n, m, l;
    cin >> n >> m >> l;
    ll d[301][301], d2[301][301];
    rep(i, n) rep(j, n) d[i][j] = d2[i][j] = (i == j ? 0 : LINF);

    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = d[b][a] = c;
    }

    rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    rep(i, n) rep(j, n) {
        if (d[i][j] <= l) d2[i][j] = 1;
    }

    rep(k, n) rep(i, n) rep(j, n) d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);

    ll q;
    cin >> q;

    rep(i, q) {
        ll s, t;
        cin >> s >> t;
        s--, t--;
        cout << (d2[s][t] == LINF ? -1 : d2[s][t] - 1) << endl;
    }

    return 0;
}


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

#define gc() std::getchar()
#define pc(i) std::putchar(i)

template <typename T>
inline T read(){ 
	T x = 0;
	char ch = gc();
	bool f = 0;
	while(!std::isdigit(ch)){ 
		f = (ch == '-');
		ch = gc();
	} 
	while(std::isdigit(ch)){ 
		x = x * 10 + (ch - '0');
		ch = gc();
	} 
	return f ? -x : x; 
}

template <typename T>
void put(T x){ 
	if (x < 0){ 
		x = -x;
		pc('-');
	} 
	if (x < 10){ 
		pc(x + 48);
		return;
	} 
	put(x / 10);
	pc(x % 10 + 48);
	return ;
} 

#define For(i, j, k) for(int i = j; i <= k; ++i)
#define Rep(i, j, k) for(int i = j; i >= k; --i)
#define rdi() read <int> ()
#define rdl() read <long long> ()
#define pti(i) put <int> (i), putchar(' ')
#define ptl(i) put <long long> (i), putchar(' ')
#define pub(i) push_back(i)
#define pob() pop_back()

typedef long long ll;
typedef float fl;
typedef double db;

const int N = 2.2e5;
int f[N], b[N];

int get1(int x){ 
	if (f[x] != x) f[x] = get1(f[x]);
	return f[x];
} 

void fake_main(){ 
	int n = rdi(), m = rdi();
	
	For(i, 1, n) f[i] = i, b[i] = 1;
	
	For(i, 1, m) { 
		int x = get1(rdi()), y = get1(rdi());
		if (x != y) { 
			f[y] = x;
			b[x] += b[y];
			b[y] = 0;
		} 
	} 
	
	int ans = 0;
	For(i, 1, n) ans = std::max(ans, b[i]);
	
	printf("%d\n", ans);
} 

int main(){ 
	fake_main();
	
	return 0;
} 

Measured memory_bytes: 5256
N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
max_A = max(A)
#B = sorted(set(A), key = A.index)
#B = sorted(B, reverse = True)
#max_A = B[0]
try:
  second_max = sorted(set(A))[-2]
except:
  second_max = max_A
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)

Measured memory_bytes: 29120
n = gets.to_i

$memo = [nil] * (n+1)

def ruka(i)
  if i == 0
    return 2
  elsif i == 1
    return 1
  else
    if $memo[i].nil?
      $memo[i] = ruka(i-1)+ruka(i-2)
    end
    return $memo[i]
  end
end

puts ruka(n)

Measured memory_bytes: 1788
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 2e9;

void init() {

}

ll n,m,par[N],ans,cur,a[N],u[N],v[N],cnt[N];

int findPar(int a) {

    if(a==-1) return -1;

    if(par[a]==a) return a;

    return par[a] = findPar(par[a]);

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    memset(par,-1,sizeof(par));

    cin >> n >> m;

    ans =  n*(n-1)/2;

    for(int i=0;i<m;++i) {

        cin >> u[i] >> v[i];

    }

    for(int i=m-1;i>=0;--i) {

        a[i] = cur;
        int parA = findPar(u[i]);
        int parB = findPar(v[i]);
        if(parA==-1 && parB==-1) par[u[i]] = par[v[i]] = v[i], cnt[v[i]] = 2, cur += 1;
        else if(parA==-1 && parB!=-1) par[u[i]] = findPar(v[i]), cur += cnt[par[v[i]]], cnt[par[v[i]]]++;
        else if(parA!=-1 && parB==-1) par[v[i]] = findPar(u[i]), cur += cnt[par[u[i]]], cnt[par[u[i]]]++;
        else if(parA!=parB) cur += cnt[parA]*cnt[parB], par[parA] = parB, cnt[parB] += cnt[parA];

    }

    for(int i=0;i<m;++i) {

        cout << ans-a[i] << '\n';

    }

    return 0;

}

Measured memory_bytes: 5248
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ColoringEdgesonTree solver = new ColoringEdgesonTree();
        solver.solve(1, in, out);
        out.close();
    }

    static class ColoringEdgesonTree {
        int[] results;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            results = new int[n - 1];

            List<List<Pair>> lists = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                lists.add(new ArrayList<>());
            }

            for (int i = 0; i < n - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                lists.get(a).add(new Pair(b, i));
                lists.get(b).add(new Pair(a, i));
            }

            StringBuilder sb = new StringBuilder();
            long result = 0;
            for (int i = 0; i < n; i++) {
                result = Math.max(lists.get(i).size(), result);
            }
            sb.append(result).append("\n");

            dfs(0, 0, lists);

            for (int i = 0; i < n - 1; i++) {
                sb.append(results[i] + "\n");
            }
            out.print(sb.toString().trim());

        }

        public void dfs(int parent, int pColor, List<List<Pair>> lists) {
            List<Pair> children = lists.get(parent);
            int color = 1;
            if (color == pColor) {
                color++;
            }
            for (Pair p : children) {
                if (p.node == parent) {
                    continue;
                }
                if (results[p.route] > 0) {
                    continue;
                }
                results[p.route] = color;
                dfs(p.node, color, lists);
                color = (color + 1 == pColor) ? color + 2 : color + 1;
            }

        }

        class Pair {
            public final Integer node;
            public final Integer route;

            public Pair(Integer node, Integer route) {
                this.node = node;
                this.route = route;
            }

        }

    }
}



Measured memory_bytes: 80540
#include<iostream>
using namespace std;
int main() {
	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T' << endl;
	}

	if (b == 'T') {
		cout << 'A' << endl;
	}

	if (b == 'C') {
		cout << 'G' << endl;
	}

	if (b == 'G') {
		cout << 'C' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int A[10000000];
int m,count=0;
int G[1000000];
 
void insert(int *A,int n,int g){
  int v;
  int i,j;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      count++;
    }
    A[j+g]=v;
  }
}
void shell(int *A,int n){
  int h,i;
  for(i=0,h=1;;i++){
    if(h>n)break;
    G[i]=h;
    h=3*h+1;
  }
  m=i+1;
  for(i=m-1;i>=0;i--){
    insert(A,n,G[i]);
  }
}
int main(){
  int n,i,j;
  scanf("%d",&n);
 
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  shell(A,n);
  printf("%d\n",m-1);
  for(i=m-2;i>=0;i--){
    printf("%d",G[i]);
    if(i)printf(" ");
  }
  printf("\n%d\n",count);
  for(i=0;i<n;i++)printf("%d\n",A[i]);
 
  return 0;
}

Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
int n,t,x[maxn],cur,a,minx=1;
int abs(int b){
    return b>0?b:-b;
}
int main(){
    cin>>n>>t>>a;
    for(int i=1;i<=n;i++){
        cin>>cur;
        x[i]=t*1000-6*cur;
        if(abs(x[i]-a*1000)<abs(x[minx]-a*1000)) minx=i;
    }
    cout<<minx<<endl;
    return 0;
}

Measured memory_bytes: 256