akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> S)
{
    vector<ll> inc; // 純粋に開き括弧が増加 (((())((((
    vector<pair<ll, ll>> inc2; // 一時的に閉じ括弧が増えるが最終的に開き括弧が増える (()))))(((((
    vector<ll> dec; // 純粋に閉じ括弧が増加 ))))()))))
    vector<pair<ll, ll>> dec2; // 一時的に閉じ括弧が最終的な閉じ括弧の数より多くなる )))))(((()
    for (ll i = 0; i < N; i++) {
        ll min_diff = 0;
        ll max_diff = 0;
        ll diff = 0;
        for (auto ch : S[i]) {
            if (ch == '(') {
                diff++;
            }
            if (ch == ')') {
                diff--;
            }
            min_diff = min(min_diff, diff);
            max_diff = max(max_diff, diff);
        }
        if (diff >= 0) {
            if (min_diff >= 0) {
                inc.push_back(diff);
            } else {
                inc2.emplace_back(min_diff, diff);
            }
        }else {
            if (min_diff >= diff) {
                dec.push_back(diff);
            } else {
                dec2.emplace_back(min_diff, diff);
            }
        }
    }

    sort(begin(inc2), end(inc2), greater<pair<ll,ll>>());
    sort(begin(dec2), end(dec2));

    ll open = 0;
    for (auto i : inc) {
        open += i;
    }
    for (auto&& i : inc2) {
        if (open + i.first < 0) {
            cout << NO << endl;
            return;
        }
        open += i.second;
    }
    for (auto&& i : dec2) {
        if (open + i.first < 0) {
            cout << NO << endl;
            return;
        }
        open += i.second;
    }
    for (auto i : dec) {
        open += i;
    }
    if (open == 0) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 42520
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	int n; cin >> n;
	n = n % 1000;
	if(n == 0) cout << "0" << endl;
	else cout << 1000 - n << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

ll id(ll x, ll y) 
{
    if(x > y) swap(x, y);
    return x * 1005 + y;
}

int main()
{
    ll N;
    cin >> N;
    ll M = id(N, N);
    
    mat G(M);
    vec inD(M, -1);
    REP(i,1,N+1) {
        ll a, b;
        cin >> a;
        if(inD[id(i,a)] == -1) inD[id(i,a)] = 0;
        REP(j,0,N-2) {
            cin >> b;
            G[id(i,a)].pb(id(i,b));
            if(inD[id(i,b)] == -1) inD[id(i,b)] = 0;
            ++inD[id(i,b)];
            a = b;
        }
    }

    REP(i,0,M) {
        if(inD[i] == 0) {
            G[id(0,0)].pb(i);
            ++inD[i];
        }
    }

    auto H = G;

    vec S, I;
    ll k = 0;
    S.push_back(id(0, 0));
    while(!S.empty()) {
        ll v = S.back(); S.pop_back();
        I.push_back(v);
        while(!G[v].empty()) {
            ll nv = G[v].back(); G[v].pop_back();
            --inD[nv];
            if(inD[nv] == 0) S.push_back(nv);
        }
    }

    vec D(M, 0);
    ll m = -1;
    bool isDAG = true;
    REP(i,0,M) {
        if(SZ(G[i]) > 0) {
            isDAG = false;
            break;
        }
    }
    if(isDAG) {
        FORR(i,I) {
            FORR(nv,H[i]) D[nv] = MAX(D[nv],D[i]+1);
        }
        FORR(i,I) m = MAX(m,D[i]);
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 101196
#include<bits/stdc++.h>
using namespace std;
bool ss(int a,int b,int c)
{
	if(b>a&&b<c||(b<a&&b>c))return 1;
	else if(b==a&&b>c||(b==c&&b>a))return 1;
	else return 0;
}
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int count=0;
	for(int i=1;i<n-1;i++)
	{
		if(ss(a[i-1],a[i],a[i+1]))count++;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> vec(N, vector<int>(3));
    rep(i, N) rep(j, 3) cin >> vec[i][j];
    vector<vector<ll>> dp(100010, vector<ll>(3));
    rep(i, N) rep(j, 3) rep(k, 3) {
        if (j == k) continue;
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + vec[i][k]);
    }
    ll ans = max({dp[N][0], dp[N][1], dp[N][2]});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
n, m = gets.split.map(&:to_i)
firsts = []
lasts = []
m.times.map do
  a, b = gets.split.map(&:to_i)
  firsts << b if a == 1
  lasts << a if b == n
end

puts (firsts & lasts).empty? ? "IMPOSSIBLE" : "POSSIBLE"


Measured memory_bytes: 11352
City = Struct.new(:prefecture, :year, :serial, :idx)

n, m = gets.split.map(&:to_i)
cities = []
(1..m).each do |i|
  prefecture, year = gets.split.map(&:to_i)
  cities << City.new(prefecture, year, '0', i)
end

prefectures = cities.group_by(&:prefecture)
prefectures.keys.each do |pi|
  cities = prefectures[pi]&.sort_by(&:year)
  next if cities.nil?
  cities.map.with_index do |city, idx|
    first = format('%06d', pi)
    last = format('%06d', idx + 1)
    city.serial = first + last
  end
end

prefectures.values.flatten.sort_by { |city| city.idx }.each { |c| puts c.serial }


Measured memory_bytes: 42744
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"Yes"<<'\n';
}

void no(){
    cout<<"No"<<'\n';
}

void solve(){
    int n;
    double m;
    cin>>n>>m;
    vector<double> a(n);
    double sm =0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sm+=a[i];
    }
    sort(all(a));
    int ctr = 0;
    for(int i=n-1;ctr<m && i>=0;i--){
        if(a[i]/sm>=1/(4*m)){
            ctr++;
        }
    }
    if(ctr==m){
        yes();
    }else{
        no();
    }
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <numeric>

int main()
{
	int n, input1, input, max, min;
	long long sum;

	std::cin >> n;
	std::cin >> input1;
	
	max = input1;
	min = input1;
	sum = input1;

	for (int i = 0; i < n-1; i++)
	{
		std::cin >> input;
		min = std::min(min, input);
		max = std::max(max, input);
		sum += input;
	}

	std::cout << min << " " << max << " " << sum << std::endl;
	return 0;
}


Measured memory_bytes: 3080
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

#define int ll


const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, x[111];
main() {
    file("threesum");
    ios;
    cin>>n;
    fo(i,1,n,1) cin>>x[i];
    sort(x+1,x+n+1);
    int res=INF2;
    fo(mid,1,100,1){
    int ans=0;
    fo(i,1,n,1) ans+=(x[i]-mid)*(x[i]-mid);
    chmin(res,ans);
    }
    cout<<res;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll res[1223456];
signed main() {
	ll n, m, d, a, cnt = 0; string s; cin >> s;
	for (int h = 0; h < 4; h++) {
		if (s[h] == '2') { cnt++; }
	}
	cout << cnt << endl;
    return 0;
}

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

ll TopDown(vector< int > &heights, int n)
{
    vector< ll > incurr(n);
    incurr[0] = 0;
    incurr[1] = abs(heights[0] - heights[1]);
    for(int i=2;i<n; i++){
        incurr[i] = min(abs(heights[i] - heights[i-1]) + incurr[i-1], abs(heights[i] - heights[i-2]) + incurr[i-2]);
    }
    return incurr[n-1];
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    vector< int >  heights(n);
    for(int i=0;i<n;i++){
        cin >> heights[i];
    }
    ll ans = TopDown(heights,n);
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

        int ans = s.size();
		int n = s.size() - t.size();
  		int m = t.size();
  
        for(int i = 0; i <= n; i++){
                int cnt = 0;
                for(int j=0; j < m; j++){
                        if(t[j] != s[i+j]){
                                cnt++;
                        }
                }

                ans = min(ans,cnt);
        }

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


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

ll vacation(int a[][3], int n){
	ll dp[n][3];
	
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	// int ans = max(dp[0])
	for(int i=1;i<n;i++){

		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}

	ll ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return ans;
}

int main(){
	int n;
	cin>>n;
	int a[n][3];

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

	cout<<vacation(a,n)<<"\n";
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
using namespace std;
static const int N = 5001;

int dp[N][N];

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

    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] != s[j]) continue;
            dp[i][j] = dp[i + 1][j + 1] + 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans = max(ans, min(dp[i][j], j - i));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 97920
#include <stdio.h>

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);

    int value = 1;
    for(int i = 0; i < n; i++){
        value += (value < k)? value : k;
    }
    printf("%d\n", value);
    return 0;
}

Measured memory_bytes: 128
<?php
$a = explode(" ",trim(fgets(STDIN)));
if($a[0]==1){
$a[0] +=13;
}
if($a[1]==1){
$a[1] +=13;
}

if ($a[0]>$a[1]){
  echo 'Alice';
}elseif($a[0]==$a[1]){
  echo 'Draw';
}else{
  echo 'Bob';
}

Measured memory_bytes: 3576
# include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(!isdigit(ch))  
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		s=(s<<1)+(s<<3)+ch-'0';
		ch=getchar();
	}
	return s*w;
}
#define F(n) for(int i=1;i<=n;i++)
int a[1001],b[1001],n;
int cs[]={1,1,2,6,24,120,720,5040,40320};
int cantor(int c[])
{
	int ans=0;
	for(int i=1;i<=n;i++) 
	{
		int cnt=0;
		for(int j=i+1;j<=n;j++) 
		{
			if(c[j]<c[i]) cnt++;
		}
		ans+=cs[n-i]*cnt;
	}
	return ans;
}
int main()
{
    n=read();
    F(n)
    {
    	a[i]=read();
    }
    F(n)
    {
    	b[i]=read();
    }
    cout<<abs(cantor(a)-cantor(b));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) (a>b) ? (a) : (b)
