akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int r, s, p;
int price(char c) {
	if (c == 's') {
		return r;
	} 
	if (c == 'r') {
		return p;
	}
	return s;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	vector<int> win(n); 
	int answer = 0;
	for (int i = 0; i < n; ++i) {
		if (i < k) {
			win[i] = 1;
			answer += price(t[i]);
		} else {
			if (t[i] == t[i - k]) {
				if (!win[i - k]) {
					answer += price(t[i]);
					win[i] = 1;
				}
			} else {
				answer += price(t[i]);
				win[i] = 1;
			}
		}	
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
    if (a%b == 0) return(b);
    else return(gcd(b, a%b));
}

int main() {
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        int s;
        cin >> s;
        a[i]=abs(s-x);
    }

    if(n==1){
        cout << a[0] << endl;
        return 0;
    }

    int ans = gcd(a[0],a[1]);
    for(int i = 2; i < n; i++) {
        ans = gcd(ans,a[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
    ll n,ans=0;
    double d;
    cin>>n>>d;
    rep(i,n){
        double x,y,r;
        cin>>x>>y;
        r=sqrt(x*x+y*y);
        if(r<=d)ans++;
    }
  cout<<ans<<endl;
}



Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,r;cin>>n>>r;
  int ans=0;
  if(n>=10){
    ans=r;
  }else{
    ans=r+100*(10-n);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int K,N;
    int i;

    scanf("%d %d", &K, &N);

    //int a[N] = {0};
    int a[200000+1] = {0};
    int d;
    int ans=0;

    scanf("%d", &a[0]);
    for( i = 1; i <= N-1; i++ ){
        scanf("%d", &a[i]);
        d = a[i] - a[i-1];
        if( d > ans ){
            ans = d;
        }
    }

    if( K - (a[N-1] - a[0]) > ans ){
        ans = K - (a[N-1] - a[0]);
    }

    printf("%d\n", K-ans);

    return 0;
}


    


Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W) {
  int maxWidth = 0;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      dp[i][j] = (G[i][j] + 1) % 2;
      maxWidth |= dp[i][j];
    }
  }

  for ( int i = 1; i < H; i++ ) {
    for ( int j = 1; j < W; j++ ) {
      if ( G[i][j] ) {
	dp[i][j] = 0;
      } else {
	dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
	maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }

  return maxWidth * maxWidth;
}

int main(void) {
  int H, W;
  scanf("%d %d", &H, &W);

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) scanf("%d", &G[i][j]);
  }

  printf("%d\n", getLargestSquare(H, W));

  return 0;
}

Measured memory_bytes: 17968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
    		int count1 = 0;
    		int count9 = 0;
    		int count7 = 0;
    		int count4 = 0;
        	for(int i = 0; i < 4; i++) {
        		int N = in.nextInt();
        		switch(N) {
        		case 1:
        			count1++;
        			break;
        		case 9:
        			count9++;
        			break;
        		case 7:
        			count7++;
        			break;
        		case 4:
        			count4++;
        			break;
        		}
        	}
        	String str = "NO";
        	if(count1 == 1 && count9 == 1 && count7 == 1 && count4 == 1) {
        		str = "YES";
        	}
        	out.println(str);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
def slove(n, a):
    
    count = [0]*(n+1)
    for x in a :
        count[x] +=1

    for i in count[1:]:
        print(i)
    
if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    slove(n, a_list)

Measured memory_bytes: 32128
#include<cstdio>

#define int long long

int x;

const int low=-200;
const int high=200;

signed main(){
	scanf("%lld",&x);
	for(int a=low;a<=high;++a)for(int b=low;b<=high;++b){
		if(a*a*a*a*a-b*b*b*b*b==x)return printf("%lld %lld\n",a,b),0;
	}
	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),sum(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      sum[i]+=a[j];
    }
    for(int j=i;j<n;j++){
      sum[i]+=b[j];
    }
  }
  int m=0;
  for(int i=0;i<n;i++){
    m=max(m,sum[i]);
  }
  cout << m << endl;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
d = list(map(int,input().split()))
foruse = [0,1,2,3,4,5,6,7,8,9]
for item in d:
    foruse.remove(item)
