akhauriyash/Code-Regression huggingface dataset:
// abc150_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  int n, ans = 0;
  cin >> n >> s;
  for (int i = 0; i < n - 2; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Here your code


n = 3
e = [[int(i) for i in input().split()] for i in range(n)] 
a = []
b = []
#for i in range(101):
a.append(0)
b.append(e[0][0] - a[0])
b.append(e[0][1] - a[0])
b.append(e[0][2] - a[0])
a.append(e[1][0] - b[0])
a.append(e[2][0] - b[0])

for i in range(3):
    for j in range(3):
        if a[i] + b[j] != e[i][j]:
            print("No")
            exit()

        
print("Yes")
    




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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int a, b;
    cin >> a >> b;

    cout << ((a <= b) ? a : a - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
//long long a[5001];
int A,B;
int main(){
	cin>>A>>B;

	int S=0;
	S=A+B;
	if(S>23)S=(S-24);



	cout<<S<<endl;

	return 0;
}


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

namespace ConsoleApp63 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int D = st[0];
            int N = st[1];

            if (N % 100 != 0) {
                Console.WriteLine(Math.Pow(100, D) * N);
            } else {
                Console.WriteLine(Math.Pow(100, D) * (N + 1));
            }

            


        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

typedef pair<pair<int, int>, pair<int, pair<int, int> > > State;
const int INF = 1<<29;

inline int dist(int x1, int y1, int x2, int y2, int K) {
  int dx = abs(x2 - x1);
  int dy = abs(y2 - y1);
  return (dx + K - 1) / K + (dy + K - 1) / K;
}
int main() {
  int H, W, K; cin>>H>>W>>K;
  vector<string> data(H);
  int x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2; x1--; y1--; x2--; y2--;
  REP(i,H) {
    cin>>data[i];
  }
  //  vector<vector<int> > a(H, vector<int>(W, 0));
  vector< vector< vector<pint > > > visited(H, vector<vector<pint> >(W, vector<pint>(4, make_pair(INF, 0))));
  priority_queue< State, vector<State>, greater<State> > q;
  //  int d = dist(x1, y1, x2, y2, K);
  REP(dir,4) {
    visited[x1][y1][dir] = make_pair(0, 0);
    q.push(make_pair(make_pair(0, 0), make_pair(dir, make_pair(x1, y1))));
  }
  while (!q.empty()) {
    State cur = q.top(); q.pop();
    const int cdir = cur.second.first;

    const int cx = cur.second.second.first;
    const int cy = cur.second.second.second;

    int cdist1 = cur.first.first;
    int cdist2 = cur.first.second;
    //    cout << cx+1 << " " << cy+1 << " " << cdir << "=" << cdist1 << "," << cdist2 << endl;
    if(cx == x2 && cy == y2) {
      int ans = cdist1;
      if(cdist2 > 0) ans++;
      cout << ans << endl; return 0;
    }
    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, -1, 0, 1};
#ifdef DEBUG
#endif
      const int nx = cx + dx[cdir];
      const int ny = cy + dy[cdir];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(data[nx][ny] == '@') continue;
      for(int rot = -1; rot <= 1; rot++) {
	int ndir = (cdir + rot + 4) % 4;
	int ndist2 = cdist2;
	int ndist1 = cdist1;
	if(rot == 0) {
	  ndist2++;
	  if(ndist2 >= K) {
	    ndist2 = 0; ndist1 ++;
	  }
	} else {
	  ndist2++;
	  if(ndist2 > 0) {
	    ndist2 = 0; ndist1 ++;
	  }
	}
	if(rot != 0) ndist2 = 0;
	if(ndist1 > visited[nx][ny][ndir].first) continue;
	if(ndist1 == visited[nx][ny][ndir].first && ndist2 >= visited[nx][ny][ndir].second) continue;
	visited[nx][ny][ndir] = make_pair(ndist1, ndist2);
	q.push(make_pair(make_pair(ndist1, ndist2), make_pair(ndir, make_pair(nx, ny))));
    }
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 144496
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll int,ll int>
#define PI 2*acos(0)
#define INF 1e8
#define mx 1000006
using namespace std;
const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
// ax+by and a>b
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll d=gcd(b,mod(a,b),x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
ll abso(ll a)
{
    if(a>=0) return a;
    return -a;
}
string s,t;
ll n;
ll solve()
{
    n=t.size();
    ll ans=INF;
    for(int i=0;i+n<=s.size();i++){
        string r=s.substr(i,n);
        ll cnt=0;
        for(int j=0;j<n;j++){
            if(t[j]!=r[j]) cnt++;
        }
        ans=min(ans,cnt);
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>s>>t;
    if(s==t){
        cout<<0;
        return 0;
    }
    cout<<solve();
    return 0;
}
//1028C


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n,m,a,b,road[50]={};
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		road[a-1]++;
		road[b-1]++;
	}
	for(int j=0;j<n;j++){
		cout<<road[j]<<endl;
	}
	return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int64_t> A(N);
    for(auto &e : A) cin >> e;
    vector<int64_t> cnt(N);
    for(auto &e : A) {
        e--;
        cnt[e]++;
    }
    vector<int64_t> C(N);
    rep(i, N) C[i] = cnt[i] * (cnt[i] - 1) / 2;
    int64_t ans = accumulate(C.begin(), C.end(), 0LL);
    for(auto &e : A) {
        int64_t t = cnt[e] * (cnt[e] - 1) / 2;
        int64_t u = (cnt[e] - 2) * (cnt[e] - 1) / 2;
        cout << ans - t + u << '\n';
    }
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX = 510000;
const int INF =2000000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//gcd,lcmセット
ll gcd(ll a, ll b){
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}
ll lcm(ll a, ll b){	
   return a*b/gcd(a, b);
}
int pow_kai(int a, int n){//aのn乗を計算します。
  int x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}
// a^n mod を計算する
long long modPow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
// a^{-1} mod を計算する
ll modInv(ll a, ll mod) {
    return modPow(a, mod - 2, mod);
}

// combinationのテーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
 
bool isPrime(ll x){
    int i;
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
//dfsではvector<vector<int>> g(n);で◎
int main(){
    //COMinit();
    //string a,b;
    ll n,p,tmp;
    cin>>n;
    tmp=INF;
    ll cnt=0;
    REP(i,n){
        cin>>p;
        if(p<=tmp){
            cnt++;
            tmp=p;
        }
    }
//答え出力パート
    cout<<cnt
    <<endl;
}

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

int d, g;
int p[10], c[10];
bool flag[10];
int ans = 1010;

void solve(int i, int num, int score){
  if(i == d){
    if(score >= g){
      ans = min(ans, num);
      return;
    }
    for(int j=d-1; j>=0; --j){
      if(flag[j]){
        int need = min(p[j]-1, (g-score-1)/(100*(j+1))+1);
        score += 100 * (j+1) * need;
        num += need;
        if(score >= g){
          ans = min(ans, num);
          return;
        }
      }
    }
    return;
  }
  flag[i] = false;
  solve(i+1, num+p[i], score+100*(i+1)*p[i]+c[i]);
  flag[i] = true;
  solve(i+1, num, score);
  return;
}

int main(){
  cin >> d >> g;
  for(int i=0; i<d; ++i) cin >> p[i] >> c[i];
  for(int i=0; i<d; ++i) flag[i] = true;
  solve(0, 0, 0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long int h, w, dp[1005][1005];
char arr[1005][1005];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> h >> w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> arr[i][j];
		}
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			if(arr[i][j]=='#'){
				dp[i][j]=0;
			}
			else if(i==0 or j==0){
				dp[i][j]=0;
			}
			else if(i==1 && j==1){
				dp[i][j]=1;
			}
			else{
				dp[i][j]=dp[i-1][j] + dp[i][j-1] % mod;
			}
		}
	}
	cout << dp[h][w]%mod << endl;
}

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

int b[200010];

int f(int d, int n) {
	int ans = 2*d+2*n+1;
	if(n%2)	ans -= (2*d-1);
	else	ans += (2*d-1);
	return ans/4;
}

int main() {
	int i, j, n;
	// freopen("in.txt", "r", stdin);
	cin >> n;
	for(i = 1; i <=n; ++i) {
		int x;
		cin >> x;
		int z = f(i, n-i+1);
		// cout << z << endl;
		b[z] = x;
	}
	for(i = 1; i <= n; ++i) {
		cout << b[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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; }






int main() {
  ll D,T,S; // �ѿ������
  cin >> D >> T >> S; // ɸ������

  if((double)D/S<=T){
  
  cout << setprecision(12) << "Yes" << endl; // ɸ�����
  }else{
     cout << setprecision(12) << "No" << endl; // ɸ�����
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>

using namespace std;

int digit(int n, int d) {
	int m = (int)(n/pow(10,d)) * pow(10,d);
	return (n - m)/pow(10,d-1);
}

int sum_of_digit(int n) {
	int res = 0;
	for (int i = 1; i < 6; ++i) {
		res += digit(n,i);
	}
	return res;
}

int main(void) {
	int N,A,B;
	cin >> N >>  A >> B;
	int res = 0;
	for (int i = 1; i < N+1; ++i) {
		int sod = sum_of_digit(i); 
		if (sod >= A && sod <= B) {
			res += i;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n, k, i;
  cin >> n >> k;
  vector<int> h(n);
  for(i = 0; i < n; i++)
  {
    cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  int hmin = 1000000000;
  for(i = 0; i < n-k+1; i++)
  {
    if(h.at(i+k-1) - h.at(i) < hmin)
    {
      hmin = h.at(i+k-1) - h.at(i);
    }
  }
  cout << hmin << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	int n;
	cin >> n;
	vector<vector<ll>> a(n, vector<ll>(n, 0));
	vector<vector<ll>> d(n, vector<ll>(n, INT_MAX));
	REP(i, n) {
		REP(j, n) {
			cin >> a[i][j];
		}
	}
	priority_queue<pair<ll,P>,vector<pair<ll, P>>,greater<pair<ll, P>>> q;
	REP(i, n) {
		FOR(j, i + 1, n) {
			q.push(pair<ll, P>(a[i][j],P(i, j)));
		}
	}
	ll res = 0;
	ll prev = 0;
	while (!q.empty()) {
		bool flag = false;
		bool flag2 = false;
		pair<ll, P> p2 = q.top();
		P p = p2.second;
		q.pop();
		REP(k, n) {
			if (d[p.first][k] + d[k][p.second] == a[p.first][p.second]) {
				flag = true;
			}
			if (d[p.first][k] + d[k][p.second] < a[p.first][p.second]) {
				flag2 = true;
			}
		}
		if (flag) {
			d[p.first][p.second] = a[p.first][p.second];
			d[p.second][p.first] = a[p.first][p.second];
		}
		else {
			d[p.first][p.second] = a[p.first][p.second];
			d[p.second][p.first] = a[p.first][p.second];
			res += a[p.first][p.second];
		}
		if (flag2) {
			put(-1);
			return 0;
		}
		
	}
	put(res);
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

int h,w;
int fld[50][50];
int dx[]={1,-1,0,0,1,1,-1,-1},dy[]={0,0,1,-1,-1,1,-1,1};

void bfs(int sy,int sx) {
	queue<P> q;
	fld[sy][sx]=0;
	q.push(P(sx,sy));
	while(!q.empty()) {
		P p=q.front();q.pop();
		REP(i,8) {
			int nx=p.fi+dx[i],ny=p.se+dy[i];
			if(nx<0||nx>=w||ny<0||ny>=h||fld[ny][nx]==0) continue;
			fld[ny][nx]=0;
			q.push(P(nx,ny));
		}
	}
}

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

	while(true) {
		cin>>w>>h;
		if(w==0) break;
		REP(i,h) REP(j,w) cin>>fld[i][j];
		int cnt=0;
		REP(i,h) {
			REP(j,w) {
				if(fld[i][j]==1) {
					cnt++;
					bfs(i,j);
				}
			}
		}
		cout<<cnt<<endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
	int a,b,c;
  cin >> a>>b>>c;
  if(a==b && c==a){
    cout<<"Yes"<<endl;
  }else{
	cout << "No"<<endl;
  }
	return 0;
}


Measured memory_bytes: 256
def an_invisible_hand(N: int, T: int, A: list) -> int:
    max_profit = 0
    max_profit_pair_num = 0
    min_price = A[0]

    for price in A[1:]:
        # 今まで訪れた街の中で最安値で買えるところで買えるだけ
        # 買って今いる街で全て売ると仮定して利益を算出
        profit = price - min_price

        if max_profit < profit:
            # 利益の最大値を更新できるなら更新する。
            max_profit = profit
            max_profit_pair_num = 1
        elif max_profit == profit:
            # 最大利益を出せる街のペアに対して操作を
            # 行うので、その数を保持する。
            max_profit_pair_num += 1

        min_price = min(min_price, price)

    # 最大利益を出せる街のペアに対して、最高値を 1 下げるか最安値を 1 あげるか
    # すれば利益を 1 円減らせる。ただ、一つのペアを変更してもそのほかのペアが残
    # っていればそのペアを利用して最高利益をあげられるので全ペアに同じ操作が必要
    # 。結局、最大利益をあげるペアの数が最小操作回数で、それらに 1 の変化を与え
    # れば良いので最小コストでもある。
    return max_profit_pair_num


if __name__ == "__main__":
    N, T = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = an_invisible_hand(N, T, A)
    print(ans)


Measured memory_bytes: 14252
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
#N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
#flag = True
#for k in range(N):
#ans = 0
#print(ans)
#print('Yes')
#print('No')
S = input()
if S[-1] != 's':
	print(S + 's')
else:
	print(S+'es')

Measured memory_bytes: 61692
#include<stdio.h>
//#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
using namespace std;
#define inf 1e9+7
int min(int a,int b) {return a<b?a:b;}
#define mem(a,b) memset(a,b,sizeof(a))
map<int,int>a;
int main()
{

     int s,m=1;
     scanf("%d",&s);
     while(!a[s])
     {
         a[s]=1;
         if(s%2) s=3*s+1;
         else s=s/2;
         m++;
     }
     printf("%d\n",m);
     return  0;
}


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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c;
  
  if(a>b){
    swap(a,b);
  }
  
  if(b>c){
    swap(b,c);
  }
  
  if(a>b){
    swap(a,b);
  }
  
  cout << a << ' ' << b << ' ' << c << endl;
}


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
	public static void main(String[] args){
		int i, n, m, a, b;
		TreeSet<Integer> setA = new TreeSet<Integer>();
		TreeSet<Integer> setB = new TreeSet<Integer>();
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			for(i = 0; i < n; i++) {
				a = sc.nextInt();
				setA.add(a);
			}
			m = sc.nextInt();
			for(i = 0; i < m; i++) {
				b = sc.nextInt();
				setB.add(b);
			}
			setA.addAll(setB);
			for(int output : setA) {
				System.out.println(output);
			}
		}
	}
}



Measured memory_bytes: 197964
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx = 0, ans = 1;
	for(int i = n; i >= 1; i--){
		int m = i, cnt = 0;
		while(m%2 == 0){
			m /= 2;
			cnt++;
		}
		if(cnt > mx){
			mx = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int a, b, n;

    while(cin >> a >> b >> n){
        int sum = 0;
        int tmp = a;
        for(int i=1; i<=n; i++){
            tmp *= 10;
            sum += (tmp/b) % 10;
            tmp %= b;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 0
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a;
  scanf("%d", &a);
  printf("%d\n", a * a);
}

Measured memory_bytes: 128
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var s = Console.ReadLine();

            var ans = "No";
            if (s.Length % 2 == 0)
            {
                if (test.CountContainWords(s, "hi") == s.Length / 2)
                {
                    ans = "Yes";
                }
            }

            Console.WriteLine(ans);
        }

        public int Gcd(int a, int b)
        {
            for (var i = b; i > 1; i -= 1)
            {
                if (a % i == 0 && b % i == 0)
                {
                    return i;
                }
            }
            return 1;
        }
        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public long[] ConvertLongArray(string[] x)
        {
            var convertedArray = new long[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = long.Parse(x[i]);
            }

            return convertedArray;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

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

typedef long long int int64;

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

#define POS(i,j,k) (((i)*5+(j))*2+(k))

int64 calc(int bit,int *f,int *p,int n){
  int ans=0;
  int i,j,k;
  for(i=0;i<n;i++){
    int cnt=0;
    for(j=0;j<5;j++){
      for(k=0;k<2;k++){
	if(f[POS(i,j,k)]==1 && ((bit>>(2*j+k))&0x01)==1) cnt++;
      }
    }
    ans+=p[11*i+cnt];
  }
  return ans;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *f=(int *)malloc(sizeof(int)*n*5*2);
  int i,j,k;
  for(i=0;i<n;i++){
    for(j=0;j<5;j++){
      for(k=0;k<2;k++){
	scanf("%d",f+POS(i,j,k));
      }
    }
  }
  int *p=(int *)malloc(sizeof(int)*n*(10+1));
  for(i=0;i<n;i++){
    for(j=0;j<=10;j++){
      scanf("%d",p+11*i+j);
    }
  }
  int64 max=calc(1,f,p,n);
  for(i=2;i<(1<<10);i++){
    max=MAX(max,calc(i,f,p,n));
  }
  printf("%lld\n",max);
}

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


Measured memory_bytes: 128
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
using namespace std;
int main()
{
    string s;
    cin>>s;
    if((s[2]==s[3])&&(s[4]==s[5]))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}



Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i).sort
bc = m.times.map {gets.split.map(&:to_i)}.sort_by {|b, c| -c}

e = Enumerator.new {|y|
  bc.each do |b, c|
    b.times {y << c}
  end
  loop {y << 0}
}

result = 0
as.each do |a|
  nxt = e.next
  result += a < nxt ? nxt : a
end

puts result

Measured memory_bytes: 25460
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int m = x.nextInt();
		int f = x.nextInt();
		int r = x.nextInt();
		int go = m + f;
		while( m !=  -1 || f != -1 || r != -1){
			if( m == -1 || f == -1 || go < 30){
				System.out.println("F");
			}else if( go >= 80){
				System.out.println("A");
			}else if( go >= 65){
				System.out.println("B");
			}else if( go >= 50 || r >= 50){
				System.out.println("C");
			}else if( go >= 30){
				System.out.println("D");
			}
			m = x.nextInt();
			f = x.nextInt();
			r = x.nextInt();
			go = m + f;
		}
	}
}

Measured memory_bytes: 19452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>> s(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>s[i][j];
  rep(i,h)rep(j,w){
    if(s[i][j]=='#')continue;
    s[i][j]='0';
    for(int dx=-1;dx<=1;dx++){
      for(int dy=-1;dy<=1;dy++){
        int nx=i+dx,ny=j+dy;
        if(0<=nx&&nx<h&&0<=ny&&ny<w){
          if(s[nx][ny]=='#')s[i][j]++;
        }
      }
    }
  }
  rep(i,h)rep(j,w){
    cout<<s[i][j];
    if(j==w-1)cout<<endl;
  }
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	string num;
  int mi_re = INF;
  cin >> num;
  rep(i, num.size() - 2) {
    string num_3;
    int num_i;
    num_3 = num.substr(i, 3);
    num_i = stoi(num_3);
    mi_re = min(mi_re, abs(num_i - 753));
  }
  cout << mi_re << endl;
	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
f=sorted(map(int,input().split()))

def cnt(ans):
    rt=0
    for i in range(n):
        rt+=max(0,a[i]-int(ans//f[i]))
    return rt

lans,rans=0,max(a[i]*f[i] for i in range(n))
while 1:
    if rans-lans<=1:
        break
    mans=(rans+lans+1)//2
    if cnt(mans)<=k:
        rans=mans
    else:
        lans=mans
if rans==lans:
    print(rans)
else:
    if cnt(lans)>k:
        print(rans)
    else:
        print(lans)

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

typedef pair<int,int> P;
#define X first
#define D second

int main()
{
    int n, m;
    while(cin>>n>>m, n|m) {
        vector<int> k(n);
        long long int dp[150][11][77] = {0};
        vector< vector<P> > stone(n);
        for(int i=0; i<n; i++) {
            cin>>k[i];
            for(int j=0; j<k[i]; j++) {
                int x, d;
                cin>>x>>d;
                stone[i].push_back(P(x,d));
            }
        }
        for(int i=0; i<n; i++) for(int j=0; j<k[i]; j++) for(int l=0; l<=m; l++) dp[i][j][l] = 10000000000;
        for(int i=0; i<k[0]; i++) dp[0][i][m] = 0;
        for(int i=0; i<k[1]; i++) dp[1][i][m-1] = 0;

        for(int i=0; i<n; i++) {
            for(int j=0; j<k[i]; j++) {
                for(int l=0; l<=m; l++) {

                    if(i+1>=n) continue;
                    for(int jj=0; jj<k[i+1]; jj++) {
                        int add;
                        add = abs((stone[i+1][jj].D+stone[i][j].D)*(stone[i+1][jj].X-stone[i][j].X));
                        dp[i+1][jj][l] = min(dp[i+1][jj][l], dp[i][j][l]+add);
                    }

                    if(i+2>=n) continue;
                    for(int jj=0; jj<k[i+2]; jj++) {
                        int add;
                        add = abs((stone[i+2][jj].D+stone[i][j].D)*(stone[i+2][jj].X-stone[i][j].X));
                        dp[i+2][jj][l-1] = min(dp[i+2][jj][l-1], dp[i][j][l]+add);
                    }
                }
            }
        }

        long long int ans = 10000000000;
        for(int j=0; j<k[n-1]; j++) {
            for(int l=0; l<=m; l++) {
                ans = min(ans, dp[n-1][j][l]);
            }
        }
        for(int j=0; j<k[n-2]; j++) {
            for(int l=1; l<=m; l++) {
                ans = min(ans, dp[n-2][j][l]);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2220
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

unordered_map<ll, int> used;
ll S[100001];

int main() {
	ll N, X, M;
	cin >> N >> X >> M;

	if (N == 1) {
		cout << X << endl;
		return 0;
	}

	ll i = 2;
	ll A = X;
	S[1] = A;
	while (i<=N) {
		A = A * A % M;
		S[i] = S[i-1] + A;
		if (used[A] > 0) break;
		used[A] = i;
		i++;
	}

	ll ans;
	if (used[A] == N) {
		ans = S[N];
	} else {
		int s = used[A];
		int e = i;
		ll k = S[e] - S[s];
		int l = e - s;
		ll t = (N - s) / l;
		ll r = (N - e) % l;
		ans = S[s] + (S[e] - S[s]) * t + (S[s+r] - S[s]);
		//cout << s << " " << e << " " << t << " " << r << endl; // **** debug ****
	}

	cout << ans << endl;

	//cout << A << " " << used[A] << endl; // **** debug ****

	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll R, G;
    cin >> R >> G;
    cout << 2 * G - R << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
int w[100];
int s[101], t[101];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>w[i];
    rep(i,1,N+1) s[i]=s[i-1]+w[i-1];
    rer(i,N,0) t[i]=t[i+1]+w[i];
    int ans=1e7;
    rep(i,1,N){
        ans=min(ans,abs(s[i]-t[i]));
    }
    cout <<ans<<"\n";
}

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

int main() {
  int n; cin >> n;
  vector<long long> nums(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  
  long long answer = *max_element(nums.begin(), nums.end()) -
                     *min_element(nums.begin(), nums.end());
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010];
int main()
{
	int N;
	cin >> N;
	map<int, int> mp;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mp[A[i]]++;
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		mp[A[i]]--;
		bool plus = true;
		for (int j = 1; j * j <= A[i]; j++) {
			if (A[i] % j == 0) {
				if (mp[j] > 0 || mp[A[i] / j] > 0) {
					plus = false;
					break;
				}
			}
		}
		//cout << plus << endl;
		mp[A[i]]++;
		if (plus) ans++;
	}
	cout << ans << endl;
}

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

int N;

void merge_sort (int array[], int left, int right) {
    int i, j, k, mid;
    int work[N];
    if (left < right) {
        mid = (left + right)/2;
        merge_sort(array, left, mid);
        merge_sort(array, mid+1, right);
        for (i = mid; i >= left; i--) {
            work[i] = array[i];
        }
        for (j = mid+1; j <= right; j++) {
            work[right-(j-(mid+1))] = array[j];
        }
        i = left;
        j = right;
        for (k = left; k <= right; k++) {
            if (work[i] < work[j]) array[k] = work[i++];
            else                   array[k] = work[j--];
        }
    }
}

int main(int argc, const char * argv[]) {
    
    int i;
    cin >> N;
    int d[N];
    
    for(i=0; i<N; i++) cin >> d[i];
    
    merge_sort(d, 0, N-1);
    
    cout << d[N/2] - d[N/2 - 1];
    
    return 0;
}




Measured memory_bytes: 7312
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = 0;
        int res = 0;
        for (int a=1; a<=5; a++) {
          x = sc.nextInt();
          if(x == 0){
            res = a;
            break;
        	}
        }
      System.out.println(res);
    }
}

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

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> Ls(N);
    for(int i = 0; i < N; i++) {
        int l; cin >> l;
        Ls[i] = l;
    }
    int ans = 0;
    sort(Ls.begin(), Ls.end());
    for(int i = 0; i < N-2; i++) {
        for(int j = i + 1; j < N-1; j++) {
            for(int k = j + 1; k < N; k++) {
                if (Ls[i] + Ls[j] > Ls[k]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=2e5+100;
typedef long long LL;
LL a[maxn],x[maxn],sum[maxn];
int n;
int main()
{
    //freopen("1.txt","r",stdin);
    while (scanf("%d",&n)!=EOF)
    {
        memset(x,0,sizeof(x));
        memset(sum,0,sizeof(sum));
        for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
        x[1]=sum[1]=a[1];
        for (int i=2;i<=n;i++)
        {
            x[i]=x[i-1]^a[i];
            sum[i]=sum[i-1]+a[i];
        }

        int l=1;
        LL ans=0;
        for (int r=1;r<=n;r++)
        {
            for ( ;sum[r]-sum[l-1]!=(x[r]^x[l-1]);l++);
            ans+=r-l+1;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
 
vi g[N];
int a[N];
int b[N];
int n;
ll solve(int sign){
	int i;
	ll ans = 0;
	ll cur = 0;
	Fo(i, 0, n){
		cur += a[i];
		if(sign==1){
			//positive
			if(cur<=0) ans += -cur+1, cur = 1;
		}
		else{
			//negative
			if(cur>=0) ans += cur+1, cur = -1;
		}
		sign *= -1;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,k,j;
	cin >> n;
	fo(i, n) cin >> a[i], b[i] = a[i];
	cout << min(solve(-1), solve(1)) << endl;
	
	return 0;
} 


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

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

int main(){
	ll n,k; cin >> n >> k;
	cout << modpow(k,n,mod) << endl;
}


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

int Maximum_Porfit(int* num, int size)
{
    int maxi = -2000000000, mini = 0;
    mini = num[0];
    for(int j = 1; j < size; j++)
    {
        maxi = num[j] - mini > maxi ? num[j] - mini: maxi;
        mini = num[j] < mini? num[j]: mini;
    }
    return maxi;
}

int main()
{
    int count = 0;
    cin >> count;
    int *num = new int[count];
    for(int i = 0; i < count; i++)
    {
        cin >> num[i];
    }
    cout << Maximum_Porfit(num, count) << endl;
}


Measured memory_bytes: 3876
<?php

while (true) {
    fscanf(STDIN, '%d', $n);

    if (0 == $n) {
        break;
    }

    $format = join(' ', array_map(function () { return '%f'; }, range(1, $n)));
    $nums = fscanf(STDIN, $format);

    $m = array_sum($nums) / $n;
    $s = sqrt(array_sum(array_map(function ($i) use ($m) { return pow($i - $m, 2); }, $nums)) / $n);

    echo "$s\n";
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;


lli layer[51]; // layer[i]: レベルi に含まれる層数
lli p[51]; // p[i]: レベルi に含まれるパティの数
int main() {
    lli n, x;
    cin2(n, x);

    layer[0] = 1;
    p[0] = 1;
    REPE(i,1,n) {
        layer[i] = layer[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
        //cout3(i, layer[i], p[i]);
    }
    // Ln-1 一個分まるまるあるかどうかをチェック
    lli cur = n;
    lli ans = 0;
    //if (x > layer[cur-1] + 1) {
    //    ans += p[cur-1];
    //    x -= layer[cur-1] + 2;
    //    ans += 1;
    //}
    //else {
    //    x--;
    //}
    //cur--;
    //if (x > layer[cur-1] + 1) {
    //    ans += p[cur-1];
    //    x -= layer[cur-1] + 2;
    //    ans += 1;
    //}
    //else {
    //    x--;
    //}
    //cur--;
    //if (x > layer[cur-1] + 1) {
    //    ans += p[cur-1];
    //    x -= layer[cur-1] + 2;
    //    ans += 1;
    //}
    //else {
    //    x--;
    //}

    REPE_R(cur,n,1) {
        if (x > layer[cur-1] + 1) {
            ans += p[cur-1];
            x -= layer[cur-1]+2;
            ans++;
        }
        else {
            x--;
        }
    }
    if (x > 0)
        ans++;

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){	
			final int N = sc.nextInt();
			
			LinkedList<Integer> stack = new LinkedList<Integer>();
			int answer = 0;
			
			int old = 0;
			for(int i = 0; i < N; i++) {
				final int a = sc.nextInt();
				
				if(old + 1 == a) {
					old = a;
				}
			}
			
			
			System.out.println(old == 0 ? -1 : (N - old));
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 44280
<?php
$a = [];

fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; ++$i){
    fscanf(STDIN, "%d %d", $X, $L);
    $a[] = ['X' => $X, 'L' => $L, 'S' => $X - $L, 'T' => $X + $L];
}

usort($a, function($x, $y) {return $x['T'] > $y['T'];});
$cur = -PHP_INT_MAX;
$ans = 0;
for($i = 0; $i < $N; ++$i) {
    if ($cur <= $a[$i]['S']){
        $ans++;
        $cur = $a[$i]['T'];
    }
}

printf("%d", $ans);


Measured memory_bytes: 50164