#define min(a,b) (a<b) ? (a) : (b)
#define abs(a) (a>=0) ? (a) : (-a)
int main()
{
    long n,m;
    scanf("%ld %ld",&n,&m);
    
    printf("%ld",(abs((n-2)))*(abs((m-2))));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rep1(i,n) for (ll i = 1; i <= (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pl> vp;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

ll LINF = 1000000000000000000;

int main() {
  ll n;
  cin >> n;

  ll ans = 1;
  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }

  }
  rep(i, n){
    ll tmp = a[i];
    show(tmp);
    show(ans);
    show(1e18/ans)
      if(ans>LINF/tmp ||((LINF)%tmp>0 && ans==LINF/tmp)){
      cout << -1 << endl;
      return 0;
    }
    ans *= tmp;
    if(ans>LINF){
      cout << -1 << endl;
      return 0;
    }

  }

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


Measured memory_bytes: 8836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    ll a,b,k;
    cin >> a >> b >> k;
    if(k <= a){
        cout << a-k << " " << b << endl;
    }else if(k <= a+b){
        cout << 0 << " " <<  b-(k-a) << endl;;
    }else{
        cout << 0 << " " << 0 <<endl;
    }
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func solve(s string) string {
	letters := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}

	length := len(s)
	if length < 26 {
		ret := s
		for _, v := range letters {
			if !strings.Contains(s, v) {
				ret += v
				break
			}
		}
		return ret
	} else {
		startSuffix := length - 1
		for i := length - 1; i >= 1; i-- {
			if s[i-1] < s[i] {
				break
			}
			startSuffix--
		}
		if startSuffix == 0 {
			return "-1"
		}

		qIndex := startSuffix
		target := s[startSuffix-1]
		for i := startSuffix; i < length; i++ {
			if s[i] > target && s[i] < s[qIndex] {
				qIndex = i
			}
		}
		return s[:startSuffix-1] + s[qIndex:qIndex+1]
	}
}

func main() {
	s := input()
	fmt.Println(solve(s))
}


Measured memory_bytes: 640
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    dp = [[0] * (N + 1) for _ in range(N + 1)]
    p = [0] * (N + 1)
    for i in range(N):
        p[i], p[i + 1] = il()

    for l in range(2, N + 1):
        for i in range(1, N - l + 2):
            j = i + l - 1
            dp[i][j] = MAX
            for k in range(i, j):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j])
    print(dp[1][N])