#print(foruse)

for i in range(n,100000):
    flag = 1
#    print('test:'+str(i))
    for item in list(str(i)):
        if int(item) not in foruse:
            flag = 0
    if flag == 1:
        print(i)
        break



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    int res = 0;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            res += a[i] * a[j];
        }
    }
    cout << res << "\n";
}


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

ll count ( ll n)
{
    ll ans =0;
    while( n%2==0)
    {
        n= n/2;
        ans++;
    }
    return ans;
}

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll ans = INT_MAX;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans = min(ans , count(a[i]));
    }
    cout<<ans;
}

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

void fnInput(vector<int>& rvnSeq)
{
  int nSeqSiz;
  cin >> nSeqSiz;
  rvnSeq.resize(nSeqSiz);

  for (int& rnSeq : rvnSeq)
    cin >> rnSeq;
}
  
int fnLowerCnt(const vector<int>& cnrvnSeq)
{
  int nMaxSeqCnt = 0;
  int nBgn = 0;

  while (nBgn < cnrvnSeq.size() - 1)
  {
    int nSeqCnt = 0;
    int nFoward;

    for (nFoward = nBgn; nFoward < cnrvnSeq.size() - 1; nFoward++)
      if (cnrvnSeq[nFoward] >= cnrvnSeq[nFoward + 1])
        nSeqCnt++;
      else
        break;

    nBgn = nFoward + 1;
    nMaxSeqCnt = max(nMaxSeqCnt, nSeqCnt);
  }
  return nMaxSeqCnt;
}
  
int main()
{
  vector<int> vnSeq;

  fnInput(vnSeq);
  cout << fnLowerCnt(vnSeq) << endl;

  return 0;
}

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

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_parallel(P a1,P a2,P b1,P b2){
	return EQ(cross(a1-a2,b1-b2),0.0);
}

int is_intersected_ls(P a1,P a2,P b1,P b2){
	return cross(a2-a1,b1-a1)*cross(a2-a1,b2-a1) < EPS &&
		cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1) < EPS;
}

P intersection_ls(P a1,P a2,P b1,P b2){
	P b = b2 - b1;
	double d1 = abs(cross(b,a1-b1));
	double d2 = abs(cross(b,a2-b1));
	double t = d1 / (d1 + d2);
	return a1 + (a2 - a1) * t;
}

double polygon_area(int n, P p[]){
	double s = cross(p[n-1],p[0]);
	for(int i=0;i<n-1;i++) s += cross(p[i],p[i+1]); 
	return fabs(s) / 2;
}

int main(void){
	while(1){
		double s=0;
		P l[3][2],p[3];

		for(int i=0;i<3;i++){
			if(!(cin>>l[i][0].real()>>l[i][0].imag()>>l[i][1].real()>>l[i][1].imag())) return 0;
		}

		for(int i=0;i<3;i++){
			int j = (i + 1) % 3;
			if(is_parallel(l[i][0],l[i][1],l[j][0],l[j][1]) ||
				 !is_intersected_ls(l[i][0],l[i][1],l[j][0],l[j][1])){
				s = -1;
				break;
			}
			else{
				p[i] = intersection_ls(l[i][0],l[i][1],l[j][0],l[j][1]);
			}
		}

		if(s == -1 || p[0]==p[1] && p[1]==p[2]){
			cout<<"kyo\n";
		}
		else{
			s = polygon_area(3,p);
			if(s >= 1900000) cout<<"dai-kichi\n";
			else if(s >= 1000000) cout<<"chu-kichi\n";
			else if(s >= 100000) cout<<"kichi\n";
			else cout<<"syo-kichi\n";
		}
	}

	return 0;
}

Measured memory_bytes: 0
def solve():
    H, N = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    
    INF = 10 ** 9
    dp = [INF for _ in range(10 ** 7)]
    dp[0] = 0

    for a, b in A:
        for i in range(H+1):
            if dp[i] == INF: continue
            dp[i+a] = min(dp[i+a], dp[i] + b)
            
    return min(dp[H:])

print(solve())


