akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++ i){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int i = lower_bound(a.begin(), a.end(), a.back() / 2) - a.begin();
	if(i && a[i] - a.back() / 2 >= (a.back() + 1) / 2 - a[i - 1]){
		-- i;
	}
	cout << a.back() << " " << a[i] << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			int m = sc.nextInt();
			int n = sc.nextInt();
			
			if((m|n) == 0){
				break;
			}
			
			
			int[] bs = new int[n];
			
			for(int i =0 ; i < n; i++){
				bs[i] = sc.nextInt();
			}
			
			
			int max = 1500000;
			int min = 0;
			for(;;){
//				System.out.println(max +" "+ min);
				if(max == min){
					break;
				}
				int t = (max+min)/2;
				
				boolean ok =true;
				
				int ind = 0;
				for(int i =0 ; i < m;i++){
					int cap = t;
					for(;ind < n && cap >= bs[ind]; ind++){
						cap -= bs[ind];
					}
				}
				ok = (ind == n);
				
				if(ok){
					max = t;
				}else{
					min = t+1;
				}
			}
			
			System.out.println(min);
		}
		
		
		
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

int w,h;
char fig[60][11];
bool visited[60][10],ans;

struct Point{
	int x,y;
	Point(int X,int Y):x(X),y(Y){}
};

struct Result{
	int mass;
	double xg;
	Result(int M,double G):mass(M),xg(G){}
};

Result dfs(int y0,int x0){
	char color=fig[y0][x0];
	int xl=77,xr=-1;

	visited[y0][x0]=true;

	double x_tmp=0;
	vector<Result> ress;
	queue<Point> qu; qu.push(Point(x0,y0));
	while(!qu.empty()){
		Point a=qu.front(); qu.pop();

		x_tmp+=a.x+0.5;
		if(a.y+1==h || (fig[a.y+1][a.x]!='.' && fig[a.y+1][a.x]!=color)){
			xl=min(xl,a.x);
			xr=max(xr,a.x+1);
		}

		if(a.y>0 && fig[a.y-1][a.x]!='.' && fig[a.y-1][a.x]!=color
		&& !visited[a.y-1][a.x]){
			ress.push_back(dfs(a.y-1,a.x));
		}

		rep(i,4){
			int xx=a.x+dx[i],yy=a.y+dy[i];
			if(0<=yy && yy<h && 0<=xx && xx<w && fig[yy][xx]==color
			&& !visited[yy][xx]){
				visited[yy][xx]=true;
				qu.push(Point(xx,yy));
			}
		}
	}

	int mass=4;
	rep(i,ress.size()) mass+=ress[i].mass;
	x_tmp/=4;
	double xg=4*x_tmp/mass;
	rep(i,ress.size()) xg+=ress[i].mass*ress[i].xg/mass;

	if(!(xl<xg && xg<xr)) ans=false;

	return Result(mass,xg);
}

