akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node
{
	int key;
	Node *next;
	Node *prev;
};

Node *nil;

void init()
{
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key)
{
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;

	nil->next->prev = x;
	x->next = nil->next;
	x->prev = nil;
	nil->next = x;
}

void deleteNode(Node *t)
{
	if (t == nil) return;
	t->next->prev = t->prev;
	t->prev->next = t->next;
	free(t);
}

void deleteFirst()
{
	deleteNode(nil->next);
}

void deleteLast()
{
	deleteNode(nil->prev);
}

Node *listSearch(int key)
{
	Node *cur = nil->next;
	while (cur != nil && cur->key != key)
	{
		cur = cur->next;
	}
	return cur;
}

void deleteKey(int key)
{
	deleteNode(listSearch(key));
}

/*
0 1 2 3 4(改行)
*/
void printList()
{
	Node *cur = nil->next;
	int isF = 0;
	while (cur != nil)
	{
		if (isF++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

/*
insert x	: 連結リストの先頭にキー x を持つ要素を継ぎ足す。
delete x	: キー x を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
deleteFirst	: リストの先頭の要素を削除する。
deleteLast	: リストの末尾の要素を削除する。
*/
int main()
{
	init();

	int n;
	scanf("%d", &n);

	char com[20];
	int key;
	for (int i = 0; i < n; i++)
	{
		scanf("%s%d", com, &key);
		if (com[0] == 'i')
		{
			insert(key);
		}
		else
		{
			if (strlen(com) == 6)
			{
				deleteKey(key);
			}
			else if (com[6] == 'F')
			{
				deleteFirst();
			}
			else
			{
				deleteLast();
			}
		}
	}
	printList();
}


Measured memory_bytes: 33824
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll ;
const int maxn=101,maxw=1e5+1;
ll dp[maxn][maxw];
int main (){
    int n,w;
    cin>>n>>w;
    ll v[n],a[n];
    for(int i=0;i<n;i++)cin>>a[i]>>v[i];
    //
    for(int i=1;i<=n;i++){
    	for(int j=0;j<=w;j++){	if(a[i-1]<=j)dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1]]+v[i-1]);
    	else dp[i][j]=dp[i-1][j];
    	}
    }
    cout<<dp[n][w];
    return 0;
}