Measured memory_bytes: 197292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(int i=(a);i<(int)(b);i++)
#define repi(i,n) fori(i,0,n)
#define forr(i,a,b) for(int i=int(b-1);i>=int(a);i--)
#define repr(i,n) forr(i,0,n)
#define all(x) (x).begin(),(x).end()
#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const ll MOD = 1000000007;

void solve(ll n, string s){
    ll ans=1;
    ll cnt=0;
    repi(i,2*n){
        bool f1=cnt%2==0;
        bool f2=s[i]=='B';
        if(f1^f2){
            ans=(ans*cnt)%MOD;
            cnt--;
        }else{
            cnt++;
        }
    }
    if(cnt){
        cout<<0<<endl;
        return;
    }
    repi(i,n)ans=(ans*(i+1))%MOD;
    cout<<ans<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    string s;
    cin >> s;
    solve(n, s);
    return 0;
}


Measured memory_bytes: 772
from sys import stdin
from copy import deepcopy

n = int(stdin.readline().rstrip())
t = list(map(int,stdin.readline().rstrip().split()))
m = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

for i in li:
    lin = deepcopy(t)
    lin[i[0]-1] = i[1]
    print(sum(lin))

Measured memory_bytes: 3444
let [a, b, c, d] = require("fs").readFileSync("/dev/stdin", "utf8").split(" ").map(Number);
let [f1, f2, f3] = [a - c, a - b, b - c].map(n => Math.abs(n) <= d)
console.log(f1 || f2 && f3 ? "Yes" : "No");

Measured memory_bytes: 30468
#include<stdio.h>
#define NIL -1
typedef struct{
  int p,l,r;
}node;

void print(node *u,int i){
  int p=u[i].p;
  
  printf("node %d: ",i);
  printf("parent = %d, ",u[i].p);
  printf("sibling = %d, ",sibling(u,i));
  printf("degree = %d, ",degree(u,i));
  printf("depth = %d, ",depth(u,i));
  printf("height = %d, ",height(u,i));
  if(u[i].p == NIL) printf("root\n");
  else{
    if(u[i].l == NIL && u[i].r == NIL) printf("leaf\n");
    else printf("internal node\n");
  }
}

int sibling(node *u, int i){
  int p = u[i].p;

  if(p == NIL) return NIL;
  if(u[p].l == i) return u[p].r;
  else return u[p].l;
}

int degree(node *u,int i){
  int count=0;

  if(u[i].l != NIL) count++;
  if(u[i].r != NIL) count++;
  
  return count;
}

int depth(node *u,int x){
  int count=0,temp;

  while(u[x].p != NIL){
    count++;
    temp = u[x].p;
    x = temp;
  }
  return count;
}

//
int height(node *u, int x){
  int count1=0,count2=0;
  int res;
  
  if(u[x].l != NIL) count1 = height(u,u[x].l)+1;
  if(u[x].r != NIL) count2 = height(u,u[x].r)+1;
  res = (count1>=count2) ? count1 : count2;
  count1 = count2 = 0;
  
  return res;
}

int main(){
  node u[30];
  int n,id,l,r;
  int i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) u[i].p = u[i].l = u[i].r = NIL;
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    u[id].l = l;
    u[id].r = r;
    u[l].p = u[r].p = id;
  }
  for(i=0;i<n;i++) print(u,i);
  
 
return 0;
}



Measured memory_bytes: 2096
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] a = new int[n];
			int[] b = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = scanner.nextInt();
			for (int i = 0; i < n; i++)
				b[i] = scanner.nextInt();
			Arrays.sort(a);
			Arrays.sort(b);
			for (int i = 0; i < n / 2; i++) {
				if (a[n - 1 - i * 2] > b[n - 1 - i]) {
					System.out.println((i * 2) + 1);
					continue loop;
				}
			}
			System.out.println("NA");
		}
	}
}

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

#pragma GCC diagnostic warning "-Wconversion"

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

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

        int n;
        cin >> n;

        string s;
        cin >> s;

        int addf = 0;
        int val = 0;
        forc(c, s)
        {
                if (c == '(')
                        val++;
                else
                        val--;
                if (val == -1)
                {
                        addf++;
                        val++;
                }
        }

        fora(i, addf)
                cout << '(';
        cout << s;
        fora(i, val)
                cout << ')';
        cout << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1


