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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b;
  cin>>a>>b;
  int res=0;
  if(a>b){
      res+=a;
      if(a-1>b)res+=a-1;
      else res+=b;
  }
  else {
      res+=b;
      if(b-1>a)res+=b-1;
      else res+=a;
  }
  out(res);

  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e8
#define MOD 1000000007
typedef long long ll;

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

      string s; cin >> s;
      if(s=="ABC") cout << "ARC" << endl;
      else cout << "ABC" << endl;
      return 0;
}


Measured memory_bytes: 3648
#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>;

int main() {
    ll N, M;
    cin >> N >> M;
    ll ans;
    if (N == 1 && M == 1) ans = 1;
    else if (N == 1 || M == 1) ans = N * M - 2;
    else ans = (N - 2) * (M - 2);
    cout << ans << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>

using namespace std;
int plas(int N){
	if(N<0)	return N*-1;
	return N;
}

int main(){
	int N;
	cin >> N;
	int A=1;
	for(int i=0;;i++){
		if(A*2>N){
			cout << A << endl;
			break;
		}
		A*=2;
	}
	return 0;
}


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

int main()
{
	int n,m;
	int a[100][100];
	int b[100];
	int sigma;
	cin>>n>>m;

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

		}
	}
	for(int j=0;j<m;j++) cin>>b[j];

	for(int i=0;i<n;i++){
		sigma=0;
		for(int j=0;j<m;j++){
			sigma+=a[i][j]*b[j];

		}
		cout<<sigma<<endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/

int main()
{
ll n,m,i,x,y,c=0,a,b,k,r;
cin>>n>>m;
vector<ll>v;
vector<pair<ll,ll> >v1;
for(i=0;i<n;i++)
{
    cin>>k;
    v.pb(k);
}
for(i=0;i<m;i++)
{
    cin>>x>>y;
    v1.pb({y,x});
}
sort(v.begin(),v.end());
sort(v1.begin(),v1.end(),greater<pair<ll,ll> >());
a=0,b=v1[0].ss;
for(i=0;i<n;i++)
{
  if(v1[a].ff<=v[i])
        break;
  v[i]=v1[a].ff;
  b--;
  if(b==0)
  {
      a++;
      b=v1[a].ss;
  }
}
for(i=0;i<n;i++)
{
   c=c+v[i];
}
cout<<c<<endl;
}


Measured memory_bytes: 3188
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string a, b;
	cin >> a >> b;
	string c = a + b;
	int n = c.size();
	int x = 0;
	REP(i, n) {
		x *= 10;
		x += c[i] - '0';
	}
	for (int i = 0;i*i <= x;i++) {
		if (i*i == x) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rep1(i, n) for(ll i = 1; i < (n); ++i)
#define rep4(i, start, end, step) for (ll i = (start); i < (end); i += (step))

#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF 0x3fffFFFF
#define INF_NEG (INF * -1)
#define INF_LONG (INF << 32)
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef char str255[256];
// char *用、strlen の ll 版
ll StrLen(char *s) { for(ll ptr = 0L;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
ll StrDel(char *s, int n) { ll l = StrLen(s); s[l - n + 1L] = '\0'; return l - n; }
// 正の整数の桁数
ll NumDigits(ll l){ char s[30]; sprintf(s, "%lld", l); return StrLen(s); }

int isFirst = 1;
template <class T> 
void print(T t) { if (isFirst) cout << t, isFirst = 0; else cout << " " << t; }

void chmin(ll& a, ll b) { if (a > b) a = b; }
void chmax(ll& a, ll b) { if (a < b) a = b; }

signed main()
{
    cout << fixed << setprecision(9);

    ll N; cin >> N;
    vector<ll> d(N); rep(i, N) cin >> d[i];

    sort(d.begin(), d.end());
    ll min_K = d[N / 2 - 1] + 1;
    ll max_K = d[N / 2];
    cout << max_K - min_K + 1 << endl;

    return 0;
}


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

#define x first
#define y second
#define pii pair<int,int>
#define N 1001

deque<pii> q;
int sx,sy,tx,ty;
int n,m,dis[N][N];
int dx[4]= {1,-1,0,0};
int dy[4]= {0,0,1,-1};

char str[N][N],vis[N][N];

int main(void) {
    int i,dir,j;
    pii p,np;
    memset(dis,0x3f,sizeof dis);
    scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&tx,&ty);
    for(i=1; i<=n; ++i)
		scanf("%s",str[i]+1);
    q.push_back({sx,sy});
	dis[sx][sy]=0;
    while(!q.empty()) {
        p=q.front();
		q.pop_front();
        if(vis[p.x][p.y])continue;
        vis[p.x][p.y]=1;
        for(dir=0; dir<4; ++dir) {
            np= {p.x+dx[dir],p.y+dy[dir]};
            if(np.x&&np.x<=n&&np.y&&np.y<=m &&
			   str[np.x][np.y]^'#' &&
			   dis[np.x][np.y]>dis[p.x][p.y]) {
            	dis[np.x][np.y]=dis[p.x][p.y];
				q.push_front(np);
			}
        }
        for(i=-2; i<=2; ++i)
			for(j=-2; j<=2; ++j) {
                np= {p.x+i,p.y+j};
                if(np.x>=1&&np.x<=n&&np.y>=1&&np.y<=m &&
				   str[np.x][np.y]^'#' &&
				   dis[np.x][np.y]>dis[p.x][p.y]+1) {
                	dis[np.x][np.y]=dis[p.x][p.y]+1;
					q.push_back(np);
				}
			}
    }
    printf("%d\n",dis[tx][ty]^0x3f3f3f3f?dis[tx][ty]:-1);
}

Measured memory_bytes: 9680
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

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

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (char i : s) {
		if (i == '+')ans++;
		else ans--;
	}
	cout << ans;
	return 0;
}













Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
using namespace std;

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	int ans=1e9;
	ans=min(ans,a+b);
	ans=min(ans,c+b);
	ans=min(ans,a+c);
	ans=min(ans,b+c);
	ans=min(ans,a+c);
	ans=min(ans,a+b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int x, y;
    int small, large;

    while (1){
        scanf("%d %d",&x, &y);
        if (x == 0 && y == 0){
            break;
        }else{
            if (x <= y){
                small = x;
                large = y;
            }else{
                small = y;
                large = x;
            }
            printf("%d %d\n", small, large);
        }
    }

    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int X, t;

    scanf("%d%d", &X, &t);

    if(t > X){
        printf("0\n");
    }else{
        printf("%d\n", X - t);
    }

    return 0;
}

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

int main()
{
    int N,price=0,ans,i,j;
    scanf("%d",&N);
    int A[N+2];
    A[0] = 0;
    A[N+1] = 0;
    for(i=1;i<N+1;i++){
        scanf("%d",&A[i]);
        price += abs(A[i-1] - A[i]);
    }
    price += abs(A[N]);
    for(i=1;i<N+1;i++){
        ans = price + abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]));
        printf("%d\n",ans);
    }

    return 0;

}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    ll sum = 0;
    for(int i = n - 1; i >= 0; i--){
        a[i] += sum;
        sum += (b[i] - a[i] % b[i]) % b[i]; 
    }
    cout << sum << endl;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
     int n;
     cin >> n;
     vector<ll> v;
     for(int i = 0; i < n; i++){
        ll ele;
        cin >> ele;
        v.push_back(ele);
     }
     cout << (*max_element(v.begin(),v.end())) - (*min_element(v.begin(),v.end())) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>

