akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const ll CFMOD = 998244353;
const double PI  = 3.14159265358;
const double EPS = 1e-6;
 
#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset(v,0,sizeof(v))
#define EB push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define vec vector
#define __ <<' '<<
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int dp[1000010][2];

void solve(){
    string s;
    
    cin >> s;
    s += '0';
    reverse(ALL(s));
    s += '0';
    for(auto &i:s)  i -= '0';
    
    dp[0][1] = INF;
    rep1(i, siz(s)-1){
        dp[i][0] = min(dp[i-1][0] + s[i], dp[i-1][1] + s[i] + 1);
        dp[i][1] = min(dp[i-1][0] + 10 - s[i], dp[i-1][1] + 9 - s[i]);
    }
    
    cout << dp[siz(s)-1][0] << '\n';
}

int main() {
    kiyohime;
    int T = 1;
    
    while(T--){
        solve();
    }
}


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

const int maxi = 311;
ll a[maxi][maxi];
string s;

ll warshall(int n) {
    ll ret = 0;

    for(int u = 1; u <= n; u++) {
        for(int v = u+1; v <= n; v++) {
            bool lol = true;
            for(int k = 1; k <= n; k++) {
                if(k == u || k == v) continue;
                if(a[u][v] > a[u][k] + a[k][v]) return -1;
                else if(a[u][v] == a[u][k] + a[k][v]) lol = false;
            }
            if(lol) ret += a[u][v];
        }
    }

    return ret;
}

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

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

    cout<<warshall(n)<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  int f =0;
  int i;
 for ( i=1 ; i<10 ; i++ ){
    int M =1;
    int j;
    for ( j=0; j<i ; j++ ) {
      M*=10;
    }
  f+=(N%M-N%(M/10))/(M/10);
     if ( N < M ) {
      break;
  }
  }
  if ( N%f == 0 ) cout << "Yes" << endl;
  else cout << "No" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
#include<set>
#include<stack>
#include<fstream>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007


