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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

	ll cost = 0;

	if (2 * C < A + B) {
		ll total = min(X, Y);
		cost += 2 * C * total;
		X -= total;
		Y -= total;
	}

	if (X > 0) {
		cost += X * min(A, 2 * C);
		X = 0;
	}

	if (Y > 0) {
		cost += Y * min(B, 2 * C);
		Y = 0;
	}

	print(cost);
}

Measured memory_bytes: 256
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

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

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    int temp = __gcd(i, j);
                    sum += __gcd(temp, k);
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;
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);}

int main(){
  ll n; cin>>n;
  cout<<n*(n-1)/2<<endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,M[105][105];
int prim(){
  int u,minv;
  int d[105],p[105],color[105];
  for(int i=0;i<n;i++){
    d[i]=1234567890;
    p[i]=-1;
    color[i] = 0;
  }
  d[0]=0;
  while(1){
    minv = 1234567890;
    u = -1;
    for(int i=0;i<n;i++){
      if(minv > d[i] && color[i]!=2){
	u=i;
	minv = d[i];
      }
    }
    if(u==-1)break;
    color[u]=2;
    for(int v=0;v<n;v++){
      if(color[v]!=2&&M[u][v]!=1234567890){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=1;
	}
      }
    }
  }
  int sum = 0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}
int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin >> e;
      M[i][j]=(e==-1)? 1234567890 : e;
    }
  }
  cout << prim() << endl;
  return 0;
}

Measured memory_bytes: 3088
// ABC157E - Simple String Queries

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

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

	vector< set<int> > alpha(26);

	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		alpha[c - 'a'].insert(i + 1);
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int op;
		cin >> op;
		if (op == 1) {
			int iq;
			char cq;
			cin >> iq >> cq;

			for (int j = 0; j < 26; j++) {
				alpha[j].erase(iq);
			}
			alpha[cq - 'a'].insert(iq);
		} else if (op == 2) {
			int l, r;
			cin >> l >> r;

			int answer = 0;
			for (int j = 0; j < 26; j++) {
				set<int>::iterator it;
				it = alpha[j].lower_bound(l);
				if ((it != alpha[j].end())&&(*it <= r)) {
					answer++;
				};
			}
			cout << answer << endl;
		}
	}
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
//------------------------------------------------------------
string s,t;

void solve() {
  cin>>s>>t;
  bool bl=true;

  int ss=s.size(); int ts=t.size();

  if (ss<ts) {print("UNRESTORABLE");return;}

  // 辞書順にするためにreverse
  reverse(all(s));
  reverse(all(t));

  // s中のtを見つける
  rep(i,0,ss-ts+1)
  {
    bl=true;
    rep(j,0,ts)
    {
      if(s[i+j]!='?' && s[i+j]!=t[j]) //tはs内に存在しない
      {bl=false; break;}
    }
    if(bl)
    {
      // s内のtへの書き換え
      rep(k,0,ts) s[i+k]=t[k];
      break;
    }
  }

  if(!bl) {print("UNRESTORABLE");return;}

  rep(i,0,ss) if(s[i]=='?') s[i]='a';

  reverse(all(s));

  print(s);  return;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			
			if(H==0&&W==0) {
				break;
			}
			for(int a=0;a<H;a++) {
				for(int b=0;b<W;b++) {
					System.out.print("#");
				}
					System.out.println();
		}
			System.out.println();
		}
	
	}
}