using namespace std;
int main(void) {
    int a,b,c;
    cin >> a; // 一回あたりの価格
    cin >> b; // 持ってる価格
    cin >> c; // upper limit

    auto max = b / a;
    if (max > c) {
        cout << c << endl;
    } else  {
        cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 888
/* **********************************JAI SAI RAM ************************************* */
//HELP IN CODEFORCES ROUND 641
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);   
    ll i,j,k,l,m,n,o,p,x,y;
    cin>>x>>y;
    ll flag=0;
    for(i=0;i<=x;i++)
    {
        if(2*i+4*(x-i)==y)
        {
            flag=1;
        }
        if(2*(x-i)+4*(i)==y)
        {
            flag=1;
        }
    }
    if(flag)
    cout<<"Yes\n";
    else 
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3612
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin>>
#define co cout<<
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

map<string,int>rohan;

int main()
{
// #ifndef RAHUL
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif

long long x;
cin>>x;
std::vector<string> v(x);

for (int i = 0; i < x; ++i)
{
	/* code */
	cin>>v[i];
	rohan[v[i]]++;
}

int max1=INT_MIN;

for(auto x:rohan){
	int w=x.second;

	max1=max(max1,w);
}

for(auto x:rohan){
	if(x.second==max1){
		cout<<x.first<<endl;
	}
}

return 0;
}




Measured memory_bytes: 25100
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

void solve()
{
    string s, t;
    cin>>s>>t;
    char c= t[t.length()-1];
    s= s+ (c);
    if(s==t)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
}

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


Measured memory_bytes: 3652
#include <cstdio>

using namespace std;

int main() {
    char a1, a2, a3, b1, b2, b3, c1, c2, c3;
    scanf("%c%c%c\n", &a1, &a2, &a3);
    scanf("%c%c%c\n", &b1, &b2, &b3);
    scanf("%c%c%c", &c1, &c2, &c3);
    printf("%c%c%c\n", a1, b2, c3);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x);
#define rl(x) scanf("%lld",&x);
#define pi(x) printf("%d",x);
#define pl(x) printf("%lld",x);
#define lfd() printf("\n");
#define sp() printf(" ");
map<int,int> cnt;
int n;
int a;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		cnt[a]++;
	}
	int res=0;
	for(__typeof(cnt.begin()) it=cnt.begin();it!=cnt.end();it++){
		if(it->first<=it->second)
			res+=it->second-it->first;
		else
			res+=it->second;
	}
	cout<<res<<endl;
	return 0;
}


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

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

