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

#define fi first
#define se second

#define debug(x) cerr << #x << " : " << x << endl;

#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())

typedef long long ll;


// code //
const int mxN = 105;
int n;
int a[mxN];

int main() {
	cin >> n;
	for(int i=0; i<n; ++i) cin >> a[i];
	sort(a, a+n);
	int ans=0;
	for(int i=0; i<n; ++i) {
		for(int j=i+1; j<n; ++j) {
			for(int k=j+1; k<n; ++k) {
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]) {
					if(a[i]+a[j]>a[k])ans++;
				}
			}
		}
	}
	cout << ans;
}


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

int main()
{
	  long long int n;
	  cin>>n;
	  long long int a[n],ans[n];
	  long long int imu=0,imran=0;
	  for (int i=0;i<n;i++){
        cin>>a[i];
        imu+=a[i];
        if(i%2==1){
            imran+=a[i];
        }
	  }
	  ans[0]=imu/2-imran;
	  cout<<ans[0]*2<<" ";
	  for(int i=1;i<n;i++){
        ans[i]=a[i-1]-ans[i-1];
        cout<<ans[i]*2;
        if(i!=n-1){
            cout<<" ";
        }
	  }
	  cout<<endl;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

  set<string> candidate;
  for (int i = 'a'; i <= 'z'; i++) {
    if (candidate.size() >= K) break;
    for (int j = 0, N = s.size(); j < N; j++) {
      if (s[j] == i) {
        for (int i = 1; i <= 5; i++) {
          if (j + i <= N) candidate.insert(s.substr(j, i));
        }
      }
    }
  }

  vector<string> v(candidate.size());
  copy(candidate.begin(), candidate.end(), v.begin());
  sort(v.begin(), v.end());
  cout << v[K - 1] << endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int h,w;cin>>h>>w;
	vector<vector<char>> a(h,vector<char>(w));
	vector<int> cnt(26,0);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin>>a[i][j];
			cnt[a[i][j] - 'a'] ++;
		}
	}
	if (w % 2 == 0 && h % 2 == 0){
		for(int i = 0; i < 26; i++) {
			if (cnt[i] % 4 != 0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	else if (w % 2 == 1 && h % 2 == 1){
		int check = 0;
		bool check2 = false;
		for(int i = 0; i < 26; i++) {
			if (cnt[i] % 4 == 0)continue;
			if (cnt[i] % 4 == 2){
				if (check == (h / 2) + (w / 2)){
					cout << "No" << endl;
					return 0;
				}
				else{
					check++;
				}	
			}
			else{
				if (check2){
					 cout << "No" << endl;
					 return 0;
				}
				check2 = true;
			}
		}
	}
	else {
		int check = 0;
		for(int i = 0; i < 26; i++) {
			if (cnt[i] % 2 == 1){
					cout << "No" << endl;
					return 0;
			}
			if (cnt[i] % 4 == 2){
				if ( w % 2 == 1){
					if (check == h / 2){
						cout << "No" << endl;
						return 0;
					}
					else{
						check++;
					}
				}
				else{
					if (check == w / 2){
						cout << "No" << endl;
						return 0;
					}
					else{
						check++;
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 2000009
#define DEUG 1
#include<stack>
#define inf 0x3f3f3f3f
#define mod 1000000007
#define ll long long
using namespace std;

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    int a,b,c,ans=0;
    scanf("%d%d%d",&a,&b,&c);
    while((a%2==0)&&(b%2==0)&&(c%2==0))
    {
       // printf("asjdf\n");
        int aa,bb,cc;
        aa=b/2+c/2;
        bb=a/2+c/2;
        cc=a/2+b/2;
        a=aa,b=bb,c=cc;
        ans++;
        if(ans>100000000)
            break;
    }
    if(ans>100000000)
        printf("-1\n");
    else
        printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(x) for x in input().split()]

if n % 2 == 0:
    b = a[n - 1 : 0 : -2] + a[0 : n - 1 : 2]
else:
    b = a[n - 1 : : -2] + a[1 : n - 1 : 2]

print(*b)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using ld = long double;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int64 N;
	vector<int64> h;
	cin >> N;
	h.resize(N);
	REP(i, N) cin >> h[i];
	int64 res = 0;
	while(1){
		int32 now = 0;
		int32 sum = 0;
		REP(i, N){
			if(h[i] > 0){
				now = 1;
				h[i]--;
			}
			else{
				res += now;
				now = 0;
			}
			sum += h[i];
		}
		res += now;
		if(sum == 0) break;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;

const int MAXN = 2e5 + 5;
int A[MAXN];
int preMax[MAXN];
int sufMax[MAXN];
int main() {
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &A[i]);
        }

        preMax[0] = -1;
        for(int i = 1; i <= n; ++i) {
            preMax[i] = max(preMax[i-1], A[i]);
        }
        sufMax[n + 1] = -1;
        for(int i = n; i >= 1; --i) {
            sufMax[i] = max(sufMax[i+1], A[i]);
        }
        
        for(int i = 1; i <= n; ++i) {
            int tt = max(preMax[i-1], sufMax[i + 1]);
            printf("%d\n", tt);
        }
    }
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    ll odp = 0;
    for (ll i = 0; i < (1 << (n - 1)); ++i)
    {
        ll s = 0;
        ll akt = 0;
        for (ll j = 0; j < n - 1; ++j)
        {
            akt = akt * 10 + (nap[j] - '0');
            if ((i & (1LL << j)) > 0)
            {
                s += akt;
                akt = 0;
            }
        }
        akt = akt * 10 + (nap[n - 1] - '0');
        s += akt;
        odp += s;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::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; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    VL a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n) rep(j,n){
        if (i <= j) continue;
        chmax(ans, abs(a[i] - a[j]));
    }
    view(ans);
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
static const bool DEBUG = true;
int main()
{
    ifstream fIn("input.txt");
    if (DEBUG)
    {
        if(fIn.is_open()) cin.rdbuf(fIn.rdbuf());
    }

    int a, b;
    cin >> a >> b;
    int ans = max(a - b * 2, 0);
    cout << ans << endl;
    return 0;
}

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

int n;

vector<int> v;
vector<int> vv;

long long int can[54];
bool ava[54];

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		vv.push_back(a);
	}
	for (int i = 1; i <= 52; i++){
		ava[i] = true;
	}
	for (int i = 52; i >= 1; i--){
		ava[i] = false;
		memset(can, 0, sizeof(can));
		can[0] = 1;
		for (long long int j = 1; j <= 50; j++){
			can[j] ^= (1LL << j);
			for (long long int k = 1; k <= j; k++){
				if (!ava[k])continue;
				can[j] |= can[j%k];
			}
		}
		bool ng = false;
		for (int j = 0; j < n; j++){
			if (((can[v[j]] >> vv[j]) & 1LL)){
				
			}
			else{
				ng = true;
				break;
			}
		}
		if (ng){
			ava[i] = true;
			if (i >= 51){
				puts("-1");
				return 0;
			}
		}
	}
	long long int mask = 0;
	for (int i = 0; i <= 50; i++){
		if (ava[i]){
			mask |= (long long int)(1LL << (long long int)(i));
		}
	}
	printf("%lld\n", mask);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  ll x;
  cin >> x;
  
  ll ans = 0;
  for(int i = 0; i < 10e10; i++) {
    if(x >= 500) {
      x = x - 500;
      ans = ans + 1000;
    } else {
      break;
    }
  }
  for(int i = 0; i < 10e10; i++) {
    if(x >= 5) {
      x = x - 5;
      ans = ans + 5;
    } else {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */
                                      /* Yani mishe mnm shakh sham ? ...  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define bug() cout << "BUG" << endl ;
#define X first
#define Y second
#define sz(x) (int)x.size()
#define per(how) cout << fixed << setprecision(how)
#define bit(a , b) (a >> b) & 1
#define all(v) v.begin() , v.end()
#define LB(x) (x & -x)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 , MOD = 1e9 + 7 , SQRT = 350 ;
inline void smin(ll &x , ll y) { x = min(x , y) ; }
inline void smax(ll &x , ll y) { x = max(x , y) ; }


string s ; 

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s ; 
	ll res = 0 ; 
	for(ll i = 1 ; i < s.size() ; i++)
	{
		string cur = "" ; 
		for(ll j = 0 ; j < s.size() - i ; j++)
		{
			cur += s[j] ; 
		}
		if(cur.size() % 2 == 0)
		{
			ll x = cur.size() / 2 ; 
			string a = "" , b = "" ; 
			for(ll k = 0 ; k < x  ; k++)		a += cur[k] ;
			for(ll k = x  ; k < cur.size() ; k++)	b += cur[k] ; 
			if(a == b)	smax(res , a.size()) ;  
		//	cout << a << " " << b << endl ; 
		}
	}
	cout << 2 * res << endl ; 
	return 0 ; 
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


void solve(long long N, long long H, std::vector<long long> a, std::vector<long long> b){
    // 振り最強ソード
    long long a_max = *max_element(all(a));
    sort(all(b));
    reverse(all(b));
    long long count = 0;

    for (int i=0; i<N; i++) {
        if (a_max < b[i]) {
            H -= b[i];
            count++;
            if (H <= 0) break;
        }
    }

    while (H > 0) {
        H -= a_max;
        count++;
    }
    cout << count << endl;
}

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


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

int main()
{
    bool arr[100000];
    for (int i = 0; i < 100000; ++i)
    {
       arr[i] = 0;
    }


    for (int i = 1; i <= 9; ++i)
    {
        for (int j = 1; j <= 9; ++j)
        {
            arr[i*j] = true;
        }
    }

    int n;
    cin >> n;

    if(arr[n]) cout << "Yes";
    else cout << "No";
    return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n;
    cin >> n;
    auto pf = prime_factorize(n);
    ll res = 0;
    for(auto p : pf){
        ll prime = p.first;
        ll kazu = p.second;
        ll check = 1;
        while(kazu >= check){
            kazu -= check;
            check++;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3608
s = input()
l = []
cnt = 0

for i in s:
    l.append(i)
if (l[0]=='A') and (l[2:-1].count('C')==1):
        idx =l[2:-1].index('C')
        idx += 2
        del l[idx]
        del l[0]
        for i in range(len(l)):
            if l[i].islower()==True:
                cnt += 1
        if cnt == len(l):
            print('AC')
        else:
            print('WA')
    
else:
    print('WA')

Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int main() {
	int w, h, n, x[100], y[100], a[100],w1,w2,h1,h2;
	cin >> w >> h >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i] >> y[i] >> a[i];
	w1 = w;
	w2 = 0;
	h1 = h;
	h2 = 0;
	for (int i = 1; i <= n; i++) {
		switch (a[i]) {
		case 1:
			if (w2 < x[i])w2 = x[i];
			break;
		case 2:
			if (w1 > x[i])w1 = x[i];
			break;
		case 3:
			if (h2 < y[i])h2 = y[i];
			break;
		case 4:
			if (h1 > y[i])h1 = y[i];
			break;
		}
	}
	if (w1 - w2 <= 0 || h1 - h2 <= 0)cout << 0 << endl;
	else cout << (w1 - w2)*(h1 - h2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
ll INF=300000;

int main(){
    int A, B, C, K;
    cin>>A>>B>>C>>K;
    int Max=max(max(A, B), C);
    int Sum=A+B+C-Max;
    for(int i=0; i<K; i++){
        Max*=2;
    }
    Sum+=Max;
    cout<<Sum<<endl;
    
}

Measured memory_bytes: 256
str = gets.chomp!

if /(\d\d)(\d\d)/ =~ str
   fron = $1.to_i
   back = $2.to_i
end


if fron > 12
  if back > 12 || back == 0
    puts "NA"
  elsif back <= 12 && back >= 1
    puts "YYMM"
  end
elsif fron <= 12 && fron >= 1
  if back > 12 || back == 0
    puts "MMYY"
  elsif back <= 12 && back >= 1
    puts "AMBIGUOUS"
  end
elsif fron == 0
  if back <= 12 && back >= 1
     puts "YYMM"
  else
     puts "NA"
  end
end

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

int main(){
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> P(N);
	for(int i=0; i<N; i++) cin >> P[i].first >> P[i].second;
	sort(P.begin(), P.end());
	ll ans = 0;
	for(int i=0; i<N; i++){
		if(M >= P[i].second){ ans += (long long)P[i].first * P[i].second;}
		else{
			ans += (long long)P[i].first * M;
			break;
		}
		M -= P[i].second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int A,B,C,K,ans;
int main()
{
	scanf("%d%d%d%d",&A,&B,&C,&K);
	int a=min(K,A);
	ans+=a;K-=a;
	int b=min(K,B);
	K-=b;
	int c=min(K,C);
	ans-=c;K-=c;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int inp[100010][3];

int dp[100010][3];

int solve(int ind, int last) {
    if(ind == -1) return 0;

    if(dp[ind][last] != -1) return dp[ind][last];

    int res = 0;

    for(int i = 0; i < 3; i++) {
        if(i != last) {
            res = max(res, inp[ind][i] + solve(ind-1, i));
        }
    }

    dp[ind][last] = res;
    return res;
}

int main(){


    int n;
    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>inp[i][0]>>inp[i][1]>>inp[i][2];
        dp[i][0] = -1;
        dp[i][1] = -1;
        dp[i][2] = -1;
    }

    int ans = solve(n-2, 0) + inp[n-1][0];
    ans = max(ans, solve(n-2,1) + inp[n-1][1]);
    ans = max(ans, solve(n-2,2) + inp[n-1][2]);

    cout<<ans<<endl;
    


}


Measured memory_bytes: 10368
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const long long lmax=1999999999;
const long long lmx=1999999999999999999;
long long dm,k,d,m,ans,q,n;
string s;
int main(){std::ios::sync_with_stdio(false);
cin>>n;
cin>>s;
cin>>q;
while(q--)
{
	cin>>k;
	dm=d=m=ans=0;
	for(long long i=0;i<n;i++)
	{
		if(s[i]=='C')
		{
			ans+=dm;
		}
		else if(s[i]=='M')
		{
			dm+=d;
			m++;
		}
		else if(s[i]=='D')
		{
			d++;
		}
		if(i+1>=k)
		{
			if(s[i-k+1]=='D')
			{
				dm-=m;
				d--;
			}
			else if(s[i-k+1]=='M')
			{
				m--;
			}
		}
	}
	cout<<ans<<endl;
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 1948
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100010];

int solve() {
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (a[a[i]] == i)
            res++;
    }
    
    return res / 2;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N;
vv<int> A;
int level = 1;

void dfs(int a, int b) {
    if (a + (1 << b) >= N) return;

    int l = b + 1;
    for (int i = a; i < N; i += 1 << b) {
        for (int j = a + (1 << b); j < N; j += 1 << b) {
            A[i][j] = l;
        }
    }

    dfs(a, b + 1);
    dfs(a | (1 << b), b + 1);
}

int main() {
    cin >> N;

    A = vvec(N, N, 0);

    dfs(0, 0);

    rep(i, 0, N - 1) {
        rep(j, i + 1, N) {
            cout << A[i][j] << ' ';
        }
        cout << endl;
    }
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
vector<int> V[MC];
int G[MC];

int dfs(int p , int q){
	int z = 0;
	for(auto u : V[q]){
		if(u == p) continue;
		z ^= dfs(q,u) + 1;
	}
	return z;
}

int main(){
	scanf("%d" , &N);
	repp(i,1,N){
		int x,y;
		scanf("%d%d" , &x , &y);
		V[x].PB(y);
		V[y].PB(x);
	}
	printf("%s\n" , dfs(-1,1) == 0 ? "Bob" : "Alice");
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

void showPq(priority_queue<LL, VEC<LL>, greater<LL>> pq) {
  while (pq.empty() == false) {
    cerr << pq.top() << ", ";
    pq.pop();
  }
  cerr << endl;
}

int main() {
  LL N, K;
  cin >> N >> K;
  VEC<LL> V(N);
  REP(i, 0, N) cin >> V[i];
  LL ma = 0;
  REP(a, 0, K + 1) {
    REP(b, 0, K - a + 1) {
      int size = N;
      int c = K - a - b;
      // DUMP("begin", a, b, c);
      priority_queue<LL, VEC<LL>, greater<LL>> pq;
      LL sum = 0;
      REP(i, 0, a) {
        if (size <= 0) break;
        // DUMP("a   ", V[i]);
        pq.push(V[i]);
        sum += V[i];
        size--;
      }
      REP(i, 0, b) {
        if (size <= 0) break;
        // DUMP("b   ", V[N - i - 1]);
        pq.push(V[N - i - 1]);
        sum += V[N - i - 1];
        size--;
      }
      // showPq(pq);
      REP(i, 0, c) {
        if (pq.empty()) break;
        // DUMP("pq.top   ", pq.top());
        if (pq.top() >= 0) break;
        sum -= pq.top();
        pq.pop();
        size++;
      }
      // DUMP(a, b, c, sum);
      ma = max(ma, sum);
    }
  }
  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a, b;
  double ans;
  scanf("%d\n",&a);
  b = a % 2;
  if(b == 0){
    ans =a / 2;
    ans = ans / a;
  }else{
    ans = a / 2 + 1;
    ans = ans / a;
  }
  printf("%f\n",ans);
  return 0; 
}

Measured memory_bytes: 256
n=int(input())
tbl=[[0 for i in range(2)]for j in range(n)]
for i in range(n):
    var=input()
    var=var.split()
    tbl[i][0]=var[0]
    tbl[i][1]=int(var[1])
for i in range(1,14):
    if((['S',i] in tbl)==False):
        print("S "+str(i))
for i in range(1,14):
    if((['H',i] in tbl)==False):
        print("H "+str(i))
for i in range(1,14):
    if((['C',i] in tbl)==False):
        print("C "+str(i))
for i in range(1,14):
    if((['D',i] in tbl)==False):
        print("D "+str(i))




Measured memory_bytes: 5600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	int a, b, c;
	cin >> a >> b >> c;
	c += (a*100);
	c += (b * 10);
	if (c % 4 == 0)
		puts("YES");
	else
		puts("NO");

	return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;

//非再帰トポロジカルソート 隣接リストを渡す 返り値のサイズがnじゃないならnot DAG
std::vector<ll> topo_sort(std::vector<std::vector<ll>>& graph){
  ll n=graph.size();
  std::vector<ll> ret,num(n,0);
  std::queue<ll> que;
  rep(i,0,n){
    for(ll j:graph[i])num[j]++;
  }
  rep(i,0,n){
    if(num[i]==0)que.push(i);
  }
  while(!que.empty()){
    ll u=que.front();que.pop();
    ret.push_back(u);
    for(ll i:graph[u]){
      num[i]--;
      if(num[i]==0)que.push(i);
    }
  }

  return ret;
}
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m;
  std::cin>>n>>m;
  std::vector<std::vector<ll>> graph(n),graphinv(n);

  rep(i,1,n+m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graphinv[b].push_back(a);
  }

  std::vector<ll> a=topo_sort(graph),ainv(n),ans(n);
  rep(i,0,n)ainv[a[i]]=i;
  ans[a[0]]=0;
  rep(i,1,n){
    ll now=a[i],max=-1;
    for(ll j:graphinv[now]){
      if(ainv[j]>max){
        ans[now]=j;
        max=ainv[j];
      }
    }
    ans[now]++;
  }

  rep(i,0,n)std::cout<<ans[i]<<"\n";
  return 0;
}

Measured memory_bytes: 14184
//--------------------------------------------------------------------------------
// Code By:
//					######                  #               ######
//					##   #                  #               #
//					#####      ##       #####      ##       #   ###
//					##   #              #   #               #   # #
//					##    #	            #####               ##### #
//---------------------------------------------------------------------------------

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

                             /* ----------------------------- START of Template ---------------*/
#define ll long long int
#define FOR(x,to) for(x=0;x<(to);x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<long long int> >
#define vll vector<long long int>
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SZ(X) ((int)(X).size())
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second

void getZarr(string str, vll &Z)
{
    ll n = str.length();
    ll L, R, k;
    L = R = 0;
    for (ll i = 1; i < n; ++i)
    {
        if (i > R)
        {
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else
            {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
   } } }}
vector<ll>isprime;
void seive(ll size){
	isprime.resize(size+1,1);
	ll i,j;
	isprime[0]=0;
	isprime[1]=0;
	for(i=2;i*i<=size;i++){
		if(isprime[i]){
			for(j=2;j*i<=size;j++)isprime[i*j]=0;
		}
	}
}
ll power(ll x,unsigned ll y, ll m){
	if(y==0)return 1;
	ll p=power(x,y/2,m);
	p=(p*p)%m;
	if(y%2!=0)p=(p*x)%m;
	return p;
}
ll modinverse(ll a,ll m){
	return power(a,m-2,m);
}


                       /* ----------------------          End Of Template --------------------------------*/

ll findans(){
	string s;
	cin>>s;
	ll n=s.size(),i,ans=0,cnt=0;
	for(i=0;i<n;i++){
		if(s[i]=='R')cnt++,ans=max(cnt,ans);
		else cnt=0;
	}
	cout<<ans<<endl;
	return 0;


}

int main(){
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t,i;
//	cin>>t;
t=1;
	for(i=0;i<t;i++){
		findans();
	}
return 0;
}





Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, X, T;
	cin >> N >> X >> T;

	if (N % X == 0) {
		cout << N / X * T << endl;
	}
	else
	{
		cout << (N / X + 1) * T << endl;
	}
	return 0;
}


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

int main(void)
{
    string s;

    cin >> s;
    vector<int> ans;

    for(int i = 0; i < s.size(); ++i)
    {
        if(s[i] == '0')
        {
            ans.push_back(0);
        }
        else if(s[i] == '1')
        {
            ans.push_back(1);
        }
        else
        {
            if(ans.size() > 0) ans.pop_back();  
        }
    }

    for(int i = 0; i < ans.size(); ++i)
    {
        cout << ans[i];
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    string s;cin>>s;
    if(s=="RRR") cout<<3<<endl;
    else if(s=="RRS" || s=="SRR") cout<<2<<endl;
    else if(s!="SSS") cout<<1<<endl;
    else cout<<0<<endl;
    
    return 0;
}

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

vector<int> vec;
vector<int> dp(100001,-1);

int back(int i){
    if(i+1==vec.size()-1) return abs(vec[i+1]-vec[i]);
    if(i+2==vec.size()-1) return abs(vec[i+2]-vec[i]);
    if(dp[i]!=-1) return dp[i];
    
    int two=0,one=0;
    if(i+2<vec.size()){
        two= abs(vec[i+2]-vec[i]) + back(i+2);
    }
    if(i+1<vec.size())
        one= abs(vec[i+1]-vec[i]) + back(i+1);
    
    dp[i]=min(one,two);
    return dp[i];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        vec.push_back(a);
    }
    cout<<back(0);
	return 0;
}

Measured memory_bytes: 3576
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    map<ll, ll> m;
    for (int i = 0; i < n; i++)
    {
        ll temp, temp1;
        cin >> temp >> temp1;
        m[temp] += temp1;
    }
    ll sum = 0;
    for (auto x : m)
    {
        //cout << x.first << " " << x.second << "\n";
        sum += x.second;
        if (sum >= k)
        {
            return cout << x.first << "\n", 0;
        }
    }
}


Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(500000)

def dfs(n):
    global N
    if n==0:
        return 0
    if n-1==0:
        return abs(H[n]-H[n-1]) + dfs(n-1)
    if dp[n]!=-1:
        return dp[n]

    ans = 0
    ans = min(abs(H[n]-H[n-1]) + dfs(n-1), abs(H[n]-H[n-2]) + dfs(n-2))
    dp[n] = ans
    return ans

N = int(input())
*H, = map(int, input().split())

dp = [-1]*N

print(dfs(N-1))

Measured memory_bytes: 96688
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e3+7;
ll dp[maxn][maxn];
ll C[maxn][maxn];
ll fac[maxn];
ll inv[maxn][maxn];
ll ivv[maxn];
int n,a,b,c,d;
ll dfs(int cnt,int k)
{
	if(cnt==n) return 1;
	if(k>b) return cnt==n;
	ll &ret=dp[cnt][k];
	if(ret!=-1) return ret;
	ret=0;
	ret=dfs(cnt,k+1);
	for(int i=c;i*k+cnt<=n&&i<=d;i++)
	{
		ret=(ret+dfs(cnt+i*k,k+1)*C[n-cnt][i*k]%mod*fac[i*k]%mod*inv[k][i]%mod*ivv[i]%mod)%mod;
	}
	//dbg(cnt,k,ret);
	return ret;
}
ll invv(ll a,ll b=mod-2)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
int main()
{
	fac[0]=1;
	for(int i=0;i<maxn;i++)
	{
		if(i) fac[i]=fac[i-1]*i%mod;
		C[i][i]=C[i][0]=1;
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	for(int i=1;i<maxn;i++)
	{
		inv[i][0]=1;
		ll tmp=invv(fac[i]);
		ivv[i]=tmp;
		for(int j=1;j<maxn;j++)
			inv[i][j]=inv[i][j-1]*tmp%mod;
	}
	memset(dp,-1,sizeof(dp));
	cin>>n>>a>>b>>c>>d;
	cout<<dfs(0,a)<<endl;
}


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

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{*
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

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

    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end());
    int best = a[0];
    for (int i = 0; i<n; i++) if (min(a[i], a[n-1] - a[i])>min(best, a[n-1]-best)) best = a[i];

    cout<<a[n-1]<<' '<<best;


}


Measured memory_bytes: 3676
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main{
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int n=sc.nextInt();
		int hon=0,pon=0,bon=0;
		if (n%10==2||n%10==4||n%10==5||n%10==7||n%10==9) 
			System.out.println("hon");
		else if(n%10==0||n%10==1||n%10==6||n%10==8)
			System.out.println("pon");
		else if(n%10==3) 
			System.out.println("bon");
		else throw new AssertionError();
		
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 32468
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A, B, C, D; std::cin >> A >> B >> C >> D;
  for(;;) {
    C -= B; if(C <= 0) fin("Yes");
    A -= D; if(A <= 0) fin("No");
  }
  return 0;
}


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


int main()
{
    int X;
    cin >> X;
    if(X >= 2000){
        cout << 1 << endl;
    } else {
        int hundreds = X / 100;
        int underHundreds = X % 100;
        if(underHundreds <= hundreds * 5){
            cout << 1 << endl;
        } else{
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (1010)
#define P (1000000007)
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,jc[N],b[N],s[N],f[N][N],ans;
int calc(int i,int j){
	if(i>j)return 0;
	return j-i+1-s[j]+s[i-1];
}
int main(){
	read(n),read(m),n<<=1,jc[0]=1;
	for(int i=1;i<=m;i++){
		int x,y;
		read(x),read(y);
		b[x]=y,b[y]=x;
		s[x]=s[y]=1;
	}
	for(int i=1;i<=n;i++)s[i]+=s[i-1];
	for(int i=2;i<=n;i++)jc[i]=1ll*(i-1)*jc[i-2]%P;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if((j-i)&1){
				bool fl=0;
		        for(int k=i;k<=j;k++)
				if(b[k]&&(b[k]<i||b[k]>j)){fl=1;break;}
				if(fl)continue;
				f[i][j]=jc[calc(i,j)];
		        for(int k=i+1;k<j;k++)
				f[i][j]=(f[i][j]-1ll*f[i][k]*jc[calc(k+1,j)]%P+P)%P;
				ans=(ans+1ll*f[i][j]*jc[calc(1,i-1)+calc(j+1,n)]%P)%P;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main() {
    // insert code here...
    int a,b;
    string str,k; 
    
    while (true) {

        cin>>str;
        if(str=="-")break;
        cin>>a;
        for (int i=0; i<a; i++) {
            cin>>b;
            k=str.substr(0,b);
            str += k; 
            str.erase(0,b);
        }
        cout << str << endl;
    }
           
    return 0;
}



Measured memory_bytes: 3192
#include<iostream>

using namespace std;

int main()
{
	int tri[31]={1,1,2};
	for(int i=3;i<=30;i++)	tri[i]=tri[i-1]+tri[i-2]+tri[i-3];

	for(int n;cin>>n,n;)
		cout<<(tri[n]+3650)/3650<<endl;

	return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int not_prime[1000000001];

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    vector<int> ans;
    cin >> n;
    cout << n << ":";
    int i = 2, rt = sqrt(n);
    while(n != 1 && i <= rt){
        if(not_prime[i]){
            i++;
            continue;
        }
        int j = i;
        while(j <= rt){
            not_prime[j] = 1;
            j += i;
        }

        while(n % i == 0){
            n /= i;
            cout << " " << i;
        }

        i++;
    }
    if(n != 1){
        cout << " " << n;
    }
    cout << endl;
}



Measured memory_bytes: 3268
# 089A

# N人(数値）：標準入力
N = int(input())

# N人の生徒たちを上手く分けて、3人以上の数を最大化する
# N人を3で除法した数値を出力する
# 除法の解の小数点以下を切り捨て

print(int( N / 3 ))

Measured memory_bytes: 8908