if __name__ == '__main__':
    main()



Measured memory_bytes: 7320
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	double l;
	cin >> l;
	double a = l / 3;
	double b = a * a * a;
	printf("%.10f\n", b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pow(int x,int y){
    int z=1;
    while(y){
        z *= x;y--;
    }
    return z;
}
int main(){
    int n,m,i,j,c,k,t,d,ans;
    while(cin >> n >> m){
        if(n==0 && m==0) break;
        ans = m+1;int f[n];
        for(i=0;i<3;i++){
            cin >> c;
            for(j=0;j<c;j++){
                cin >> k;f[k-1] = i;
            }
        }
        t = 0;d = 0;
        for(i=1;i<=n;i++){
            t += pow(3,n-i)*abs(f[i-1]-d);
            if(f[i-1]==1) d = abs(d-2);
        }
        ans = min(ans,t);
        t = 0;d = 2;
        for(i=1;i<=n;i++){
            t += pow(3,n-i)*abs(f[i-1]-d);
            if(f[i-1]==1) d = abs(d-2);
        }
        ans = min(ans,t);
        cout << ((ans<=m) ? ans:-1) << endl;
    }
}


Measured memory_bytes: 3088
#include<cstdio>
long long a,b,c;
int main() {
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a+b>=c) {
		printf("No");
		return 0;
	}
	long long p=(c-a-b)*(c-a-b),t=4*a*b;
	if (t<p) printf("Yes"); else printf("No");
	return 0;
} 