Measured memory_bytes: 37248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    int n,a,b;
    int c1=0,c2=0;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i]=='c'){
            cout<<"No"<<endl;
        }else if(s[i]=='a'&&a+b>c1+c2){
            c1++;
            cout<<"Yes"<<endl;
        }else if(s[i]=='b'&&a+b>c1+c2&&b>c2){
            c2++;
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[n], b[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> b[i];
  }

  long long int sum_a = 0, sum_b = 0;
  for(int i = 0; i < n; i++) {
    sum_a += a[i];
    sum_b += b[i];
  }
  long long int t = sum_b - sum_a;
  long long int t_a = 0;
  long long int t_b = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] < b[i]) {
      t_a += (b[i] - a[i] + 1) / 2;
    }
    else if(a[i] > b[i]) {
      t_b += a[i] - b[i];
    }
  }
  if(t >= t_a && t >= t_b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int dp[2100][2100];

int main() {
	int N;
	cin >> N;
	vector<int> wpos(N), bpos(N);
	for (int i = 0; i < N * 2; ++i) {
		char c; int x;
		cin >> c >> x;
		if (c == 'W') wpos[x - 1] = i;
		else          bpos[x - 1] = i;
	}

	// (B, i) の前に (B, iより大きい) + (W, j以上) が何個あるか
	vector<vector<int> > black(N, vector<int>(N + 1));
	vector<vector<int> > white(N, vector<int>(N + 1));

	for (int i = 0; i < N; ++i) {
		// (B, i) の前に (B, iより大きい) が何個あるか
		for (int j = i + 1; j < N; j++) {
			if (bpos[j] < bpos[i]) black[i][N]++;
			if (wpos[j] < wpos[i]) white[i][N]++;
		}
		// (B, i) の前に (W, j以上) が何個あるか
		for (int j = N - 1; j >= 0; j--) {
			int c1 = 0, c2 = 0;
			if (wpos[j] < bpos[i]) ++c1;
			if (bpos[j] < wpos[i]) ++c2;
			black[i][j] = black[i][j + 1] + c1;
			white[i][j] = white[i][j + 1] + c2;
		}
	}

	for (int i = 0; i < 2100; ++i) for (int j = 0; j < 2100; ++j) dp[i][j] = INF32;
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N; ++j) {
			if (i < N) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + black[i][j]);
			if (j < N) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + white[j][i]);
		}
	}
	cout << dp[N][N] << endl;
}


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

int main(){
    double r,s,l,pi;
    pi = 3.141592653589793;
    cin >> r;
    cout << fixed << setprecision(6) << pi*r*r << " " << pi*r*2 << endl;
    return 0;
}


Measured memory_bytes: 3276
x = input().split()
fn = 0
sn = 0
 
for i in range(len(x)):
  if int(x[i]) == 5:
    fn += 1
  elif int(x[i]) == 7:
    sn += 1
 
if fn == 2:
  if sn == 1:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 8972
A,B,C,D = map(int,input().split())

while A > 0 and C > 0:
#高橋くん攻撃！
	C = C - B
	if C <=0:
		print("Yes")
		break