int main()
{
	int N;
	cin>>N;
	ll A[N];
	double lsum=0.0;
	ll mx=pow(10,18);
	REP(i,0,N){
		cin>>A[i];
		lsum+=log10(A[i]);
		if(A[i]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	//cout<< std::fixed << std::setprecision(15) <<lsum<<endl;
	if(lsum>18.0){
		cout<<-1<<endl;
		return 0;
	}
	ll ans=1;
	REP(i,0,N){
		ans*=A[i];
		if(ans>mx){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 4636
#include <cstdio>
#include <algorithm>

using namespace std;

int p[1043];

int main() {
  int n, K;
  scanf("%d%d", &n, &K);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
  }
  sort(p, p + n);
  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += p[i];
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    m += h * 60;
    cout.precision(18);
    cout << sqrt(max(0.,a * a + b * b - 2 * a * b * cos(asin(1) * 44 / 12 / 60 * m)))
         << endl;
    return 0;
}


Measured memory_bytes: 4228
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;


#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 100005

int used[N];

int main(void) {
	ll n, x, m;
	scanf("%lld%lld%lld", &n, &x, &m);
	if (x == 0) {
		printf("0\n");
		return 0;
	}

	CL(used, -1);
	used[x] = 0;

	vector<ll> v;
	ll c;

	ll X = x;
	while (true) {
		int nxt = used[x] + 1;
		x = (x * x) % m;
		if (used[x] != -1) {
			c = x;
			break;
		}

		v.pb(x);
		used[x] = nxt;
	}

	ll sum = 0;
	vector<ll> st;
	REP(i, used[c]) {
		sum += X;
		X = (X * X) % m;

		st.push_back(sum);
	}

	sum = 0;
	vector<ll> cycle;
	x = X;
	do {
		sum += x;
		x = (x * x) % m;
		cycle.pb(sum);
	} while (x != X);

	if (n <= sz(st)) {
		printf("%lld\n", st[n - 1]);
	}
	else {
		n -= sz(st);
		n--;
		ll cnt = n / sz(cycle);
		ll ans = sz(st) ? st.back() : 0; 
		ans += cnt * cycle.back();
		n %= sz(cycle);
		ans += cycle[n];

		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 4576
using System;

namespace AtCoderBeginnerContest095
{
    class ABC095C
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int C = int.Parse(s[2]);
            int X = int.Parse(s[3]);
            int Y = int.Parse(s[4]);
            int m = 0;
            if(A + B < C * 2)
            {
                m += A * X;
                m += B * Y;
            }
            else
            {
                if (X < Y)
                {
                    m += X * (C * 2);
                    if (B < C * 2) m += B * (Y - X);
                    else m += C * (Y - X) * 2;
                }
                else
                {
                    m += Y * (C * 2);
                    if (A < C * 2) m += A * (X - Y);
                    else m += C * (X - Y) * 2;
                }
            }
            Console.WriteLine(m);
        }
    }
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

ll modpow(ll a, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	string s;
	cin >> s;
	int n = SZ(s);
	vector<ll> memo(n);
	memo[0] = s[n-1]-'0';
	FOR(i, 1, n - 1) {
		ll tmp = s[n - 1 - i] - '0';
		memo[i] = (memo[i - 1] + modpow(10LL, i, 2019LL)*tmp % 2019)%2019;
	}
	map<ll, int> memo2;
	memo2[0] = 1;
	FOR(i, 0, n - 1) {
		memo2[memo[i]]++;
	}
	ll res = 0;
	for(auto itr = memo2.begin(); itr != memo2.end(); itr++) {
		ll tmp = itr->second;
		res += tmp*(tmp - 1) / 2;
	}
	pv(res)
	return(0);
}

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

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

int main(void)
{
    int n,m; cin>>n>>m;
    int h[n],ma[n];
    rep(i,n){
        cin>>h[i];
        ma[i]=0;
    }
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }
    int ans=0;
    rep(i,n){
        if(h[i]>ma[i]) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<pair<string, int>> p(N);
  for (int i = 0; i < N; i++) {
    string S;
    int Point;
    cin >> S >> Point;
    p.at(i) = make_pair(S, -1 * Point);
  }
  vector<pair<string, int>> pp = p;
  sort(p.begin(), p.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (p.at(i) == pp.at(j)) {
        cout << j + 1 << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

int main(){
	ll x,ans=0;
	scanf("%lld",&x);
	ans=2*(x/11);
	x%=11;
	if (x&&x<=6) ans++;
	else if (x) ans+=2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9;
const long double PI=acos(-1);

ll a[10004];

void f(){
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                ll x=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
                if(x<=10000){
                    a[x]++;
                }
            }
        }
    }
}

void solve(int T){
    f();
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cout<<a[i]<<"\n";
    }
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}

/*
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9;
const long double PI=acos(-1);

map<ll,int>mp;

ll po(ll x,int y){
    ll res=1;
    for(int i=0;i<y;i++){
        res*=x;
        res%=MOD;
    }
    return res;
}

void f(int x){
    map<ll,int>s;
    for(int i=2;i*i<=x;i++){
        int tmp=0;
        while(x%i==0){
            tmp++;
            x/=i;
        }
        if(tmp){
            s[i]=tmp;
        }
    }
    if(x>=2){
        s[x]++;
    }
    for(auto i : s){
        mp[i.fi]=max(i.se,mp[i.fi]);
    }
}

void solve(int T){
    int n;
    cin>>n;
    vector<int>a(n);
    cin>>a[0];
    ll x=a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        f(a[i]);
    }
    ll ans=1;
    for(auto i:mp){
        ans=((ans%MOD) * (po(i.fi,i.se)%MOD))%MOD;
    }
    ll final_ans=0;
    for(int i=0;i<n;i++){
        final_ans+=(ans/a[i]);
        final_ans%=MOD;
    }
    cout<<final_ans<<"\n";
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}
*/


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	ll x;
	cin >> x;
	cout << x % 500 / 5 * 5 + (x - x % 500) * 2 << endl; 
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int i,j,k,n;
  cin>>n;
  long int weight;
  long int w[n];
  long long int p[n];
  cin>>weight;
  for(i=0;i<n;i++)
  {
   cin>>w[i]; 
   cin>>p[i];
  }
  long long int v[n+1][weight+1];
  for(i=0;i<n+1;i++)
  {
   v[i][0]=0; 
  }
  for(i=0;i<=weight;i++)
  {
   v[0][i]=0; 
  }
  for(i=1;i<n+1;i++)
  {
    for(j=1;j<weight+1;j++)
    {
    	if(j-w[i-1]>=0)
      v[i][j]=max(v[i-1][j],v[i-1][j-w[i-1]]+p[i-1]);
      else
      {
      	v[i][j]=v[i-1][j];
      }
      
    }
  }
  //for(i=0;i<n+1;i++)
  //{
  //  for(j=0;j<weight+1;j++)
  //  {
  //    cout<<v[i][j]<<" ";
  //  }
  //  cout<<endl;
  //}
  cout<<v[n][weight];
  
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e6+7;
int n,k;
vector<pair<int,int>> g;

int32_t main()
{
	fast;

	cin>>n>>k;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			g.push_back({i,j});

	int tot = n*(n-1)/2;
	int x = tot-k;
	if(x<n-1)
		return cout<<-1, 0;

	while(k)
	{
		k--;
		g.pop_back();
	}

	cout<<g.size()<<endl;
	for(int i=0;i<g.size();i++)
		cout<<g[i].first<<" "<<g[i].second<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <string>
#include <vector>
#include <queue> 
#include <stack>
#include <deque> 
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <utility>
#include <bitset>
#include <stdio.h>
#include <iomanip>
#include <climits>
#include <cmath>
#include <functional>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <regex>
#define FOR(i,n) for(int i=0; i<n ; i++)
#define pi 3.14159265358979323846
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int INF = 2000 * 1000 * 1000;
const int MAX = 1005; // 2*2^ceil(log_2(n)) - 1
using namespace std;
int popcount(int n) { bitset<32> b(n); return b.count(); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); 	return temp ? (a / temp * b) : 0; }
template <typename T>
T modpow(T base, T exp, T modulus){ base %= modulus; T result = 1; while (exp > 0){ if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus;	exp >>= 1; }return result; }
inline bool isInteger(const std::string & s){ if (s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false; char * p; strtol(s.c_str(), &p, 10); return (*p == 0); }


int main()
{	
	int n; cin >> n;
	vector<int> v(n); 
	vector<ll> cum(n+1);
	FOR(i, n) scanf("%d", &v[i]);
	cum[0] = v[0]; for (int i = 1; i < n; i++) cum[i] = v[i] + cum[i-1];
	ll upd = 0, ans = 0, ans2 = 0;
	FOR(i, n)
	{
		cum[i+1] += upd;
		int diff = 0;
		if (i&1 && cum[i] >= 0)	diff= abs(cum[i])+1,upd -= diff,cum[i] -= diff, cum[i + 1] -= diff;		
		else if (!(i & 1) && cum[i] <= 0) diff = abs(cum[i]) + 1, upd += diff, cum[i] += diff, cum[i + 1] += diff;
		ans += diff;
	}
	cum[0] = v[0]; for (int i = 1; i < n; i++) cum[i] = v[i] + cum[i - 1];
	upd = 0;
	FOR(i, n)
	{
		cum[i + 1] += upd;
		int diff = 0;
		if ((i & 1) && cum[i] <= 0) diff = abs(cum[i]) + 1, upd += diff, cum[i] += diff, cum[i + 1] += diff;
		else if (!(i & 1) && cum[i] >= 0) diff = abs(cum[i]) + 1, upd -= diff, cum[i] -= diff, cum[i + 1] -= diff;
		ans2 += diff;
	}

	cout << min(ans,ans2)<< endl;
	return 0;
}






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

string word[4] = {"dream", "dreamer", "erase", "eraser"};
string S;

int main() {
    cin >> S;
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i++) {
        reverse(word[i].begin(), word[i].end());
    }
    bool r;
    for (int i = 0; i < S.size();) {
        r = 0;
        for (int j = 0; j < 4; j++) {
            string d = word[j];
            if (S.substr(i,d.size()) == d) {
                r = 1;
                i += d.size();
            }
        }
        if (!r) {
            break;
        }
    }
    if (r) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}inline void read(i64 &x){
	x=0;i64 f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}const int maxn=100005;
int a[maxn],n;
int main(){
	read(n);rep(i,0,n-1)read(a[i]);
	sort(a,a+n,greater<int>());
	int i=0;
	while(i+1<n&&i+1<a[i+1])i++;
	int j=i;
	while(j<n&&i<a[j])j++;
	if(((a[i]-i)%2==0)||((j-i)%2==0)){
		puts("First");
	}else{
		puts("Second");
	}
	return 0;
}

Measured memory_bytes: 640
import itertools

N = int(input())
P_list = list(map(int, input().split()))
Q_list = list(map(int, input().split()))

all_comb_list = []

for i, comb in enumerate(itertools.permutations(range(1, N + 1))):
    comb = list(comb)
    if P_list == comb:
        P_index = i
    if Q_list == comb:
        Q_index = i

ans = abs(P_index - Q_index)

print(ans)

Measured memory_bytes: 3188
import sys
#input = sys.stdin.buffer.readline

def main():
    N = str(input())
    M = len(N)-1
    ans = 0
    for i in range(2**M):
        u = [0]
        for j in range(M):
            if (i>>j)&1:
                u.append(j+1)
        u.append(M+1)
        l = len(u)
        for k in range(l-1):
            num = int(N[u[k]:u[k+1]])
            ans += num
            
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());
  if (k > 0) {
    h.erase(h.begin(), h.begin() + min(k, n));
  }
  ll ans = 0;
  rep(i, h.size()) {
    ans += h[i];
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    
    int w,h,x,y,r;
    
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    
    bool b = x >= r && x <= w-r && y>=r && y <= h-r;
    printf("%s\n",b?"Yes":"No");
    return 0;
}


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

int main() {
	int M, D;
	scanf("%d%d", &M, &D);
	int ans = 0;
	for(int i = 1; i <= D; i++) {
		int d1 = i / 10;
		int d2 = i % 10;
		if(d1 >= 2 && d2 >= 2 && d1 * d2 <= M) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
# define INF 0x3f3f3f3f 

using namespace std;

int dis[12345];

int main() {
    ll a;
    long double b;
    cin >> a >> b;
    a *= b;
    ll ans = a;
    cout << ans;

}


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

//50 
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	cout << v[n / 2] - v[(n / 2) - 1];
}
	


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

ll calcNumOfCombination(ll n, ll r){
	ll num = 1;
	for(ll i = 1; i <= r; i++){
		num = num * (n - i + 1) / i;
	}
	return num;
}

int main(){
	int n, p;
	cin >> n >> p;
	vector<int> a(n);
	ll ev = 0, od = 0;
	rep(i, n){
		int a;
		cin >> a;
		if(a % 2 == 0) ev++;
		else od++;
	}
	ll ans;
	if(od == 0){
		if(p == 0) ans = 1LL << n;
		else ans = 0;
	}else{
		ans = 1LL << (n-1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
class Main{
  
  static int[] h;
  static long mod = 1000000007;
  
  static class Node{
    List<Node> child;
    long w=0, h=0;
    long dp1=1, dp2=1;
    Node(long w, long h){this.w=w;this.h=h;}
  }
  
  static Node dfs(int l, int r, long base){
    if(r-l==0)return null;
    long minh = Integer.MAX_VALUE;
    for(int i=l;i<r;++i)minh = Math.min(minh, h[i]);
    int minl = l;
    int w = -1;
    List<Node> nodelist = new ArrayList<>();
    for(int i=l;i<=r;++i){
        if(i==r || h[i]==minh){
            ++w;
            if(minl!=i)nodelist.add(dfs(minl, i, minh));
            minl = i+1;
        }
    }
    Node node = new Node((long)w, minh - base);
    node.child = nodelist;
    return node;
  }
    
  
  static long pow(long a, long p, long mod){
    long res = 1;
    for(int i=0;i<64;++i){
      if(((p>>i)&1)==1)res=(res*a)%mod;
      a = (a*a)%mod;
    }
    return res;
  }
  
  static void culc(Node node){
    if(node.child.isEmpty()){
		node.dp1 = pow(2, node.h, mod) ;
        node.dp2 = (pow(2, node.w, mod)-2+mod)%mod;
    }else{
        long dp1 = 1;
        long dp2 = 1;
        for(Node c : node.child){
            culc(c);
			dp1 = (dp1*c.dp1)%mod;
			dp2 = (dp2 * (c.dp1*2+c.dp2)%mod)%mod;
		}
		dp2 = (dp2 - dp1*pow(2, node.child.size(), mod)%mod + mod)%mod;
        node.dp1 = (dp1 * pow(2, node.h, mod)%mod);
        node.dp2 = (dp1*((pow(2, node.w + node.child.size(), mod)-2+mod)%mod)%mod + dp2*(pow(2, node.w, mod)%mod))%mod;
    }
  }
  
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    h = new int[n];
    for(int i=0;i<n;++i)h[i]=scan.nextInt();
	Node root = dfs(0, n, 0);
    culc(root);
    System.out.println((root.dp1+root.dp2)%mod);
  }
}


Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    S = input()
    S = S[:-1]
    #print(S)
    
    ans = 0
    for i in range(1000):
        i_str = str(i)
        i_str = i_str.zfill(3)
        
        flg1 = True
        cnt = 0
        for i in i_str:
            flg2 = False
            for j in range(cnt, len(S)):
                if i == S[j]:
                    flg2 = True
                    cnt = j+1
                    break
            if flg2 == False:
                flg1 = False
                break
                
        if flg1 == True:
            #print(i_str)
            ans += 1
            
    print(ans)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 40304
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10;
int a[maxn],p[maxn];
int main(){
	int n=read();
	REP(i,1,n){
		int x=read();
		a[x]=i;
	}
	int tmp=0,ans=0;
	REP(i,1,n){
		if(a[i]>a[i-1]) tmp++;
		else tmp=1;
		ans=max(ans,tmp);
	}
	printf("%d\n",n-ans);
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    ll n;
    cin >> n;
    if(n % 2 == 0 || n % 5 == 0){
        cout << -1 << endl;
        return 0;
    }

    ll cnt = 1,temp = 7;
    while(temp % n != 0){
        temp = 10*temp+7;
        temp %= n;
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3592
import Data.List ( sort, sortBy )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [_,k] <- readInts 
  ls    <- readInts 
--  print $ maxSnuke k ls
  print $ solve ls k 

maxSnuke
  :: Int -> [Int] -> Int
maxSnuke k = sum . take k . sortBy (flip compare)

-- https://atcoder.jp/contests/abc067/submissions/4912288
solve :: [Int] -> Int -> Int
solve = ((.) sum ) . (flip take) . reverse . sort

Measured memory_bytes: 508
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;
using pr  = pair<int, int>;

const ll MOD = 998244353;

int main()
{
	int X, Y;
	cin >> X >> Y;

	for (int i = 0; i <= X; ++i)
	{
		if (i * 2 + (X - i) * 4 == Y)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
import sys
input=sys.stdin.readline
p=[]
n,w=map(int,input().split())
for i in range(n):
	a,b=map(int,input().split())
	p.append([a/b,a,b])
p.sort(key=lambda x:-x[0])
ans=0
i=0
while w>0 and i<n:
	if w>=p[i][2]:
		ans+=p[i][1]
	else:
		ans+=p[i][1]*(w/p[i][2])
		break
	w-=p[i][2]
	i+=1
print(ans)


Measured memory_bytes: 27132
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    s = input()
    # A,B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    # xy = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    r = 1
    b = s[0]
    for i in range(1, N):
        if s[i] == b:
            continue
        r += 1
        b = s[i]
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
# ABC 083 B - Some Sums
# スペース区切りの整数の入力
b = [int(s) for s in input().split()]
sum = 0
for i in range(1, b[0]+1):
    s = 0
    t = i
    while t != 0:
        s = s + t % 10
        t = t // 10
    if (b[1] <= s) and (s <= b[2]):
        sum = sum + i
print(sum)

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, string).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, string).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [[i32; 3]; n]
    }
    let mut values = vec![vec![0; 3]; n];
    for i in 0..3 {
        values[0][i] = v[0][i];
    }
    for i in 1..n {
        for a in 0..3 {
            for b in 0..3 {
                if a == b {continue;}
                values[i][a] = cmp::max(values[i][a], values[i - 1][b] + v[i][a])
            }
        }
    }

    println!("{}", values[n - 1].iter().max().unwrap());
}


Measured memory_bytes: 14588
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    double height;
    double ans;
    vector<double> data;
    vector<double>::iterator itMax, itMin;
    while(cin >> height)
    {
        data.push_back(height);
    }
    cout << setprecision(3) << fixed;
    ans = *(max_element(data.begin(),data.end()))
        - *(min_element(data.begin(),data.end()));
    cout << ans << endl;

    return EXIT_SUCCESS;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

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

bool is_prime(int n) {
  for (int i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}

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

  map<int,int> mp;

  FOR(i,2,n+1) {
    int x = i;
    FOR(j,2,i+1) {
      if (!is_prime(j)) continue;
      while (x%j == 0) {
        x /= j;
        mp[j]++;
      }
    }
  }

  ll ans = 1;
  for (auto p : mp) {
    ans *= (1 + p.se);
    ans %= mod;
  }

  cout << ans << endl;
 }

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	tmp = 0;
	while(a > 0 && c > 0){
		tmp++;
		if(tmp % 2 == 1) c -= b;
		else a -= d;
	}	
	if (a > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
//	cout << ans << endl;
}

Measured memory_bytes: 3632
N, M , X ,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

max_x = max(x)
max_y = max(y)
min_y = min(y)
#print(max_x)
#print(max_y)
#print(Y-X)

XY_list = []
xy_list = []
for i in range(X+1, Y+1):
    XY_list.append(i)

if max_x   >= min_y:
    print("War")
    exit()

for i in range(max_x +1, min_y+1):
    xy_list.append(i)

#print(XY_list)
#print(xy_list)
set_XY = set(XY_list)
set_xy = set(xy_list)

print("No War" if set_XY & set_xy else "War")




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

using namespace std;

#define LL long long
#define N 300000
#define P(x,y) make_pair(x,y)
#define ss second

const LL sum=1000000000000000LL;
LL n,m,s,t,x,y,a,b,tot,f[N],g[N],head[N],ans[N];
bool vis[N];
priority_queue<pair<LL,LL> > pq;
struct edge{LL v,a,b,nxt;}e[N];

void add(LL x,LL y,LL a,LL b){
	e[++tot].v=y; e[tot].a=a; e[tot].b=b; e[tot].nxt=head[x]; head[x]=tot;
}

int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	for (LL i=1;i<=m;++i){
		scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
		add(x,y,a,b); add(y,x,a,b);
	}
	memset(f,0x3f,sizeof f); f[s]=0;
	memset(vis,0,sizeof vis);
	pq.push(P(-f[s],s));
	while (!pq.empty()){
		LL u; for (u=pq.top().ss,pq.pop();vis[u]&&!pq.empty();u=pq.top().ss,pq.pop());
		if (vis[u]) break; vis[u]=1;
		for (LL i=head[u],v;i;i=e[i].nxt)
			if (f[v=e[i].v]>f[u]+e[i].a){
				f[v]=f[u]+e[i].a;
				pq.push(P(-f[v],v));
			}
	}
	memset(g,0x3f,sizeof g); g[t]=0;
	memset(vis,0,sizeof vis);
	pq.push(P(-g[t],t));
	while (!pq.empty()){
		LL u; for (u=pq.top().ss,pq.pop();vis[u]&&!pq.empty();u=pq.top().ss,pq.pop());
		if (vis[u]) break; vis[u]=1;
		for (LL i=head[u],v;i;i=e[i].nxt)
			if (g[v=e[i].v]>g[u]+e[i].b){
				g[v]=g[u]+e[i].b;
				pq.push(P(-g[v],v));
			}
	}
	for (LL i=n;i;--i)
		ans[i]=max(ans[i+1],sum-f[i]-g[i]);
	for (LL i=1;i<=n;++i) printf("%lld\n",ans[i]);
	
	return 0;
}
			

Measured memory_bytes: 21492
package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	s := readStr()
	var cnt, tmp int
	for _, b := range s {
		r := rune(b)
		if r != 'A' && r != 'C' && r != 'G' && r != 'T' {
			if tmp > cnt {
				cnt = tmp
				tmp = 0
			}
		} else {
			tmp++
		}
	}
	if tmp > cnt {
		cnt = tmp
	}
	fmt.Printf("%d", cnt)
}

func readStr() string {
	s, _, _ := in.ReadLine()
	return string(s)
}


Measured memory_bytes: 640
p = [5, 7, 5, 7, 7]
while True:
    n = int(input())
    if n == 0:
        break
    word = [input() for _ in range(n)]
    flag = False
    for i in range(len(word)):
        ip = 0
        phrase = ["" for _ in range(len(p))]
        if flag:
            break
        for j in range(i, len(word)):
            if len(phrase[ip]+word[j]) == p[ip]:
                phrase[ip] += word[j]
                ip += 1
            else:
                phrase[ip] += word[j]
                if len(phrase[ip]) > p[ip]:
                    break
                if len(phrase[ip]) == p[ip]:
                    ip += 1
            if len(phrase[-1]) == 7:
                print(i+1)
                flag = True
                break




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

int main() {
	int h, w, tate, yoko, m;
	char a[105][105];
	cin >> h >> w;
	
	for (int i = 0; i < h; i++) {
	    cin >> a[i];
	}
	
	for (int i = 0; i < h; i++) {
	    for (int j = 0; j < w; j++) {
          
          	if (m == 0) {
	        	for (int k = 0; k < w; k++) {
	            	if (a[i][k] == '.') yoko++;
            	}
            }
          	
	        for (int l = 0; l < h; l++) {
	            if (a[l][j] == '.') tate++; 
	        }
          	
          	if (yoko != w && tate != h) cout << a[i][j];
          	if (yoko != w && j == w - 1) cout << endl;
          	m++;
        	tate = 0;
	    }
      	m = 0;
      	yoko = 0;
	}
	return 0;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
a = []
for _ in range(h):
    a.append(input())

for i in range(w+2):
    print("#",end="")
print()
geta = "#"
for i in range(h):
    print("{}{}{}".format(geta,a[i],geta),end="")
    print()
for i in range(w+2):
    print("#",end="")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

struct R {
    long long r;
    long long l;

    bool operator<(const R &another) const {
        return r < another.r;
    }

};

int main() {

    int N;
    cin >> N;
    vector<R> X(N);
    for ( int i = 0; i < N; i++ ) {
        long long a,b;
        cin >> a >> b;
        X[i].r = a+b;
        X[i].l = a-b;
    }

    sort( X.begin(), X.end() );

    int ans = 0;
    long long x = INT_MIN;
    for ( int i = 0; i < N; i++ ) {
        if ( X[i].l >= x ) {
            ans++;
            x = X[i].r;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

#define COMMENT

//function to query the segment tree for RMQ
int query(int *tree,int index,int s,int e,int qs,int qe)
{
	//base case: if query range is outside the node range
	if(qs>e || s>qe)
		return INT_MIN;
	//complete overlap
	if(s>=qs && e<=qe)
		return tree[index];
	//now partial overlap case is executed
	int m = (s+e)/2;
	int left_ans = query(tree,2*index,s,m,qs,qe);
	int right_ans = query(tree,2*index+1,m+1,e,qs,qe);
	return max(left_ans,right_ans);
}

//function to update a value at position to "pos"
void updateNode(int *tree,int index,int s,int e,int pos,int val)
{
	if(pos<s || pos>e)
		return ;
	if(s==e)
	{
		tree[index] = val;
		return ;
	}
	int m = (s+e)/2;
	updateNode(tree,2*index,s,m,pos,val);
	updateNode(tree,2*index+1,m+1,e,pos,val);
	tree[index] = max(tree[2*index],tree[2*index+1]);
	return;
}

int tree[1<<20], N, x, d, dp1[1<<20], dp2[1<<20];

vector<pair<int, int> > vp;

int main() {

  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N;
  for(int i = 0;i < N;i++) {
    cin >> x >> d;
    vp.push_back(make_pair(x, d));
  }

  sort(vp.begin(), vp.end());
  dp1[N-1] = N-1;
  updateNode(tree, 1, 0, N-1, N-1, dp1[N-1]);
  for(int i = N-2;i >= 0;i--) {
    int j = lower_bound(vp.begin(), vp.end(), make_pair(vp[i].first+vp[i].second, 0)) - vp.begin() - 1;
    if (i == j) {
      dp1[i] = i;
    } else {
        dp1[i] = query(tree,1,0,N-1,i+1,j);
    }
    updateNode(tree, 1, 0, N-1, i, dp1[i]);
  }


  dp2[N-1] = 2;
  dp2[N] = 1;
  for(int i = N-2;i >= 0;i--) {
    dp2[i] += dp2[i+1];
    int j = dp1[i]+1;
    dp2[i] = (dp2[i]+dp2[j])%998244353;
  }

  // for(int i = 0;i < N;i++) {
  //   debug(dp1[i]);
  // }
  cout << dp2[0] << endl;

  return 0;
}


Measured memory_bytes: 8816
n,m = gets.split.map(&:to_i)
arr = Array.new(n+1){Array.new(0)}
m.times do
  a,b = gets.split.map(&:to_i)
  arr[a] << b
  arr[b] << a
end
check = 0
until arr[1].empty?
  a = arr[1].pop
  check = 1 if arr[a].include?(n)
end
if check != 0
  puts :POSSIBLE
else
  puts :IMPOSSIBLE
end

Measured memory_bytes: 21500
#include <bits/stdc++.h>
using namespace std;
#define pii pair <int, int>
#define ll long long
#define pdd pair <double, double>
#define pll pair <ll, ll>
#define pb push_back
#define vi vector <int>
#define vvi vector <vi>
#define PI 3.14159
int main(){
    ios::sync_with_stdio(0);cin.tie(nullptr);
    int pessoas, temporario;
    vi qtosTem;
    cin>>pessoas;
    for(int i=0;i<=pessoas;i++){
        qtosTem.pb(0);
    }
    for(int i=1;i<pessoas;i++){
        cin>>temporario;
        qtosTem[temporario]++;
    }
    for(int i=1;i<=pessoas;i++){
        cout<<qtosTem[i]<<endl;
    }
}

Measured memory_bytes: 4288
n, m, p = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    A[i][2] = - (A[i][2]-p)

#import numpy as np
# A = np.full(np.inf, (n+1, n+1))

# scipy.sparse.csgraph.bellman_ford


S = [10**13 for i in range(n+1)]

S[1]=0
for i in range(m):
    if A[i][0] == 1:
        S[A[i][1]]=A[i][2]

for j in range(n-1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])

#print(S)
ans1 = -S[n]

for j in range(n):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])
#print(S)
ans2 = -S[n]

if ans1 != ans2:
    print(-1)
else:
    print(max(0, ans1))

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

#define ll long long int 
#define pii pair<int, int>
#define INF 0x3f3f3f3f
#define fi first
#define se second
#define f(n) for(int i = 0; i < n; i++)
#define f2(n) for(int i = 1; i <= n; i++)
#define debug(x) if(on)cout << x << endl
#define on true
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back


int main(){


	ll N;
	vector<ll> v;

	cin >> N;

	ll aux;
	f(5){
		cin >> aux;
		v.pb(aux);
	}

	sort(v.begin(), v.end());

	ll mn = v[0];

	aux = N / mn;

	if(N > mn && N % mn != 0)
		aux++;

	if(N >= mn)
		aux--;

	cout << 5 + aux << endl;

return 0;
}


Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    fun readInt():Int{ return readLine()!!.toInt()}
    fun readLong():Long{return readLine()!!.toLong()}
    fun readString():String{return readLine()!!}
    fun readIntList():List<Int>{return readLine()!!.split(" ").map { it.toInt() }}
    fun readLongList():List<Long>{return readLine()!!.split(" ").map { it.toLong() }}
    fun readStringList():List<String>{return readLine()!!.split(" ")}
    fun readIntLists(n: Int, sorted: Boolean=false):List<List<Int>>{return if(sorted){(0 until n).map { readIntList().sorted() }}else{(0 until n).map { readIntList()}}}
    fun readLongLists(n:Int, sorted: Boolean=false):List<List<Long>>{return if(sorted){(0 until n).map { readLongList().sorted() }}else{(0 until n).map { readLongList()}}}
    fun readStringLists(n:Int):List<List<String>>{return (0 until n).map { readStringList() }}
    val a=readString()
    val b=readString()
    val n=a.length-b.length
    var ans=0
    for (i in 0..n){
        val tmp=a.slice(i until i+b.length)
        var s=0
        for (j in 0 until b.length){
            if(tmp[j]==b[j]) {
                s++
            }
        }
        ans= max(ans, s)
    }
    println(b.length-ans)
}


Measured memory_bytes: 37964