Measured memory_bytes: 78336
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n, x;
        n = sc.nextInt();
        for(int i=1;i<=n;i++){
            x = i;
            if(i%3 == 0){
                System.out.print(" " + i);
                continue;
            }
            while(true){
                if(x%10 == 3){
                    System.out.print(" " + i);
                    break;
                }
                x /= 10;
                if(x<1) break;
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 28796
#include <stdio.h>
#include <math.h>
int main(){
  int n,ans,i,j;
  while(scanf("%d",&n)!=EOF){
    int pn[n];
    ans=0;
    for(i=0;i<n;i++){
      pn[i]=1;
    }
    for(i=2;i<=sqrt(n);i++){
      if(pn[i-1]){
	for(j=2;i*j<=n;j++){
	  pn[i*j-1]=0;
	}
      }
    }
    for(i=1;i<n;i++){
      if(pn[i]==1)ans++;
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 4500
#include <stdio.h>

int main(void)
{
        int n,a,i,j,s=0;

        scanf("%d",&n);

        //if (n>200)    return 1;

        for(i=1;i<=n;i++){
                a=0;
                for (j=1; j<=i;j++){
                        if ((i%2==1)&&(i%j==0))
                                a++;
                }
                if(a==8)
                        s++;
        }

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

        return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	private static int[] j={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k=sc.nextInt();
		System.out.println(j[k-1]);
	}

}


Measured memory_bytes: 20948
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  ll n_sqrt = sqrt(n);
  for (; n_sqrt > 0; n_sqrt--) {
    if (n % n_sqrt == 0) {
      cout << n_sqrt + (n / n_sqrt) - 2 << endl;

      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct{
	long *A;
	long n;
}heap;

int p(int i){return (i/2);}
int l(int i){return (2*i);}
int r(int i){return (2*i+1);}

void maxHeapify(heap *H,long i){
	long *A;
	long n,largest,temp;
	A=H->A;n=H->n;
	if(l(i)<=n && A[l(i)] > A[i]){
		largest = l(i);
	}else{
		largest = i;
	}
	if(r(i)<=n && A[r(i)] > A[largest]){
		largest = r(i);
	}
	if(largest!=i){
		temp=A[i];A[i]=A[largest];A[largest]=temp;
		maxHeapify(H,largest);
	}
}

void buildMaxHeap(heap *H){
	long i;
	for(i=H->n/2;i>=1;i--){
		maxHeapify(H,i);
	}
}

main(){
	long n,i,m;
	heap *H;
	scanf("%ld",&n);
	mymalloc(H,1);
	H->n=n;
	mymalloc(H->A,n+1);
	for(i=1;i<=n;i++){
		scanf(" %ld",&m);
		H->A[i]=m;
	}
	buildMaxHeap(H);
	for(i=1;i<=n;i++){
		printf(" %ld",H->A[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 4508
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        out.println(Math.min(Math.min(a+b,b+c),a+c));
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21204
use proconio::input;
use proconio::marker::{Chars};
use std::iter::Iterator;
use std::collections::HashSet;

fn main() {
    input! {
    a: f64,
    b: f64,
    h: f64,
    m: f64,
    }


    //間の角度
    let mut rad = (30.0 * h + 0.5 * m) - 6.0 * m;

    let radian = (rad as f64) * std::f64::consts::PI / 180_f64; 

    let ans = (((a * a) + (b * b)) - (2.0 * a * b * radian.cos())).sqrt();

    //ルート（a*a* + b*b -2a*b*cosA）


     println!("{}", ans);
}


Measured memory_bytes: 2988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        while(true){
            String data[] = reader.readLine().split(" ");
            int a= Integer.parseInt(data[0]);
            int b= Integer.parseInt(data[1]);
            if(a==0 && b==0)
                break;
             
            builder.append(Integer.toString(a<b?a:b)).append(" ").append(Integer.toString(a<b?b:a)).append("\n");
        }
        System.out.print(builder);
    }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    string S, T;
    cin >> S >> T;
    sort(S.begin(), S.end());
    sort(T.begin(), T.end(), greater<char>());

    bool ok = (S < T);
    cout << (ok ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

string s;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> s;

    for(int i=0; i < s.size(); ++i) {
        if(s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

#define int long long

using namespace std;

const int MAXN = 1010;

int N, M;

vector<pair<int,int>> L[MAXN*MAXN];

char A[MAXN][MAXN];

int f(int x, int y)
{
	return (x-1)*M + y;
}

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

int D[MAXN*MAXN];

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

    cin >> N >> M;

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    for(int i = 1 ; i <= N ; i++)
    {
    	for(int j = 1 ; j <= M ; j++)
    	{
    		cin >> A[i][j];
    	}
    }

    for(int i = 1 ; i <= N ; i++)
    {
    	for(int j = 1 ; j <= M ; j++)
    	{
    		for(int x = -2 ; x <= 2 ; x++)
    		{
    			for(int y = -2 ; y <= 2 ; y++)
    			{
    				if(1 <= i+x && i+x <= N && 1 <= j+y && j+y <= M)
    				{
    					if(A[i][j] == '.' && A[i+x][j+y] == '.')
    					{
    						L[f(i,j)].push_back({f(i+x,j+y), 1});
    					}
    				}
    			}
    		}

    		for(int d = 0 ; d < 4 ; d++)
    		{
    			if(1 <= i+dx[d] && i+dx[d] <= N && 1 <= j+dy[d] && j+dy[d] <= M)
				{
					if(A[i][j] == '.' && A[i+dx[d]][j+dy[d]] == '.')
					{
						L[f(i,j)].push_back({f(i+dx[d],j+dy[d]), 0});
					}
				}
    		}
    	}
    }

    for(int i = 0 ; i < MAXN*MAXN ; i++)
    {
    	D[i] = 1e18;
    }

    D[f(x1,y1)] = 0;

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;

    Q.push((pair<int,int>){0, f(x1,y1)});

    while(Q.size())
    {
    	int nodo = Q.top().second;
    	int cost = Q.top().first;
    	Q.pop();

    	for(auto v : L[nodo])
    	{
    		if(cost + v.second < D[v.first])
    		{
    			D[v.first] = cost + v.second;
    			Q.push({D[v.first], v.first});
    		}
    	}
    }

    if(D[f(x2,y2)] == 1e18)cout << -1 << '\n';
    else cout << D[f(x2,y2)] << '\n';

    return 0;
}

Measured memory_bytes: 206600
import statistics
N = int(input())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
left = statistics.median(A)
right = statistics.median(B)
if N%2 == 0:
  print(int(right*2 - left*2 + 1))
else: 
  print(right-left+1)

Measured memory_bytes: 28844
from math import atan as arctan
from math import degrees


def main():
    a, b, x = map(int, input().split(" "))
    bottom_area = x / a
    if bottom_area >= a * b / 2:
        print(abs(degrees(arctan((2 * x / (a ** 3)) - (2 * b / a)))))
    else:
        print(90 - degrees(arctan(2 * x / a / (b ** 2))))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size();
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
	int a,b;
	cin>>a>>b;
	cout<<max(0,a-b*2);
	
}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

using namespace std;

int main()
{
    string str;
    cin>>str;
    int k=0;
    for(int i=0; i< str.size(); ++i)
    {
        if(str[i] == '+')k++;
        else k--;
    }
    cout<<k;
    return 0;
}


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

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

  if (s == 22){
    cout << "Christmas Eve Eve Eve"<< endl;
  }
  else if ( s == 23){
    cout << "Christmas Eve Eve"  << endl;
  
  }
  else if (s == 24){
    cout << "Christmas Eve" << endl;
}
 else{
   cout << "Christmas" << endl;
 }
}
  




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

int n,m,a,b,c,x,y;

int main(){
  int i=0,j=0,sum=0;
  cin >> a >> b >> c >> x >> y;
  if(a+b>c*2){
    while(min(x,y)>i){
      sum+=c*2;
      i++;
      j++;
    }
  }
  while(i<x){
    if(a>c*2){
      sum += c*2;
      i++;
    }
    else {
      sum += a;
      i++;
    }
  }
  while(j<y){
    if(b>c*2){
      sum += c*2;
      j++;
    }
    else {
      sum += b;
      j++;
    }
  }
  cout << sum << endl;
  
  

  return 0;
}


Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

//文字列Sのi文字目以降初めてアルファベットjが出現するindex。O(|S|*文字種)
mat next_index(string &s){
  int len = s.size();
  mat nx(len,vec(26,INF));
  REP(i,len-1) nx[i][s[i+1]-'a'] = i+1;
  RREP(i,len-1) REP(j,26) nx[i][j] = min(nx[i][j],nx[i+1][j]);
  return nx;
}

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

  string s,t;
  cin >> s >> t;

  string u = s+s;

  mat nx = next_index(u);

  int n = s.size();

  int ans = 0, now = n-1;
  REP(i,t.size()){
    int id = nx[now][t[i]-'a'];
    if(id == INF){
      cout << -1 << endl;
      return 0;
    }
    ans += id-now;
    now = id%n;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 51152
#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
 while(cin>>m>>n>>o){
   m-=n;
   cout<<m%o<<endl;
 }
    return 0;
}


Measured memory_bytes: 3640
#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 <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int a,b; cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3648
Mod = 10**9+7
inv = [0]*41
inv[1] = 1
for i in range(2,41):
  inv[i] = (-(Mod//i)*inv[Mod%i])%Mod
n,m = map(int,input().split())

primes = []
k = 2
while k*k <= m:
  f = 1
  for p in primes:
    if k%p == 0:
      f = 0
      break
  if f == 1:
    primes += [k]
  k += 1
# print(primes)

d = {}
a = m
for p in primes:
  c = 0
  while a%p == 0:
    c += 1
    a //= p
  if c>0:
    d[p] = c
if a > 1:
  d[a] = 1
# print(d)

s = 1
for k in d.values():
  # print(k)
  t = 1
  for i in range(k):
    t = t*(k+n-1-i)*inv[i+1]%Mod
  s = s*t%Mod
print(s)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100001
#define N -1

void maketree(int,int);
void print(int);

struct Node{ 
  int p, l/*葉があることの確認*/, r/*右側にある数*/, depth;
};
struct Node T[MAX];

int flag,k,leaf;
 
int main(){
  int i, j, id, c/*葉を入れる変数*/, n, parent;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r =N;
  }
  T[0].depth = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%d%d", &id, &k);
    flag = 0;
    if(k != 0){
      for ( j = 0; j < k; j++ ){
	scanf("%d", &c);
	maketree(id, c);
	flag++;
      }
    }
  }
  for ( i = 0; i < n; i++ ){
    parent = T[i].p;
    while(1){                 /* rootに到り付くまで、depthをインクリメントさせる。*/
      if(parent == -1) break;
      parent = T[parent].p;
      T[i].depth++;
    }
    print(i);
    printf("\n");
  }
  return 0;
}

void maketree(int id, int c){
  T[c].p = id;
  if(flag == 0){
    T[id].l = c;
    leaf = c;
  }
  else{
    T[leaf].r = c;
    leaf = c;
  }
}

void print(int u){
  if(T[u].p == N){
    if(T[u].l == N) printf("node %d: parent = -1, depth = 0, root, []", u);
    else{
      leaf = T[u].l;
      printf("node %d: parent = -1, depth = 0, root, [%d", u,leaf);
      while(1){
	if(T[leaf].r == N) break;
	printf(", %d", T[leaf].r);
	leaf = T[leaf].r;
      }
      printf("]");
    }
  }
  else{
    if(T[u].l == N) printf("node %d: parent = %d, depth = %d, leaf, []", u, T[u].p, T[u].depth);
    else{
      leaf = T[u].l;
      printf("node %d: parent = %d, depth = %d, internal node, [", u, T[u].p, T[u].depth);
      printf("%d", leaf);
      while(1){
	if(T[leaf].r == N) break;
    printf(", ");
    printf("%d", T[leaf].r);
    leaf = T[leaf].r;
      }
      printf("]");
    }
  }
}

Measured memory_bytes: 2168
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        while(n >= 2){
            n/=2;
            cnt++;
        }
        System.out.println((int)Math.pow(2,cnt));
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define INF 10000000
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int N;
//各辺を取り除いたときに、連結になるかどうかをDFSで調べる
//現在みている頂点:v
void dfs(vector<vector<bool>> &graph, vector<bool> &seen, int v){
    //頂点vを訪問済みにする
    seen.at(v)=true;
    //未訪問の次の地点を探索
    rep(u,N){
        if(graph.at(v).at(u)==false) continue;
        if(!seen.at(u)) dfs(graph,seen,u);
    }
    return;
}
int main(){
    int M;
    cin>>N>>M;
    vector<int> A(50),B(50);
    vector<vector<bool>> graph(50,vector<bool>(50,false));
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        A.at(i)=a;
        B.at(i)=b;
        graph.at(a).at(b)=true;
        graph.at(b).at(a)=true;
    }
    int ans=0;
    rep(i,M){
        //辺を削除
        graph.at(A.at(i)).at(B.at(i)) = false;
        graph.at(B.at(i)).at(A.at(i)) = false;

        vector<bool> seen(50);
        rep(i,N) seen.at(i)=false;
        //頂点0からdfs
        dfs(graph,seen,0);
        
        bool bridge=false;
        rep(j,N){
            if(!seen.at(j)){
                bridge=true;
            }
        }
        if(bridge) ans++;

        //辺をつなぎなおす
        graph.at(A.at(i)).at(B.at(i))=true;
        graph.at(B.at(i)).at(A.at(i))=true;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

string s,t;
int dp[3005][3005];

int solve(int i,int j){
    if(i==s.size() or j==t.size())
        return 0;
    int &ret = dp[i][j];
    if(~ret)return ret;
    ret=max(solve(i+1,j),solve(i,j+1));
    if(s[i]==t[j]){
        ret=max(ret,1+solve(i+1,j+1));
    }
    return ret;
}

void trace(int i,int j){
    if(i==s.size() or j==t.size())
        return;
    int curr=solve(i,j);
    int path1=solve(i+1,j);
    int path2=solve(i,j+1);
    int path3=solve(i+1,j+1);
    if(path1==curr){
        trace(i+1,j);
    }
    else if(curr==path2){
        trace(i,j+1);
    }
    else if(curr==(1+path3)){
        cout<<s[i];
        trace(i+1,j+1);
    }
    return ;
}

int main(){
    cin>>s>>t;
    memset(dp,-1,sizeof dp);
    solve(0,0);
    trace(0,0);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 35968
/**
 * 品物の重さが4種類しかないことを利用する
 * 同じ重さであれば価値が高いものから選ぶべきなのは明らか
 */

#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int N, W;
int wmin;
vector<int> V[5];


// 種類iまでの品物を容量jに詰めたときの最大価値
int knapsack(int i, int j)
{
    // 品物を入れないなら価値0
    if(i == 0) return 0;

    // 容量0なら価値0
    if(j == 0) return 0;

    // 種類iの品物を入れるパターンを試す
    // 1つも入れない場合、knapsack(i-1, j) が最大価値
    // 入れる場合は価値の高いものから入れる。その場合
    // (入れる価値の総和) + knapsack(i-1, j-(入れる重さの総和)) が最大価値
    // なお、j < (入れる重さの総和) の場合は弾くこと
    //
    // N <= 100 だから、これでかなり再帰の深さは抑えられるはず…
    int totalmax = knapsack(i-1, j);
    int vadd = 0;
    int wadd = 0;
    for(size_t k = 0; k < V[i].size(); ++k) {
        vadd += V[i][k];
        wadd += wmin + (i-1);
        if(j < wadd) break;
        totalmax = max(totalmax, vadd + knapsack(i-1, j-wadd));
    }

    return totalmax;
}

void solve()
{
    int result = knapsack(4, W);
    cout << result << "\n";
}

int main()
{
    cin >> N >> W;
    REP(i, N) {
        int w, v;
        cin >> w >> v;
        if(i == 0) {
            wmin = w;
            V[1].push_back(v);
        }
        else {
            V[1+w-wmin].push_back(v);
        }
    }
    FOR(i, 1, 5) {
        sort(begin(V[i]), end(V[i]), greater<int>());
    }

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using ll = long long;
int main(int argc, char ** argv)
{
  //
  ll k, n;
  std::cin >> k >> n;

  ll ans = 0;
  ll max = 0;
  std::vector<ll> a(n);
  ll diff;
  std::cin >> diff;
  a[0] = 0;
  for (int i = 1; i < n; ++i) {
    std::cin >> a[i];
    a[i] -= diff;
    ans += a[i] - a[i - 1];
    max = std::max(a[i] - a[i - 1], max);
  }
  ans += k - a[n - 1];
  max = std::max(k - a[n - 1], max);
  std::printf("%lld\n", ans - max);

  return 0;
}


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

int main(){
  int N,seki = 1;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    if (A.at(i) % 2 == 0){
      seki *= 2;
    }
    else {
      seki *= 1;
    }
  }
  cout << pow(3,N) - seki << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b;
    string s;
    cin >> a >> b >> s;
    
    bool check = true;
    int count = 0;
    for(int i = 0; i < a+b+1; i++){
        if(s[i] == '-'){
            if(i!=a){
                check = false;
                break;
            }
            count++;
        }
    }
    if(count != 1){
        check = false;
    }
    if(check){
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}

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

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

	string s; cin >> s;
	string z[210000];
	int N = s.length();
	z[0] = s[0];
	int t = 1;
	int cnt = 1;
	for (int i = 1; i < N; i++) {
		z[t].push_back(s[i]);
		if (z[t-1].compare(z[t]) != 0) {
			cnt++;
			t++;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 11156
#include<stdio.h>
int dir(char[], char[]);
int main(void){
    int n,a,t=0,h=0;
    char T[108],H[108];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s",T,H);
        a=dir(T,H);
        if(a==0){
            t+=3;
        }else if(a==1){
            h+=3;
        }else{
            t++;
            h++;
        }
    }
    printf("%d %d\n",t,h);
    return 0;
}
int dir(char x[],char y[]){
    int c=0;
    while(x[c]!='\0' || y[c]!='\0'){
        if(x[c]<y[c]){
            return 1;
        }else if(x[c]>y[c]){
            return 0;
        }else{
            c++;
            continue;
        }
        c++;
    }
    return 2;
}


Measured memory_bytes: 2052
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: f64,
        b: f64,
        h: f64,
        m: f64
    }
    let pi = std::f64::consts::PI;
    let xa = a * (pi * (60.0 * h + m) / 360.0).sin();
    let ya = a * (pi * (60.0 * h + m) / 360.0).cos();
    let xb = b * (pi * m / 30.0).sin();
    let yb = b * (pi * m / 30.0).cos();
    println!("{}", ((xa - xb).powi(2) + (ya - yb).powi(2)).sqrt());
}


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

using namespace std;

#define ll long long




void solve() {

	int r, d, s;
	cin >> r >> d >> s;
	int n = 10;
	while(n--) {
		s = r * s - d;
		cout << s << "\n";
	}
	

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
int main()
{
	int w,a,b,c,x,y,z,count=0;
	scanf("%d %d %d %d", &a, &b, &c,&w);
	for (x = 0; x <= a; x++)
		for (y = 0; y <= b; y++)
			for (z = 0; z <= c; z++)
				if (500 * x + 100 * y + 50 * z == w)
					count++;
	printf("%d", count);
	system("pause");
	return 0;
}

Measured memory_bytes: 376
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n), b(n), c(n), dp(3);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	dp[0] = a[0], dp[1] = b[0], dp[2] = c[0];
	for(int i = 1; i < n; i++){
		int aa = dp[0], bb = dp[1], cc = dp[2];
		dp[0] = a[i] + max(bb, cc);
		dp[1] = b[i] + max(cc, aa);
		dp[2] = c[i] + max(aa, bb);
	}
	cout << *max_element(dp.begin(), dp.end());
	return 0;
}


Measured memory_bytes: 4572
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;const int mod=1000000007;int minn[200005],c[200005],w[200005],sz[200005],f[200005],g[200005];
inline int qpow(int a,int b=mod-2) {int rtv=1;for (;b;b>>=1,a=1LL*a*a%mod) if (b&1) rtv=1LL*rtv*a%mod;return rtv;}
int main() {//freopen("ball.in","r",stdin),freopen("ball.out","w",stdout);
	int n,x,y,mn2=0x3f3f3f3f,ans;scanf("%d%d%d",&n,&x,&y);
	memset(minn,0x3f,sizeof minn);for (register int i=1;i<=n;++i) {
		scanf("%d%d",c+i,w+i),minn[c[i]]=min(minn[c[i]],w[i]),++sz[c[i]];
	}for (register int i=*f=1;i<=n;++i) f[i]=1LL*f[i-1]*i%mod;g[n]=qpow(f[n]);
	for (register int i=n-1;~i;--i) g[i]=1LL*g[i+1]*(i+1)%mod;
	for (register int i=*minn=1;i<=n;++i) if (minn[*minn]>minn[i]) *minn=i;
	for (register int i=1;i<=n;++i) if (i^*minn) mn2=min(mn2,minn[i]);
	for (register int i=1;i<=n;++i) if (!(w[i]^minn[c[i]]&&w[i]+minn[c[i]]<=x)&&
	!(c[i]^*minn&&w[i]+minn[*minn]<=y)&&!(c[i]==*minn&&w[i]+mn2<=y)) --sz[c[i]];
	*sz=sz[*minn];for (register int i=1;i<=n;++i) if (i^*minn&&minn[i]+minn[*minn]<=y) *sz+=sz[i];
	for (register int i=ans=1;i<=n;++i) if (sz[i]&&(minn[i]+minn[*minn]<=y||i==*minn)) ans=1LL*ans*g[sz[i]]%mod;
	printf("%lld",1LL*ans*f[*sz]%mod);return 0;
}

Measured memory_bytes: 4992
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;

class Main {
    // returns x! / (y! * z!)
    static String permutation(int x, int y, int z) {
        // make y bigger than z
        if (z > y) {
            int tmp = y;
            y = z;
            z = tmp;
        }

        BigDecimal result = BigDecimal.ONE;

        int counter = 1;

        for (int i = y + 1; i <= x; i++) {
            result = result.multiply(new BigDecimal(String.valueOf(i)));
            if (counter <= z) {
                result = result.divide(new BigDecimal(String.valueOf(counter)));
                counter++;
            }
        }

        for (int i = counter; i <= z; i++) {
            result = result.divide(new BigDecimal(String.valueOf(counter)));
        }

        return result.toString();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");

        int n = Integer.parseInt(input[0]);
        int m = Integer.parseInt(input[1]);
        int r = Integer.parseInt(input[2]);

        /* 一応ACだが、遅い.
        int nm = n*m;
        
        if(r < nm){
            System.out.println("0");
            return;
        }
        
        int beads = r - nm;
        System.out.println(permutation(beads+n-1, beads, n-1));
        */

        // 以下、他の方のコードを参考にして再実装.
        // 上のプログラムが異常に遅いのは実はアルゴリズムの問題ではなくて、
        // BigDecimalがBigIntegerに比べて圧倒的に遅いのが原因だったみたい.

        r -= n * m;
  
        if (r < 0) {
            System.out.println("0");
            return;
        }

        BigInteger result = BigInteger.ONE; 

        for (int i = 0; i < Math.min(r, n - 1); i++) {
            result = result.multiply(new BigInteger(String.valueOf(r + n - 1 - i))).divide(new BigInteger(String.valueOf(i + 1)));
        }

        System.out.println(result.toString());
    }
}


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


int main(){
	int n,m;
	cin >> n >> m;
	
	int x = 100*(n-m);
	x += 1900*m;
	
	int y=1;
	for(int i=0;i<m;i++){
		y *= 2;
	}
	
	cout << x * y << endl;
	
	return 0;
}


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

const int MAXP = 1000002;
int isP[MAXP], S[MAXP];

int main() {
  fill(isP, isP+MAXP, 1);
  isP[0] = isP[1] = 0;
  for(int i = 2; i < MAXP; ++i) {
    if(!isP[i]) continue;
    for(int j = i*2; j < MAXP; j += i) isP[j] = 0;
  }
  for(int i = 0; i+1 < MAXP; ++i) S[i+1] = S[i] + isP[i];

  int n;
  while(cin >> n && n) {
    int res = 0;
    for(int i = 0; i < n; ++i) {
      int p, m;
      cin >> p >> m;
      int X = S[min(MAXP-1,p+m+1)] - S[max(0,p-m)];
      if(X) {
        res += X-1;
      } else {
        res -= 1;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 8972
n, x, m = map(int, input().split())

mn = min(n, m)
S = set()
A = []
a = x
sum_9 = 0 # sum of pre + cycle

for _ in range(mn):
    if a in S: break
    S.add(a)
    A.append(a)
    sum_9 += a
    a = a*a % m
    if a == 0:
        print(sum_9)
        exit()

if len(A) >= mn:
    print(sum_9)
    exit()

st_len = A.index(a)
cyc_len = len(A) - st_len
ed_len = (n - st_len) % cyc_len

cyc_num = (n - st_len) // cyc_len

pre = sum(A[:st_len])
cyc = sum_9 - pre
btm = sum(A[st_len: st_len + ed_len])

print(pre + cyc * cyc_num + btm)


Measured memory_bytes: 13012
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, count1 = 0, count2 = 0;
		
		a = sc.nextInt();
		
		b = sc.nextInt();
		c = sc.nextInt();
		if(c == 5)++count1;
		else if(c == 7)++count2;
		
		if(a == 5)++count1;
		else if(a == 7)++count2;
		if(b == 5)++count1;
		else if(b == 7)++count2;
		
		if(count1 == 2 && count2 == 1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		sc.close();
	}

}


Measured memory_bytes: 20948
from collections import defaultdict, deque
N = int(input())
tree = defaultdict(list)
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    tree[a].append((b, c))
    tree[b].append((a, c))
Q, K = map(int, input().split())
XY = []
for _ in range(Q):
    XY.append(list(map(int, input().split())))

# distance from node [K]
dists = [None] * (N + 1)
dists[K] = 0
q = deque([K])
while len(q) > 0:
    v = q.popleft()
    d = dists[v]
    for to, c in tree[v]:
        if dists[to] is None:
            dists[to] = d + c
            q.append(to)

for x, y in XY:
    ans = dists[x] + dists[y]
    print(ans)


Measured memory_bytes: 73456
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define Maxn 100010
#define V 1000010
ll Ans=0;
int n;
char seq[Maxn];
struct Node{
	int son[26];
}tree[V];
int root; 
int sum[V];
int cnt=0;
void Insert(int &k,int at){
	if(!k)k=++cnt;
	if(at==10){
		sum[k]++;
		return;
	}
	Insert(tree[k].son[seq[at]-'a'],at+1);
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;++i){
		scanf("%s",seq);
		sort(seq,seq+10);
		Insert(root,0);
	}
	for(register int i=1;i<=cnt;++i)Ans+=1ll*sum[i]*(sum[i]-1)/2; 
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 53376
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
ll a[200007], b[200007];

void solve() {
    ll i, j, k, l, t, n, x, y, r;
    cin>>k;
    n=7;
    for(i=1;i<=10000000;i++) {
        n=n%k;
        if(n==0) break;
        n=( ((n%k)*(10%k)%k)+(7%k))%k;
    }
    //if(k%2==0) cout<<"-1";
    if(i>=10000000) cout<<"-1";
    else cout<<i;
}
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input1.txt", "r", stdin);
        freopen("output1.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Measured memory_bytes: 3652
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    a, b, x = LI()
    if a <= x <= a + b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    _, m, x = LI()
    a = LI()
    print(min(bisect.bisect_left(a, x), m - bisect.bisect_right(a, x)))
    return

#C
def C():
    n = II()
    x = LI()
    xb = x[::1]
    xb.sort()
    a = xb[n // 2 - 1]
    b = xb[n // 2]
    for i in range(n):
        if x[i] <= a:
            print(b)
        elif x[i] >= b:
            print(a)
        
    return

#D
def D():
    n = II()
    a = LI()
    a.sort()
    maxa = max(a) / 2
    ans = inf
    for i in range(n):
        if abs(maxa - a[i]) < abs(maxa - ans):
            ans = a[i]
    print(max(a), ans)
    return


#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 59248
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
	if(n<=1)return false;
	if(n<=3)return true;
	if(n%2==0||n%3==0)return false;
	for(ll i=5;i*i<=n;i+=6)
	{
		if(n%i==0||n%(i+2)==0)return false;
	}
	return true;
}

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)r=(r*a)%m;
		b = b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

ll addmod(ll a,ll b)
{
    if(a+b<mod)return a+b;
    else return a+b-mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll modinv(ll a)
{
    return modexp(a,mod-2,mod);
}
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll x,y,a,b,c; cin>>x>>y>>a>>b>>c;
	vi arr(a),brr(b),crr(c);
	rep(i,0,a)cin>>arr[i];
	rep(i,0,b)cin>>brr[i];
	rep(i,0,c)cin>>crr[i];
	sort(all(arr),greater<ll>());
	sort(all(brr),greater<ll>());
	sort(all(crr),greater<ll>());

	vpi sol;
	rep(i,0,x)sol.pb({arr[i],1});
	rep(i,0,y)sol.pb({brr[i],2});
	rep(i,0,c)sol.pb({crr[i],3});
	sort(all(sol),comp);
	//for(auto x:sol)cout<<x.fi<<" "<<x.se<<endl;

	ll cnt = 0,r = 0,g = 0;
	ll ans = 0;
	for(ll i =0;i<x+y+c;i++)
    {
        if(cnt<x+y)
        {
            if(sol[i].se==3)cnt++,ans+=sol[i].fi;
            else if(sol[i].se==1&&r<x)cnt++,r++,ans+=sol[i].fi;
            else if(sol[i].se==2&&g<y)cnt++,g++,ans+=sol[i].fi;
        }
    }
    cout<<ans<<endl;
	return 0;
}
/*
6
1 2 3 4 5 -6
*/


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

int main() {
  long long count=0;
  int N;
  cin>>N;
  vector<int>A(N);
  rep(i,N){
    int x;
    cin>>x;
    A[i]=x;
  }
  sort(A.begin(),A.end());
  cout<<A[N-1]-A[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int q = 0;
  for(int i = 1; i < 1001; i++) {
    if(A <= i * 0.08 && !(A + 1 <= i * 0.08)) {
      if(B <= i * 0.1 && !(B + 1 <= i * 0.1)) {
        q += i;
        cout << q << endl;
        break;
      }
    }
  }
  if(q == 0) {
    cout << -1 << endl;
  }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    Vi ans(n,0);
    int count=1,oe=0,l=0,r=0;
    REP(i,0,n){
        if(i==n-1){
            if(count%2==0){
                ans[l]=count/2;
                ans[r]=count/2;
            }else{
                if(oe==1){
                    ans[l]=count/2+1;
                    ans[r]=count/2;
                }else{
                    ans[l]=count/2;
                    ans[r]=count/2+1;
                }
            }
            break;
        }
        
        if(s[i]=='R' && s[i+1]=='R'){
            count++;
        }
        if(s[i]=='R' && s[i+1]=='L'){
            oe=count%2;
            count++;
            l=i;r=i+1;
        }
        if(s[i]=='L' && s[i+1]=='R'){
            if(count%2==0){
                ans[l]=count/2;
                ans[r]=count/2;
            }else{
                if(oe==1){
                    ans[l]=count/2+1;
                    ans[r]=count/2;
                }else{
                    ans[l]=count/2;
                    ans[r]=count/2+1;
                }
            }
            count=1;
        }
        if(s[i]=='L' && s[i+1]=='L'){
            count++;
        }
    }
    REP(i,0,n) cout<<ans[i]<<" ";
    return 0;
}


Measured memory_bytes: 1488