akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;

vl<ll> divisor(ll n)
{
    vl<ll> v;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0) 
        {
            if(n/i==i) v.pb(i);
            else
            {
                v.pb(i);
                v.pb(n/i);
            }
        }
    }
    return v;
}

int main()
{
    ll a,b,i,j,n,m,k,t;
    string s;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy";
    else if(s=="Cloudy") cout<<"Rainy";
    else cout<<"Sunny";
}

Measured memory_bytes: 3564
import java.util.*;

class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
         
        int max = 1200;
        boolean[] p = new boolean[max];
        for(int i=2; i<max; i++) p[i] = true;
        for(int i=2; i<Math.sqrt(max); i++){
            for(int j=i*i; j<max; j+=i) p[j] = false;
        }

        int[][] dp = new int[max][15];
        dp[0][0] = 1;
        for(int k=1; k<max; k++){
            if(!p[k]) continue;
            for(int i=max-1; i>=0; i--){
                if(i-k<0) continue;
                for(int j=14; j>=1; j--){
                    dp[i][j] += dp[i-k][j-1];
                }
            }
        }
 
        while(true){
            int n = sc.nextInt(), K = sc.nextInt();
            if(n==0 && K==0) break;
            System.out.println(dp[n][K]);
        }
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 21360
import sys,bisect,heapq

mod = 10**9+7

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])

def GCD(a,b):
    while(a%b != 0):
        a,b = b,a%b
    return b

def LCM(a,b):
    return a*b//GCD(a,b)

def main():
    H,W = LI()
    a = [[c=="#" for c in S()] for _ in range(H)]
    b = [[True for _ in range(W)] for _ in range(H)]

    r = 0
    for h in range(H):
        for w in range(W):
            if b[h][w]:
                q = []
                T = 0
                F = 0
                q.append([a[h][w],h,w])
                while(q):
                    flag,h_s,w_s = q.pop()
                    if b[h_s][w_s] and a[h_s][w_s] == flag:
                        if flag:
                            T += 1
                        else:
                            F += 1
                        b[h_s][w_s] = False
                        for i in [[-1,0],[1,0],[0,-1],[0,1]]:
                            if 0<=h_s+i[0]<=H-1 and 0<=w_s+i[1]<=W-1 and b[h_s+i[0]][w_s+i[1]]:
                                q.append([not(flag),h_s+i[0],w_s+i[1]])
                r += T*F
    return r




if __name__ == "__main__":
    print(main())


Measured memory_bytes: 72412
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] table = new int[m];
		
		for(int i = 0; i < n; i++) {
			int k = sc.nextInt();
			for(int j = 0; j < k; j++) {
				int a = sc.nextInt();
				table[a-1]++;
			}
		}
		
		int count = 0;
		for(int i = 0; i < m; i++) {
			if(table[i] == n) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();
	}
}


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

