akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int x =  sc.nextInt();
			if(x == 0) {
				System.out.println(1);
			}else {
				System.out.println(0);
			}
			




		}catch(Exception e) {
			e.printStackTrace();
		}

	}


}

Measured memory_bytes: 35704
#include<bits/stdc++.h>
#define ll long long
#define maxn 55
using namespace std;
ll dp[maxn][maxn*maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,A;
	cin >> n >> A;
	
	dp[0][0] = 1;
	for(int i=1,val;i<=n;i++) {
		cin >> val;
		for(int j=i;j>=1;j--) {
			for(int k=val;k<=2500;k++) {
				dp[j][k] += dp[j-1][k-val];
			}
		}	
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
		ans += dp[i][A*i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
S = {}
for i in range(N):
    s = input().rstrip()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

M = int(input())
for i in range(M):
    T = input().rstrip()
    if T in S:
        S[T] -= 1
        if S[T]==0:
            del S[T]

#print(S)
if len(S)==0:
    print('0')
else:
    print(max(list(S.values())))


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

ll lucas(ll i,vector<ll> &num)
{
  if(i==0) {num.at(0)=2; return 2;}
  if(i==1) {num.at(1)=1; return 1;}
  if(num.at(i)!=0) {return num.at(i);}
  num.at(i)=lucas(i-1,num)+lucas(i-2,num);
  return num.at(i);
}  

int main() 
{
  ll N; cin>>N;
  vector<ll> num(N+1);
  cout<<lucas(N,num)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  string s; cin >> s;
  int ans = 0; string tmp = "", prev = "";
  REP(i, s.size()){
    tmp += s[i];
    if(ans == 0){
      prev = tmp; tmp = "";
      ans++;
    } else {
      if(tmp != prev){
        prev = tmp; tmp = "";
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
from copy import deepcopy
k = int(input())

lun = []
for i in range(1,10):
    lun.append(i)

if k <= 9:
    print(lun[k-1])
    exit()

prev_lun = deepcopy(lun)

while True:
    size = len(lun)
    for pl in prev_lun:
        for i in [-1, 0, 1]:
            d = pl%10 + i
            if 0 <= d <= 9:
                lun.append(pl*10 + d)
            if len(lun) == k:
                # print(lun)
                print(lun[k-1])
                exit()
                
    prev_lun = deepcopy(lun[size:])


Measured memory_bytes: 8212
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;

signed main(){
    
    while(1){
        int n; cin >> n;
        if(n == 0) break;
        vector<int> a(n + 2);
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
    
        a[0] = a[n + 1] = -1;
        int ans = n;

        for(int i = 1; i <= n; i++){
            //cout << "i = " << i << endl;
            int tmp = a[i];
            for(int j = 1; j <= 3; j++){
                a[i] = j;
                
                int l, r;
                l = r = i;
                int hoge = 0;
                while(1){
                    
                    if(a[l] == -1 || a[r] == -1 || a[l] != a[r]){
                        //cout << i << " " << j << " " << hoge << endl;
                        ans = min(ans, n - hoge);
                        break;
                    }

                    int cnt = 2;
                    if(l == r) cnt--;
                    int curColor = a[l];
                    // 右へ---
                    while(a[r + 1] == curColor){
                        r++;
                        cnt++;
                    }
                    // 左へ
                    while(a[l - 1] == curColor){
                        l--;
                        cnt++;
                    }
                    
                    if(cnt >= 4){
                        l--;
                        r++;
                        hoge += cnt;
                    }else{

                        //cout << i << " " << j << " " << hoge << endl;
                        ans = min(ans, n - hoge);
                        break;
                    }
                }
            }
            a[i] = tmp;
        }

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



Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int x,y; cin >> x >> y;
		if(x==0&&y==0)break;
		double mi=1e9;
		for(int i=0;i<=x;i++){
			double d=sqrt(i*i+(x-i)*(x-i));
			if(abs(d-y)<mi){
				mi=abs(d-y);
			}
		}
		printf("%.8f\n",mi );
	}
}


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

#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int arr[maxn];
	for (int i = 1; i <= n; ++i) cin >> arr[i];
	int cur = 0, prev = arr[1], mx = 0;
	for (int i = 2; i <= n; ++i) {
		if (arr[i] <= prev) {
			prev = arr[i];
			++cur;
		}
		else {
			mx = max(mx, cur);
			cur = 0;
			prev = arr[i];
		}
	}
	mx = max(mx, cur);
	cout << mx << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	ll n;
	cin >> n;
	ll cnt=1;
	map<ll,ll> my;
	my[n]=1;
	ll q=n-1;
	for(ll i=1; i*i<=q; i++)
	{
		if(q%i==0)
		{
			my[i]++;
			my[q/i]++;
			if(i!=(q/i))cnt+=2;
			else cnt++;
		}
	}
	ll q1=n;
	ll i;
	for(i=2; i*i<=n; i++)
	{
		q1=n;
		while(q1%i==0)
		{
			q1/=i;
		}
		if((q1-1)%i==0 && my.find(i)==my.end())
		{
			my[i]++;
			cnt++;
		}
	}
	if(my.find(2)==my.end())
	{
		cnt++;
	}
	if(my.find(1)!=my.end())
	{
		cnt--;
	}
	cout << cnt<< endl;
	// for(auto x:my)
	// {
	// 	cout<<x.first<<" ";
	// }
	return 0;
}


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

qq = [[0]*10 for _ in range(10)]

def start(n):
    return int(str(n)[0])
def end(n):
    return int(str(n)[-1])

for i in range(1,N+1):
    qq[start(i)][end(i)] += 1

ans = 0
for i in range(1,10):
    for j in range(i,10):
        if i == j:
            ans += qq[i][j]**2
        else:
            ans += qq[i][j]*qq[j][i]*2

print(ans)

Measured memory_bytes: 40556
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
}







int main()
{
	abc();


	int k;
	cin >> k;
	while (k--) {
		cout << "ACL";
	}




}

Measured memory_bytes: 3640
import java.util.*;

class Main{

    int gcd(int x, int y){
        return y > 0 ? gcd(y, x%y) : x;
    }

    void print(int x, int y){
        int g = gcd(x, y);
        System.out.println(x/g + "/" + y/g);
    }

    void solve(){
        Scanner sc = new Scanner(System.in);
        String in = sc.next();
        int o, p, l, d;
        o = p = -1;
        String all = "", sub = "";
        for ( int i = 0; i < in.length(); i++ ){
            if ( in.charAt(i) == '.' ){
                o = i;
            } else if ( in.charAt(i) == '(' ) {
                p = i;
                sub = all;
            } else if ( in.charAt(i) == ')' ) {
            } else {
                all += in.charAt(i);
            }
        }
        d = in.length() - o - 1;
        l = p - o - 1;
        if ( p == -1 ){
            print(Integer.parseInt(all), (int)Math.pow(10, d));
        }else {
            d -= 2; // for ()
            print(Integer.parseInt(all)- Integer.parseInt(sub), (int)Math.pow(10, d) - (int)Math.pow(10, l) );
        }
    }

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



Measured memory_bytes: 26328
#include<stdio.h>


 int main ()

 {
     int i,j,n=5;
     int a[100];

     int temp=0;

     for ( i=0;i<n;i++)
     {
         scanf ("%d", &a[i]);
     }


     for (i=0;i<n-1;i++)
     {
         for (j=i+1;j<n;j++)
         {
             if (a[i]<a[j])
             {
                 temp=a[i];
                 a[i]=a[j];
                 a[j]=temp;
         }
     }
     }
     for (i=0;i<n;i++)
     {
         if (i==4)
         {
             printf("%d\n", a[i]);
         }
         else
         {
          printf ("%d ", a[i]);
         }


     }



   return 0;
 }

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

/*
substitute 0 for cannot through path
'x' and 'y' is point of construction
'row' is a
'column' is b
*/
/*
void cannotThroughPath(int x, int y, int row, int column){
	int v[row][column];

	if(x == 1 && y != 1){
		for(int i = 0; i < column; ++i){
			v[x-1][i] = 0;
		}
	} else if(x != 1 && y == 1){
		for(int i = 0; i < row; ++i){
			v[i][y-1] = 0;
		}
	} else if(x != 1 && y != 1){
		v[x-1][y-1] = 0;
	}
}
*/

int main(void){
	int a,b; //number of road

	while(std::cin >> a >> b){ //input road
		if(a == 0 && b == 0) //end of input
			break;

		//make matrix a x b
		int path[a+1][b+1];
		int array[a+1][b+1];

		for(int i = 0; i <= a; ++i){
			for(int j = 0; j <= b; ++j){
				path[i][j] = 0;
				array[i][j] = 0;
			}
		}
		
		int num; //number of construction
		std::cin >> num;
		
		int x, y; //point of construction
		for(int i = 0; i < num; ++i){
			std::cin >> x >> y;
			//path[x-1][y-1] = 0;
			array[x][y] = 1;
		}


		for(int i = 1; i <= a; ++i){
			for(int j = 1; j <= b; ++j){
				if(i == 1 && j == 1 && array[i][j] == 0){
					path[i][j] = 1;
				} else if(array[i][j] == 1){
					path[i][j] = 0;

				} else {
					path[i][j] = path[i-1][j] + path[i][j-1];
				}
			}
		}
		
		std::cout << path[a][b] << std::endl; //output answer
	}
	return 0;
}

Measured memory_bytes: 3104
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var a = firstLine[0];
            var b = firstLine[1];
            var k = firstLine[2];

            if (a >= k)
            {
                WriteLine($"{a - k} {b}");
            }
            else
            {
                b = b - (k - a) > 0 ? b - (k - a) : 0;
                WriteLine($"0 {b}");
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vector<int> p(N);
    REP(i, N) cin >> p.at(i);

    bool ok = true;
    REP(i, N) {
        if (p.at(i) != i+1) {
            if (p.at(p.at(i)-1) != i+1) {
                ok = false; 
                break;
            }
        }
    }
    if (ok) { 
        int count = 0;
        REP(i, N) { 
            if (p.at(i) != i+1) count += 1;
        }
        if (count > 2) ok = false;
    }
    if (ok) {
        print("YES");
    } else {
        print("NO");
    }
}

int main()
{
    solve();

    return 0;
}


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

using namespace std;
using ll = long long;

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);++i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

const int MAX_N = 1e5+1;

int parent[MAX_N];
ll size[MAX_N];
int root(int x) {
  if (parent[x] == x)
    return x;
  return parent[x] = root(parent[x]);
}
void unite(int x, int y) {
  if (root(x) == root(y))
    return;
  x = root(x);
  y = root(y);
  parent[x] = y;
  size[y] += size[x];
  size[x] = size[y];
  return;
}
bool same(int x, int y) {
  return root(x) == root(y);
}
int get_size(int x) {
  return size[root(x)];
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; in(N); in(M);

  rep(i, N) {
    parent[i] = i;
    size[i] = 1;
  }
  int a[M], b[M];
  rep(i, M) {
    in(a[i]); in(b[i]);
    --a[i]; --b[i];
  }
  reverse(a, a+M);
  reverse(b, b+M);

  vector<ll> ans;
  ll inconv = (ll)N * (N-1) / 2;
  ans.push_back(inconv);
  rep(i, M) {
    if (same(a[i], b[i])) {
      ans.push_back(ans.back());
      continue;
    }

    inconv -= get_size(a[i]) * get_size(b[i]);
    unite(a[i], b[i]);
    ans.push_back(inconv);
  }
  ans.pop_back();
  reverse(all(ans));
  iter(it, ans) {
    out(*it);
  }

  return 0;
}


Measured memory_bytes: 4212
N = int(input())
A = list(map(int,input().split()))

S = sum(A)

D = dict()
for a in A:
    if a in D:
        D[a] += 1
    else:
        D[a] = 1

Q = int(input())

for _ in range(Q):
    B, C = map(int,input().split())
    if B in D:
        S -= D[B] * B
        S += D[B] * C
        if C in D:
            D[C] += D[B]
        else:
            D[C] = D[B]
        D[B] = 0
    print(S) 


Measured memory_bytes: 20576
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define TEST ll t;cin>>t;while(t--)
ll sizes[100001];
ll arr[100001];

bool ok=true;
ll A[100001];
pll B[100001];

ll root(ll i){
    while(i!=arr[i]) i=arr[i];
    return(i);
}
void Union(ll i,ll j){
    ll root_i=root(i),root_j=root(j);
    if(root_i==root_j) return;
    if(sizes[root_i]>sizes[root_j]) swap(root_i,root_j);
    sizes[root_j]+=sizes[root_i];
    arr[root_i]=arr[root_j];
    return;
}
bool prime[10000];
vector<ll> v;
void era(){
    memset(prime,true,sizeof prime);
    for(ll p=2;p*p<=10000;p++){
        if(prime[p]){

            for(ll q=p*p;q<=10000;q+=p){
                prime[q]=false;
            }
        }
    }

    return;
}
/*

ll dif(string s,string p){
    ll a=(s[0]-'0')*100+(s[1]-'0')*10+(s[2]-'0');
    ll b=(p[0]-'0')*100+(p[1]-'0')*10+(p[2]-'0');
    return(abs(a-b));
}
bool is357(ll i){
    bool a=false,b=false,c=false;
    while(i){
        if(i%10==3) a=true;
        else if(i%10==5) b=true;
        else if(i%10==7) c=true;
        else return(false);
        i/=10;
    }
    return(a&b&c);
}

void dfs(ll i,bool a,bool b,bool c){
    if(i>N) return;
    if(a&& b&&c) ans++;
    dfs(i*10+3,true,b,c);
    dfs(i*10+5,a,true,c);
    dfs(i*10+7,a,b,true);
    return;
}
*/
ll count_div[101];
void cnt(ll N){

    for(ll i=0;i<v.size();i++){
        if(v[i]>N) break;
        while(N%v[i]==0){
            N/=v[i];
            count_div[v[i]]++;
        }
    }
    return;
}
int main(){
    IO
    ofstream fout("a.out");
    ll N,ans=0;
    cin>>N;
    memset(count_div,0,sizeof count_div);

    era();

    for(ll i=2;i<=100;i++) if(prime[i]) v.push_back(i);

    for(ll i=2;i<=N;i++) cnt(i);
    //for(ll i=0;i<=100;i++) fout<<i<<" "<<count_div[i]<<endl;
    ll M=v.size();
    for(ll i=0;i<M;i++) if(count_div[v[i]]+1>=75) ans++;
    for(ll i=0;i<M;i++){
        for(ll j=0;j<M;j++){
            if(i==j) continue;

            if(count_div[v[i]]+1>=3 && count_div[v[j]]+1>=25) {
                    ans++;
                    //cout<<v[i]<<" "<<v[j]<<endl;
            }
            if(count_div[v[i]]+1>=5 && count_div[v[j]]+1>=15) {
                    ans++;
                    //cout<<v[i]<<" "<<v[j]<<endl;
                }

        }
    }
    for(ll i=0;i<M;i++)
        for(ll j=i+1;j<M;j++)
    for(ll k=0;k<M;k++){
        if(i==j || j==k || i==k) continue;

        if(count_div[v[i]]+1>=5 && count_div[v[j]]+1>=5 && count_div[v[k]]+1>=3) {
                ans++;
        //cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<endl;
        }
    }

    cout<<ans;
    return(0);
}


Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

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) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N, K;
  cin >> N >> K;
  vi h(N);
  cin >> h;

  vi dp(N, INF);
  dp[0] = 0;
  rep(i, N - 1) {
    rep(j, K) {
      if (i >= j)
        dp[i + 1] = min(dp[i - j] + abs(h[i - j] - h[i + 1]), dp[i + 1]);
    }
  }
  out(dp[N - 1]);
}


Measured memory_bytes: 1024
n = gets.chomp.to_i
sum = 0
x = gets.chomp.split(' ').map{|i|
  ii = i.to_i
  sum += ii
  ii
}

ave = (1.0 * sum) / n

low = ave.floor
hi = low + 1

lowsum = 0
hisum = 0
x.each{|i|
  lowsum += (low - i) ** 2
  hisum += (hi - i) ** 2
}

puts lowsum < hisum ? lowsum : hisum


Measured memory_bytes: 1788
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    IN n;

    int s = 0,t = n;
    while(t > 0){
        s += t%10;
        t /= 10;
    }

    n%s == 0 ? Yes : No;
    
	return  0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL dp[2005][2005];
LL sum[2005][2005];

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

    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for(int i = 0; i < n; ++i) {
        cin >> s[i];

    }
    for(int i = 0; i < m; ++i) {
        cin >> t[i];

    }

    dp[0][0] = 1;
    sum[1][1] = 1;
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if(i == 0 && j == 0) continue;
            if(i - 1 >= 0 && j - 1 >= 0 && s[i - 1] == t[j - 1]) {
                dp[i][j] = sum[i][j];

            }
            sum[i + 1][j + 1] = (sum[i + 1][j] + sum[i][j + 1]) % MOD - sum[i][j] + dp[i][j];
            sum[i + 1][j + 1] = (sum[i + 1][j + 1] + MOD) % MOD;
        }
    }
    cout << sum[n + 1][m + 1] << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    forr(i,5)
    {
        cin>>x;
        A.pb(x);
    }
    sort(all(A),greater<>());
    forr(i,4)
    {
        cout<<A[i]<<" ";
    }
    cout<<A[4]<<endl;
    return 0;
}