#青木くんの攻撃！
	A = A - D
	if A <=0:
		print("No")
		break

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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    //
    //  スイッチの状態を全探索
    //

    int ans = 0;
    vector<set<int>> ccond;   // 電球のスイッチ接続条件
    vector<int> parr;         // スイッチの個数のparity

    for (int i = 0; i < M; i++) {
        int n;
        cin >> n;
        set<int> tarr;
        for (int j = 0; j < n; j++) {
            int k;
            cin >> k;
            tarr.insert(k);
        }
        ccond.push_back(tarr);
    }

    for (int k = 0; k < M; k++) {
        int c;
        cin >> c;
        parr.push_back(c);
    }

    for (int i = 0; i < (1 << N); i++) {
        //  i が スイッチの状態
        //  これをbit列として扱い、スイッチの状態と見做す
        int cur_switch = i;

        //
        //   電球毎に調べる
        //
        int num_on = 0;
        for (int j = 0; j < ccond.size(); j++) {
            set<int> cur_cond = ccond[j];  // 現在の電球の条件
            int curp = parr[j];  // スイッチの個数のparity
            int num = 0;  //  電球が点灯した数

            //
            //   現在のスイッチの状態のbitを調べる
            //
            for (int k = 0; k < N; k++) {
                //
                //  k bit目が立っているか？
                //  ここが bit 全探索のキモ
                //
                //  k bit目が立っている場合
                //  switch on と見做す
                //
                if (cur_switch & (1 << k)) {
                    //
                    //  k番目がONで、現在の電球に
                    //  繋がっている
                    //
                    if (cur_cond.find(k + 1) != cur_cond.end()) {
                        num++;
                    }
                }
            }
            if (num % 2 == curp) {
                num_on++;
            }
        }
        if (num_on == M) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


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

#define int long long
#define all(V) (V).begin(),(V).end()
#define umap unordered_map
#define uset unordered_set
#define br cout<<"\n";

const int MAXN=1e5+10, MOD=1e9+7;
int n,m;
int arr[MAXN];
int t[5*MAXN],lazy[5*MAXN];

int doit(int a,int b){
	return min(a,b);
}

void build(int start,int end,int index=1){
	if(start==end){
		t[index]=INT_MAX;
		return ;
	}
	int mid = start+end >> 1;
	build(start,mid,index << 1);
	build(mid+1,end,index<<1|1);
	t[index] = doit(t[index<<1], t[index<<1|1]);
}

void propagate(int start,int end,int index){
	t[index] = lazy[index];
	// bcz leaf not hv childs
	if(start!=end){
		lazy[index<<1] = lazy[index];
		lazy[index<<1|1] = lazy[index];
	}
	lazy[index]=-1;
}

int Query(int start,int end,int l,int r,int index=1){

	if(lazy[index]!=-1){
		propagate(start,end,index);
	}
	// out range
	if(r<start or end<l){
		return INT_MAX;
	}
	// in Raange
	if( l<=start and end<=r){
		return t[index];
	}
	int mid = start+end >>1;
	return doit(Query(start,mid,l,r,index<<1), Query(mid+1,end,l,r,index<<1|1));
}

void pUpdate(int start,int end,int point,int val,int index=1){
	if(start==end){
		t[index]=val;
		return ;
	}
	int mid = start+end>>1;
	if(point <= mid){
		pUpdate(start,mid,point,val,index<<1);
	}
	else{
		pUpdate(mid+1,end,point,val,index<<1|1);
	}
	t[index] = doit(t[index <<  1] , t[index << 1 | 1]);
}


void rangeUpdate(int start,int end,int l,int r,int val,int index){
	if(lazy[index]!= -1){
		propagate(start,end,index);
	}
	if(l>end or r<start){
		return;
	}
	// in range
	if(l<=start and end<=r){
		lazy[index]=val;
		propagate(start,end,index);
		return;
	}
	int mid = start+end>>1;
	rangeUpdate(start,mid,l,r,val,index<<1);
	rangeUpdate(mid+1,end,l,r,val,index<<1|1);
	t[index] = doit(t[index<<1],t[index<<1|1]);
}




signed main()
{
// 	#ifndef ONLINE_JUDGE
// 		freopen("./input.txt","r",stdin);
// 		freopen("./output.txt","w",stdout);
// 	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n>>m;
	memset(lazy,-1,sizeof lazy);
	build(0,n-1);
	for(int i=1; i<=m; i++){
		int q; cin>>q;
		if(q==1){
			int s,t; cin>>s>>t;
			cout<<Query(0,n-1,s,t,1); br;
		}
		else{
			int s,t,x; cin>>s>>t>>x;
			rangeUpdate(0,n-1,s,t,x,1);
		}
	}	

}


Measured memory_bytes: 9184
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 500005;
const int K = 20;
vector < int > g[N];
int b[N], a[N], dp[N], l[N], r[N], s[N];
int dfs(int v, int d, int p){
    s[v] = a[v] * d;
    int t = 0;
    int mx = 0;
    b[v] = a[v];
    for (auto u: g[v]){
        if (u == p) continue;
        s[v] += dfs(u, d + 1, v);
        b[v] += b[u];
        t += l[u] + b[u];
        r[v] += r[u] + b[u];
        mx = max(mx, l[u] + b[u]);
    }
    if (2 * mx > t){
        int s1 = 0;
        for (auto u: g[v]){
            if (u == p) continue;
            if (l[u] + b[u] == mx) continue;
            s1 += r[u] + b[u];
        }
        if (mx > s1) l[v] = mx - s1;
        else l[v] = t % 2;
    } else{
        l[v] = t % 2;
    }
    return s[v];
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans = 1e9;
    for (int i = 0; i < n; i++) a[i + 1] = s[i] - '0';
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            dp[j] = 0;
            b[j] = 0;
            s[j] = 0;
            r[j] = 0;
            l[j] = 0;
        }
        int c = dfs(i, 0, -1);
        if (l[i] == 0){
            ans = min(ans, c / 2);
        }
    }
    if (ans == 1e9){
        cout << -1;
    } else{
        cout << ans;
    }
}


Measured memory_bytes: 21888
MOD = 10 ** 9 + 7