pair<long long, long long> ChineseRem(const vector<long long> &b, const vector<long long> &m) {
  long long r = 0, M = 1;
  for (int i = 0; i < (int)b.size(); ++i) {
	long long p, q;
	long long d = extGcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d)
	if ((b[i] - r) % d != 0) return make_pair(0, -1);
	long long tmp = (b[i] - r) / d * p % (m[i]/d);
	r += M * tmp;
	M *= m[i]/d;
  }
  return make_pair(mod(r, M), M);
}

int main() {
  int N, M, D;
  cin >> N >> M >> D;
  vector<long long> A(M);
  for (int i = 0; i < M; ++i) cin >> A[i];
  bool ok = true;
  for (int i = 0; i < D; ++i) {
	vector<long long> b, m;
	for (int j = 0; j < M; ++j) {
	  int R; cin >> R;
	  if (R != -1) b.push_back(R), m.push_back(A[j]);
	}
	if (b.empty()) continue;

	pair<long long, long long> tmp = ChineseRem(b, m);

	if (tmp.second == -1) ok = false;
	if (N < tmp.first) ok = false;

	N = N - (N - tmp.first) % tmp.second;
  }
  if (ok) cout << N << endl;
  else cout << -1 << endl;
}



Measured memory_bytes: 3136
var
	n,s,max,i,a:longint;
begin
	readln(n);
	s:=0; max:=0;
	for i:=1 to n do
	begin
		read(a);
		s:=s+a;
		if a>max then max:=a;
	end;
	writeln(s-max div 2);