int main(){
	for(;scanf("%d%d",&w,&h),w;){
		rep(i,h){
			scanf("%s",fig[i]);
			rep(j,w) visited[i][j]=false;
		}

		ans=true;
		rep(j,w) if(fig[h-1][j]!='.') { dfs(h-1,j); break; }
		puts(ans?"STABLE":"UNSTABLE");
	}

	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

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

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

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

	vector<int> num(n, 1);
	vector<bool> canR(n);
	canR[0] = true;

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;

		num[x]--;
		num[y]++;
		if (canR[x]) {
			canR[y] = true;
		}

		if (num[x] == 0) {
			canR[x] = false;
		}
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (canR[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
        self.size = [1] * (n)
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)

uf = UnionFind(n)

for _ in range(m):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    uf.union(x,y)

root = set([])

for i in range(n):
    root.add(uf.find(i))

print(len(root))

Measured memory_bytes: 17576
#include<bits/stdc++.h>
using namespace std;
long gyaku(int a,int p){
    long ans = 1;
    long tmp = a;
    for(int i=1;i<=(p-2);i*=2){
        if(i & (p-2))ans *= tmp;
        tmp = (tmp*tmp)%p;
        ans %= p;
    }
    return ans%p;
}

long gcd(long a,long b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

vector<int>prime;
void makePrime(long n){
    prime.push_back(2);
    for(long i=3;i<=n;i+=2){
        bool chk = true;
        for(int j=0;j<prime.size() && prime[j]*prime[j] <= i;j++){
            if(i % prime[j]==0){
                chk=false;
                break;
            }
        }
        if(chk)prime.push_back(i);
    }
}

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    long mod = 1e9+7;
    makePrime(1000);
    long seki = 1;
    map<int,int>primes;
    for(int i=0;i<n;i++){
        for(int j=0;j<prime.size();j++){
            int tmp = 0;
            while(a[i]%prime[j]==0){
                a[i] /= prime[j];
                tmp++;
            }
            primes[prime[j]] = max(primes[prime[j]],tmp);
        }
        primes[a[i]] = 1;
    }
    while(primes[2]>0){
        seki *= 2;
        seki %= mod;
        primes[2]--;
    }
    for(int i=3;i<=1000000;i+=2){
        while(primes[i] > 0){
            seki *= i;
            seki%=mod;
            primes[i]--;
        }
    }
    long ans = 0;
    for(int i=0;i<n;i++){
        if(seki%b[i]==0){
            ans += seki/b[i];
        }else{
            ans += seki * gyaku(b[i],mod);
        }
        ans %= mod;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 27112
#include<bits/stdc++.h>	
 
#define f first
#define s second
#define pb push_back
                         	
#define ll long long
 
#define int ll
 
#define ull unsigned long long
 
#define mp make_pair
                          
  
using namespace std;
                       
 
const int inf = 1e9 + 7;
 
const ll ll_inf = 1e18;
const int K = 2e6 + 50;
const int N = 3e5 + 200;
 
const int bl = 320;
 
const int ep = 1e-7;
 
const int pro = 31;
 
const double pi = 3.141592653589793238462643;
                                         
ll binpow (ll a, ll n)
{
	if(n == 0)
		return 1ll;           
    ll res = 1;
    while (n) {
        if (n & 1)                                          
        {
            res *= a;
            res %= inf;
        }      	
        a *= a;
        n >>= 1;
        a %= inf;
    }                          
    return res;
}   
          
  
 
void boost()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);                                        
}
 
void fr()
{
    freopen("road-to-work.in","r",stdin);
    freopen("road-to-work.out","w",stdout);
}

int a[100];
pair<int,int>dpm[100],dpa[100];
 
void solve() 
{
	int n,k;
	cin >> n;
	for (int i = 1;i <= n;++i)
	{
		cin >> a[i];	
	}
	dpm[0].f = 1000;
	dpa[9].s = 1000;
	for (int i = 1;i <= n;++i)
	{
		for (int j = 0;j < i;++j)
		{
			dpm[i] = max(dpm[i],max(dpm[j],mp(dpa[j].s + dpa[j].f * a[i],0ll)));
			dpa[i] = max(dpa[i],max(mp(dpa[j].f + dpa[j].s / a[i],dpa[j].s % a[i]),mp(dpm[j].s + dpm[j].f / a[i],dpm[j].f % a[i])));	
		}	
		//cout << dpa[i].s << " ";
	}
	cout << dpm[n].f + dpm[n].s * a[n];   
}   	                        	
 
main()
{
	//boost();
	int q = 1;
	//cin >> q;
	while(q--)
	{
		solve();
	}
}

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

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> an(n);
  for (auto& ai : an) {
    cin >> ai;
  }
  if (n % 2 != 0) {
    an.push_back(0);
  }
  sort(an.begin(), an.end());
  int diff = 0;
  n = an.size();
  for (int i = 0; i < n / 2; ++i) {
    diff += an[n - i * 2 - 1] - an[n - i * 2 - 2];
  }
  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
r = [0] * n
g = [0] * n
b = [0] * n
R, G, B = 0, 0, 0
for i in range(n - 1, -1, -1):
    if s[i] == 'R': R -= -1
    elif s[i] == 'G': G -= -1
    else: B -= -1
    r[i] = R
    g[i] = G
    b[i] = B
# print(r)
# print(g)
# print(b)

ans = 0
for i in range(1, n - 1):
    for j in range(i):
        if s[j] != s[i]:
            t = i + i - j
            if s[i] == 'R':
                if s[j] == 'G':
                    ans += b[i + 1]
                    if t < n and s[t] == 'B': ans += -1
                else:
                    ans += g[i + 1]
                    if t < n and s[t] == 'G': ans += -1
            elif s[i] == 'G':
                if s[j] == 'R':
                    ans += b[i + 1]
                    if t < n and s[t] == 'B': ans += -1
                else:
                    ans += r[i + 1]
                    if t < n and s[t] == 'R': ans += -1
            elif s[i] == 'B':
                if s[j] == 'R':
                    ans += g[i + 1]
                    if t < n and s[t] == 'G': ans += -1
                else:
                    ans += r[i + 1]
                    if t < n and s[t] == 'R': ans += -1
print(ans)

Measured memory_bytes: 68536
#include <iostream>
#include <string.h>
using namespace std;

int D[31][31];
int color[3][31];

int main(void)
{
	int N, C;
	cin >> N >> C;

	for (int before = 1; before <= C; before++) {
		for (int after = 1; after <= C; after++) {
			cin >> D[before][after];
		}
	}

	memset(color, 0, sizeof(color));

	for (int h = 1; h <= N; h++) {
		for (int w = 1; w <= N; w++) {
			int pos = (h+w)%3;
			int c;
			cin >> c;
			color[pos][c]++;
		}
	}

	int ans = 1000 * 500 * 500;

	for (int color1 = 1; color1 <= C; color1++) {
		for (int color2 = 1; color2 <= C; color2++) {
			if (color1 == color2) continue;
			for (int color3 = 1; color3 <= C; color3++) {
				if (color1 == color3) continue;
				if (color2 == color3) continue;

				int total_iwakan = 0;

				for (int before = 1; before <= C; before++) {
					total_iwakan += D[before][color1] * color[0][before];
					total_iwakan += D[before][color2] * color[1][before];
					total_iwakan += D[before][color3] * color[2][before];
				}
				ans = std::min(ans, total_iwakan);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

	readChars(): string[] {
		let S = this.readLine();
		return new Array(S.length).fill(null).map((_, i) => S.charAt(i));
	}

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
} 

function maximum(A: number[]): number {
	let M = A[0];
	for(let i=1; i<A.length; i++) {
		M = Math.max(M, A[i]);
	}
	return M;
}

function solve(): string {
	let reader = new Reader();
	let N = reader.readInt();

	let A = reader.readInts(),
		B = reader.readInts();

	let B_sum = B.reduce((prev, current) => prev+current, 0);
	let A_sum = A.reduce((prev, current) => prev+current, 0);
	let ops = B_sum-A_sum;
	for(let i=0; i<N; i++) {
		if (A[i] < B[i]) {
			ops -= Math.ceil((B[i]-A[i])/2);
		} 
	}
	if (ops >= 0)
		return 'Yes';
	return 'No';
}

console.log(solve());


Measured memory_bytes: 33788
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int A,B;
int main(void)
{
  cin >> A>> B;
  if(A>=13)
    {
      cout << B << endl;
    }
  else if(A>=6 && A<=12)
    {
      cout << B/2 << endl;
    }
  else if(A<=5)
    {
      cout << 0 << endl;
    }
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val (l, r) = List.fill(3)((sc.nextInt(), sc.nextInt(), sc.nextInt()))
    .map { case (a, b, c) => (a - b, b - c) }.unzip
  println(if (l.forall(_ == l.head) && r.forall(_ == r.head)) "Yes" else "No")
}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int t[210], v[210];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> t[i];
  REP(i, n) cin >> v[i];

  double ret = 0, sp = 0;
  REP(i, n) {
    for(double j=0; j<t[i]; j+=0.5) {
      bool flag1 = true, flag2 = true;
      double ti = t[i]-j-0.5;
      FOR(k, i+1, n) {
        ti += t[k];
        if(sp+0.5-ti > v[k+1]) flag1 = false;
        if(sp-v[k+1] > ti) flag2 = false;
      }
      if(sp+0.5 <= v[i] && flag1 && (sp+0.5-(t[i]-j-0.5)) <= v[i+1]) {
        ret += sp*0.5;
        ret += 0.125;
        sp += 0.5;
      } else if(sp - v[i+1] <= t[i]-j-0.5 && flag2) {
        ret += sp*0.5;
      } else {
        sp -= 0.5;
        ret += sp*0.5;
        ret += 0.125;
      }
    }
  }
  cout <<fixed << setprecision(15) << ret << endl;

  return 0;
}

Measured memory_bytes: 256
from sys import stdin
import fractions
def lcm(a,b):
    return a * b // fractions.gcd(a,b)
A,B,C,D = [int(x) for x in stdin.readline().rstrip().split()]
div_C = (B // C) - ((A-1) // C)
div_D = (B // D) - ((A-1) // D)
div_lcm = (B // lcm(C,D)) - ((A-1) // lcm(C,D))
ans = B - A  - div_C - div_D + div_lcm + 1
print(ans)

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n, m; cin >> n >> m;
  int maxi = m;
  rep(i, n){
    int a, b; cin >> a >> b;
    m += a - b;
    maxi = max(maxi, m);
    if(m < 0)maxi = inf;
  }
  if(maxi == inf)cout << 0 << endl;
  else cout << maxi << endl;
  return 0;
}



Measured memory_bytes: 3112
/*
Though leaves are many, the root is one;
Through all the lying days of my youth
I swayed my leaves and flowers in the sun,
Now may I wither into the truth.

- William Butler Yeats
*/
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
#include <bitset>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:6
*Problem:Distance Sums
*Date:2019-7-12
*Algorithm:Orange Boy's Greedy and Sorting
*Stats:WA*/

bool debug=false;


template<typename T1,typename T2> ostream& operator<<(ostream& o,pair<T1,T2> p){
	o<<"{";
	o<<p.first<<","<<p.second;
	o<<"}";
	return o;
}

ll n;
ll d[100005];
map <ll,ll> m;
pair<ll,ll> p[100005];
ll sub[100005];
ll sz[100005];
vector <pair<ll,ll> >res;
 
 int fa[100005];
 
int getFa(int x){
	if(fa[x]==x){
		return x;
	}
	return fa[x]=getFa(fa[x]);
}
 
 
void Union(int a,int b){
	if(fa[a]==fa[b]){
		return;
	}
	fa[getFa(a)]=getFa(b);
}

ll dp[100005];

ll dis[100005];

vector<int> nei[100005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>d[i];
		if(d[i]>n*(n-1)/2){
			cout<<-1;
			return 0;
		}
		m[d[i]]=i;
		p[i].first=d[i];
		p[i].second=i;
		sz[i]=1;
	}
	sort(p,p+n);
	reverse(p,p+n);
	memset(sub,-1,sizeof(sub));
	for(ll i=0;i<n-1;i++)
	{
		ll de=p[i].first;
		ll x=p[i].second;
		sub[x]=n-sz[x]*2;
		if(sub[x]==0){
			cout<<-1;
			return 0;	
		}
		if(m.find(de-sub[x])==m.end()){
			cout<<-1;
			return 0;
		}
		ll par=m[de-sub[x]];
		sz[par]+=sz[x];
		dp[par]+=dp[x]+sz[x];
		res.push_back(make_pair(x,par));
	}
	
	for(int i=0;i<n-1;i++){
		nei[res[i].first].push_back(res[i].second);
		nei[res[i].second].push_back(res[i].first);
	}
	
	queue<int> q;
	memset(dis,-1,sizeof(dis));
	q.push(p[n-1].second);
	dis[p[n-1].second]=0;
	
	while(!q.empty()){
		int last=q.front();
		q.pop();
		
		for(int to:nei[last]){
			if(dis[to]==-1){
				dis[to]=dis[last]+1;
				q.push(to);
			}
		}
	}
	
	ll sm=0;
	for(int i=0;i<n;i++){
		sm+=dis[i];
	}
	if(sm!=p[n-1].first){
		cout<<-1;
		return 0;
	}
	
	for(ll i=0;i<n-1;i++)
	{
		cout<<res[i].first+1<<" "<<res[i].second+1<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 20724
loop do
  t = gets.chomp
  break if t == "#"
  cards = 4.times.map { gets.split }.transpose
  won = 0
  score = 13.times.map { |i|
    l = cards[i][won][1]
    won = cards[i].each_with_index.max_by { |c, _|
      if [t, l].include?(c[1])
        s = ["T", "J", "Q", "K", "A"].index(c[0]) + 10 rescue c[0].to_i
        c[1] == t ? s + 20 : s
      else
        0
      end
    }[1]
  }.select(&:even?).count
  puts score > 6 ? "NS #{score-6}" : "EW #{7-score}"
end

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

#define INF 100000000001


int main() {
    string s; cin>>s;
    if(s[1]=='R') cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
ll arr[405];
ll pref[405];
ll dp[405][405];
ll rec(ll i, ll j)
{
	if(i == j)
		return dp[i][j] = 0;
	if(dp[i][j] != 0)
		return dp[i][j];
	ll k;
	ll ans = 1e18;
	for(k=i;k<j;k++)
	{
		ll temp = 0;
		dp[i][k] = rec(i,k);
		dp[k+1][j] = rec(k+1,j);
		ll a,b;
		if(i == 0)
			a = pref[k];
		else
			a = pref[k] - pref[i-1];
		b = pref[j] - pref[k] + a;
		ans = min(ans, dp[i][k] + dp[k+1][j] + b);
	}
	return dp[i][j] = ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll i,j,k,n;
 	cin >> n;
 	for(i=0;i<n;i++)
 		cin >> arr[i];
 	pref[0] = arr[0];
 	for(i=1;i<n;i++)
 		pref[i] = arr[i] + pref[i-1];
 	rec(0,n-1);
	cout << dp[0][n-1] << endl;
	return 0;
}

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

int main(){
  int a;
  cin>>a;
  vector<int> base(a);
  for(int &x:base){
    cin>>x;
  }
  int b;
  cin>>b;
  vector<vector<int>> pow(b,vector<int>(2));
  for(int i=0;i<b;i++){
    cin>>pow[i][0]>>pow[i][1];
  }
  int sum=0;
  for(int i=0;i<a;i++){
    sum+=base[i];
  }
  for(int i=0;i<b;i++){
    int log=sum;
    int g=pow[i][0]-1;
    log+=pow[i][1]-base[g];
    cout<<log<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
int main(void){
	ll N,A,B,ans;
	scanf("%lld%lld%lld",&N,&A,&B);
	if(A>B)ans=0;
	else if(N==1 && A==B)ans=1;
	else if(N==1)ans=0;
	else{
		ans = B*(N-1)+A-(A*(N-1)+B)+1;
	}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
using CompLib.Util;
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = sc.IntArray();

        foreach(int i in a)
        {
            if(i % 2 == 0)
            {
                if(i%3==0 || i % 5 == 0)
                {

                }
                else
                {
                    Console.WriteLine("DENIED");
                    return;
                }
            }
        }

        Console.WriteLine("APPROVED");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
n=int(input())

niroku=[]
siji=[1]
for i in range(20):
    siji.append(siji[-1]*26)
siji[0]=0
keta=0
for i in range(20):
    if(n>siji[i]):
        n-=siji[i]
        keta=i+1
n-=1
#print(n,keta)

for i in range(keta):
    niroku.append(n%26)
    n//=26
#print(niroku)

ans=""
for ni in niroku:
    ans=chr(97+ni)+ans
print(ans)

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

int main()
{
    int A[3];
    for(int i = 0; i < 3; ++i) cin >> A[i];
    sort(A, A + 3);
    cout << A[0] + A[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int q,h,s,d;
	cin>>q>>h>>s>>d;
	long long int n;
	cin>>n;
	h=min(h,2*q);
	s=min(s,2*h);
	long long int a=(n/2)*min(2*s,d) + (n%2)*min(2*h,s);
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int S = (1 << 20);
int tab[S], n, pref[S], ans, wh[S];

int main(){

	cin >> n;
	for (int i = 1; i <= n; i ++){
		cin >> tab[i];
		wh[tab[i]] = i;
	}	
	
	int buf = 1;
	for (int i = 2; i <= n; i ++){
		
		if (wh[i] > wh[i - 1]){
			buf ++;
		}
		else buf = 1;
		ans = max(ans, buf);
	}
	
	cout << n - max(ans, 1) << endl;
	return 0;
}

Measured memory_bytes: 5120
n,m = gets.split(" ").map(&:to_i)
a = []
n.times do |n_c|
  get_num = gets.split(" ").map(&:to_i)
  k = get_num[0]
  a_tmp = get_num.drop(1)

  a << a_tmp
end

flag = []

m.times do |m_c|
  t_flag = true
  a.each do |row|
    if row.find { |cell| cell == m_c+1}.nil?
      t_flag = false
      break
    end
  end
  flag.push(t_flag)
end

p flag.count {|f| f === true}
  


Measured memory_bytes: 1788
#!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
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = I()
    a = LI()
    f = defaultdict(int)
    for i in a:
        f[i-1] += 1
        f[i] += 1
        f[i+1] += 1
    print(max(f.values()))
    return

#E
def E():
    n = I()
    a = LI()
    f = defaultdict(int)
    f[0] = 4
    for i in a:
        f[i] += 1
    f = list(map(list, f.items()))
    f.sort(key = lambda x:-x[0])
    ans = 1
    k = 0
    for i,j in f:
        if j >= 4 and k == 0:
            print(i*i)
            quit()
        if j >= 2:
            k += 1
            ans *= i
        if k == 2:
            print(ans)
            quit()
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    E()


Measured memory_bytes: 76440
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

ll f(ll n, ll halnum, vector<map<ll,ll>>& vw, vll& v, vll& w, ll nod, ll cw){
  if(cw < 0){
    return -1e18;
  }
  if(cw == 0){
    return 0;
  }
  if(nod <= halnum){
    auto tmp = vw[nod].upper_bound(cw);
    tmp--;
    return tmp-> second;
  }
  return max(f(n, halnum, vw, v, w, nod/2, cw), f(n, halnum, vw, v,w, nod/2, cw - w[nod]) + v[nod]);
}

int main(){
  ll n;
  cin >> n;
  ll dep = 1;
  while(pow(2,dep)-1 < n){
    dep++;
  }
  vll w(n+1),v(n+1);
  REP(i,1,n){
    cin >> v[i] >> w[i];
  }
  ll q; cin >> q;
  vll qv(q+1), ql(q+1);
  REP(i,1,q){
    cin >> qv[i] >> ql[i];
  }
  ll hal = (dep + 1) / 2;
  ll halnum = pow(2,hal) - 1;
  vector<map<ll,ll>> vw(halnum + 1);
  vw[0].insert({0,0});
  REP(i,1,halnum){
    ll bef = i / 2;
    for(auto x:vw[bef]){
      vw[i].insert(x);
    }
    
    for(auto x:vw[bef]){
      ll befw = x.first;
      ll befv = x.second;
      ll curw = befw + w[i];
      ll curv = befv + v[i];
      if(vw[i].find(curw) == vw[i].end()){
        vw[i][curw] = curv; 
      }else{
        vw[i][curw] = max(vw[i][curw], curv);
      }
    }
  //     REP(i,1,halnum){
  //   cout << i << " ";
  //   for(auto x:vw[i]){
  //     cout << "("<<x.first << ", " << x.second << "), " ;
  //   }
  //   cout << endl;
  // }
    vector<ll> era;
    auto cur = vw[i].begin();
    ll befwei = -1;
    ll befval = -1;
    while(cur != vw[i].end()){
      ll curwei = cur->first;
      ll curval = cur->second;
      if(befval >= curval){
        //vw[i].erase(cur);
        era.push_back(curwei);
        // cout << befval << " !!! " << curwei << endl;
      }else{
        befval = curval;
        befwei = curwei;
      }
      cur++;
    }
    for(auto cur:era){
      vw[i].erase(cur);
    }
    
  }
  // REP(i,1,halnum){
  //   cout << i << " ";
  //   for(auto x:vw[i]){
  //     cout << "("<<x.first << ", " << x.second << "), " ;
  //   }
  //   cout << endl;
  // }
  vll ans(q+2);
  REP(i,1,q){
    ans[i] = f(n, halnum, vw, v, w, qv[i], ql[i]);
  }
  REP(i,1,q){
    cout << ans[i] << endl;
  }
}

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

int n;
int cand[26];
int top,second;
int num;
char temp;
bool TIE;

int main() {
	while(true){
		//?????????
		for (int i = 0; i < 26; i++) {
			cand[i]=0;
		}
		top=0;
		second=0;
		TIE=true;

		//??\???
		cin >> n;
		if(n==0)break;

		for (int i = 0; i < n; i++) {
			cin >> temp;
			//cout << temp << " a ";
			num=(++cand[temp-'A']);
			//???????¨????
			if(num>top)top=num;
			else if(num>second)second=num;

			//???????¢?????¨????
			if (top > second + (n - i - 1)) {

				for (int j = 0; j < 26; j++) {
					if (cand[j] == top) {
						char moji='A' + j;
						cout<<moji<<" " << i + 1 << endl;
						break;
					}
				}
				TIE=false;
				//cout << "c" << endl;
				//??¢??????????????\???
				while(i<n-1){
					cin >> temp;
					//cout<<temp<<" b ";
					i++;
				}
				break;
				//cout << "d" << endl;
			}
			//cout << "e" << endl;
		}
		if(TIE)cout<<"TIE"<<endl;

		//cout<<"u"<<endl;
	}
	return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N,K = 420;
char ch [] = {'.','#'};

int main()
{
	cin >> N;

	string S,T;
	int i;
	for(i = 0;i < 420;i++){
		bool flag = false;
		FOR(j,0,4){
			string r;
			cout << S + ch [j / 2] << endl;
			cout << T + ch [j % 2] << endl;
			fflush(stdout);
			cin >> r;
			if(r == "end"){
				return 0;
			}
			else if(r == "T"){
				S += ch [j / 2];
				T += ch [j % 2];
				flag = true;
				break;
			}
		}
		if(flag == false){
			break;
		}
	}
	for(;i < 420;i++){
		FOR(j,0,4){
			string r;
			cout << ch [j / 2] + S << endl;
			cout << ch [j % 2] + T << endl;
			fflush(stdout);
			cin >> r;
			if(r == "end"){
				return 0;
			}
			else if(r == "T"){
				S = ch [j / 2] + S;
				T = ch [j % 2] + T;
				break;
			}
		}
	}


	return 0;
}


Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 0; i < n-1; i++)
    {
        if (p[i] == i+1) {
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    if (p[n-1] == n) {
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
n=int(input())
prime=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
counts=[0]*len(prime)
for i in range(len(prime)):
  k=n
  while k>0:
    counts[i]+= k//prime[i]
    k//=prime[i]
ans=0
for i in range(len(prime)):
  if counts[i]>=74:
    ans+=1
for i in range(len(prime)):
  for j in range(len(prime)):
    if i!=j and counts[i]>=2 and counts[j]>=24:
      ans+=1
for i in range(len(prime)):
  for j in range(len(prime)):
    if i!=j and counts[i]>=4 and counts[j]>=14:
      ans+=1
for i in range(len(prime)):
  for j in range(len(prime)-1):
    for k in range(j+1,len(prime)):
      if i!=j and i!=k and counts[i]>=2 and counts[j]>=4 and counts[k]>=4:
        ans+=1
print(ans)

Measured memory_bytes: 39664
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	vector<char> v;
	for (int i = 0; i < s.length(); ++i) {
		if (v.empty()) v.emplace_back(s[i]);
		else if (v.back() == 'T') v.emplace_back(s[i]);
		else if (v.back() == 'S') {
			if (s[i] == 'S') v.emplace_back(s[i]);
			else v.pop_back();
		}
	}
	cout << v.size();
	return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
template <long long mod>
class Combination
{
    std::vector<long long> fact, finv, inv;
public:
    Combination(int sz)
    {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for (int i = 2; i < sz; ++i)
        {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        finv[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (fact[n] * finv[k] % mod) * finv[n - k] % mod;
    }
    long long P(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fact[n] * finv[n - k] % mod;
    }
    long long H(long long n, long long k)
    {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i)
    {
        return fact[i];
    }
    long long getinv(int i)
    {
        return inv[i];
    }
    long long getfinv(int i)
    {
        return finv[i];
    }
};
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
  Combination<MOD> comb(3000010);
  ll ans = 0;
  ans = comb.C(r2+c2+2, c2+1) - 1;
  ans += 2*MOD - comb.C(r1+c2+1, c2+1) + 1;
  ans %= MOD;
  ans += 2*MOD - comb.C(r2+c1+1, c1) + 1;
  ans %= MOD;
  ans += comb.C(r1+c1, c1) - 1;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 70528
package main

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

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	A, B, C := sc.i(), sc.i(), sc.i()
	K := sc.i()
	k := 0
	for A >= B {
		B *= 2
		k++
	}
	for B >= C {
		C *= 2
		k++
	}
	if k <= K {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

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

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

// a^{-1} (mod) を計算
func Inv(a int) int {
	return Pow(a, mod-2)
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 2e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n;
vector<int> v[N];
int dp[N];
int ans;

void dfs(int x, int p = -1) {
  vector<int> cnt(20, 0);
  for (auto it : v[x]) {
    if (it == p)
      continue;
    dfs(it, x);
    for (int i = 0; i < 20; i++) {
      cnt[i] += (dp[it] >> i) % 2;
    }
  }
  int mx = -1;
  for (int i = 0; i < 20; i++) {
    if (cnt[i] > 1) {
      mx = max(mx, i);
    }
  }
  for (int i = mx + 1; ; i++) {
    if (!cnt[i]) {
      ans = max(ans, i);
      dp[x] |= (1 << i);
      mx = i;
      break;
    }
  }
  for (int i = mx + 1; i < 20; i++) {
    if (cnt[i] == 1) {
      dp[x] |= (1 << i);
    }
  }
  //cout << x << " " << dp[x] << "\n";
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    for (int i = 1, x, y; i < n; i++) {
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }
    dfs(1);
    cout << ans;
    return 0;
}

Measured memory_bytes: 18688
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
main(){
    int a;
    long long sum=0;
    scanf("%d",&a);
    vector<int> v;
    while(a--){
        int x;
        scanf("%d",&x);
        v.push_back(x);
        sum+=x;
    }
    sort(v.begin(),v.end());
    int vs=v.size();
    int cnt=0;
    int i=vs-1;
    while(1){
        if(i<0) break;
        cnt++;
        if(v[i]*3>2*sum) break;
        sum-=v[i];
        i--;
    }
    printf("%d\n",cnt);

}


Measured memory_bytes: 892
local n = io.read("*n", "*l")
local cnt = 0
local w_a , w_b, w_ab = 0, 0, 0
for i = 1, n do
  local ss = io.read()
  for p in ss:gmatch("AB") do
    cnt = cnt + 1
  end
  ss = ss:gsub("AB", "")
  local a, b = false, false
  if 0 < #ss then
    if ss:sub(1, 1) == "B" then
      b = true
    end
    if ss:sub(#ss, #ss) == "A" then
      a = true
    end
    if a and b then w_ab = w_ab + 1
    elseif a then w_a = w_a + 1
    elseif b then w_b = w_b + 1
    end
  end
end
if 0 < w_a or 0 < w_b then
  print(cnt + w_ab + math.min(w_a, w_b))
else
  print(cnt + math.max(0, w_ab - 1))
end


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

using ll=long long;
const ll z=0;

int main() {
  string S;
  cin >> S;
  int K=S.size();
  vector<int> DP(K+1,0);
  DP[0]=0;
  DP[1]=1;
  if(S[0]!=S[1])
  DP[2]=2;
  else if(S[0]==S[1])
  DP[2]=1;
  for(int i=3;i<=K;i++){
    if(S[i-2]!=S[i-1]){
      DP[i]=DP[i-1]+1;
    }
    else
      DP[i]=DP[i-3]+2;
  }
  
  cout << DP[K] << endl;
  
}


Measured memory_bytes: 1412
arr1 = gets.to_s.chomp.chars
arr2 = gets.to_s.chomp.chars
n = arr1.size 
eq = false

n.times do |i|
    eq = true
    n.times do |j|
        if i + j >= n
            current = i + j - n 
        else
            current = i + j
        end

        if arr1[j] != arr2[current]
            eq = false
            break 
        end
    end

    break if eq
end

if eq
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    path = [[] for _ in range(N+1)]
    path[0].append(1)
    for _ in range(M):
        a, b = map(int, readline().split())
        path[a].append(b)
        path[b].append(a)
    d = deque([0])
    parents = [0] * (N+1)
    parents[0] = -1
    while d:
        x = d.popleft()
        for i in path[x]:
            if parents[i] == 0:
                parents[i] = x
                d.append(i)
    ans = parents[2:N+1]
    if 0 in ans:
        print('No')
    else:
        print('Yes')
        for i in range(N-1):
            print(ans[i])

if __name__ == '__main__':
    main()

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

long long n, ans = 0;
vector<long long> a;

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) ans += a[i] - 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let (n, a, b) = i::u3();
    let mut ans = 0;
    for i in 1..(n + 1) {
        let k = i % 10 + i / 10 % 10 + i / 100 % 10 + i / 1000 % 10 + i / 10000 % 10;
        if k >= a && k <= b {
            ans += i;
        }
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

vector<int> x[100];

int main() {
  int n, d;
  cin >> n >> d;
  rep(i, n) rep(j, d) {
    int _x;
    cin >> _x;
    x[i].eb(_x);
  }

  int ans = 0;
  rep(i, n) REP(j, i + 1, n) {
    int tmp = 0;
    rep(k, d) tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
    int t = sqrt(tmp);
    if (t * t == tmp) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256