def main(N, K):
  W = []
  i = 1
  while i <= N:
    v = N // i
    j = N // v
    # keys.append((v, j - i + 1))
    W.append(j - i + 1)
    i += j - i + 1

  l = len(W)
  dp = [0] * l

  total = 0
  for i, w in enumerate(W):
    total += w
    dp[l - i - 1] = total

  for i in range(2, K + 1):
    tmp = [0] * l
    total = 0
    for j, w in enumerate(W):
      v = dp[j] * w
      total += v
      total %= MOD
      tmp[l - j - 1] = total

    dp = tmp

  return dp[0]


if __name__ == '__main__':
  N, K = map(int, input().strip().split())
  # import time
  # t = time.time()
  print(main(N, K))
  # print(time.time() - t)

Measured memory_bytes: 8772
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}


int main()
{
  int n,m;
  while(cin>>n>>m,n)
  {
    vector<int> a(n,1);
    int cnt = 0, p=0;
    while(cnt!=n)
    {
      REP(i,m) while(!a[++p%n]){}
      a[p%=n]=0;cnt++;
    }
    cout<<(p==0?n:p)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3104
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, A[101010];

int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    for (int j = 0; j < N; ++j) { cin >> A[j]; }

    sort(A, A+N);

    int it = lower_bound(A, A+N-1, A[N-1]/2) - A;
    if (it == N-1) --it;
    if (it > 0 && abs(A[N-1] - A[it] - A[N-1]/2.0) > abs(A[N-1] - A[it-1] - A[N-1]/2.0)) {
        --it;
    }

    cout << A[N-1] << " " << A[it] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int n, m;

int nowt = 0;
long long ans = 0;

int main(){
  scanf("%d%d", &n, &m);
  
  int sum[n];
  sum[0] = 0;
  
  for(int i = 1; i < n; i++){
    scanf("%d", &sum[i]);
    sum[i] += sum[i - 1];
  }
  
  for(int i = 0; i < m; i++){
    int ai;
    scanf("%d", &ai);
    if(ai > 0){
      ans += sum[nowt + ai] - sum[nowt];
    }else{
      ans += sum[nowt] - sum[nowt + ai];
    }
    nowt += ai;
    ans = ans % 100000;
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 1412
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

vector<ll> fact;

void init(ll N){
  fact.resize(N+1);
  fact[0]=1;
  for(ll i = 0; i < N; i++)  fact[i+1]=((i+1)*fact[i])%lmod;
}

ll ppow(ll a,ll b){
  // aのb乗を求める
  ll res = 1;
  while(b){
    if(b%2) res=(res*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return res;
}

ll imod(ll n){
  // nのmodの逆元を求める
  ll P=mod;
  return ppow(n,P-2);
}

ll comb_mod(ll n,ll k){
  //nまで埋めた階乗テーブルを渡す
  if(k>n) return 0LL;
  else return (fact[n] * imod(fact[k]) % mod) * imod(fact[n-k]) % mod ;
  //nCk % mod を返す
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M; cin >> N >> M ;
  init(ll(2e5+1));
  int sq = ll(sqrt(M));
  vector<bool> vec(sq+2,true);
  ll ans = 1LL;
  dump(sq);
  REP(x,2,sq+2){
    if(!vec[x]) continue;
    if(M%ll(x)!=0LL) continue;
    for(int y = x; y <= sq+1; y += x) vec[y] = false;
    ll cnt = 0;
    while(M%ll(x)==0LL){
      cnt++; M /= x;
    }
    (ans *= comb_mod(N+cnt-1,cnt)) %= lmod; // nHk
    dump(ans,x,cnt,M);
  }
  if(M!=1LL) (ans *= N) %= lmod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,ma=-1,minp;
  cin >> N;
  rep(i,N){
    ll A,B;
    cin >> A >> B;
    if(A>ma){
      ma=A;
      minp=B;
    }
  }
  cout << ma + minp << endl;
}

Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, T = in.next().toInt
  val _hoge = new Array[(Int, Int)](N)
  for (i <- 0 until N) {
    val a, b = in.next().toInt
    _hoge(i) = (-a, b)
  }
  val hoge = _hoge.sorted


  val A = new Array[Int](N+1)
  val B = new Array[Int](N+1)
  for (i <- 1 to N) {
    val (a, b) = hoge(i-1)
    A(i) = -a
    B(i) = b
  }

  // 
  val dp = Array.fill[Int](T)(-1)
  dp(0) = 0

  for (k <- 1 to N) {
    val t = A(k)
    val score = B(k)

    for (i <- (0 until T - t).reverse) {
      if(dp(i) != -1) {
        dp(i+t) = Math.max(dp(i+t), dp(i) + score)
      }
    }

    dp(0) = Math.max(dp(0), score)
  }


  println(dp.max)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

int main(){

  int d;

  while(cin >>d){
    int sum=0;
  for(int i=1;i<600/d ;i++){
    sum+=(i*d)*(i*d)*d;
  }
  cout <<sum <<endl;
}
}



Measured memory_bytes: 2988
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val word = sc.next

    def go(n: Int): Int ={
      if (n % 2 == 0 & word.slice(0, n / 2) == word.slice(n / 2, n)) n
      else go(n - 1)
    }
    println(go(word.length - 1))
  }
}


Measured memory_bytes: 25540
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll k, a, b;
  cin >> k >> a >> b;

  ll qua = b / k;
  ll test = qua * k;
  if (test < a)
    puts("NG");
  else
    puts("OK");

  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main(void)
{
    int n,i=0;
    cin>>n;
    if(100<=n&&n<=111)
    i=111;
    
    if(112<=n&&n<=222)
    i=222;
    
    if(223<=n&&n<=333)
    i=333;
    
    if(334<=n&&n<=444)
    i=444;
    
    if(445<=n&&n<=555)
    i=555;
    
    if(556<=n&&n<=666)
    i=666;
    
    if(667<=n&&n<=777)
    i=777;
    
    if(778<=n&&n<=888)
    i=888;
    
    if(889<=n&&n<=999)
    i=999;
    cout<<i<<endl;
    return 0;
}


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

public class Prog
{
    public void run()
    {
        var input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        int L;
        int R;
        int min = 0;
        int max = N;
        for (int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split();
            L = int.Parse(input[0]);
            R = int.Parse(input[1]);
            if (L > min)
            {
                min = L;
            }
            if (R < max)
            {
                max = R;
            }
        }
        int ans = max - min + 1;
        if(ans < 0)
        {
            ans = 0;
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var prog = new Prog();
        prog.run();
    }
}

//Array.ConvertAll(int.Parse)

Measured memory_bytes: 15180
#include<set>
#include<iostream>
using namespace std;
int	main(){

	/*int W;
	cin >> W;
	cout << 32*W << endl;*/

	int H,R;
	cin >> H >> R;

	if(H + R == 0){
		cout << "0" << endl;
	}

	else if(H + R > 0){
		cout << "1" << endl;
	}

	else {
		cout << "-1" << endl;
	}

}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, a[100], b[100], c[100];

int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	REP(i, n) cin >> b[i];
	REP(i, n - 1)cin >> c[i];
	ll ans = 0;
	REP(i, n) {
		ans += b[a[i] - 1];
	}
	REP(i, n - 1) {
		if (a[i + 1] - a[i] == 1) ans += c[a[i] - 1];
	}
	cout << ans << endl;
}
	


Measured memory_bytes: 256
n, k = map(int, input().split())
c = 10**9+7
a = k*(k-1)//2
b = n*(n+1)//2 - (n-k)*(n+1-k)//2
t = b-a+1
ans = t%c
for i in range(k, n+1):
    t += n-i - i
    ans = (ans+t)%c
print(ans)

Measured memory_bytes: 9128
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(input())
X = inpl()
Y = [[x, i] for i, x in enumerate(X)]
Y = sorted(Y)
if (N-1)%2==1:
    l = Y[(N-1)//2][0]
    r = Y[(N-1)//2+1][0]
    for i in range(N):
        if X[i]<=l:
            print(r)
        else:
            print(l)

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int A, B, N;
string S, T;

int main(){
    cin >> N >> S >> T;
    REP(i, N){
        cout << S[i] << T[i];
    }
    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double

using namespace std;

int n, q, k, used[100100];
ll dp[100100];
vector<pii> g[100100];
set<pair<ll, int> > sett;
const ll inf = (ll)1e18;

int main() {
	scanf("%d", &n);
	for(int i = 1, u, v, w; i <= n - 1; i++) {
		scanf("%d%d%d", &u, &v, &w);
		g[u].pb(mp(v, w));
		g[v].pb(mp(u, w));
	}
	scanf("%d%d", &q, &k);

	cerr << q << " " << k << endl;
	
	for(int i = 1; i <= n; i++) dp[i] = inf;
	dp[k] = 0;
	sett.insert(mp(0, k));
	while(!sett.empty()) {
		pair<ll, int> p = *sett.begin();
		sett.erase(sett.begin());
		int v = p.s;
		for(int i = 0; i < g[v].sz; i++) {
			int to = g[v][i].f;
			ll w = g[v][i].s;
			if(dp[to] > dp[v] + w) {
				sett.erase(mp(dp[to], to));
				dp[to] = dp[v] + w;
				sett.insert(mp(dp[to], to));
			}
		}
	}
	
	for(int i = 1; i <= n; i++) {
		cerr << dp[i] << endl;
	}
	cerr << endl;

	for(int i = 1, x, y; i <= q; i++) {
		scanf("%d%d", &x, &y);
		printf("%lld\n", dp[x] + dp[y]);
	}

	return 0;
}

Measured memory_bytes: 14580
# Template 1.0
import sys, re
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor, trunc, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b = map(str, input().split())

u,v = MAP()

z = input()

if(z==a):
    print(u-1, v)
else:
    print(u, v-1)

Measured memory_bytes: 76548
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
  int index = 1;
  while (true) {
    int W;
    scanf("%d ", &W);
    if (W == 0) {
      break;
    }
    int N;
    scanf("%d ", &N);
    vector<int> dp(W + 1, -1);
    for (int i = 0; i < N; i++) {
      int value, weight;
      scanf("%d,%d ", &value, &weight);
      //printf("%d,%d\n", value, weight);

      for (int j = W; j >= 0; j--) {
	if (dp[j] >= 0 && j + weight <= W) {
	  dp[weight + j] = max(dp[weight + j], dp[j] + value);
	}
      }
      dp[weight] = max(dp[weight], value);
      /*for (int i = 0; i <= W; i++) {
	if (dp[i] >= 0) {
	  printf("dp:%d, %d\n", i, dp[i]);
	}
      }
      printf("\n");*/
    }
    int max_weight = 0, max_value = -1;
    for (int i = 0; i <= W; i++) {
      if (max_value < dp[i]) {
	max_weight = i;
	max_value = dp[i];
      }
    }
    printf("Case %d:\n%d\n%d\n", index++, max_value, max_weight);
  }
  return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int L = -1, R = 1e6;
    REP(i, m) {
        int l, r;
        cin >> l >> r;
        L = max(l, L);
        R = min(r, R);
    }
    int ans = max(0, R - L + 1);
    cout << ans << endl;
}


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

using namespace std;

int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> points(N, K-Q);
    for (int i = 0; i < Q; ++i) {
        int A;
        cin >> A;
        points[A-1] += 1;
    }
    for (int i = 0; i < N; i++)
    {
        if (points[i] > 0) cout << "Yes"<<"\n";
        else cout <<"No"<<"\n";
    }
 }






Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
	int n, s, t, M, m, h;
	while(1){
		cin >> n;
		if(not n) break;
		t = 0;
		M = 0;
		m = 1001;
		for (int i = 0; i < n; ++i){
			cin >> s;
			t += s;
			M = max(M, s);
			m = min(m, s);
		}
		cout << (t-M-m) / (n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
import sys
sys.setrecursionlimit(10 ** 7)

MOD = 10**9 + 7
N, K = map(int,input().split())

edge = [[] for _ in range(N)]

for _ in range(N-1) :
    fromNode, toNode = map(int,input().split())

    fromNode -= 1
    toNode -= 1

    edge[fromNode].append(toNode)
    edge[toNode].append(fromNode)

# 深さ優先探索
def bfs(nowNode, fromNode) :
    colorNum = K  # 使用可能な色の数
    if fromNode == -1 :  # 根の場合
        colorNum -= 1
    else :
        colorNum -= 2

    if len(edge[nowNode]) - 1 > K :  # つながっている頂点数 - 1(親) == K までOK
        return 0

    caseNum = 1
    for nextNode in edge[nowNode] :
        if nextNode == fromNode :
            continue
        caseNum *= colorNum
        colorNum -= 1
        caseNum = caseNum % MOD

    for nextNode in edge[nowNode] :
        if nextNode == fromNode :
            continue
        caseNum *= bfs(nextNode, nowNode)
        caseNum = caseNum % MOD

    return caseNum

ans = bfs(0, - 1) * K
ans = ans % MOD
print(ans)



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

int main() {
  int N;
  cin >> N;
  int a[100100];
  for (int i = 1; i <= N; i++) cin >> a[i];

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int j = a[i];
    if (i < j && a[j] == i) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,Q;
  cin >> N >> Q;
  map<int,int> mp_H,mp_W;
  int mn_H=N,mn_W=N;
  set<int> se_H,se_W;
  while(Q--){
    int id;
    int x;
    cin >> id >> x;
    mp_H[N] = N;
    mp_W[N] = N;
    if(id == 2){
      if(chmin(mn_W,x)){
        mp_W[mn_W] = mn_H;
      }
      se_W.emplace(x);
    }else{
      if(chmin(mn_H,x)){
        mp_H[mn_H] = mn_W;
      }
      se_H.emplace(x);
    }
  }
  ll sum = (ll)(N-2)*(N-2);
  // cout << "\n";
  int now = mn_W;
  for(auto m: mp_H){
    while(se_H.size() && *se_H.begin() < m.first){
      // cout << *se_H.begin() << " " << m.second << "\n";
      se_H.erase(*se_H.begin());
      sum -= now-2;
    }
    if(se_H.size()){
      now = m.second;
      sum -= now-2;
      se_H.erase(*se_H.begin());
    }
  }
  // cout << "\n";
  for(auto m: mp_W){
    while(se_W.size() && *se_W.begin() < m.first){
      // cout << *se_W.begin() << " " << m.second << "\n";
      se_W.erase(*se_W.begin());
      sum -= now-2;
    }
    if(se_W.size()){
      now = m.second;
      sum -= now-2;
      se_W.erase(*se_W.begin());
    }
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 22252
w,a,b = map(int,input().split())
if a > b :
    if a - (b+w) >= 0 : print("{}".format(a - b - w))
    else : print(0)
else :
    if b - (a+w) >= 0 : print("{}".format(b - a -w))
    else : print(0)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int n, k, r, i;
  string s;
  cin >> n >> k;
  i = 0;
  while (n!=0) {
    r = n%k;
    n = n/k;
    i++;
  }
  cout << i << endl;
  return(0);
}



Measured memory_bytes: 256
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(n):
    l.append([a[i], i + 1])

ls = sorted(l)
for i in range(n):
    print(ls[i][1], end='')
    if i < n - 1:
        print(' ', end='')
print()


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while(true)
    {
        string x; cin >> x;
        if(x == "0") break;
        int ans = 0;
        REP(i, x.length())
        {
            ans += x[i]-'0';
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3184
from itertools import product

n = int(input())

digit = len(str(n))

cnt = 0
for d in range(3, digit+1):
    gen = product(["7", "5", "3"], repeat=d)
    for gen_num in gen:
        s = "".join(gen_num)
        if "7" not in s:
            continue
        if "5" not in s:
            continue
        if "3" not in s:
            continue
        if int(s) > n:
            continue
        cnt += 1
print(cnt)

Measured memory_bytes: 43248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    ll X;
    cin >> X;
    
    ld A = 100.0;
    int ans = 0;
    ll B = (ll)A;
    
    while ((ll)(A) < X) {
        A *= 1.01;
        B = (ll)A;
        A = (ld)(B);
        ans++;
    }
    cout << ans << endl;
    

    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;


int main() {
    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) return 0;
        if (a > b) swap(a, b);
        printf("%d %d\n", a, b);

    }
}


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

int main(){
  int N;
  cin>>N;
  vector<int64_t> ryuka(87);
  ryuka.at(0)=2ll;
  ryuka.at(1)=1ll;
  for(int i=2;i<=N;i++){
    ryuka.at(i)=ryuka.at(i-2)+ryuka.at(i-1);
  }
  printf("%lld\n", ryuka.at(N));
    
}

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

int main()
{
  // 入力
  string s;
  cin >> s;
  
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'o') {
      count++;
    }
  }
  
  // 出力
  if (count + (15 - s.size()) >= 8)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

}


Measured memory_bytes: 256