end.

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=(int)5e5+5;
char s[MAXN];
int main(){
	int len,i=1;
	long long ans=0;
	scanf("%s",s+1);
	len=strlen(s+1);
	while(i<=len){
		int sum1=0,sum2=0;
		while(s[i]^'>'&&i<=len){
			i++;
			sum1++;
		}
		while(s[i]^'<'&&i<=len){
			i++;
			sum2++;
		}
		if(sum1>sum2)
			sum1^=sum2^=sum1^=sum2;
		ans+=(1ll*sum1*(sum1-1)>>1)+(1ll*sum2*(sum2+1)>>1);
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n, m, v, p;
int a[100005], b[100005];

bool moze(int q) {
	copy(a, a+q, b);
	copy(a+q+1, a+n, b+q);
	int h = a[q] + m;
	ll w = 0;
	reverse(b, b+n-p);
	for (int i=0; i<n-p; i++) {
		if (b[i] > h)
			return false;
		w += h - b[i];
		if (w < max(0, (v - p) + i - (n - p - 1)) * 1ll * m)
			return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n >> m >> v >> p;
	for (int i=0; i<n; i++)
		cin >> a[i];
	sort(a, a+n);
	int l = 0, r = n-2, o = n-1;
	while (l <= r) {
		int mid = (l+r) / 2;
		if (moze(mid)) {
			o = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}

	cout << n-o << '\n';
}

Measured memory_bytes: 1024
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)

Measured memory_bytes: 55432
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll tmp_max=INF;
    ll ans;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    sort(all(A));
    ll n=A[sz(A)-1];
    rep(i,N-1){
        if(chmin(tmp_max,abs(n-2*A[i]))) ans=A[i];
    }
    cout<<n<<" "<<ans<<endl;
}


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

struct dat {
  string name;
  int id, point;
};
bool operator<(const dat &l, const dat &r) {
  if (l.name != r.name) return l.name < r.name;
  return l.point > r.point;
}

int n;
vector<dat> v;

int main() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].name >> v[i].point;
    v[i].id = i + 1;
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; ++i) cout << v[i].id << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
    multiset<int,greater<int>> cas;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		auto itr=cas.upper_bound(a);
		//cout<<*itr<<endl;
		//for(auto ite=cas.begin();ite!=cas.end();ite++)cout<<*ite<<endl;
		if(cas.end()!=itr)cas.erase(itr);
		cas.insert(a);
	}
	//for(auto ite=cas.begin();ite!=cas.end();ite++)cout<<*ite<<endl;
	cout<<cas.size()<<endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int K;
    cin >> K;
    int count = 1;
    int mod = 7;
    for (int i = 0; i < K; ++i){
        if (mod % K == 0) break;
        ++count;
        mod = (mod * 10 + 7) % K;
    }
    if (mod % K == 0) cout << count << endl;
    else cout << -1 << endl;
}

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

int main() {
    int n, result = 0;
    cin >> n;
    vector<vector<vector<pair<int, int>>>> graph(n + 1, vector<vector<pair<int, int>>>(n + 1));
    for (int i = 1; i <= n; i++) {
        pair<int, int> prev;
        prev.first = i;
        cin >> prev.second;
        if (prev.first > prev.second) {
            swap(prev.first, prev.second);
        }
        for (int j = 2; j < n; j++) {
            pair<int, int> current;
            current.first = i;
            cin >> current.second;
            if (current.first > current.second) {
                swap(current.first, current.second);
            }
            graph[prev.first][prev.second].emplace_back(current);
            prev = move(current);
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    vector<vector<bool>> visited(n + 1, vector<bool>(n + 1));
    function<int(int, int)> dfs = [&](int i, int j) {
        if (dp[i][j] != 0) {
            return dp[i][j];
        }
        dp[i][j] = 1;
        visited[i][j] = true;
        for (auto& p : graph[i][j]) {
            if (visited[p.first][p.second]) {
                dp[i][j] = -1;
                break;
            }
            auto t = dfs(p.first, p.second);
            if (t == -1) {
                dp[i][j] = -1;
                break;
            }
            dp[i][j] = max(dp[i][j], t + 1);
        }
        visited[i][j] = false;
        return dp[i][j];
    };
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            auto t = dfs(i, j);
            if (t == -1) {
                cout << -1;
                return 0;
            }
            result = max(result, t);
        }
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 43776
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
 
    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)
 
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)

import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
C = list(map(int,input().split()))
#print(C)
LR = []
ans = [0 for _ in range(Q)]
for i in range(Q):
  temp= list(map(int,input().split()))
  LR.append((temp,i)) #クエリとID