int main(){
	int t;
	int field[5][5];
	scanf("%d",&t);
	while(t--){
		int ans = 0;
		rep(i,5)rep(j,5)scanf("%d",&field[i][j]);
		rep(i,5)rep(j,5){
			for(int y=1; y+i<=5; y++){
				for(int x=1; x+j<=5; x++){
					bool flag = true;
					rep(k,y)rep(l,x)if( field[i+k][j+l]==0 ){ flag=false; break; }
					if( flag ){
						ans = max(ans, y*x);
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#define SIZE 105

int main(void){
    int x, n, i, p, count[SIZE] = {0}, a, b, ans;
    scanf("%d %d", &x, &n);
    for(i = 0; i < n; i++){
        scanf("%d", &p);
        count[p]++;
    }
    a = x;
    while(count[a] != 0)
        a--;
    b = x;
    while(count[b] != 0)
        b++;
    ans = (x - a <= b - x) ? a : b; 
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    ll t[n];
    for (ll i=0;i<n;i++){
        cin >> t[i];
    }
    ll ans=1,x;
    for (ll i=0;i<n;i++){
        if (t[i]==0)continue;
        x=t[i]/gcd(ans,t[i]);
        ans*=x;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	String s = scn.next();
      	String[] list = s.split("");
      	int count = 0;
      	int min = n;
      	for(int i=1; i<n; i++){
      		if(list[i].equals("E")) count++;
    	}
    	min = Math.min(min, count);
    	for(int i=1; i<n; i++){
      		if(list[i-1].equals("W")) count++;
      		if(list[i].equals("E")) count--;
      		min = Math.min(min, count);
    	}
      	System.out.println(min);
	}
}


Measured memory_bytes: 67020
#include <stdio.h>

int main(void){
  int a, b, c, x, xx;
  int ans=0;

  scanf("%d %d %d", &a,&b,&c);
  scanf("%d", &x);
  
  for (int i=0; i<a+1; i++){
    for (int j=0; j<b+1; j++){
      for (int k=0; k<c+1; k++){
        if (x == i*500 + j*100 + k*50) ans++;
      }
    }
  }

  printf("%d\n",ans);
  return(0);
}



Measured memory_bytes: 1736
N = int(input())

mod = 10 ** 9 + 7

count = [0] * (N+1)
def prime_fac(n,c):
    while n % 2 == 0:
        n //= 2
        c[2] += 1
    i = 3
    while n != 1:
        if n % i == 0:
            c[i] += 1
            n //= i
        else:
            i += 2
    return 0
        
for i in range(1,N+1):
    prime_fac(i,count)

ans = 1
for i in count[1:]:
    if i >= 1:
       ans *= (i+1) % mod
       ans %= mod

print(ans)

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

int main() {
    int q, h, S, D; cin >> q >> h >> S >> D;
    int n; cin >> n;
    int Q = 4 * q;
    int H = 2 * h;
    int L = min(min(Q, H), S);
    Int ans;
    if (2 * L > D) {
        ans = ((Int)n / 2) * D;
        ans += ((Int)n % 2) * L; 
    }
    else {
        ans = (Int)L * n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
H=[int(i) for i in input().split()]
idx,score=-1,1000
for i in range(N):
    tscore = abs(T-H[i]*0.006-A)
    if tscore<score:
        score=tscore
        idx=i
print(idx+1)


Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include <iomanip>
#include<cstdlib>
using namespace std;
#define MPI  3.14159265358979323846

int main(){
  int a, b, h, m;
  
  cin >> a >> b >> h >> m;
  
  int minTime = h * 60 + m;
  
  float theta_h = minTime * 0.5;
  float theta_m = minTime * 6 % 360;
  
  if(theta_h == theta_m){
    cout << fixed << setprecision(15) << abs(b - a) << endl;
    return 0;
  }
  
  double radian;
  
  if(theta_h > theta_m) radian = (theta_h - theta_m) * MPI / 180.0;
  else radian = (theta_m - theta_h) * MPI / 180.0;
  
  double ans = sqrt(a*a + b*b - 2*a*b*cos(radian));

  cout << fixed << setprecision(15) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4084
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e9+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

int main()
{
	//int ans = 0;
	int n;
	cin >> n;
	ll sum = (ll)0;
	vdef a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}

	ll ans1 = sum;
	for (int i = 1; i < n; i += 2)
	{
		ans1 -= (ll)2 * (ll)a[i];
	}
	cout << ans1 << endl;

	ll ans = ans1;
	ll ans_prev = ans1;
	for (int i = 1; i < n; ++i)
	{
		ans = (ll)(2 * a[i - 1]) - ans_prev;
		ans_prev = ans;
		cout << ans << endl;
	}
	//cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int n,ans=0;
	int h,w;
	cin>>n;
	cin>>h>>w;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x>=h&&y>=w) ans++;
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int x,a;
	cin >> x >> a;
	if(x<a) cout << 0 << endl;
	else cout << 10 << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  for(int i = 0; i < 10000000; ++i){
    if(i%2 == 0){
      c -= b;
      if(c <= 0){
	cout << "Yes" << endl;
	break;
      }      
    } else {
      a -= d;
      if(a <= 0){
	cout << "No" << endl;
	break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	ll a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1;
	system("pause");
}

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

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

    long long c[5]={0};    
    string s = "MARCH";
    
    for(int i=0;i<N;i++){
        string str;
        cin>>str;
        for(int j=0;j<5;j++){
            if(str[0]==s[j]){
                c[j]++;
            }
        }          
    }

    long long ptn=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ptn+=c[i]*c[j]*c[k];
            }
        }
    }

    cout<<ptn<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
 
int main(){
    int n,tmp,min=INT_MAX,max=INT_MIN;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&tmp);
        if(max<tmp-min){
	  max=tmp-min;
	}
	if(min>tmp){
	  min=tmp;
	}
    }
    printf("%d\n",max);
    return 0;
}


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

using namespace std;

int main() {
    vector<int> a;

    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;

        if (n == 0) {
            int x;
            cin >> x;
            a.emplace_back(x);
        } else if (n == 1) {
            int p;
            cin >> p;
            cout << a[p] << endl;
        } else if (n == 2) {
            a.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,a,b,c,d,e;
  string s;
  cin >> s;
 
  a=0,b=0;
  
  for(int i=0;i<s.size();i++){
    if(i%2 == 0){
      
    if(s[i] == '0'){
       a++;
    }
     else if(s[i] == '1'){
       b++;
  }
    }
 else{
    if(s[i] == '1'){
           a++;
    }
   else if(s[i] == '0'){
     b++;
  }
 }
  }
  cout << min(a,b) << endl;
}
      


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int n, k, st = 1, c = 0;
	cin >> n >> k;
	int a[n];
	REP(i,n) cin >> a[i];
	while(st < n){
		st += k - 1;
		c++;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
template<typename T>
using gtree = tree<T, null_type, less<T> ,rb_tree_tag, tree_order_statistics_node_update>;

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

  Int n;
  cin>>n;
  vector<Int> p(n),f(n);
  for(Int i=0;i<n;i++) cin>>p[i];
  for(Int i=0;i<n;i++) cin>>f[i];
  
  using P = pair<Int, Int>;
  vector<P> gx,gy;

  gtree<P> ay;
  
  for(Int i=0;i<n;i++){
    gx.emplace_back(p[i],i);
    gy.emplace_back(f[i],i);
    ay.insert(P(f[i],i));
  }
  sort(gx.begin(),gx.end());
  sort(gy.begin(),gy.end());
  
  vector<Int> rx(n),ry(n);
  for(Int i=0;i<n;i++){
    rx[i]=gx[i].second;
    ry[i]=gy[i].second;
  }

  vector<Int> ux(n,0),uy(n,0);
  auto calc=[&]()->Int{
    Int res=0;
    for(Int i=0,j=0;i<n;i++){
      if(ux[rx[i]]) continue;
      while(j<n&&(uy[ry[j]]||gx[i].first>=gy[j].first)) j++;
      if(j<n) res++,j++;
    }
    return res;
  };

  Int win=calc();
  //cout<<win<<endl;

  auto check=[&](Int i,Int m)->Int{
    Int k=ay.find_by_order(m)->second;
    uy[k]=1;
    ay.erase(P(f[k],k));

    Int res=0;
    if(p[i]<f[k]){
      res = (win-1==calc());
    }else{
      res = (win==calc());
    }
    
    uy[k]=0;
    ay.insert(P(f[k],k));
    return res;
  };
  
  for(Int i=0;i<n;i++){  
    ux[i]=1;

    Int ub=0;
    auto it=ay.upper_bound(P(p[i],n+1));
    if(it==ay.end()) ub=ay.size();
    else ub=ay.order_of_key(P(*it));

    // if(ub<n-i)  cout<<i<<" "<<p[i]<<":"<<ub<<":"<<ay.find_by_order(ub)->first<<endl;
    
    Int l,r;
    if(ub!=(Int)ay.size()&&check(i,ub)){
      l=ub,r=n-i;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(i,m)) l=m;
	else r=m;
      }
    }else{
      l=0,r=ub;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(i,m)) l=m;
	else r=m;
      }
    }
    
    Int k=ay.find_by_order(l)->second;
    if(p[i]<f[k]) win--;

    uy[k]=1;
    ay.erase(P(f[k],k));
    
    if(i) cout<<" ";
    cout<<f[k];

    //for(P p: ay) cout<<p.first<<" ";		     
    //cout<<endl;
    //cout<<k<<" "<<f[k]<<":"<<win<<endl;
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3740
from sys import stdin
from sys import setrecursionlimit
from collections import Counter
setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int,stdin.readline().rstrip().split()))
su = sum(a)

q = int(input())
cc = Counter(a)

for _ in range(q):
    b,c = map(int,input().split())
    cc[c] += cc[b]
    su += c*cc[b]-b*cc[b]
    cc[b] -= cc[b]
    print(su)

Measured memory_bytes: 93048
import math
import copy




def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=input()
b=input()
c=input()
def func():
    result=0
    for idx in range(0,len(a)):
        if a[idx]==b[idx]==c[idx]:
            result+=0
        elif a[idx]!=b[idx] and a[idx]!=c[idx] and b[idx]!=c[idx]:
            result+=2
        else:
            result+=1
    return result

print(func()) 







Measured memory_bytes: 3668
import java.util.Scanner;
import static java.lang.Math.*;

import java.io.PrintWriter;
class Main{
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		
		while(sc.hasNext()){
			int temp [] = new int[1001];
			while(true){
				int in1 = sc.nextInt(),
					in2 = sc.nextInt();
				if(in1 == 0 && in2 == 0)break;
				temp[in1]++;
				temp[in2]++;
			}
			int count = 0;
			for(int i:temp){
				if(i % 2 == 1)count++;
			}
			if(count != 2)out.println("NG");
			else if(temp[1] % 2 == 1 && temp[2] % 2 == 1)out.println("OK");
			else out.println("NG");
			out.flush();
		}
	}
} 

Measured memory_bytes: 31560
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;

	private void mainrun() {
		scan = new Scanner(System.in);

		long a,b,ans,n,ax,bx;

		while(scan.hasNext()) {
			a = scan.nextInt();
			b = scan.nextInt();


			//最大公約数
			ans = 1;
			n = Math.min(a, b);

			for(long i = 1;i <= n;i++) {


				if(a % (n/i) == 0 && b % (n/i) == 0) {
					ans = n/i;
					break;
				}
			}

			//最小公倍数

			ax = bx = 1;

			while(true) {
				if(a * ax == b * bx) {
					break;
				}else if(a * ax > b * bx){
					bx++;
				}else if(a * ax < b * bx){
					ax++;
				}
			}
			System.out.println(ans + " " + a * ax);
		}

		scan.close();

	}

}