Measured memory_bytes: 128
#
# 9d
#

def main():
    s = input()
    q = int(input())
    for i in range(q):
        l = list(input().split())
        a = int(l[1])
        b = int(l[2])
        if l[0] == "print":
            print(s[a:b+1])
        elif l[0] == "reverse":
            s = s[0:a] + s[a:b+1:][::-1] + s[b+1:]
        elif l[0] == "replace":
            s = s[0:a] + l[3] + s[b+1:]
        else:
            pass


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x,l,r,t;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;

    cin >> n >> t >> a;

    double _min = INF;

    rep1(i,n){
        ll h;
        cin >> h;
        double te = t - h * 0.006;

        if(_min > abs((double)a-te)){
            _min = abs((double)a-te);
            ans = i;
        }
    }

    std::cout << ans << endl; 

    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  ll ans=-999999999;
  for(ll lef=0;lef<=k;++lef){
    for(ll rig=0;rig+lef<=k;++rig){
      if(lef==0&&rig==0)continue;
      priority_queue<ll,vector<ll>,greater<>> que;
      if(lef+rig>=n){
        rep(i,n)que.push(a[i]);
      }
      else{
        rep(i,lef)que.push(a[i]);
        rep(j,rig)que.push(a[n-j-1]);
      }
      ll nokori=k-(lef+rig);
      while(que.top()<0&&nokori>0){
        que.pop();
        nokori--;
        if(que.empty())break;
      }
      ll sum=0;
      while(!que.empty()){
        sum+=que.top();
        que.pop();
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
#define PB push_back
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(b%a==0)cout<<a+b<<endl;
    else cout<<b-a<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e6 + 4;
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

long long f (long long n) {
	long long res = 1;
	for (long long i = 2 ; i <= n ; ++ i) {
		res *= i;
		res %= mod;
	}
	return res;
}

long long b (long long n) {
	long long res = 1, b = mod - 2;
	while (b) {
		if (b & 1ll) res *= n;
		n *= n;
		n %= mod;
		res %= mod;
		b >>= 1;
	}
	return res;
}

long long C (long long n, long long k) {
	long long res = f(n);
	// cerr << "OK";
	res = (res * b(f(k))) % mod;
	// cerr << "OK";
	res = (res * b(f(n - k))) % mod;
	return res;
}

int main () {
	// boost;
	int x, y;
	cin >> x >> y;
	if (x * 2 < y || y * 2 < x) cout << 0, exit(0);
	int d = x + y;
	if (d % 3 != 0) cout << 0, exit(0);
	int cnt = 0, id = 0;
	for (int i = 0 ; i <= d ; ++ i) {
		int j = d - i;
		if (i * 2 < j || j * 2 < i) continue;
		// cout << i << " " << j << "\n";
		++cnt;
		if (i == x && j == y) id = cnt;
	}
	// cout << cnt - 1 << " " << id - 1 << "\n";
	cout << C (cnt - 1, id - 1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void make_diverse(string s, vector<bool> used) {
  for (char c = 'a'; c <= 'z'; c++) {
    if (used[c - 'a'] == false) {
      cout << s << c << '\n';
      return;
    }
  }
}

void agc022a(string s) {
  vector<bool> used(26);
  int n = s.size();

  for (int i = 0; i < n; i++) {
    used[s[i] - 'a'] = true;
  }

  //使用済みアルファベットが25種類以下の場合
  for (char c = 'a'; c <= 'z'; c++) {
    if (used[c - 'a'] == false) {
      cout << s << c << '\n';
      return;
    }
  }

  string s2 = s;
  if (!next_permutation(s2.begin(), s2.end())) {
    cout << -1 << '\n';
    return;
  }

  int cnt = 0;

  while (s[cnt] == s2[cnt]) {
    cout << s2[cnt];
    cnt++;
  }
  cout << s2[cnt] << '\n';

  return;
}

int main() {
  string s;
  cin >> s;
  agc022a(s);
  return 0;
}

Measured memory_bytes: 256
import math

n = int (input())
sqr = int (math.sqrt(n))
ans = 1 # n itself

def check (x) :
    tmp = n
    while (tmp % x == 0) :
        tmp /= x
    return True if tmp % x == 1 else False

for i in range (2, sqr + 1) :
    if (n % i == 0) :
        if (check (i)) :
            ans += 1
        if (i != n / i and check (n / i)) :
            ans += 1
    
m = n - 1
if (m > sqr) :
    ans += 1 # m
    for i in range (2, sqr + 1) :
        if (m % i == 0) :
            ans += 1 
            if (i != m / i) :
                ans += 1

print (ans)

Measured memory_bytes: 3064
def gcd(x,y):
    tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)

A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,k;
  scanf("%d%d%d",&a,&b,&k);
  int i;
  for(i=a;i<=b && i<=a+k-1;i++){
    printf("%d\n",i);
  }
  for(i=MAX(i,b-k+1);i<=b;i++){
    printf("%d\n",i);
  }
  return;
}

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

Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) {
            return 0;
        }
        vector<vector<char>> v(h, vector<char>(w, '\0'));
        pair<int, int> start;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> v[i][j];
                if (v[i][j] == '@') {
                    start = make_pair(i, j);
                }
            }
        }
        constexpr char REACHABLE = '$';
        function<void(int, int)> f = [&v, &f, w, h, REACHABLE](int i, int j) {
            // ?????¢????¶???????
            if (i == -1 || j == -1 || i == h || j == w) {
                return;
            }
            // ?§??????§?????????
            else if (v[i][j] == '#') {
                return;
            }
            // ????????°?????§??????
            else if (v[i][j] == REACHABLE) {
                return;
            }
            else {
                v[i][j] = REACHABLE;
                f(i - 1, j);
                f(i + 1, j);
                f(i, j - 1);
                f(i, j + 1);
            }
        };
        f(start.first, start.second);
        auto r = accumulate(begin(v), end(v), 0,
                            [REACHABLE](int z, const vector<char>& vv) {
                                return z + count(begin(vv), end(vv), REACHABLE);
                            });
        cout << r << endl;
    }
}