LR.sort(key=lambda x : x[0][1]) #右端で昇順にソート
#print(LR)
CMAX = max(C)
Tree = BIT(N)
last = [-1 for _ in range(CMAX)] #色を0index
left,right = LR[0][0]
for j in range(right):
  mae = last[C[j]-1]
  last[C[j]-1] = j
  if mae !=-1:
    Tree.add(mae+1,-1) #BITは1から
  Tree.add(last[C[j]-1]+1,1) #BITは1から
  #print(Tree.get(left,right))
#print(last)
D = []
#for i in range(1,N+1):
#  detemp = Tree.get(i,i)
#  D.append(detemp)
#print(D)

temp = Tree.get(left,right)
ID = LR[0][1]
ans[ID] = temp
lastright = right  
#print(Tree.get(left,right))
for i in range(1,Q):
  left,right = LR[i][0]
  #print(right,lastright)
  if lastright < right:
    for j in range(lastright,right):
      mae = last[C[j]-1]
      last[C[j]-1] = j
      #print(C[j],mae,j,last[C[j]-1] )
      if mae !=-1:
        #rint(C[j],"A")
        Tree.add(mae+1,-1) #BITは1index
      Tree.add(j+1,1) #BITは1index
  temp = Tree.get(left,right)
  ID = LR[i][1]
  ans[ID] = temp
  lastright = max(right,lastright)
  #print(last)


print(*ans,sep="\n")



Measured memory_bytes: 227528
#include<iostream>
#include<string>
using namespace std;
string a;
int c;
int saiki(int,int);
int main(){
  int ans;
  while(1){
    c=0;
    a.clear();
    getline(cin,a);
    if(a==".")break;
    ans=saiki(0,0);

    //out 
    if(ans==-1)cout << "no" << endl;
    else cout << "yes" << endl;
  }
  return 0;
}
int saiki(int I,int n){//n:1=( 2=[
  for(int i=I;i<a.size();i++){
    if(a[i]=='('){
      i=saiki(i+1,1);
      if(i==-1)return -1;
    }
    else if(a[i]=='['){
      i=saiki(i+1,2);
      if(i==-1)return -1;
    }
    else if(a[i]==')'){
      c++;
      if(n==1){
	c--;
	return i;
      }
    }
    else if(a[i]==']'){
      c++;
      if(n==2){
	c--;
	return i;
      }
    }
    else if(a[i]=='.'){
      if(c!=0)return -1;
      if(n==0)return 0;
    }
  }
  return -1;
  
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

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

    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class P
{
    public int w { get; set; }
    public int L { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            if (n == 0 && k == 0) break;
            var a = new int[k];
            var zero = false;
            for (int i = 0; i < k; i++)
            {
                var wa = int.Parse(Console.ReadLine().Trim());
                if (wa == 0) { zero = true; a[i] = n + 1; }
                else a[i] = wa;
            }
            Array.Sort(a);
            Console.WriteLine(zero ? getAns2(a) : getAns1(a));
        }
    }
    public static int getAns2(int[] a)
    {
        var ps = new List<P>();
        var tmax = 1; var pre = a[0]; var pres = 0;
        for (int i = 1; i < a.Length - 1; i++)
        {
            if (a[i] == pre + 1) { tmax++; }
            else
            {
                ps.Add(new P { w = a[pres] - 1, L = tmax });
                ps.Add(new P { w = a[i - 1] + 1, L = tmax });
                pres = i;
                tmax = 1;
            }
            pre = a[i];
        }
        ps.Add(new P { w = a[pres] - 1, L = tmax });
        ps.Add(new P { w = a[a.Length - 2] + 1, L = tmax });
        var dret = new Dictionary<int, int>();
        var ret = 0;
        foreach (var x in ps)
        {
            if (dret.ContainsKey(x.w)) dret[x.w] += x.L;
            else dret[x.w] = x.L + 1;
            ret = Math.Max(ret, dret[x.w]);
        }
        return ret;
    }
    public static int getAns1(int[] a)
    {
        var tmax = 1; var pre = a[0]; var ret = tmax;
        for (int i = 1; i < a.Length; i++)
        {
            if (a[i] == pre + 1) { tmax++; }
            else { ret = Math.Max(ret, tmax); tmax = 1; }
            pre = a[i];
        }
        ret = Math.Max(ret, tmax);
        return ret;
    }
}


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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {FIN;
    

    string s;cin>>s;
    int n = s.length()-1;
    ll sum = 0;
    fore(i,0,1<<n){
        ll cur = s[0]-'0';
        fore(j,0,n){
            if(i&(1<<j)){
                sum+=cur;
                cur = s[j+1]-'0';
            }else{
                cur*=10;
                cur+=s[j+1]-'0';
            }
        }sum+=cur;
    }
    cout<<sum<<"\n";
    return 0;
}


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

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

    int n, k;
    cin >> n >> k;
    
    if(n == k){
        cout << 1 << endl;
        return 0;
    }

    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    n--; k--;
    cout << (n + k - 1) / k << endl;

    return 0;
}