Measured memory_bytes: 26492
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
  int n; cin>>n;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  // pmpmpm...
  ll an=1e18, sm=0, t=0;
  for(int i=0;i<n;i++){
    t += a[i];
    if (i%2==0 && t <= 0) sm += -t+1, t += -t+1;
    else if (i%2==1 && t >= 0) sm += t+1, t -= t+1;
  }
  an = min(an,sm);
  sm=0,t=0;
  for(int i=0;i<n;i++){
    t += a[i];
    if (i%2==1 && t <= 0) sm += -t+1, t += -t+1;
    else if (i%2==0 && t >= 0) sm += t+1, t -= t+1;
  }
  an = min(an,sm);
  cout<<an<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

typedef complex<double> base;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main() 
{
    IOS
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ctr=0;int ctr2=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
            ctr++;
        else
            ctr2++;
    }
    int ans=0;
    for(int i=0;i<ctr2;i++)
        if(s[i]=='W')
            ans++;
    print(ans);    
}   


Measured memory_bytes: 3736
function swap(A, i, j) {
	var tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}
function parent(i) {
	return Math.floor(i / 2);
}
function left(i) {
	return i * 2;
}
function right(i) {
	return i * 2 + 1;
}
function maxHeapify(A, i) {
	var l = left(i);
	var r = right(i);

	var largest;
	if (l <= heap.length && A[l] > A[i]) {
		largest = l;
	} else {
		largest = i;
	}
	if (r <= heap.length && A[r] > A[largest]) {
		largest = r;
	}

	if (largest != i) {
		swap(A, i, largest);
		maxHeapify(A, largest);
	}
}
function buildMaxHeap(A) {
	for (var i = Math.floor(heap.length / 2); i > 0; i--) {
		maxHeapify(A, i);
	}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');

var size = +lines.shift()
var vals = lines.shift().split(' ');
var heap = ['NA'];
for (var i = 0; i < size; i++) {
	heap.push(+vals[i]);
}

buildMaxHeap(heap);

heap.shift();
console.log(' ' + heap.join(' '));

Measured memory_bytes: 104736
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k; cin >> n >> k;
  if (k > (n-1)*(n-2)/2) cout << -1 << endl;
  else {
    ll nedge = (n-1)*(n-2)/2;
    cout << nedge - k + n - 1 << endl;
    for (ll i=2; i<n+1; i++) cout << 1 << ' ' << i << endl;;
    bool is_match = false;
    for (ll j=2; j<n+1; j++) {
      for (ll l=j+1; l<n+1; l++) {
        if (nedge == k){ is_match = true; break;}
        cout << j << ' ' << l << endl;
        nedge--;
      if (is_match) break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<char> t(Q), d(Q);
    REP(i, Q) { cin >> t[i] >> d[i]; }
    int l = -1, r = N;

    RREP(i, Q - 1) {
        if (d[i] == 'L' && t[i] == s[l + 1])
            l++;
        if (d[i] == 'R' && t[i] == s[r - 1])
            r--;
        if (d[i] == 'L' && t[i] == s[r])
            r++;
        if (d[i] == 'R' && t[i] == s[l])
            l--;
    }

    cout << r - l - 1 << endl;

    return 0;
}

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

int main() {
  long n;
  cin >>n;
  int ans=0;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
    ans+=a.at(i);
  }
  sort(a.begin(),a.end());
  cout<<ans-a.at(n-1)/2<<endl;
}

Measured memory_bytes: 256
let () =
  let a, b, c, x, y = Scanf.scanf "%d %d %d %d %d" (fun a b c x y -> a, b, c, x, y) in
  Array.init 100001 (fun x -> x)
  |> Array.map (fun i -> a *  (max 0 (x-i)) +  b * (max 0 (y-i))  + 2 * c * i)
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"

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

int intpow(int D) {
    switch (D) {
        case 0 :
            return 1;
        case 1:
            return 100;
        case 2:
            return 10000;
        default:
        return 0;
    }
}

signed main () {
    int N, D;
    cin >> D >> N;
    if (N != 100 ) {
        cout << N *intpow(D) << endl;
    } else {
        cout << (N + 1) *intpow(D) << endl;
    }

    return 0;
}

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

int main() {
	// your code goes here
	int N;
	
	while(cin >> N && N){
		int ices[10]={};
		int tmp;
		for(int i=0;i<N;i++){
			cin >> tmp;
			ices[tmp]++;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<ices[i];j++)
				cout << '*';
			if(ices[i]==0)
				cout << '-';
				cout << endl;
		}
		
	}
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
ll d;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>d;
    int res=0;
    for (int i=0; i<n; i++) {
	ll x,y;
	cin>>x>>y;
	if (d*d >= x*x+y*y) res++;
    }
    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
using PII = pair<int, int>;
using VP  = vector<PII>;
using VVP = vector<VP>;
int n, a, x, y, res;
bool ok;
VVP v;
inline void Check(int mask) {
    int nrb = __builtin_popcount(mask);
    if (nrb <= res)
        return;
    for (int i = 0; i < n; ++i)
        if (mask & (1 << i))
            for (const PII& P : v[i]) {
                tie(x, y) = P;
                if ((!(mask & (1 << x)) && y) || ((mask & (1 << x)) && !y))
                    return;
            }
    res = nrb;
    return;
}
int main() {
    DAU
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a;
        v[i].resize(a);
        for (PII& P : v[i]) {
            cin >> P.first >> P.second;
            --P.first;
        }
    }
    for (int mask = 0; mask < (1 << n); ++mask)
        Check(mask);
    cout << res;
    PLEC
}


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

std::vector<std::pair<int, int> > graph[1024];
int n;

int p[1024];
int d[1024];

void init() {
  for(int i = 0; i < 1024; ++i) {
    graph[i].clear();
  }
}

class CalcReduction_ {
public:
  int operator () () {
    for(int i = 0; i < 1024; ++i) {
      dist[i] = 2000000000;
    }
    dist[1] = 0;
    dfs1(1);
    int id = GetFar();
    for(int i = 0; i < 1024; ++i) {
      dist[i] = 2000000000;
    }
    dist[id] = 0;
    dfs1(id);
    int id2 = GetFar();
    return dist[id2];
  }
  void dfs1(int id) {
    for(std::pair<int, int> ToCost : graph[id]) {
      int to   = ToCost.first;
      int cost = ToCost.second;
      if( graph[to].size() == 1 ) continue;
      int newcost = dist[id] + cost;
      if( newcost < dist[to] ) {
        dist[to] = newcost;
        dfs1(to);
      }
    }        
  }
  int GetFar() {
    int fardist = 0;
    int farid = 0;
    for(int i = 1; i <= n; ++i) {
      if( graph[i].size() == 1 ) continue;
      if( fardist <= dist[i] ) {
        fardist = dist[i];
        farid = i;
      }
    }
    return farid;
  }
    
private:
  int dist[1024];
};

CalcReduction_ CalcReduction;

int main(int argc, char *argv[]) {

  for(;;) {
    init();
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 2; i <= n; ++i) {
      int t;
      scanf("%d", &t);
      p[i] = t;
    }
    for(int i = 2; i <= n; ++i) {
      int t;
      scanf("%d", &t);
      d[i] = t;
    }
    for(int i = 2; i <= n; ++i) {
      int from = i;
      int to   = p[i];
      int cost = d[i];
      graph[from].push_back(std::pair<int, int>(to, cost));
      graph[to].push_back(std::pair<int, int>(from, cost));
    }
    int res = 0;
    // step 1
    for(int i = 2; i <= n; ++i) {
      res += d[i];
    }
    // step 2
    for(int i = 1; i <= n; ++i) {
      if( graph[i].size() == 1 ) continue;
      for(std::pair<int, int> ToCost : graph[i]) {
        int to   = ToCost.first;
        int cost = ToCost.second;
        if( graph[to].size() == 1 ) continue;
        res += cost;
      }
    }
    // step 3
    res -= CalcReduction();
    printf("%d\n", res);
  }

      
  return 0;
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	long long int l[N], r[N], ans = 0;

	for(int i=0; i<N; i++){
		cin >> l[i] >> r[i];
		ans += r[i] - l[i] + 1;
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256