int main(){
	int n,t,a;
	cin >> n >> t >> a;
	vector<int> h(n);
	rep(i, n){
		cin >> h.at(i);
		h.at(i) = 1000*t - h.at(i)*6;
	}

	int ans = __INT_MAX__;
	int inde = __INT_MAX__;

	rep(i, n){
		int kari = 1000*a-h.at(i);
		ans = min(ans, abs(kari));
		if(ans == abs(kari)){
			inde = i;
		}
	}
	cout << inde+1 << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[n+1];
    for(ll i = 1; i <= n; i++)
        cin >> a[i];
    ll ans = 0;
    vector<ll> c(n+1, 1);
    for(ll i = 1; i <= n; i++){
        if(c[i]!=1) continue;
        ll check = a[i];
        if(i==a[check] && check==a[i]){
            ans++;
            c[check]=0;
        }
        c[i]=0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
//#define sllit set<long long int>::iterator
#define pll pair<long long int,long long int>
#define vpll vector<pair<long long int,long long int> >
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli ndigit(lli n){lli count=0;if(n==0)	return 1;while(n){count++;n/=10;}return count;}

/******************************START********************************/
int main()
{
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,t,d,n,m,sum=0,ans=0,temp;
    cin >> n;
    t=n;
    map<string,lli>ma;
    while(t--){
    	cin >>s1;
    	ma[s1]++;
    	if(ans<ma[s1])	ans=ma[s1];
	}
	map<string,lli>::iterator it;
	for(it=ma.begin();it!=ma.end();it++){
		if(it->second == ans)	cout << it->first << endl;
	}
	
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
int n,m,k,cnt;
map<int,int>Hash;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>k;
        for(int j=1;j<=k;j++){
            int x;cin>>x;
            Hash[x]++;
            if(i==n&&Hash[x]==n)cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int m,n;int a[100005];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);int mmin=1000000005;
    for(int i=0;i<=n-m;i++)
    {
        mmin=min(mmin,a[i+m-1]-a[i]);
    }
    cout<<mmin<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int main () {
  int N; cin >> N;
  
  vector<vector<int>>a(2, vector<int>(N));
  rep(i,2) {
    rep(j,N) {
      cin >> a[i][j];
    }
  }
  int count = 0;
  rep(i,N) {
    int sum =0;
    for(int j=0; j<=i; j++) {
      sum += a[0][j];
    }
    for (int j=i; j<=N-1; j++) {
      sum += a[1][j];
    }
    count = max(count, sum);
  }
  cout << count << endl;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    int D,ans=0;
    pair<int,int> P;

    cin>>D;


    vector<int> c(26);
    vector<vector<int> > s(D,c);

    vector< set<pair<int,int> > > Sets(D);

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

    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++){
            cin>>s[i][j];
            Sets[i].insert(make_pair(s[i][j],j));
        }
    }

    for(int i=0;i<D;i++){
        P = *(Sets[i].rbegin());
        ans=P.second;
        ans++;
        cout<<ans<<endl;
        
    }






    return 0;
}



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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

int main() {
  int n, k; cin >> n >> k;
  vl h(n); ina(h,n);
  RSORT(h);
  ll sum = 0;
  REP(i,k,n) {
    sum += h[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
using namespace std;
char mp[4]={'R','G','Y','B'};
int main ()
{
    int n,m,d,cx,cy;
    scanf("%d%d%d",&n,&m,&d);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cx=i+j+500,cy=i-j+500,printf("%c",mp[cx/d%2+cy/d%2*2]);
        printf("\n");
    }
    return 0;
}

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

const int MAX_N = 100000;
int n, k, x[MAX_N], ans = INT_MAX;

int main() {
    cin >> n >> k;
    rep(i, n) cin >> x[i];
    rep(i, n - k + 1) {
        int l = x[i], r = x[k+i-1];
        int num = r - l + min(abs(l), abs(r));
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(2, 1), 1)

    def test_2(self):
        self.assertEqual(think(4, 3), 9)

    def test_3(self):
        self.assertEqual(think(1, 1), 0)

    def test_4(self):
        self.assertEqual(think(13, 3), 81)


def solve():
    n, m = read()
    result = think(n, m)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, m):
    result = 0
    if n >= 2:
        result += (n * (n - 1)) // 2
    if m >= 2:
        result += (m * (m - 1)) // 2
    return result


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 49772
#include<iostream>
#include<vector>
#include<map>

using namespace std;

typedef pair<int, int> cood;

int main(void) {
	map <cood, int > field;
	vector<long long int> ans(10, 0);
	int H, W, N;
	cood pos, shift;

	cin >> H >> W >> N;

	for (int i = 0; i < N; i++) {
		cin >> pos.first;
		cin >> pos.second;
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				shift.first = pos.first + dx;
				shift.second = pos.second + dy;
				if (shift.first >= 1 && shift.first <= H && shift.second >= 1 && shift.second <= W)	field[shift]++;
			}
		}
	}

	for (auto itr = field.begin(); itr != field.end(); itr++) {
		int x, y;
		x = (itr->first).first;
		y = (itr->first).second;
		if (x > 1 && x < H && y > 1 && y < W) ans[itr->second] ++;
	}

	ans[0] = ((long long int)H - 2) * (W - 2);

	for (int i = 1; i <= 9; i++) {
		ans[0] -= ans[i];
	}

	for (int i = 0; i <= 9; i++) cout << ans[i] << endl;

	//system("pause");

	return 0;
}

Measured memory_bytes: 56448
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S, T;

signed main(){
    cin >> S >> T;
    int ans = INT_MAX;
    rep(i, S.size()-T.size()+1){
        int tmp = 0;
        rep(j, T.size()){
            if(S[i+j] != T[j]) tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
ll n ; 
string s ; 
const ll MAXN = 1e5 + 10 ; 
const ll MOD = 13 ; 
const ll M = (ll)1e9 + 7  ;
ll dp[MAXN][MOD] ; 
ll power(ll x,ll y){
	if ( y == 0 ) return 1 ;
	if ( y == 1 ) return x ;
	if ( y % 2 == 0 ){
		ll f = power(x,y/2LL) ; 
		return ( (f % MOD) * (f % MOD) ) % MOD ; 
	}
	else {
		ll f = power(x,y/2LL) ; 
		return ((((f % MOD) * (f % MOD)) % MOD) * (x % MOD)) % MOD ; 
	}
}
ll dfs(ll index,ll curRemainder){ // DP state are the index of the current number and the remainder up to the current number
	if ( index == n ){
		if ( curRemainder == 5 ) return 1 ; 
		return 0 ; 
	}
	if ( dp[index][curRemainder] != -1 ) return dp[index][curRemainder] ; 
	ll ans = 0 ; 
	if ( s[index] != '?' ){
		ans += dfs(index+1, (curRemainder + (s[index]-'0')*power(10,index) ) % MOD) % M; 
	}
	else{
		for(ll i=0;i<10;i++){
			ans += dfs(index+1, (curRemainder + i % MOD * power(10,index) % MOD ) % MOD) % M ; 
		}
	}
	return dp[index][curRemainder] = ans % M; 
}
int main(){
    fastio
    memset(dp,-1,sizeof dp) ; 
    cin >> s ; 
    reverse(s.begin(),s.end()) ; 
    n = (ll) s.size() ; 
    cout << dfs(0,0) << endl;
    return 0 ;
}


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


int main()
{
    int x; cin >> x;
    int ans = 0;
    if(x >= 1800) ans = 1;
    else if(x >= 1600) ans = 2;
    else if(x >= 1400) ans = 3;
    else if(x >= 1200) ans = 4;
    else if(x >= 1000) ans = 5;
    else if(x >= 800) ans = 6;
    else if(x >= 600) ans = 7;
    else if(x >= 400) ans = 8;

    cout << ans << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 3632
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Measured memory_bytes: 27428
int main(void){
        int W,H,x,y,r;
        scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

        if(x-r<0||y-r<0||x+r>W||y+r>H){
                puts("No");
    }else
                puts("Yes");

        return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int n = max(a/d+1, c/b+1);
  for(int i=1; i<=n; i++){
    if(c-b*i<1){
      cout << "Yes" << endl;
      exit(0);
    }
    if(a-d*i<1){
      cout << "No" << endl;
      exit(0);
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N,K;
cin >> N >> K;
vector<int> vec(N);
int a = 0;
for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
    if (vec.at(i) >= K) a++;
}

cout << a << endl;

return 0;
}

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

struct edge {
    int src, dest, cost; 
    edge(int s, int t, int c): src(s), dest(t), cost(c) {}
};
const int INF = 1e8;

void warshall_floyd(vector<vector<int> > &d, vector<edge> &edges) {
    for(size_t i=0; i<d.size(); ++i) {
        d[i].assign(d[i].size(), INF);
        d[i][i] = 0;
    }
    for(auto &e : edges) {
        d[e.src][e.dest] = e.cost;
    }
    const size_t n = d.size();
    for(size_t j=0; j<n; ++j) {
        for(size_t i=0; i<n; ++i) {
            for(size_t k=0; k<n; ++k) {
                d[i][k] = min(d[i][k], d[i][j] + d[j][k]);
            }
        }
    }
}

int main(void) {
    int n, m, s, g1, g2;
    while(cin >> n >> m >> s >> g1 >> g2 && n) {
        vector<edge> edges;
        vector<vector<int> > d(n, vector<int>(n, INF));
        --s; --g1; --g2;
        REP(i, m) {
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            edges.push_back(edge(b1-1, b2-1, c));
        }
        warshall_floyd(d, edges);
        int cost = numeric_limits<int>::max();
        REP(i, n) {
            cost = min(cost, d[s][i] + d[i][g1] + d[i][g2]);
        }
        cout << cost << endl;
    }
    return 0;
}

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

int main(){
  string str;
  
  cin >> str;
  
  if((str[2] == str[3]) && (str[4] == str[5])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

vector<ll> toDigit(ll num)
{
	vector<ll> d;
	while (num)
	{
		d.push_back(num%10);
		num /= 10;
	}
	reverse(d.begin(), d.end());
	return d;
}

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

ll modPow(ll a, ll n)
{
	if (n == 1) return a%MOD;
	if (n&1) return (a*modPow(a, n-1)) % MOD;
	ll tmp = modPow(a, n/2);
	return (tmp*tmp) % MOD;
}


int main(int argc, char **argv)
{
	ll N; cin >> N;

	ll cnt[10][10] {};

	FOR(i, 1, N+1)
	{
		vector<ll> v = toDigit(i);
		++cnt[v.front()][v.back()];
	}

	ll res{0};
	FOR(i, 1, 10) FOR(k, 1, 10)
		res += cnt[i][k] * cnt[k][i];

	std::cout << res << std::endl;
}

Measured memory_bytes: 256
def recKF(p1,p2,n):
    if n != 0:
        a = 1/2
        b = 3**(1/2)/2
        s = Point( p1.x + (p2.x-p1.x)/3, p1.y + (p2.y-p1.y)/3 )
        t = Point( p1.x + (p2.x-p1.x)*2/3, p1.y + (p2.y-p1.y)*2/3 )
        v = Point( t.x-s.x, t.y-s.y )
        rot_v = Point( v.x*a - v.y*b, b*v.x + a*v.y )
        u = Point( rot_v.x + s.x, rot_v.y + s.y)
        recKF(p1,s,n-1)
        print(s.x,s.y)
        recKF(s,u,n-1)
        print(u.x,u.y)
        recKF(u,t,n-1)
        print(t.x,t.y)
        recKF(t,p2,n-1)
        
from collections import namedtuple
Point = namedtuple("Point", ["x","y"])
p1 = Point(0,0)
p2 = Point(100,0)
n = int(input())
print(p1.x,p1.y)
recKF(p1,p2,n)
print(p2.x,p2.y)


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

int main()
{
	stringstream ss;
	// 入力
	int N;
	cin>>N;
	ll a[N+1];
	for(int i=1;i<=N;i++){
    	cin>>a[i];
	}
	ll ans=0;
	for(int i=1;i<=N;i++){
		ans+=a[i]-1;
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long[] a = new long[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextLong();
		}
		sc.close();
		
		long ans = 0;
		for(int i=0; i<n-1; i++){
			if(a[i] + a[i+1] > x){
				long d =(a[i] + a[i+1]) - x;
				if(d>a[i+1]){
					a[i+1] = 0;
					a[i] -= d - a[i+1];
					ans += d;
				}else{
					a[i+1] -= d;
					ans += d;
				}
			}
		}
		System.out.println(ans);
	}

}

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

int NMAX = 100000;
vector<vector<int>> g(NMAX);
vector<vector<int>> edges(NMAX - 1);
vector<int> root(NMAX);
vector<int> color(NMAX);
int cMax = 1;
vector<int> used(NMAX);	//隣接edgeに既に使った色;

void dfs(int v, int prev) {
	for (int next : g.at(v)) {
		if (next == prev)
			continue;
		root[next] = v;
		used[v]++;
		if (used[v] == color[v])
			used[v]++;
		color[next] = used[v];
		if (used[v] > cMax)
			cMax = used[v];
		dfs(next, v);
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0, a, b; i < n - 1; i++) {
		cin >> a >> b;
		a--, b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
		edges.at(i) = { a, b };
	}
	dfs(0, -1);
	cout << cMax << endl;
	for (int i = 0, a, b; i < n - 1; i++) {
		a = edges[i][0];
		b = edges[i][1];
		cout << (root[b] == a ? color[b] : color[a]) << endl;
	}
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
using namespace std;static const int INF = 0x3f3f3f3f;
typedef int64_t ll;
typedef vector<ll> vll;
template<typename T,typename U> static void amin(T &x,U y){if(y<x)x=y;}
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll N;
        in >> N;
        vll a(N);
        rep(i, N) {
            in >> a[i];
        }
        ll x = a[0];
        ll y = a[N - 1];
        ll ans = INF;
        rep(i, N - 1) {
            a[i + 1] += a[i];
        }
        rep(i, N - 1) {
            x = a[i];
            y = a[N - 1] - a[i];
            amin(ans, abs(x - y));
        }
        out << (ans == INF ? abs(x - y) : ans) << endl;
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 1792
#python ABC_130_C.py

line = list(map(int, input().split(" ")))

W = line[0]
H = line[1]
x = line[2]
y = line[3]

S = W*H/2

if x==W/2 and y==H/2:
	flag=1
else:
	flag=0

print(S,flag)


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto& e : a) cin >> e;

  vector<int> t(n, -1);
  {
    vector<int> u(2e5 + 1, -1);
    for (int _ = 0; _ < 2; _++) {
      for (int i = n - 1; i >= 0; i--) {
        if (t[i] == -1 && u[a[i]] != -1) t[i] = u[a[i]];
        u[a[i]] = i;
      }
    }
  }

  vector<int> r;
  vector<int> v(n, -1);
  for (ll i = 0, j = 0; i < k; j++, i += j / n, j %= n) {
    if (v[j] != -1 && i + (i - v[j]) < k) i += (k - i - 1) / (i - v[j]) * (i - v[j]);
    v[j] = i;

    if (j < t[j]) {
      j = t[j];
    } else if (i + 1 < k) {
      i++;
      j = t[j];
    } else {
      r.push_back(a[j]);
    }
  }

  for (auto e : r) cout << e << ' ';
  cout << endl;
}


Measured memory_bytes: 5616
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

from fractions import gcd
# slist = "abcdefghijklmnopqrstuvwxyz"
N,X = map(int,input().split())
arrA = list(map(int,input().split()))
arrA = abs(np.array(arrA) - X)
arrA = list(arrA)

while len(arrA)>1:
    a = arrA.pop()
    b = arrA.pop()
    c = gcd(a,b)
    arrA.append(c)

ans = arrA[0]
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 25016
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>


using namespace std;


int main() {
	int Z, i;
	string str, str2, str3 = {};

	cin >> str >> str2;


	for (i = 0;i < str.size();i++) {

		str3.push_back(str[i]);
		if (str2.size() > i) {
			str3.push_back(str2[i]);
		}
	}

	cout << str3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    ll cnt[4]={};
    ll i;
    for(i=0; i<4; i++) {
        if(a[i]==1) cnt[0]++;
        if(a[i]==9) cnt[1]++;
        if(a[i]==7) cnt[2]++;
        if(a[i]==4) cnt[3]++;
    }
    
    ll flag=1;
    for(i=0; i<4; i++) {
        if(cnt[i]!=1) flag=0;
    }
    
    if(flag) puts("YES");
    else puts("NO");
    
    
}













Measured memory_bytes: 256
#include <cstdio>
#include <stdint.h>

int64_t as[100005];
int64_t bs[100005];

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%ld %ld",&as[i],&bs[i]);
  }
  int64_t ans=0;
  for(int i=N-1;i>=0;i--){
    int64_t inc=(bs[i]-(as[i]+ans)%bs[i])%bs[i];
    ans+=inc;
    //printf("%d: %ld\n",i,as[i]+ans);
  }
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    long double rad = ((long double)H / 12.0 + (long double)(M / 60.0) / 12.0 - (long double)M / 60.0) * 2 * M_PI;
    long double res = (long double)(A * A + B * B) - (long double)(2 * A * B) * cosl(rad);
    printf("%20.20Lf\n",sqrtl(res));
}

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

typedef long long int lli;

int main(){
  lli N,A,B,ans=0;
  lli t[1000];

  cin>>N>>A>>B;
  for(lli i=0;i<N;i++)
    cin>>t[i];

  sort(t,t+N);

  for(lli i=0;i<N;i++){
    if(t[i]<A||t[i]>=B)
      ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	p := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&p[i])
	}

	k := 0
	for i := 0; i < N; i++ {
		if i+1 != p[i] {
			k++
		}
	}
	if k <= 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main() {
    int n;
    ll ans = 1;
    cin >> n;
    for(int i = 1; i <= n; i++){
        ans = ans * i;
        ans %= div;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int k;
	cin >> k;

	int max, sum = 0;
	if (a < b) {
		max = b;
		sum += a;
		if (max < c) {
			max = c;
			sum += b;
		}
		else {
			sum += c;
		}
	} else {
		max = a;
		sum += b;
		if (max < c) {
			max = c;
			sum += a;
		}
		else {
			sum += c;
		}
	}

	for (int i = 0; i < k; i++) max *= 2;

	cout << sum + max << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
long long k;
long double sum=0;
int main()
{
	cin>>s;
	scanf("%lld",&k);
	for (int i=0;i<s.length();i++)
	{
		sum+=pow(s[i]-'0',5e15);
		if (sum>=k)
		{
			cout<<s[i];
			return 0;
		}
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  ll ans = 0;
  if (a > b) {
    ans += a;
    a--;
  } else {
    ans += b;
    b--;
  }

  cout << ans + max(a, b) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan =new Scanner(System.in);
		BigDecimal A = scan.nextBigDecimal();
		BigDecimal B= scan.nextBigDecimal();
		BigDecimal seki = B.multiply(A);
		long C = seki.longValue();
		System.out.println(C);
	}
}

Measured memory_bytes: 37364
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

    COMinit();

    ll N, P;
    cin >> N >> P;
    ll odd = 0; ll even = 0;
    REP (i, N) {
        ll a;
        cin >> a;
        if (a % 2) odd++;
        else even++;
    }

    ll ans = 0;

    if (P) {
        for (ll i = 1; i <= odd; i += 2) {
            ans += COM(odd, i);
        }
    } else {
        for (ll i = 0; i <= odd; i += 2) {
            ans += COM(odd, i);
        }
    }

    REP (i, even) {
        ans *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N = 20000 + 5;

int main()
{
	int h,a;
	cin >> h >> a;
	int sum = h / a;
	if(h % a)
		sum++;
	cout << sum << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 100005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int mod = 1e9 + 7;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
LL read(){
	LL x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int a[N], s[N], v[250005], n;
void add(int i){
	for(; i < 200009; i += i&-i) v[i]++;
}
LL sum(int i){
	LL s = 0;
	for(; i > 0; i -= i&-i) s += v[i];
	return s;
}
int ok(int x){
	int i;
	memset(v, 0, sizeof(v));
	LL ans = 0;
	for(i = 1; i <= n; i++){
		if(a[i] <= x) s[i] = s[i - 1] + 1;
		else s[i] = s[i - 1] - 1;
	}
	for(i = 0; i <= n; i++){
		ans += sum(s[i] + N - 1);
		add(s[i] + N);
	}
	return ans >= z * n * (n + 1) / 4 + 1;
}
int main(){
	int i, j, m, l = 0, r = 0, mid;
	n = read();
	for(i = 1; i <= n; i++) a[i] = read();
	r = 1e9;
	while(l < r){
		mid = l + r >> 1;
		if(ok(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d", l);
	return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N,L;

int sum = 0;
int min_taste = 100000;

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

    for(int i = 1;i <= N;i++) {
        sum += L+i-1;
        if(abs(min_taste) > abs(L+i-1)) {
            min_taste = L+i-1;
        }
    }

    cout<<sum-min_taste<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;
constexpr ll INF = (1LL << 60);
int main(){ 
  int n;
  ll z, w;
  cin >> n >> z >> w;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll res = abs(w - a[n - 1]);
  if (n > 1) res = max(res, abs(a[n - 2] - a[n - 1]));
  cout << res << endl;
  return 0;
} 


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		// 複数行の読み込み
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();
		if (e - a <= k) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}

	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

map<char,set<int>> mp;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  for (int i = 0; i < n; i++)
    mp[s[i]].insert(i);
  for (int i = 0; i < n; i++) {
    mp[s[i]].erase(i);
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j]) continue;
      string k= "";
      k.pb(s[i]);
      k.pb(s[j]);
      sort(all(k));
      char l = 'G';
      if (k == "BG")
        l = 'R';
      if (k == "GR")
        l = 'B';
      int delta = i-j;
      ans += 1LL*(mp[l].size());
      if (mp[l].find(i+delta) != mp[l].end())
        ans--;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=22;
ll inf=1e15;

ll dp[sz][(1<<sz)],ar[sz][sz],n;

ll f(int mn,int mask)
{
    if(mn==n and mask==(1<<n)-1)
        return 1;
    if(mn>=n)
        return 0;
    ll &res=dp[mn][mask];
    if(res!=-1)
        return res;
    res=0;
    for(int w=0;w<n;w++)
    {
        if((!(mask&(1<<w))) and ar[mn][w])
        {
            res=res+f(mn+1,mask|(1<<w));
            res%=mod;
        }

    }

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
                cin>>ar[i][j];
        }

        memset(dp,-1,sizeof(dp));

        cout<<f(0,0);

        
    }

    return 0;
}

Measured memory_bytes: 724492
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
template <typename Mnd> struct segment_tree {
    int sz;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> f;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e) {
        sz = 1;
        while(sz < _sz)
            sz <<= 1;
        data.assign(sz * 2, e);
    }
    //参照渡しなので代入とかもできる
    Mnd &operator[](const int &k) { return data[k + sz]; }
    //木を構築 O(n)
    void build() {
        for(int i = sz - 1; i > 0; i--)
            data[i] = f(data[2 * i], data[2 * i + 1]);
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        data[k += sz] = x;
        while(k >>= 1)
            data[k] = f(data[2 * k], data[2 * k + 1]);
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1)
                l = f(l, data[a++]);
            if(b & 1)
                r = f(r, data[--b]);
        }
        return f(l, r);
    }
};
template <typename T> vector<T> simplify(vector<T> &a) {
    int n = a.size();
    vector<T> b = a;
    sort(b.begin(), b.end());
    vector<T> res(n);
    for(int i = 0; i < n; i++)
        res[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    return res;
}
// 転倒数を計算
// depend:segment_tree
template <typename T> long long inversion_number(vector<T> &a) {
    using lint = ll;
    int n = a.size();
    vector<T> b = simplify(a);
    segment_tree<lint> count(n, [](lint a, lint b) { return a + b; }, 0);
    lint res = 0;
    for(int i = 0; i < n; i++) {
        res += count.query(b[i] + 1, n);
        count.update(b[i], count[b[i]] + 1);
    }
    return res;
}
int main() {
    ll n;
    cin >> n;
    ll N = n * (n + 1) / 2;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll l = 0, r = 10e+10;
    while(l + 1 < r) {
        ll m = (l + r) / 2;
        vector<ll> ru(n + 1, 0);
        for(int i = 0; i < n; i++) {
            ru[i + 1] = ru[i] + (a[i] > m);
        }
        for(int i = 0; i <= n; i++) {
            ru[i] = 2 * ru[i] - i;
        }
        ll tent = inversion_number(ru);
        if(tent > N / 2) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 7420
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){	

	int H, W, N;
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct StarrySky{
  static const int MAX_N = 1 << 17;
  int datm[2*MAX_N],data[2*MAX_N],n;
  StarrySky(){}
  StarrySky(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<n*2;i++) datm[i]=data[i]=0;
  }
  void add(int a,int b,int x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      data[k]+=x;
      return;
    }
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
    datm[k]=max(datm[k*2+1]+data[k*2+1],datm[k*2+2]+data[k*2+2]);
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return 0;
    if(a<=l&&r<=b) return datm[k]+data[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr)+data[k];
  }
  void add(int a,int b,int x){
    add(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  StarrySky ss(n);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>x;
      cout<<ss.query(x-1,x)<<endl;
    }else{
      cin>>s>>t>>x;
      ss.add(s-1,t,x);
    }
  }
  return 0;
}

/*
verified on 2017/02/18
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E
*/

Measured memory_bytes: 7204
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9 + 7;
const int maxn = 300005;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()
pair<int,int> t[4*maxn];
void build(int id,int l,int r)
{
  if(l>r)
    return ;
  if(l==r)
    {
      t[id].first = 0;
      t[id].second = l;
      return ;
    }

  int mid=(l+r)>>1;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  t[id]= max(t[2*id],t[2*id+1]);
}

 
void update(int id,int l,int r,int pos,int val){
	if(pos>r||pos<l||l>r)return;
	if(l==r&&l==pos){
		t[id].first += val;
		return;
	}
	int mid=(l+r)>>1;
	update(id*2,l,mid,pos,val);
	update(id*2+1,mid+1,r,pos,val);
	t[id]= max(t[2*id],t[2*id+1]);
}
pair<int,int> query(int id,int l,int r,int lq,int rq){
	if(l>r||l>rq||lq>r||lq>rq)return {-1,-1};
	if(lq<=l&&r<=rq){
		return t[id];
	}
	int mid=(l+r)>>1;
	return max(query(id*2,l,mid,lq,rq),query(id*2+1,mid+1,r,lq,rq));
}
int32_t main()
{ 
  IOS

  int n;
  cin >> n;
  vector<int> a(n), b(n) , c(n);
  multiset<int> m;
  for(int i = 0; i<n;i++){
    cin >> a[i] ;
  }  
  build(1,1,n);
  for(int i = 0;i<n;i++){
    cin >> b[i];
    m.insert(b[i]);
    update(1,1,n,b[i],1);
  }
  
  for(int i = 0;i<n;i++){
    auto it = query(1,1,n,a[i] + 1, n);
    if(it.first <= 0){
      int j = i;
      for(auto p:m){
        c[j++] = p;
      }
      break;
    }
    else{
      int val =  it.second;
      m.erase(m.find(val));
      update(1,1,n,it.second,-1);
      c[i] = val;
    }
  }
  for(int i = 0;i<n;i++){
    if(c[i] == a[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for(int i =  0;i<n;i++){
    cout << c[i] << " " ;
  }

  
    
} 



Measured memory_bytes: 25368
// C++ program to add two binary strings 
#include<bits/stdc++.h> 
using namespace std; 


// Driver program 
int main() 
{ 
	int N , M , sum = 0 , ans ;
  cin>>N>>M;
  int arr[M];  

  for(int i = 0 ; i < M ; i++)
    cin>>arr[i];

   
  for(int i = 0 ; i < M ; i++)
  {
    sum += arr[i] ;
  }

  if(sum <= N)
  {
      ans = N - sum ;
      cout<<ans ;
  }
  else
    cout<<-1 ;

	return 0; 
} 


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
//CCW??¨///////////////////////////////////
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
/////////////////////////////////////////
class Point{
  public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}

  bool operator < (const Point &p) const{
    return x!=p.x?x<p.x:y<p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x)<EPS&&fabs(y-p.y)<EPS;
  }
};
/*class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};*/
typedef Point vect;
struct seg{Point p1,p2;};
//????????´???
double norm(Point p){return p.x*p.x+p.y*p.y;}
//??¶??????
double abs(Point p){return sqrt(norm(p));}
//??????
double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}
//??????
double cross(Point a,Point b){
  return a.x*b.y-a.y*b.x;
}
//??´?????????
bool C90(seg s1,seg s2){
  return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}
bool C0(seg s1,seg s2){
  return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}
//?°???±
Point project(seg s,Point p){
  Point base = s.p2-s.p1;
  double r=dot(p-s.p1,base) / norm(base);
  return s.p1+base*r;
}
//????°?
Point reflection(seg s,Point p){
  return  p+(project(s,p)-p)*2.0;
}
//2???????????¢
double getDistancePP(Point a,Point b){
  return abs(a-b);
}
//??´??????????????¢(????°?)
double getDistanceLP(seg l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}
//?????????????????¢
double getDistanceSP(seg s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}
//????¨?????????????????¨??????????
int CCW(Point p0,Point p1,Point p2){
  Point a=p1-p0;
  Point b=p2-p0;
  if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-EPS)return CLOCKWISE;
  if(dot(a,b)<-EPS)return ONLINE_BACK;
  if(norm(a)<norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}
//??????????????????
bool intersect(Point p1,Point p2,Point p3,Point p4){
  return(CCW(p1,p2,p3)*CCW(p1,p2,p4)<=0&&CCW(p3,p4,p1)*CCW(p3,p4,p2)<=0);
}
bool intersect(seg s1,seg s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
//????????????????????¢
double getDistance(seg s1,seg s2){
  if(intersect(s1,s2))return 0.0;
  return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
    min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}
main(){
  int n;
  seg a,b;
  cin>>n;
  while(n--){
    cin>>a.p1.x>>a.p1.y>>a.p2.x>>a.p2.y;
    cin>>b.p1.x>>b.p1.y>>b.p2.x>>b.p2.y;
    printf("%.11f\n",getDistance(a,b));
  }
}

Measured memory_bytes: 3300