Measured memory_bytes: 3116
# Wrote in Mar 5, 2020 21:38 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end

#---------------

n = gets.to_i
[*1..9].each do |n2|
  [*1..9].each do |n3|
    if n==n2*n3
      yes
      exit
    end
  end
end
no



Measured memory_bytes: 2676
fn main() {
  let (n, m): (usize, usize) = read_tuple();
  let edges: Vec<(usize, usize)> = read_tuples(m);
  
  let mut ans = 0;
  for (v,w) in edges.clone() {
    let removed = edges.iter().filter(|&&e|e!=(v,w)).collect::<Vec<_>>();
    let mut uf = UnionFind::new(n);
    for &(v,w) in removed {
      uf.unite(v-1, w-1);
    }
    if uf.count() != 1 {
      ans += 1;
    }
  }
  
  println!("{:?}", ans);
}

struct UnionFind {
  n: usize,
  rp: Vec<usize>,
  rk: Vec<usize>
}

impl UnionFind {
  fn new(n: usize) -> UnionFind {
    UnionFind {
      n: n,
      rp: (0..n).collect(),
      rk: vec![1; n]
    }
  }

  fn rep(&self, p: usize) -> usize {
    if self.rp[p] == p {p} else {self.rep(self.rp[p])}
  }

  fn rank(&self, p: usize) -> usize {
    self.rk[self.rep(p)]
  }

