akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split())
flag = 0

for i in range(1, 1001):
    hati = int(i * 0.08)
    juu = int(i * 0.1)
    
    if hati == a and juu == b:
        flag = 1
        print(i)
        break
    
if flag == 0:
    print("-1")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;

vector<bool> IsPrime;
void era(int n){
    if(n+1>IsPrime.size()){
        IsPrime.resize(n+1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(int i=2; i*i<=n; ++i){
        if(IsPrime[i]){
            for(int j=2; i*j<=n; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

int main(){
    int X;
    cin >> X;
    era(1000000);
    for(int i=X; i<=1000000; ++i){
        if(IsPrime[i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 998244353LL;

int dp[3][4010];
signed main() {
    string s; cin >> s;
    int N = s.length();

    dp[0][0] = 1;
    for(int i=0; i<2*N; i++) {
        int cur = i % 2, nxt = 1 - cur;
        for(int j=0; j<=2*i; j++) {
            if(dp[cur][j] == 0) continue;
            // fprintf(stderr, "dp[%lld][%lld] = %lld\n", i, j, dp[cur][j]);
            int red = j, blue = i - red;
            if(i < N) {
                if(s[i] == '0') red += 2;
                if(s[i] == '1') red += 1, blue += 1;
                if(s[i] == '2') blue += 2;
            }

            if(red) {
                (dp[nxt][red-1] += dp[cur][j]) %= MOD;
            }
            if(blue) {
                (dp[nxt][red] += dp[cur][j]) %= MOD;
            }
        }
        fill(dp[cur], dp[cur+1], 0);
    }
    cout << dp[0][0] << endl;
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, d;
    cin >> n >> d;

    cout << (n%(2*d+1) == 0 ? n/(2*d+1) : n/(2*d+1) + 1 ) << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100

int main(){

  int i,j,n,minj,tmp,count=0;
  int arr[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }

  for(i=0;i<=n-1;i++){
    minj = i;
    for(j=i;j<=n-1;j++){
      if(arr[j]<arr[minj]){
        minj = j;
      }}
    if(arr[i]!=arr[minj]){
      tmp = arr[i];
      arr[i] = arr[minj];
      arr[minj] = tmp;
      count++;
    }}

  for(i=0;i<n-1;i++){
    printf("%d ",arr[i]);
  }

  printf("%d\n",arr[n-1]);

  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2128
import java.util.*;

class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        if(N>=K*2-1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        
    }

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <random>

using namespace std;

int main(){
	int H, W;
	while(cin >> H >> W){
		vector<string> vs(H);
		for(auto& s : vs) cin >> s;
		vector<int> height(W, 0);
		int res = max(H, W);
		for(int i=1;i<H;i++){
			for(int j=1;j<W;j++){
				int cnt = 0;
				for(int ii=0;ii<2;ii++){
					for(int jj=0;jj<2;jj++){
						if(vs[i-ii][j-jj]=='#') ++cnt;
					}
				}
				if(cnt%2 == 0){
					++height[j-1];
				} else {
					height[j-1] = 0;
				}
			}
			stack<pair<int,int>> st;
			for(int j=0;j<W;j++){
				int h = height[j];
				int p = j;
				while(!st.empty() && h <= st.top().first){
					res = max(res, (st.top().first + 1) * (j - st.top().second + 1));
					p = st.top().second;
					st.pop();
				}
				if(h > 0) st.emplace(h, p);
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

ll solve(int n,vector<ll> vec, int a = 1){
    ll sm = 0;
    ll res = 0;
    rep(i,n){
        sm += vec[i];
        if(sm == 0 || a != sm / abs(sm)){
            res += abs(sm - a);
            sm = a;
        }
        a *= (-1);
    }
    return res;
}
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    cout << min(solve(n,a,1), solve(n,a,-1)) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int imos[200005];
vector<pair<int,int>> ch[35];

int main(){
  int n,c; cin >> n >> c;
  rep(i,n){
    int s,t,c; cin >> s >> t >> c;
    c--;
    ch[c].push_back({s,t});
  }
  rep(i,c){
    sort(ch[i].begin(),ch[i].end());
  }
  
  int ans = 0;
  rep(i,c){
    rep(j,ch[i].size()){
      int s = ch[i][j].first, t = ch[i][j].second;
      while(j < ch[i].size() - 1 && ch[i][j+1].first == t){
        t = ch[i][j+1].second; j++;
      }
      imos[s*2-1]++; imos[t*2]--;
    }
  }
  
  for(int i = 1; i < 200005;i++){
    imos[i] += imos[i-1];
    ans = max(ans,imos[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  double w,h;
  int x,y;
  cin >> w >> h >> x >> y;
  cout << (w * h) / 2 << " " ;
  if(w == 2*x && h == 2*y){
    cout << 1;
  }else{
    cout << 0;
  }
}

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

int main(){
    int N;
    cin >> N;
    int temp[N];
    int result[N-1];
    int former=0;
    int latter = 0;
    for(int i=0;i<N;i++){
        cin >> temp[i];
    }
    for(int i=0;i<N-1;i++){
        for(int j=0;j<i+1;j++){
            former += temp[j];
        }
        for(int j=i+1;j<N;j++){
            latter += temp[j];
        }
        int sa = former - latter;
        result[i] = sa<0 ? -sa : sa;
        former = 0;
        latter = 0;
    }
    int re = result[0];
    
    for(int i=1;i<N-1;i++){
        if(re > result[i]) re = result[i];
    }
    cout << re;
    return 0;
}

Measured memory_bytes: 256
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    string a, b;
    cin >> a >> b;
    int n = sz(a);
    int m = sz(b);
    int res = m;
    fore(i, 0, n) {
    	if(i + m > n) break;
    	int sum = 0;
    	fore(j, 0, m) {
    		if (a[i+j] != b[j]) sum++;
    	}
    	res = min(res, sum);
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  long long p;
  cin>>n>>p;
  long long ans=1;
  vector<long long>vec;
  for(long long i=2;i*i<=p;i++){
    if(p%i==0){
      vec.push_back(i);
      vec.push_back(p/i);
    }
  }
  vec.push_back(p);
  sort(vec.begin(),vec.end());
  for(long long i=0;i<vec.size()&&p>1;i++){
    long long index=vec[i];      
    long long cnt=0;
    while(p>1&&p%index==0){
      cnt++;
      p/=index;
      if(cnt==n){
	ans*=index;
	cnt=0;
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


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

long long N,A,B,C,D,ans;
string S;
string S1,S2;
vector <string> V1,V2;

long long gcd(long long x,long long y){
  while(y>0){
    x%=y;
    swap(x,y);
  }
  return x;
}

void solve(){
  cin >> A >> B >> C >> D;
  if ((A-B)<0) {
    cout << "No" << endl;
    return;
  }
  else if ((A%B)>C) {
    cout << "No" << endl;
    return;
  }
  else if (D<B) {
    cout << "No" << endl;
    return;
  }

  else if (C>=B) {
    cout << "Yes" << endl;
    return;
  }

  long long g = gcd(D,B);
  long long x = g*((C-(A%B))/g+1)+(A%B);
  if (x>=B) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(){
  cin >> N;
  for (int i=0;i<N;i++){solve();}
}


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

using namespace std;
const int N = 1e5 + 5;
long long arr[N];
long long ans[N];

int main() {
  //  freopen("in.txt", "rt", stdin);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%lld", arr + i);
    long long v = 0;
    for (int i = n - 1; i >= 0; --i) {
        v = (2ll * arr[i] - v);
    }
    ans[0] = v / 2;
    for (int i = 1; i < n; ++i) {
        ans[i] = (arr[i - 1] - (ans[i - 1]/2))*2;
    }
    for (int i = 0; i < n; ++i) printf("%lld ", ans[i]);
}

Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int n;

vector<int> vn_odds;
vector<int> vn_evens;

map<int, int> odds_counter;
map<int, int> evens_counter;

bool comp_odds(int i, int j) {
    return odds_counter[i] > odds_counter[j];
}

bool comp_evens(int i, int j) {
    return evens_counter[i] > evens_counter[j];
}

int calc()
{
    int result;
    
    sort(vn_odds.begin(), vn_odds.end(), comp_odds);
    sort(vn_evens.begin(), vn_evens.end(), comp_evens);

    int odds_max = vn_odds[0];
    int evens_max = vn_evens[0];

    if (odds_max != evens_max) {
        result = n - odds_counter[odds_max] - evens_counter[evens_max];
    } else if (vn_odds.size() == 1 && vn_evens.size() == 1) {
        result = n / 2;
    } else if (vn_odds.size() == 1) {
        result = n - odds_counter[odds_max] - evens_counter[vn_evens[1]];
    } else if (vn_evens.size() == 1) {
        result = n - odds_counter[vn_odds[1]] - evens_counter[evens_max];
    } else if (odds_counter[odds_max] + evens_counter[vn_evens[1]] >=
               odds_counter[vn_odds[1]] + evens_counter[evens_max]) {
        result = n - odds_counter[odds_max] - evens_counter[vn_evens[1]];
    } else {
        result = n - odds_counter[vn_odds[1]] - evens_counter[evens_max];
    }

    return result;
}


int main()
{
    cin >> n;

    for (int i = 1; i <= n; i++) {
        int vn;
        cin >> vn;
        if (i % 2 != 0) {
            if (odds_counter.count(vn) > 0) {
                odds_counter[vn] += 1;
            } else {
                vn_odds.push_back(vn);
                odds_counter[vn] = 1;
            }
        } else {
            if (evens_counter.count(vn) > 0) {
                evens_counter[vn] += 1;
            } else {
                vn_evens.push_back(vn);
                evens_counter[vn] = 1;
            }
        }
    }
    
    cout << calc() << endl;
}


Measured memory_bytes: 5368
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int n; cin >> n;
    vector<int> height(n);
    collect(height, n);
    int m = 0, viewable = 0;
    rep(i,n){
        if(m<=height[i]){
            viewable++;
        }
        m = max(m,height[i]);
    }
    cout << viewable << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N, M;
    cin >> N >> M;
    unordered_set<int> A;
    rep(i, M) {
        int a;
        cin >> a;
        A.insert(a);
    }
    ll p = 1000000007;
    vll dp(N + 1, 0);
    
    dp[0] = 1;
    
    if(A.find(1) == A.end())
        dp[1] = 1;
    REP(i, 2, N + 1) { 
        if (A.find(i) == A.end()) {
            dp[i] = (dp[i - 2] + dp[i - 1]) % p;
        }
        else {
            dp[i] = 0;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
 
    int a=3;
    vector<int>v;
    char j;
    for(int i=0;i<a;i++){
        cin>>j;
        v.push_back(j);
    }
    std::sort(v.begin(),v.end());
 
    if(v[0] == 'a' && v[1] == 'b' && v[2] == 'c' ){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
 
    return 0;
}

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

const int MX = 1000002;

// Sieve of Eratosthenes
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; i++) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i + i; j <= n; j += i)
        if (!f[j]) f[j] = i;
    }
  }
  bool isPrime(int x) { return f[x]; }
  vector<int> factorList(int x) {  // prime factors
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factors(int x) {
    vector<int> f = factorList(x);
    if (f.size() == 0) return {};
    vector<P> res(1, P(f[0], 0));
    for (int p : f) {
      if (res.back().first == p)
        res.back().second++;
      else
        res.emplace_back(p, 1);
    }
    return res;
  }
};

const int 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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= 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 {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  Sieve sieve(1e6);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  map<int, int> mp;
  rep(i, n) {
    auto f = sieve.factors(a[i]);
    for (auto p : f) mp[p.first] = max(mp[p.first], p.second);
  }

  mint lcm = 1;
  for (auto p : mp) {
    rep(i, p.second) lcm *= p.first;
  }
  mint ans;
  rep(i, n) {
    mint b = lcm / a[i];
    ans += b;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 4984
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    k = [int(ki) for ki in f.readline().split()]
    k = [ki for ki in k if 0 < ki]
    print('NA' if len(k) == 0 or max(k) < 2 else len(k) + 1)

Measured memory_bytes: 8632
//ehhhhh...... i hate you......

/* optimizations and other useless stuff*/
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e14
#define ull unsigned long long int
using namespace std;
/* TYPE DEFINITIONS */
typedef     long long int   ll;
typedef     vector<ll>      vi;
typedef     pair<ll,ll>     pi;


/* Basic  Math!!! */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll ncr(int n, int k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 

/* MACROS */
#define  all(A)         (A).begin() , (A).end()
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).sbegin()) it = (a).begin(); it != (a).end(); it++)  
ll findMax(ll arr[],ll di)
{
    ll m=INT_MIN;
    for(int i=0;i<3;i++)
    {
        if(i==di)continue;
        else m=max(m,arr[i]);
    }
    return m;
}
void solve()
{
    ll n,c=0,k;
    cin>>n;
    ll arr[n][3];
    forn(i,n)forn(j,3)cin>>arr[i][j];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            ll cc=findMax(arr[i-1],j);
            if(cc+arr[i][j]>arr[i-1][j])arr[i][j]+=cc;
            else arr[i][j]=arr[i-1][j];

        }
    }
   /*forn(i,n)
    {
        forn(j,3)cout<<arr[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<*max_element(arr[n-1],arr[n-1]+3)<<endl;
}

int main()
{
    FastIO;
    ll c=0;
    ll t=1;
   // cin>>t;
    while(t--)
    {
        //cout<<"Case "<<++c<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <string.h>
using namespace std;
 
int main(){
   long long int result;
  int n;
 long long int a[100000]={};
n=0;
 
result=1;
    cin >> n;
 
 
 
    for(int i = 0; i < n; i++){
      	
        cin >> a[i];
      	if(1000000000000000000/result<a[i])result=-1;
      	if(result!=-1)result*=a[i];
      	if(result>1000000000000000000)result=-1;
      	if(a[i]==0){result=0;break;}
    }
	cout << result <<endl;
  return 0;
}


Measured memory_bytes: 4412
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,a[123];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int j=0;j<n;j++){
        cout<<a[(n-j)];
        if(j<(n-1)){
            cout<<" ";
        }
    }
    cout<<endl;
}



Measured memory_bytes: 3084
#include<stdio.h>
#include<stdlib.h>

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};

typedef struct node *NodePointer;

NodePointer r,NIL;

NodePointer find(NodePointer x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  return x;
}

void insert(int k){
  NodePointer y = NIL;
  NodePointer x = r;

  NodePointer z = (NodePointer)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  z->p = y;

  if(y == NIL){
    r = z;
  }else if(z->key < y->key){
    y->l = z;
  }else{
    y->r = z;
  }
}

void inorder(NodePointer u){
  if(u == NIL){
    return;
  }
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(NodePointer u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

void print(){
  inorder(r);
  puts("");
  preorder(r);
  puts("");
}

int main(){
  int n,i,j,z,x;
  char s[10];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0] == 'f'){
      scanf("%d",&x);
      NodePointer t = find(r,x);
      if(t == NIL)printf("no\n");
      else printf("yes\n");

    }else if(s[0] == 'i'){
      scanf("%d",&z);
      insert(z);
    }else{
      print();
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define step b=p[b];d+=c[b];a=max(a,d);

int main(){
	ll n,k,a=(ll)-1e10;
	cin>>n>>k;
	ll p[n+1],c[n+1];
	rep(i,n)cin>>p[i];
	rep(i,n)cin>>c[i];
	rep(i,n){
		ll b=i,d=0,e=0;
		step;e++;
		if(k<n)while(e<k){step;e++;}
		else{
			while(b!=i){step;e++;}
			d=d*(k/e-1);
			rep(j,e+k%e){step;}
		}
	}
	cout<<a<<endl;
}


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

using namespace std;
int n, ans[200050];
vector<int> v;
int a[200050];
int go[19][200050];
int dp[1 << 19];
bool f(int l, int r, int k)
{
	vector<int> b;
	for (int i = 0; i < n; i++)
		if (i < l || i >= r)
			b.emplace_back(a[i]);
	int m = b.size();
	for (int i = 0; i < k; i++)
		for (int j = m - 1; j >= 0; j--) {
			go[i][j] = j + 1;
			if (j + 1 < m&&b[j + 1] - b[j] <= v[i])
				go[i][j] = go[i][j + 1];
		}
	for (int i = 0; i < 1 << k; i++)dp[i] = 0;
	for (int i = 0; i < 1 << k; i++) {
		if (dp[i] == m)	return 1;
		for (int j = 0; j < k; j++)
			if ((i >> j & 1) == 0)dp[i | 1 << j] = max(dp[i | 1 << j], go[j][dp[i]]);
	}
	return false;
}
int main()
{
	int V;
	cin >> n >> V;
	for (; V > 0; V /= 2)
		v.emplace_back(V);
	v.emplace_back(0);
	reverse(v.begin(), v.end());
	for (int i = 0; i < n; i++)
		cin >> a[i];
	a[n] = 1100000000;
	if (f(n, n, v.size())) {
		for (int l = 0; l < n;) {
			int r = l + 1;
			while (a[r] - a[r - 1] <= v.back())r++;
			if (f(l, r, v.size() - 1))
				for (int i = l; i < r; i++)ans[i] = 1;
			l = r;
		}
	}
	for (int i = 0; i < n; i++)
		cout << (ans[i] ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 21032
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <fstream>
#include <deque>
#include <bitset>
#include <iomanip>
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it)
#define LL long long
#define int LL
#define INF 99999999
#define DIV 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define InitArr1(c,n) memset(&c[0],0,sizeof(int)*n)
#define InitArr2(c,n) memset(&c[0][0],0,sizeof(int)*n)
template<class T>
bool valid(T x, T w) { return 0 <= x&&x < w; }
int di[4] = { 1, -1, 0, 0 };
int dj[4] = { 0, 0, 1, -1 };
using namespace std;
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------



signed main()
{
	QUICK_CIN;


	while(true){
		int n,w;
		cin >> n >> w ;
		if(n == 0 && w == 0)break;

		map<int,int> mapp;

		REP(i,n){
			int c;
			cin >> c;
			mapp[c/w]++;
		}

		double ans = 0;
		int maxx = -1;
		int num =0;


		for(auto a:mapp){
			maxx = max(maxx,a.second);
			num = max(num,a.first);
		}

		for(auto a:mapp){
			ans += (double)a.second / maxx * (double)(num - a.first)/num;
		}

		cout << std::fixed <<  ans + 0.01 << endl;

	}


}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

int main()
{
    char x;
    cin >> x;

    cout << ('a' <= x && x <= 'z' ? 'a' : 'A') << endl;

    return 0;
}


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

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

    int a = count(S.begin(), S.end(), 'a');
    int b = count(S.begin(), S.end(), 'b');
    int c = count(S.begin(), S.end(), 'c');

    if (abs(a - b) <= 1 && abs(a - c) <= 1 && abs(c - b) <= 1)
        puts("YES");
    else
        puts("NO");
}

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

int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  char &KO = S.at(K-1);
  if (KO == 'A')
    KO = 'a';
  else if (KO == 'B')
    KO = 'b';
  else
    KO = 'c';
  cout << S << endl;
}

Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

	s, t := readString(), readString()

	n := len(s)

	ans := 0
	for i := 0; i < n; i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 2704
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	ll n, M;
	cin >> n >> M;
	ll a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	ll l = -1, r = 1e6;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		ll cnt = 0;
		rep(i, n) cnt += a + n - lower_bound(a, a + n, m - a[i]);
		if (cnt >= M)
			l = m;
		else
			r = m;
	}
	ll ans = 0;
	vector<ll> b(n + 1);
	rep(i, n) b[i + 1] = b[i] + a[i];
	ll cnt = 0;
	rep(i, n) {
		ll p = a + n - lower_bound(a, a + n, l - a[i]);
		cnt += p;
		ans += b[n] - b[n - p] + a[i] * p;
	}
	ans -= (cnt - M) * l;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, t;
int s[200005];

int main()
{
	int ans = 0;
	cin >> n >> t;
	for (int i = 0;i < n;i++) {
		cin >> s[i];
	}

	for (int i = 1;i < n;i++) {
		if (s[i] - s[i - 1] >= t) {
			ans += t;
		}
		else {
			ans += (s[i] - s[i - 1]);
		}
	}

	cout << ans + t << endl;

	return 0;
}


Measured memory_bytes: 1024
// heeeyyyy Mooortyyyyyy!!
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define ed end()  
#define bg begin()
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vll > vvll;
typedef pair< int,int > pi;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
const long long MAXN = 4e18 + 1;
const int N=500023;
#define PI 3.1415926535897932384626
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){if(b == 0) return a;return gcd(b, a%b);}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
//DEBUGGING
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
const int LG = 20;
//__builtin_popcount(n) -> returns number of set bits in n
ll expo(ll a, ll b, ll m); // a^(b) %m
//=======================

//vector<bool> vis;vis.assign(n,false); g.assign(n,{});
//vector<vll> g;
//void ipgraph(ll m){ll  u, v;while(m--){cin>>u>>v; u--, v--;g[u].pb(v);g[v].pb(u);}}
//ll lvl[N], p[N][LG];
//ll lca(ll u,ll v){if(lvl[u]<lvl[v])swap(u,v);ll i,lg; for(lg=0;(1<<lg)<=lvl[u];lg++);lg--;for(i=lg;i>=0;i--){if(lvl[u]-(1<<i)>=lvl[v]){u=p[u][i];}}if(u==v)return v;else{for(i=lg;i>=0;i--){if(p[u][i]!=-1 && p[u][i]!=p[v][i]){u=p[u][i];v=p[v][i];}}}return p[u][0];}

void solve(){
    string n;cin>>n;
    ll sum=0;
    for(ll i=0;i<n.length();i++){
        sum+=n[i]-'0';
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}

int main(){
 
   ll t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }
   return 0;
}


ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0)return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 

Measured memory_bytes: 3812
n, x = map(int, input().split())
l = [int(x) for x in input().split()]

d = [0] * (n + 1)

for i in range(1, n + 1):
    d[i] = d[i - 1] + l[i - 1]

print(sum(1 for i in d if i <= x))


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

string S;
lint dp[2][2020];

int main() {
    cin >> S;
    INIT(dp, 0);

    int N = S.size();
    lint ans = 0;
    for_(i,0,N) {
        INIT(dp[1], 0);

        dp[0][0] += 1;
        for_(j,0,2020) {
            int nj = (j * 10) + int(S[i] - '0');
            nj %= 2019;
            dp[1][nj] += dp[0][j];
        }
        ans += dp[1][0];
        swap(dp[0], dp[1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long s = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > i) {
            cout << -1;
            return 0;
        }
        if (i < n - 1 && a[i] == a[i + 1] - 1) {
            continue;
        } else if (i < n - 1 && a[i] < a[i + 1] - 1) {
            cout << -1;
            return 0;
        } else {
            s += a[i];
        }
    }
    cout << s;
 
    return 0;
}

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

int main() {
    string s; cin >> s;
    int n = s.length();

    vector<int> dp(n + 1, false);
    dp[0] = true;
    for (int i = 0; i < n; i++) {
        if (i - 4 >= 0 and s.substr(i - 4, 5) == "dream")   dp[i + 1] |= dp[i + 1 - 5];
        if (i - 6 >= 0 and s.substr(i - 6, 7) == "dreamer") dp[i + 1] |= dp[i + 1 - 7];
        if (i - 4 >= 0 and s.substr(i - 4, 5) == "erase")   dp[i + 1] |= dp[i + 1 - 5];
        if (i - 5 >= 0 and s.substr(i - 5, 6) == "eraser")  dp[i + 1] |= dp[i + 1 - 6];
    }

    puts(dp[n] ? "YES" : "NO");

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    vector<int> w(n);
    rep(i,n){
        cin >>  w[i];
        sum += w[i];
    }
  	int ans = 2e9;
    rep(i,n){
      	int any = 0;
      	rep(j,i)any += w[j];
      	int t = abs(sum - any);
        ans = min(ans,abs(t - any));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
int a[N];
void solve(){
    int x, n;
    set <int> s;
    cin >> x >> n;
    for(int i = 1; i <= n; ++i) {
        int c;
        cin >> c;
        s.ins(c);
    }
    int mn = INF;
    int ans;
    for(int i = -1000; i <= 1e3; ++i) {
        if(abs(i - x) < mn && s.find(i) == s.end()) {
            ans = i;
            mn = abs(i - x);
        }
    }
    cout << ans;
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3664
#coding:utf-8
#1_9_D 2015.4.14
s = input()

for i in range(int(input())):
    cmd = input().split()
    a,b = [int(x) for x in cmd[1:3]]

    if cmd[0] == 'print':
        print(s[a:b+1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b+1:]

Measured memory_bytes: 6724
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int n,i;
	int p[50];
	int count = 0;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> p[i];
	}

	for (i = 1; i < n - 1; ++i) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1])||( p[i - 1] > p[i] && p[i] > p[i + 1])) {
			++count;
		}
	}

	cout << count<<endl;
}


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

int main(){
  int64_t q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  int64_t iti=0,ni=0;
  if(q*2<h&&q*4<s){
    iti=q*4;
  }else if(h*2<s){
    iti=h*2;
  }else{
    iti=s;
  }
  if(iti*2<d){
    ni=iti*2;
  }else{
    ni=d;
  }
  int64_t ans=0;
  ans+=(n/2)*ni;
  ans+=(n%2)*iti;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> h(n);
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	
	int cnt = 0;
	int ans = 0;
	for(int i = 0; i < n - 1; ++i) {
		
		if( h[i + 1] > h[i] ) { 
			ans = max(ans, cnt);
			cnt = 0;
		}
		
		else cnt++;
	}
	
	if( cnt > 0 ) ans = max(ans, cnt); 
	
	cout << ans << endl;
	
	return 0;
}


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


int main(){

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long amin = 1000000001;
	int nummin;
	while(a[n-2] != 0){
		for(int i = 0; i < n; i++)
		{
			if(a[i] != 0){
				amin = a[i];
				nummin = i;
				break;
			}
		}
		for(int i = nummin+1; i < n; i++)
		{
			a[i] %= amin;
		}
		sort(a.begin(), a.end());
		
		
	}
	
		
	
	cout << a[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>


bool	OK(std::pair<int, int> &next, std::pair<int, int>& now, std::vector<std::vector<int> >& w_x, std::vector<std::vector<int> >& w_y, int dx, int dy)
{
	if (dy < 0)
	{
		if (w_y[next.first][next.second] == 1)
			return (false);
	}
	if (dy > 0)
	{
		if (w_y[now.first][now.second] == 1)
			return (false);
	}
	if (dx < 0)
	{
		if (w_x[next.first][next.second] == 1)
			return (false);
	}
	if (dx > 0)
	{
		if (w_x[now.first][now.second] == 1)
			return (false);
	}
	return (true);
}

void	bfs(std::queue<std::pair<int, int> >& Que, std::vector<std::vector<int> >&map, std::vector<std::vector<int> >& w_x, std::vector<std::vector<int> >& w_y, int w, int h)
{
	int dx[] = {1, 0, -1, 0};
	int dy[] = {0, 1, 0, -1};
	while (!(Que.empty()))
	{
		std::pair<int, int> now = Que.front();
		Que.pop();
		for (int i = 0; i < 4; i++)
		{
			std::pair<int, int> next = std::make_pair(now.first + dy[i], now.second + dx[i]);
			if (next.first >= 0 && next.first < h && next.second >= 0 && next.second < w && map[next.first][next.second] == -1 && OK(next, now, w_x, w_y, dx[i], dy[i]))
			{
				map[next.first][next.second] = map[now.first][now.second] + 1;
				Que.push(next);
			}
		}
	}
}

int main()
{
	std::vector<int> ans;
	while (true)
	{
		int w, h;
		std::cin >> w >> h;
		if (!w && !h)
			break ;
		std::vector<std::vector<int> > w_x(31, std::vector<int> (31, -1));
		std::vector<std::vector<int> > w_y(31, std::vector<int> (31, -1));
		std::vector<std::vector<int> > map(31, std::vector<int> (31, -1));
		std::queue<std::pair<int, int> > Que;
		for (int i = 0; i < 2 * h - 1; i++)
		{
			if (i % 2 == 0)
			{
				for (int j = 0; j < w - 1; j++)
					std::cin >> w_x[i / 2][j];//w[x][y] == 1なら、x, yの右に壁があるということ
			}
			else
			{
				for (int j = 0; j < w; j++)
					std::cin >> w_y[i / 2][j];//w[x][y] == 1なら、x, yの下に壁があるということ
			}
		}
		map[0][0] = 1;
		Que.push(std::make_pair(0, 0));
		bfs(Que, map, w_x, w_y, w, h);
		if (map[h - 1][w - 1] == -1)
			ans.push_back(0);
		else
			ans.push_back(map[h - 1][w - 1]);
	}
	for (std::vector<int>::iterator i = ans.begin(); i != ans.end(); i++)
	{
		std::cout << *i << '\n';
	}
	return (0);
}



Measured memory_bytes: 3160
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

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

int main() {
  fast();
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << c - (d - b) << " " << d + (c - a) << " " << a - (d - b) << " "
       << b + (c - a);
  return 0;
}



Measured memory_bytes: 3548
import numpy as np
n,d=map(int,input().split())
x=[list(map(int, input().split())) for _ in range(n)]
x=np.array(x)
count=0
for i in range(n):
  for j in range(i+1,n):
    f=np.dot((x[i,:]-x[j,:]),(x[i,:]-x[j,:]))**0.5
    if f.is_integer():
      count+=1
print(count)

Measured memory_bytes: 12424
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=2e5 + 5;
const int MOD=1e9 + 7;

int n,k;
int a[N];

int check(int x)
{
	int tot = 0;
	rep(i,1,n)
	{
		int f = a[i]/x;
		if(a[i]%x==0)
			f--;
		tot += f;
	}
	if(tot<=k)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1; // or use lo + (hi-lo)/2 in leetcode problems to avoid overflow
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		cin >> n >> k;
		rep(i,1,n)
			cin >> a[i];
		cout << binsearch(1,1e10) << endl;
	}
}

Measured memory_bytes: 5084