Measured memory_bytes: 3148
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define rep2(N1,N2) for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)for(ll k=0;k<N3;k++)
#define For(i,N) for(ll i=0;i<N;i++)

void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for (ll i = 0; i < x; i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k" << endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

ll keta(ll a) {
	ll i = 1;
	while (1) {
		if (a < pow((ll)10, i))
			return i;
		i++;
	}
}
vector<ll> v;
ll n, m;
//m進数全探索
ll inc(ll a = n - 1) {
	if (a == 0 && v[0] == m) {
		v[0] = -1;
		return v[0];
	}
	if (v[a] == m) {
		v[a] = 0;
		inc(a - 1);
		return v[a];
	}
	else {
		++v[a];
		return v[a];
	}
}

int main() {
	cout.precision(20);
	ll A, B, H , M;
	cin >> A >> B >> H >> M;
	double pi = 3.14159265358979;
	double sital = (H*60.0 + M)*pi / 360.0;
	double sitas = 2 * pi*M / 60.0;
	double sita = abs(sital-sitas);
	if (sita >= pi)
		sita = 2 * pi - sita;
	double ans = sqrt(A*A + B * B - 2 * A*B*cos(sita));
	cout << ans;
}




Measured memory_bytes: 4232
#include<iostream>
#include<set>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,ind[500003];
int p[500003],q[500003];
set<int> f,b;
vector<int> g[500003];
typedef set<int>::iterator it;
int main(){
	cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>p[i];
    	q[p[i]]=i;
	}
    for(int i=1;i<k;i++){
    	f.insert(p[i]);
	}
    for(int i=1;i<=n;i++){
        if(i+k-1<=n){
        	f.insert(p[i+k-1]);
		}
        if(i){
        	f.erase(p[i-1]);
		}
        b.insert(p[i]);
        if(i>k){
        	b.erase(p[i-k]);
		}
        it cur=f.upper_bound(p[i]);
        if(cur!=f.end()){
        	g[q[*cur]].push_back(i),ind[i]++;
		}
        cur=b.upper_bound(p[i]);
        if(cur!=b.end()){
        	g[q[*cur]].push_back(i),ind[i]++;
		}
    }
	f.clear();
    for(int i=1;i<=n;i++){
    	if(!ind[i]){
			f.insert(-i);
		}
	}
    int top=0;
	while(f.size()){
		int u=-(*f.begin());
		p[++top]=u;
		f.erase(f.begin());
		for(int i=0,ed=g[u].size();i<ed;i++){
			if(--ind[g[u][i]]==0){
				f.insert(-g[u][i]);
			}
		}
    }
	for(int i=1;i<=n;i++){
		q[p[i]]=n-i+1;
	}
    for(int i=1;i<=n;i++){
    	cout<<q[i]<<endl;
	}
    return 0;
}