  fn count(&self) -> usize {
    let mut reps = (0..self.n).map(|x|self.rep(x)).collect::<Vec<_>>();
    reps.dedup();
    reps.len()
  }
  
  fn unite(&mut self, p: usize, q:usize) {
    let rkp = self.rank(p);
    let rkq = self.rank(q);
    let (p, q) = if rkp <= rkq {(p, q)} else {(q, p)};

    let repp = self.rep(p);
    let repq = self.rep(q);
    self.rp[p] = repq;
    self.rp[repp] = repq;
    self.rk[repq] += self.rk[repp];
  }
}       

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> H(N);
    for(auto& x: H) cin >> x;

    Vvec<int> graph(N);
    for(int i=0; i<M; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    ll ans = 0;
    for(int i=0; i<N; i++){
        bool flag = true;
        for(auto& to: graph[i]){
            if(H[i] <= H[to]) flag = false;
        }
        if(flag) ans++;
    }

    cout << ans << endl;
}

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


int main(){
	int n,k;
	char ch;
	string s;
	cin >> n >> s >> k;
	
	ch=s[k-1];
	for(int i=0;i<n;i++){
		if(s[i]!=ch){
			s[i]='*';
		}
	}
	
	for(int i=0;i<n;i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int A, B, K;
        Input(out A, out B, out K);
        for(int i = 0; i < K; i++) {
            if(i % 2 == 0) {
                A -= A % 2;
                B += A / 2;
                A /= 2;
            } else {
                B -= B % 2;
                A += B / 2;
                B /= 2;
            }
        }
        Print(A, B);
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 13268
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int T;
int t[102];
int N;
int D[102],M[102];
int max_d;

map<int,int> jobs;
int dp[102][102];

// a??\??????b?????????????????????
int dfs(int a,int b) {
    //printf("%d %d\n",a,b);
    if(a==max_d+1) return 0;
    if(dp[a][b]!=-1) return dp[a][b];

    int ret=INF;
    if(t[(b+1)%T]<=jobs[a+1]) ret=min(ret,dfs(a+1,(b+1)%T));
    ret=min(ret,dfs(a+1,0)+1);

    return dp[a][b]=ret;
}

void solve() {
    jobs.clear();
    max_d=0;
    rep(i,N) {
        max_d=max(max_d,D[i]);
    }
    rep(i,max_d+1) jobs[i]=INF;
    rep(i,N) {
        jobs[D[i]]=min(jobs[D[i]],M[i]);
    }
    memset(dp,-1,sizeof(dp));
    cout<<dfs(1,0)-1<<endl;
}

int main() {
    while(cin>>T) {
        if(!T) break;
        rep(i,T) cin>>t[i];
        cin>>N;
        rep(i,N) cin>>D[i]>>M[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 1252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args) throws IOException{
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int a = Integer.parseInt(reader.readLine());
        int b = Integer.parseInt(reader.readLine());
        int c = Integer.parseInt(reader.readLine());
        int d = Integer.parseInt(reader.readLine());
        int e = Integer.parseInt(reader.readLine());
        int k = Integer.parseInt(reader.readLine());

        int cnt=0;

        if(e-d<=k && e-c<=k && e-b<=k && e-a<=k)
            cnt++;

        if(d-c<=k && d-b<=k && d-a<=k)
            cnt++;

        if(c-b<=k && c-a<=k)
            cnt++;

        if(b-a<=k)
            cnt++;

        if(cnt==4)
            System.out.println("Yay!");
        else
            System.out.println(":(");

    }
}


Measured memory_bytes: 21076
#include "bits/stdc++.h"
using namespace std;
const int maxn = 555;
int M(){
    int n;
    if(!~scanf("%d", &n)) return 0;
    map<long long, int> qtd;
    for(int e = 0; e < n; e++){
        long long x; cin >> x;
        qtd[-x]++;
    }
    long long side1 = 0;
    long long side2 = 0;
    for(auto it : qtd){
        if(it.second >= 2){
            if(side1 == 0) side1 = it.first, it.second -= 2;
            if(it.second >= 2 && side2 == 0) side2 = it.first;
        }
    }
    cout << side1 * side2 << endl;
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

ll n;
vi a;

struct SegTree{
  typedef int T;
  T e = 0;
  T m(const T&a, const T&b){return a + b;}
//###################################################
  typedef int i;i n;vector<T> d;
  void init(i m){n=1<<(32-__builtin_clz(m-1));d.resize(2*n-1);FOR(j,0,2*n-1)d[j]=e;}
  void init(vector<T>&v){n=1<<(32-__builtin_clz(sz(v)-1));d.resize(2*n-1);FOR(j,0,sz(v))d[j+n-1]=v[j];FORR(k, n-2, 0)d[k]=m(d[k*2+1],d[k*2+2]);}
  void update(i k,T a){k+=n-1;d[k]=a;while(k>0){k=(k-1)/2;d[k]=m(d[k*2+1],d[k*2+2]);}}
  T q(i a,i b,i k,i l,i r){return (r<=a||b<=l)?e:(a<=l&&r<=b)?d[k]:m(q(a,b,k*2+1,l,(l+r)/2),q(a,b,k*2+2,(l+r)/2,r));}
  T query(i a,i b){return q(a,b,0,0,n);}
};
SegTree seg;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int t;
    cin >> t;
    a.pb(t);
  }
  ll l = 0, r = mod, mid;
  ll g = (ll(n) * (n+1) / 2 + 1) / 2;
  while(r-l > 1){
    seg.init(n*2+1);
    seg.update(n, 1);
    mid = (l + r) / 2;
    int s = 0;
    ll c = 0;
    for(int aa: a){
      s += (aa >= mid) ? 1 : -1;
      c += seg.query(0, s+n+1);
      seg.update(s+n, seg.query(s+n, s+n+1) + 1);
    }
    if (c >= g){
      l = mid;
    }else{
      r = mid;
    }
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 2808
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        long[] nums=new long[n];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        Arrays.sort(nums);
        int count=0;
        long ans=1;
        for(int i=n-1;i>0;i--){
            if(count==0&&nums[i]==nums[i-1]){
                ans=nums[i];
                count++;
                i--;
            }else if(count==1&&nums[i]==nums[i-1]){
                System.out.println(ans*nums[i]);
                return;
            }
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 59536
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int lli; 
int main(void){
    // Here your code !    lli max = pow(10,4)+10;
    int n;
    cin >> n;
    lli t,a;
    cin >> t >> a;
    //int ans = t + a;
    for(int i = 0; i < n-1; i++){
        lli tt,ta;
        cin >> tt >> ta;
        lli x = std::max((t+tt-1)/tt,(a+ta-1)/ta);
        t = x*tt;
        a = x*ta;
    }
    
    //cout << t << " " << a << endl;
    cout << t+a << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;


int main(){
 ll h,w;
 cin>>h>>w;
 vector<string> v(h);
 for(ll i=0;i<h;i++){
 	cin>>v[i];
 }
 vector<vector<ll>> dp(h+1,vector<ll>(w+1,0));
 for(ll i=0;i<h;i++){
 	for(ll j=0;j<w;j++){
 		if(v[i][j]=='#')
	 		dp[i+1][j+1]=0;
		else{
			dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
		} 	
		dp[i+1][j+1]%=M;
		dp[1][1]=1;
	}
 }
 cout<<dp[h][w]<<endl;
 return 0;
}



Measured memory_bytes: 13028
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int K; cin >> K;
    vector <ll> A;
    for (int i=1; i<=9; i++) A.push_back(i);
    
    while(1){
        if (K<=A.size()){
            cout << A[K-1] << endl;
            return 0;
        }
        K-=A.size();
        vector <ll> old;
        swap(A,old);
        for (auto x:old){
            for (int i=-1; i<=1; i++){
                int d=x%10+i;
                if (0<=d && d<=9){
                    ll tmp=x*10+d;
                    A.push_back(tmp);
                }
            }
        }
    }
    return 0;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 100 + 10;
const int M = (int) 1e6 + 10;
const int K = (int) 500 + 10;
const int INF = (int) 1e9 + 7;
const int mod = (int) 1e9 + 7;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n;
vec v[N];

int cnt[N];
int max_lvl;

void calc(int x, int lvl = 0, int p = -1) {
	cnt[lvl] = max(sz(v[x]) - (p != -1), cnt[lvl]);
	max_lvl = max(max_lvl, lvl);
	for (auto it : v[x]) {
		if (it == p)
			continue;
		calc(it, lvl + 1, x);
	}
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n;
	vector<pii> e;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
		e.pb(mp(x, y));
	}
	int ans = INF;
	ll ans_cnt;
	for (auto it : e) {
		memset(cnt, 0, sizeof(cnt));
		max_lvl = 0;
		calc(it.f, 0, it.s);
		calc(it.s, 0, it.f);
		ll cnt = 1;
		for (int i = 0; i < max_lvl; i++) {
			cnt *= ::cnt[i];
		}
		max_lvl++;
		cnt *= 2;
		if (ans > max_lvl) { 
			ans = max_lvl;
			ans_cnt = cnt;
		} else if (ans == max_lvl) {
			ans_cnt = min(ans_cnt, cnt);
		}
	}
	for (int i = 1; i <= n; i++) {
		memset(cnt, 0, sizeof(cnt));
		max_lvl = 0;
		calc(i, 0, -1);
		ll cnt = 1;
		for (int i = 0; i < max_lvl; i++) {
			cnt *= ::cnt[i];
		}
		max_lvl++;
		if (ans > max_lvl) { 
			ans = max_lvl;
			ans_cnt = cnt;
		} else if (ans == max_lvl) {
			ans_cnt = min(ans_cnt, cnt);
		}
	}
	cout << ans << ' ' << ans_cnt;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func strToInt(s []string) []int {
	f := make([]int, len(s))
	for n := range s {
		f[n], _ = strconv.Atoi(s[n])
	}
	return f
}

func main() {
	var n, max, sum int
	var a, b string
	fmt.Scan(&n)
	if sc.Scan() {
		a = sc.Text()
	}
	if sc.Scan() {
		b = sc.Text()
	}

	ar := strToInt(strings.Fields(a))
	ar2 := strToInt(strings.Fields(b))
	for i := 0; i < n; i++ {
		sum = 0
		for _, x := range ar[:i+1] {
			sum += x
		}
		for _, x := range ar2[i:] {
			sum += x
		}
		if sum > max {
			max = sum
		}
	}

	fmt.Println(max)
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n,k; scanf("%d%d",&n,&k);
   int cnt=0;
   while(n){
      cnt++; n/=k;
   }
   printf("%d\n",cnt);
   return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
double dabs(double x){
    return ((x>=0.0)?(x):(0.0-x));
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans;
    int n;
    cin >> n;
    double t,a;
    cin >> t >> a;
    double tmp = 10000.0;
    REP(i,n){
        double h;
        cin >> h;
        double x = t-0.006*h;
        if(dabs(tmp-a)>dabs(x-a)){
            ans = i;
            tmp = x;
        }
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import collections


def main():
    X = int(input())
    A, B = 0, 0
    for i in range(-120, 120):
        if A == 0 and B == 0:
            for j in range(-120, 120):
                if i ** 5 - j ** 5 == X:
                    A, B = i, j
                    break
        else:
            break

    print("{} {}".format(A, B))


if __name__ == "__main__":
    main()


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

up = int(n**0.5) + 1
b = 0
for i in range(up, 0, -1):
    if n % i == 0:
        b = n // i
        break

f = 1
while b // 10 != 0:
    b //= 10
    f += 1

print(f)


Measured memory_bytes: 3188