Measured memory_bytes: 640
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  int N;
  cin >> N;
  int ans = 0;
  rep(i, N) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
  return 0;
} 


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

int main()
{
    string S;
    cin>>S;
    for(int i=0;i<S.length();i++)
    {
        if(i%2==1)
        {
            if(S[i]=='R')
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        else
        {
            if(S[i]=='L')
            {

                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()
x = A[-1] // 2
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r1 = A[idx]
    dist1 = abs(x - A[idx])
else:
    r1 = A[idx-1]
    dist1 = abs(x - A[idx-1])
x = ceil(A[-1], 2)
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r2 = A[idx]
    dist2 = abs(x - A[idx])
else:
    r2 = A[idx-1]
    dist2 = abs(x - A[idx-1])

if dist1 < dist2:
    r = r1
else:
    r = r2
print(A[-1], r)


Measured memory_bytes: 14352
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e5 + 5, M = 1e9 + 5;
ll a[N], b[N], c[N], dpa[N], dpb[N], dpc[N];
int main()
{
	ll n;
	cin >> n;
	for(ll i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];
	dpa[n] = a[n], dpb[n] = b[n], dpc[n] = c[n];
	for(ll i = n - 1; i >= 1; i--)
	{
		dpa[i] = a[i] + max(dpb[i + 1], dpc[i + 1]);
		dpb[i] = b[i] + max(dpa[i + 1], dpc[i + 1]);
		dpc[i] = c[i] + max(dpa[i + 1], dpb[i + 1]);
	}
	cout << max({dpa[1], dpb[1], dpc[1]});
}

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

int main() {
  string S;
  cin >> S;
  int l = S.size();
  rep(i,l / 2) {
    if (S[i] != S[(l + 1) / 2 + i] || S[i] != S[l - i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll mx = 1e18;
    ll ans = 1;
    sort(a.begin(), a.end());
    rep(i,n) {
        // cout << a[i] << endl;
        if (a[i] != 0 && ans > (mx+a[i]-1)/a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
        // cout << ans << " " << i << endl;
    }
    if (ans > mx) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cmax(a,b)		a = max (a, b)
#define cmin(a,b)		a = min (a, b)
#define SZ(x)		(int)x.size()

const int MAXN = 3e5 + 5;
const int oo = 0x3f3f3f3f;

int N, M;
vector<int> S[MAXN];

namespace Seg{
	struct tree {
		int son[2], siz;
	}t[MAXN * 25];
	int root[MAXN], cnt = 0;
	int NewNode(int s0, int s1, int siz){
		cnt++;
		t[cnt].son[0] = s0; t[cnt].son[1] = s1;
		t[cnt].siz = siz;
		return cnt;
	}
	void Build(int le, int ri, int &k, int o){
		k = NewNode(t[k].son[0], t[k].son[1], t[k].siz + 1);
		if (le == ri) return;
		int mi = (le + ri) >> 1;
		if (o <= mi) 	Build(le, mi, t[k].son[0], o);
		else			Build(mi + 1, ri, t[k].son[1], o);
	}
	int Query(int le, int ri, int k, int L, int R){
		if (L <= le && ri <= R) return t[k].siz;
		int mi = (le + ri) >> 1, sum = 0;
		if (L <= mi) 		sum += Query(le, mi, t[k].son[0], L, R);
		if (mi + 1 <= R)		sum += Query(mi + 1, ri, t[k].son[1], L, R);
		return sum;
	}
}using namespace Seg;

namespace solution{
	void Prepare(){
		scanf("%d%d", &N, &M);
		up (i, 1, N) {
			int le, ri;
			scanf("%d%d", &le, &ri);
			S[ri].push_back(le);
		}
		down (i, M, 1) {
			root[i] = root[i + 1];	
			up (j, 0, SZ(S[i]) - 1) Build(1, M, root[i], S[i][j]);
		}
	}	
	void Solve(){
		up (i, 1, M) {
			ll ans = 0;
			for (int j = i; j <= M; j += i) ans += Query(1, M, root[j], j - i + 1, j);
			printf("%lld\n", ans);
		}
	}
}

int main(){
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}


Measured memory_bytes: 76800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class ABC111 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String N = in.next();

            N = N.replace("1", "q");
            N = N.replace("9", "i");

            N = N.replace("q", "9");
            N = N.replace("i", "1");

            out.println(N);

        }

    }
}



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

using namespace std;

const int N = 1e5 + 100;

int a[N];

int main()
{
	int n, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n;)
	{
		if (a[i] == i)
		{
			int cnt = 0;
			while (a[i] == i)
			{
				i++;
				cnt++;
			}
			ans += cnt / 2 + (cnt & 1);
		}
		else
		{
			i++;
		}
	}
	printf("%d\n", ans);
}

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

typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)
int dp[100005];
vector <int> adj[100005];
bool vis[100005];

int dfs(int root){
    vis[root] = true;
    int size = adj[root].size();
    if(size == 0){
        return 0;
    }
    if(dp[root] != -1){
        return dp[root];
    }
    int temp = 0;
    for(int i = 0; i < size; i++){
          temp = max(temp , 1 + dfs(adj[root][i]));
    }
    return(dp[root] = temp);
}

int main(){
 speed up
 int n , m , x , y;
 memset(dp , -1 , sizeof(dp));
 cin >> n >> m;
 while(m--){
     cin >> x >> y;
     adj[x].pb(y);
 }
 for(int i =1; i <= n; i++){
     if(!vis[i]){
         dfs(i);
     }
 }
 sort(dp +1 , dp + n + 1);
 cout << dp[n] << "\n";
}

Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

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

	vector<double> a;

	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	sort(a.begin(), a.end(), greater<double>());

	while (a.size() > 1)
	{
		double x, y;
		x = a.back();
		a.pop_back();
		y = a.back();
		a.pop_back();
		a.push_back((x + y) / 2.0);
		sort(a.begin(), a.end(), greater<double>());
	}

	cout << a[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	String[] list = new String[n];
      	for(int i = 0; i < n; i ++){
        	String restaurant = sc.next();
          	int score = sc.nextInt();
          	list[i] = restaurant + "_" + (200 - score) + "_" + (i + 1);
        }
      	Arrays.sort(list);
      	for(String s : list){
        	String ans = s.split("_")[2];
          	System.out.println(ans);
        }
    }
}

Measured memory_bytes: 21716
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	r1 := getNextInt(scanner)
	c1 := getNextInt(scanner)
	r2 := getNextInt(scanner)
	c2 := getNextInt(scanner)

	cm := Com{}
	cm.init(int(1e6+1) * 2)
	var ans int64

	for i := c1; i <= c2; i++ {
		ans += cm.calc(i+r2+1, r2) - cm.calc(i+r1, i+1)
		ans %= cm.mod
		if ans < 0 {
			ans += cm.mod
		}
	}

	fmt.Fprintln(writer, ans)
}

// Com ...
type Com struct {
	facs, invs []int64
	mod        int64
}

func (cm *Com) init(n int) {
	cm.facs = make([]int64, n+1)
	cm.invs = make([]int64, n+1)

	cm.facs[0] = 1
	cm.mod = int64(1e9 + 7)
	for i := 1; i <= n; i++ {
		cm.facs[i] = (cm.facs[i-1] * int64(i)) % cm.mod
	}
	cm.invs[n] = cm.inv(cm.facs[n])
	for i := n - 1; i >= 0; i-- {
		cm.invs[i] = cm.invs[i+1] * int64(i+1) % cm.mod
	}
}

func (cm *Com) inv(n int64) int64 {
	var ii [32]int64
	ii[0] = n
	for i := 1; i < 31; i++ {
		ii[i] = (ii[i-1] * ii[i-1]) % cm.mod
	}
	var ans int64
	ans = 1
	m := cm.mod - 2
	for i := 31; i >= 0; i-- {
		for m >= 1<<uint(i) {
			ans = (ans * ii[i]) % cm.mod
			m -= 1 << uint(i)
		}
	}

	return ans
}

func (cm *Com) calc(n, k int) int64 {
	ans := cm.facs[n] * cm.invs[k]
	ans %= cm.mod
	ans = ans * cm.invs[n-k]
	ans %= cm.mod
	return ans
}


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

int main() {
    string s;
    cin >> s;
    string ans;
    for (int i = 0; i < s.size(); i++) {
        if (ans.size() == 0 || ans[ans.size() - 1] == 'Z') {
            if (s[i] == 'A') ans.push_back(s[i]);
        } else {
            if (s[i] == 'Z') ans.push_back(s[i]);
        }
    }
    if (ans.size() == 0) {
        cout << -1 << endl;
        return 0;
    }
    if (ans[ans.size() - 1] == 'A') {
        ans = ans.substr(0, ans.size() - 1);
    }
    if (ans.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    int array[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin >> N;
    cout << array[N-1] << endl;
}


Measured memory_bytes: 256
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}


func main() {
    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]
    let mod = 1_000_000_007

    var dp = Array(repeating: 0, count: n+1)
    dp[0] = 1

    var safe = Array(repeating: true, count: n+1)

    for _ in 0..<m {
        let a = Int(readLine()!)!
        safe[a] = false
    }

    for i in 0..<n {
        if i+1 <= n && safe[i+1] {
            dp[i+1] += dp[i]
            dp[i+1] %= mod
        }

        if i+2 <= n && safe[i+2] {
            dp[i+2] += dp[i]
            dp[i+2] %= mod
        }
    }
    print(dp.last!)
}

main()



Measured memory_bytes: 13932
void main() {
  problem();
}

void problem() {
  auto S = scan!int;
  auto W = scan!int;

  void solve() {
    writefln(W >= S ? "unsafe" : "safe");
  }

  solve();
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 2856
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


void solve(int n){
    vector<array<int, 2>> dp(n), v(n);
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> v[j][i];
            dp[j][i] = INF<int>;
        }
    }
    queue<pair<int, int>> Q;
    dp[0][0] = 0;
    dp[0][1] = 0;
    Q.emplace(0, 0);
    Q.emplace(0, 1);
    while(!Q.empty()){
        int y, x; tie(y, x) = Q.front(); Q.pop();
        if(v[y][x] == 2) {
            while(v[y][x] == 2) {
                dp[y-1][x] = dp[y][x];
                y--;
            }
        }
        if(v[y][x] == 1){
            while(y+1 < n && v[y+1][x] == 1) {
                dp[y+1][x] = dp[y][x];
                y++;
            }
        }
        if(y >= n-1){
            cout << dp[y][x] << "\n";
            return;
        }
        for (int i = 0; i <= 2 && y+i < n; ++i) {
            int yy = y+i, xx = x^1;
            if(dp[yy][xx] != INF<int>) continue;
            dp[yy][xx] = dp[y][x]+1;
            Q.emplace(yy, xx);
        }
    }
    puts("NA");
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3104