Measured memory_bytes: 60800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  ll h, w;
  cin >> h >> w;
  ll ans = 0;
  if (h == 1 || w == 1) {
    ans = 1;
  } else if (h % 2 == 0 || w % 2 == 0) {
    ans = (h * w) / 2;
  } else if (h % 2 != 0 && w % 2 != 0) {
    ans = (h * w + 1) / 2;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
def main():
    """"ここに今までのコード"""
    N = int(input())
    num_list = list(map(int, input().split()))
    num_list.sort()
    distinctFlg = False

    for i in range(N - 1):
        if num_list[i] == num_list[i+1]:
            distinctFlg = True
            break
    
    if distinctFlg:
        print("NO")
    else:
        print("YES")

if __name__ == '__main__':
    main()

Measured memory_bytes: 30892
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define int long long
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int B = 65, MOD1 = 1e9 + 7, MOD2 = 998244353;
const lint INF = 1e18;

int v[B][3], n;
vector<int> N;
void tovec()
{
    N.clear();
    int tmp = n;
    while(tmp)
    {
        N.pb(tmp%2);
        tmp/=2;
    }
    N.pb(0);
    reverse(N.begin(), N.end());
}
int solve()
{
    tovec();
    v[0][0] = 1;
    for(int i = 1; i < N.size(); i++)
    {
        v[i][0] = (v[i-1][0] + v[i-1][1]*(N[i]==0))%MOD1;
        v[i][1] = ((N[i]==1)*v[i-1][0] + v[i-1][1])%MOD1;
        int k2 = 1 + (N[i]==1);
        v[i][2] = (3*v[i-1][2] + k2*v[i-1][1])%MOD1;
    }
    int nn = N.size()-1;
    return (v[nn][0] + v[nn][1] + v[nn][2])%MOD1;
}
signed main()
{
    int ans=1;
    cin >> n;
    cout << solve();
    /*for(n=1; n < 50; n++)
    {
        int act = solve();
        set<int> st;
        for(int i = 0; i <= n; i++)
        {
            st.insert(i^(n-i));
        }
        ans+=st.size();
        if(ans!=act)
        {
            for(auto num: st)
            {
                cout << num << " ";
            }
            break;
        }
    }*/
}

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

int main(){
	using namespace std;

	string N,message;
	message = "No";
	cin >> N;
	if(N[0] == N[1] && N[0] == N[2]){
		message = "Yes";
	}else if(N[1] == N[2] && N[1] == N[3]){
		message = "Yes";
	}

	cout << message << 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 repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    int n ,k;
    cin >> n >> k;

    vector<bool> has(n, false);
    rep(i, k){
        int d;
        cin >> d;
        rep(j, d){
            int a;
            cin >> a;
            has.at(a-1) = true;
        }
    }

    int cnt = 0;
    rep(i, n){
        if(!has.at(i)) cnt++;
    }
    pr(cnt);

    return 0;
}



Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>

int main(){
    int n,f=1,g=1;
    scanf("%d",&n);
    int x[n],y[n];
    double d=0.0;
    for(int i=0;i<n;i++){
        scanf("%d %d",&x[i],&y[i]);
        for(int j=0;j<i;j++){
            d+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
        if(i>0){
            f*=i;
        }
        g*=i+1;
    }
    printf("%.10lf\n",2*f*d/g);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

long f(long x) {
	if(x==1) {
		return 1;
	}
	return 1+2*f(x/2);
}
int main() {
	long h,res;
	scanf("%ld",&h);
	res=f(h);
	printf("%ld",res);
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

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

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int pos = 0;
  for(int i = 1; i <= 5; i++) {
    int x;
    cin >> x;
    if(x == 0)
      pos = i;
  }
  cout << pos << '\n';
  return 0;
}


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

void solve()
{
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i,N) cin>>H[i];
  int cnt=0;
  rep(i,N) if(H[i]>=K)cnt++;
  cout << cnt << endl;
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(11);
  solve();
  return 0; 
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;



int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  lld a, b, c;
  cin >> a >> b >> c;
  lld ans = 0;
  cout << b + (min (c, a+b+1)) << "\n";
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    vector<string> siri;
    int x;
    cin >> x;
    string y;
    cin >> y;
    siri.push_back(y);
    for(int a = 1; a < x; a++){
        cin >> y;
        siri.push_back(y);
        if(siri[a-1][(int)siri[a-1].size()-1] != siri[a][0]){
            cout << "No" << endl;
            return 0;
        }
        for(int b = 0; b < a; b++){
            if(siri[b] == siri[a]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N;
  cin >> S;
  int ret = 0;
  bool flip = false;
  for(int i = 0; i < S.size(); i++) {
    if(flip && S[i] == 'x') {
      break;
    } else if(S[i] == 'x') {
      flip = true;
      ++ret;
    } else {
      ++ret;
      flip = false;
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 3340
n = int(input())
s = [input() for _ in range(n)]
ans = 0
ab = 0
a = 0
b = 0
for i in range(n):
    ans += s[i].count('AB')
    if s[i][0] == 'B' and s[i][-1] == 'A':
        ab += 1
    elif s[i][-1] == 'A':
        a += 1
    elif s[i][0] == 'B':
        b += 1
if ab > 0:
    ans += ab-1
    if a > 0:
        ans += 1
    if b > 0:
        ans += 1
    if a > 1 and b > 1:
        ans += min(a-1, b-1)
else:
    if a > 0 and b > 0:
        ans += min(a,b)
print(ans)

Measured memory_bytes: 3700
n, x = gets.split.map(&:to_i)

$a, $p = [1], [1]
n.times do |i|
  $a << $a[i] * 2 + 3
  $p << $p[i] * 2 + 1
end

def f(n, x)
  if n == 0
    return x <= 0 ? 0 : 1
  elsif x <= 1 + $a[n - 1]
    return f(n-1, x-1)
  else
    return $p[n-1] + 1 + f(n-1, x-2-$a[n-1])
  end
end

puts f(n, x)


Measured memory_bytes: 1788
import java.util.*;

class Main {
    public static void main(String[] args) {
        boolean[] bonus = new boolean[60*24*7];
        int S, N, T, P, M;
        String WEEK, TIME;
        Scanner sc = new Scanner(System.in);

        while(true) {
            Arrays.fill(bonus, false);
            S = sc.nextInt();
            N = sc.nextInt();
            T = sc.nextInt();
            WEEK = sc.next();
            TIME = sc.next();
            P = sc.nextInt();
            M = sc.nextInt();

            if(S == 0) break;

            if(WEEK.equals("All")) {
                if(TIME.equals("All")) {
                    Arrays.fill(bonus, true);
                }
                else if(TIME.equals("Night")) {
                    for(int i = 0; i < 7; i++) {
                        Arrays.fill(bonus, 60*24*i, 60*24*i + 60*6, true);
                        Arrays.fill(bonus, 60*24*i + 60*18, 60*24*i + 60*24, true);
                    }
                }
                else {
                    for(int i = 0; i < 7; i++) {
                        Arrays.fill(bonus, 60*24*i + 60*6, 60*24*i + 60*18, true);
                    }
                }
            }
            else {
                if(TIME.equals("All")) {
                    Arrays.fill(bonus, 0, 60*24, true);
                }
                else if(TIME.equals("Night")) {
                    Arrays.fill(bonus, 0, 60*6, true);
                    Arrays.fill(bonus, 60*18, 60*24, true);
                }
                else {
                    Arrays.fill(bonus, 60*6, 60*18, true);
                }
            }

            int match = 0;
            for(int start = 0; start < 60*24*7; start++) {
                int tmp = 0;
                for(int i = 0; i < M; i++) {
                    if(bonus[(start + T*i) % (60*24*7)] && bonus[(start + T*i + S) % (60*24*7)]) {
                        tmp++;
                    }
                }
                match = Math.max(match, tmp);
            }
            System.out.printf("%.10f\n", 1-Math.pow(1.0 - 1.0 / P, match * N));
        }
    }
}

Measured memory_bytes: 22248
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

bool prime[1000000];
void eratos(long long n)
{
    for (long long i = 0; i < n; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;
    for (long long i = 2; i <= sqrt(n); i++)
    {
        if (prime[i])
        {
            long long j = i + i;
            while (j <= n)
            {
                prime[j] = false;
                j += i;
            }
        }
    }
}
int main(void)
{
    eratos(1000000);
    int x;
    cin >> x;
    for (int i = x; i < 1000000; i++)
    {
        if (prime[i])
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector<int> a[110], b[111];
ll mem[1<<20][100];
int mp[55][55], mskk[55];
vector<int> v;
void dfs(int x, int par){
    v.push_back(x);
    for(int i=0; i<a[x].size(); ++i){
        if(a[x][i]==par)
            continue;
        dfs(a[x][i], x);
    }
}
void dfs2(int x, int par){
    v.push_back(x);
    for(int i=0; i<a[x].size(); ++i){
        if(a[x][i]==par)
            continue;
        dfs2(a[x][i], x);
        v.push_back(x);
    }
}
int m;
int pos[55];
ll dp(int x, int msk){
    if(x+1==v.size()){
        return msk==(1<<m)-1;
    }
    if(mem[msk][x]!=-1){
        return mem[msk][x];
    }
    ll res=0;
    res=dp(x+1, msk);
    if(mp[v[x]][v[x+1]]!=-1 && x<pos[v[x+1]])
        res+=dp(x+1, msk|mskk[mp[v[x]][v[x+1]]]);
    mem[msk][x]=res;
    return res;
}
int x[55], y[55], l[55][55];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        memset(mp, -1, sizeof mp);
        for(int i=0; i<n-1; ++i){
            scanf("%d%d",&x[i],&y[i]);
            a[x[i]].push_back(y[i]);
            a[y[i]].push_back(x[i]);
            mp[x[i]][y[i]]=mp[y[i]][x[i]]=i;
        }
        int q1[22], q2[22];
        cin>>m;
        memset(l, -1, sizeof l);
        for(int i=0; i<m; ++i){
            scanf("%d%d",q1+i, q2+i);
            l[q1[i]][q2[i]]=l[q2[i]][q1[i]]=i;
        }
        vector<int>v1, v2;
        for(int i=0; i<n-1; ++i){
            int x1=x[i], x2=y[i];
            dfs(x1, x2);
            v1=v;v.clear();
            dfs(x2, x1);
            v2=v;v.clear();
            for(int j=0; j<v1.size(); ++j){
                for(int k=0; k<v2.size(); ++k){
                    if(l[v1[j]][v2[k]]>-1){
                        mskk[i]|=(1<<l[v1[j]][v2[k]]);
                    }
                }
            }
        }
        memset(mem, -1, sizeof mem);
        dfs2(1,-1);
        for(int i=(int)(v.size())-1; i>=0; --i){
            pos[v[i]]=i;
        }
        assert(v.size()<110);
        ans=dp(0, 0);
        cout<<ans<<endl;
    }
  return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  int N=S.size(); //5
  bool flag=false;

  for (int i = 0; i < N; i++) {
    if(S.at(i)==T.at(0)){
      flag=true;
      for (int k = 1; k < N; k++) {
        int j=i+k;
        if((i+k)>=N) j=i+k-N;
        if(S.at(j)==T.at(k)) continue;
        else {
          cout << "No" << endl;
          return 0;
        }
      }
    }
    if(flag) break;
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256