akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define chalne_de continue
int mod=1000000007;
const int N = 100005;

ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
vector<int> v[N];
bool visited[N];
bool leaf(int parent, int elem)
{
	int l = v[elem].size();
	for ( int i = 0 ; i < l ; i++)
	{
		int child = v[elem][i];
		if ( child == parent)continue;
		bool find_ = leaf(elem,child);
		if ( find_)
		{
			if ( visited[elem]){
				visited[elem] = false;
				return false;
			}
			else
			{
				visited[elem] = true ;
			}
		}
	}
	if ( !visited[elem])
	{
		visited[elem] = true;
		return true;
		}
	

	else
		return false;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n ;
	rep(i,0,n-1)
	{
		int x,y;
		cin >> x >> y ;
		v[x].pb(y);
		v[y].pb(x);
	}
	/*//bool visited[N];
	memset(visited,false,sizeof(visited));
	for ( int i = 1 ; i <= n ; i++)
	{
		int cnt = 0;
		//if ( visited[i] == false)
		int l = v[i].size();
		//cout << l <<endl;
		for ( int j = 0 ; j < l;j++)
		{
			int x = v[i][j];
			//visited[x] = true;
			//cout << x << " ";
			if ( v[x].size() == 1)
				cnt++;
		}
		//cout << endl;
		if ( cnt >= 2)
		{
			cout << "First";
			return 0;
		}
	}
	*/if ( n % 2 == 1)
	{
		cout << "First";
		return 0;
	}
	leaf(-1,1);
	bool first = false;
	for ( int i = 1 ; i <= n ; i++)
	{
		if ( visited[i] == false)
		{
			first = true ;
			break;
		}
	}
	if ( first )
		cout << "First";
	else
		cout << "Second";
	return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
long long xo(long long n)
{

 long long t = n & 3;

 if (t & 1) return t / 2u ^ 1;

 return t / 2u ^ n;

}
long long n,m;
main()
{
	cin>>n>>m;
	cout<<((xo(m))^(xo(n-1)));
}


Measured memory_bytes: 256
a = input()
b = input()
l = max(len(a), len(b))

for i,j in zip(a.zfill(l), b.zfill(l)):
  if int(i) > int(j):
    print("GREATER")
    break
  elif int(i) < int(j):
    print("LESS")
    break
else:
  print("EQUAL")


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

public class Main {

	/** 「紙」を配列として定義 */
	private static int[][] paper = new int[10][10];

	/** インクのサイズ：小を表す数字 */
	private final static String INK_SIZE_S = "1";

	/** インクのサイズ：中を表す数字 */
	private final static String INK_SIZE_M = "2";

	/** 色のついていない部分のマス目の個数：初期値100 */
	private static int plainCells = 100;

	/** 一番濃いマス目の濃さ */
	private static int maximumValue = 0;

	/**
	 * <p>
	 * 入力値で与えられたマス目にインクを落とす。<br/>
	 * インクを落とすたびに濃さを1増やしていく。<br/>
	 * 最後に、色のついていない部分のマス目の個数と、一番濃いマス目の濃さを出力する。<br/>
	 * </p>
	 *
	 * @param args
	 *            利用しない。
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		// 入力値を受け取る
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// インクを垂らす
		String line = null;
		while ((line = br.readLine()) != null) {

			String[] inkInfo = line.split(",");
			int x = Integer.parseInt(inkInfo[0]);
			int y = Integer.parseInt(inkInfo[1]);
			String size = inkInfo[2];

			// 小のサイズのインクの濃さを加算
			dropInk(x, y); // 真ん中
			dropInk(x - 1, y); // 左
			dropInk(x + 1, y); // 右
			dropInk(x, y - 1); // 下
			dropInk(x, y + 1); // 上

			if (INK_SIZE_S.equals(size)) {
				continue;
			}

			// 中のサイズのインクの濃さを加算
			dropInk(x - 1, y - 1); // 左下
			dropInk(x - 1, y + 1); // 左上
			dropInk(x + 1, y - 1); // 右下
			dropInk(x + 1, y + 1); // 右上

			if (INK_SIZE_M.equals(size)) {
				continue;
			}

			// 大のサイズのインクの濃さを加算
			dropInk(x - 2, y); // 2つ左
			dropInk(x + 2, y); // 2つ右
			dropInk(x, y - 2); // 2つ下
			dropInk(x, y + 2); // 2つ上
		}

		// 結果を出力
		System.out.println(plainCells); // 色のついていない部分のマス目の個数
		System.out.println(maximumValue); // １番濃いマス目の濃さ
	}

	/**
	 * <p>
	 * 引数で指定されたマス目にインクを落とせるか（「紙」の大きさの範囲内か）を確認し、 落とせる場合はマス目の濃さを+1する。</br>
	 * この際、インクを落としたマス目の濃さが0であれば「色のついていない部分のマス目の個数」から1を引く。<br/>
	 * 「一番濃いマス目の濃さ」よりも濃くなるのであれば濃さを更新する。<br/>
	 * </p>
	 *
	 * @param x
	 *            インクを落とすマス目のx座標
	 * @param y
	 *            インクを落とすマス目のy座標
	 */
	private static void dropInk(int x, int y) {

		if (0 <= x && x < 10 && 0 <= y && y < 10) {

			// 「色のついていない部分のマス目の個数」の更新
			if (paper[x][y] == 0) {
				plainCells -= 1;
			}

			// インクの濃さの加算
			paper[x][y] += 1;

			// 「一番濃いマス目の濃さ」の更新
			if (paper[x][y] > maximumValue) {
				maximumValue = paper[x][y];
			}
		}
	}
}

Measured memory_bytes: 16928
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main()
{
int n;
cin>>n;
for(int i=1; ; i++)
{
    if(i*i>n)
    {
        cout<<(i-1)*(i-1)<<endl;
        break;
    }
}
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[1<<n];
    multiset<int,greater<int>> s[1<<n];
    for(int i=0;i<(1<<n);i++){
        cin>>a[i];
        s[i].insert(a[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<n);j++){
            if(!(j&(1<<i))){
                // cout<<i<<" "<<j<<endl;
                for(int l:s[j]){
                    s[j|(1<<i)].insert(l);
                }
                if(s[j|(1<<i)].size()>2){
                    auto itr=s[j|(1<<i)].begin();
                    ++itr,++itr;
                    s[j|(1<<i)].erase(itr,s[j|(1<<i)].end());
                    // cout<<s[j|(1<<i)].size()<<endl;
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<(1<<n);i++){
        int temp=*(s[i].begin())+*(++s[i].begin());
        ans=max(ans,*(s[i].begin())+*(++s[i].begin()));
        // cout<<ans<<" "<<*(s[i].begin())<<" "<<*(++s[i].begin())<<endl;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 41532
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<Path>[] path = Enumerable.Repeat(0,n).Select(x => new List<Path>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            path[abc[0] - 1].Add(new Path(abc[1] - 1, abc[2]));
            path[abc[1] - 1].Add(new Path(abc[0] - 1, abc[2]));
        }
        int[] qk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long[] cost = Enumerable.Repeat(long.MaxValue, n).ToArray();
        Queue<int> queue = new Queue<int>();
        queue.Enqueue(qk[1] - 1);
        cost[qk[1] - 1] = 0;
        while (queue.Count != 0)
        {
            int index = queue.Dequeue();
            List<Path> paths = path[index];
            for (int i = 0; i < paths.Count; i++)
            {
                if (cost[paths[i].To] > cost[index] + paths[i].Cost)
                {
                    cost[paths[i].To] = cost[index] + paths[i].Cost;
                    queue.Enqueue(paths[i].To);
                }
            }
        }
        for (int i = 0; i < qk[0]; i++)
        {
            int[] xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(cost[xy[0] - 1] + cost[xy[1] - 1]);
        }
    }
}
struct Path
{
    public int To;
    public long Cost;
    public Path(int to,long cost)
    {
        To = to;
        Cost = cost;
    }
}

Measured memory_bytes: 38724
//ABC093C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	vector<int> v(3);
	int ans = 0;
	for(int i=0;i<3;i++){
		cin >> v.at(i);
	}
	sort(v.begin(),v.end());
	ans += v.at(2) - v.at(1);
	v.at(0) += v.at(2) - v.at(1);
	ans += (v.at(2)-v.at(0))/2;
	if((v.at(2)-v.at(0))%2 == 1){
		ans += 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const ll INF=1e18+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	for(int& x:a) cin>>x;
	for(int& x:b) cin>>x;
	reverse(all(b));
	int same=-1;
	for(int i=0;i<n;++i){
		if(a[i]==b[i]){
			same=a[i];
			break;
		}
	}
	if(same==-1){
		cout<<"Yes"<<endl;
		for(int i=0;i<n;++i) cout<<b[i]<<" ";
		return 0;
	}
	vector<int> posSame,posDiff;
	for(int i=0;i<n;++i){
		if(b[i]==same&&a[i]==same){
			posSame.push_back(i);
		}
		if(b[i]!=same&&a[i]!=same){
			posDiff.push_back(i);
		}
	}
	if((int)posSame.size()>(int)posDiff.size()){
		return cout<<"No",0;
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<(int)posSame.size();++i){
		swap(b[posSame[i]],b[posDiff[i]]);
	}
	for(int i=0;i<n;++i) cout<<b[i]<<" ";
	return 0;
}


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

using namespace std;

int main() {

	int D;
	cin >> D;

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

	vector<vector<int>> sd(D + 1, vector<int>(27));

	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> sd[i][j];
		}
	}

	mt19937 mt{ std::random_device{}() };

	uniform_int_distribution<int> dist(1, 26);


	long long resmax = -100000000000000;
	vector<int> maxcont(D + 1);

	for (int k = 0; k < 100000; k++) {

		long long tmpres = 0;
		vector<int> cont(D + 1);
		vector<int> lastcont(27);

		for (int i = 1; i <= D; i++) {

			cont[i] = dist(mt);

			lastcont[cont[i]] = i;
			tmpres += sd[i][cont[i]];

			for (int j = 1; j <= 26; j++) {
				tmpres -= c[j] * (i - lastcont[j]);
			}

		}

		if (resmax < tmpres) {
			resmax = tmpres;
			maxcont = cont;
		}
	}

	for (int i = 1; i <= D; i++) {
		cout << maxcont[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 3700
// LQDNT_TTMinh
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define req(i,a,b) for(ll i=(a);i>=(b);--i)
#define name ""
#define pb push_back
#define sz size()
#define ff first
#define ss second
typedef pair < ll , ll > ii;
const ll maxn=1e6+7,oo=1e18,base=311,mod=1e9+7;
ll n,d,x,y,res;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//    freopen(name".inp","r",stdin);
//    freopen(name".out","w",stdout);
    cin>>n>>d;
    rep(i,1,n)
    {
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            ++res;
    }
    cout<<res;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,k;
  int build[4][3][10]={{{}}};
  cin >> n;
  int b,f,r,v;
  for(i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    build[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout << " ";
	cout << build[i][j][k];
      }
      cout << endl;
    }
    if(i<3)cout << "####################" << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
    int n,m;
    int a,b;
    cin>>n>>m;
    int i;
    if(n%2){
             a=1,b=n;
    for(i=0;i<m;i++)
        printf("%d %d\n",a++,b--);
        }
    else{
         a=1;b=n/2;
        while(a<b&&m--)
           printf("%d %d\n",a++,b--);
        a=n/2+2;b=n;
        while(m--&&m>=0)
            printf("%d %d\n",a++,b--);

    }
    return 0;
}


Measured memory_bytes: 3760
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;cin >> s >> t;
    ll n = s.size();
    ll ans = 0;
    rep(i,0,n){
        ans += s[i] != t[i];
    }
    cout << ans << endl;
}

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

int main()
{
   int n,k,s=0;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   for(int i=0;i<k;i++)
   {
       s+=a[i];
   }
   cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        
        if (age == 1) {
            System.out.println("Hello World");
        } else if (age == 2) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            System.out.println(A + B);
        }
    }
}


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


int main(){
    ll A, B, K; cin >> A >> B >> K;

    ll ans_a = A-K;
    ll ans_b;
    if(K>A) ans_b = B-(K-A);
    else ans_b = B;

    if(ans_a<0) ans_a = 0;
    if(ans_b<0) ans_b = 0;

    cout << ans_a << " " << ans_b << endl;
    return 0;
}

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

int main() {
    long long l;
    cin>>l;
    long double ans = l*l*l*0.037037037;
    cout<<fixed<<setprecision(8);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read();
    vector<int> A(N), B(N);
    for (auto& a:A) {
        a = read();
    }
    B = A;
    sort(B.begin(), B.end());
    int max1 = B[N-1], max2 = B[N-2];
    for (auto a:A) {
        printf("%d\n", a == max1 ? max2 : max1);
    }
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
int main() {
  cin >> N;
  A.resize(N);
  for (auto &val : A){
    cin >> val;
  }
  ll ans = 1LL << 60;
  //pos,neg,pos,neg
  {
    ll sum = A[0];
    ll res = 0;
    if (sum <= 0){
      res += abs(sum) + 1;
      sum = 1;
    }
    for (int i = 1; i < N; i++){
      ll next_sum = sum + A[i];
      bool neg = i % 2 != 0 ? true : false;
      if (next_sum > 0){
        if (neg){
          res += next_sum + 1;
          next_sum = -1;
        }
      }else if(next_sum < 0){
        if (not neg){
          res += abs(next_sum) + 1;
          next_sum = 1;
        }
      }else{//zero
        if (neg){
          res += 1;
          next_sum = -1;
        }else{
          res += 1;
          next_sum = -1;
        }
      }
      sum = next_sum;
    }
    ans = min(ans, res);
  }
  //neg,pos,neg
  {
    ll sum = A[0];
    ll res = 0;
    if (sum >= 0){
      res += abs(sum) + 1;
      sum = -1;
    }
    for (int i = 1; i < N; i++){
      ll next_sum = sum + A[i];
      bool neg = i % 2 == 0 ? true : false;
      if (next_sum > 0){
        if (neg){
          res += next_sum + 1;
          next_sum = -1;
        }
      }else if(next_sum < 0){
        if (not neg){//should positive
          res += abs(next_sum) + 1;
          next_sum = 1;
        }
      }else{//zero
        if (neg){
          res += 1;
          next_sum = -1;
        }else{
          res += 1;
          next_sum = 1;
        }
      }
      sum = next_sum;
    }
    ans = min(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
I = list(map(int,input().split()))
N = I[0]
K = I[1]
Q = I[2]
A = [0] * Q
for i in range(Q):
    A[i] = int(input())
C = [0] * N
for i in range(Q):
    C[A[i]-1] += 1
for i in range(N):
    ans = K - Q + C[i]
    if ans > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8632
import java.io.*;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
			int n=Integer.parseInt(br.readLine());
        String[] str=br.readLine().split(" ");
        int[] S=new int[n];
        for(int i=0;i<n;i++)
            S[i]=Integer.parseInt(str[i]);
         
        int q=Integer.parseInt(br.readLine());
        str=br.readLine().split(" ");
        int[] T=new int[q];
        for(int i=0;i<q;i++)
            T[i]=Integer.parseInt(str[i]);
         
        System.out.println(method(S,T));
         
 
    }
    static int method(int[] s,int[] t){
        if(s.length<t.length){
            int[] tmp=s;
            s=t;
            t=tmp;
        }
        
        int count=0;
        int q=s.length/4;
        for(int i=0;i<t.length;i++){
        	if(t[i]>s[q*2]){
        		if(t[i]>s[q*3]){
            		for(int j=s[q*3];j<s.length;j++)
            			if(t[i]==s[j]){count++;break;}}
            	else if(t[i]<s[q*3]){
            		for(int j=q*2;j<q*3;j++)if(t[i]==s[j]){count++;break;}}
            	else if(s[q*3]==t[i]){count++;continue;}}
        	
        	else if(t[i]<s[q*2]){
        		if(t[i]>s[q]){
            		for(int j=s[q+1];j<q*2;j++)
            			if(t[i]==s[j]){count++;break;}}
            	else if(t[i]<s[q]){
            		for(int j=0;j<q;j++)if(t[i]==s[j]){count++;break;}}
            	else if(s[q]==t[i]){count++;continue;}}
        	
        		
        	else if(s[s.length/2]==t[i]){count++;continue;}
        		
        	
        }
        
                 
        return count;
    }
 
}

Measured memory_bytes: 42880
import java.util.*;

class Main{
  
  public static void main (String args[]){
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    int t[] = new int[n];
    
    int sum = 0;
      
    for(int i=0;i<n;i++){
      t[i] = sc.nextInt();
      sum += t[i];
    }
    
    int m = sc.nextInt();
    
    int sumdri;
    
    for(int i=0;i<m;i++){
      int p = sc.nextInt();
      
      int x = sc.nextInt();
      
      System.out.println(sum - t[p-1]+x);

    }
   
    
  }
  
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val (m1,d1) = readLine()!!.split(' ').map(String::toLong)
    val (m2,d2) = readLine()!!.split(' ').map(String::toLong)

    if (m1!=m2) {
        println(1)
    } else {
        println(0)
    }
}


Measured memory_bytes: 38180
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;

int main(){
    int n;
    cin >> n;
    
    int count = 1;
    int big;
    cin >> big;
    int p;
    REP(i,n-1){
        cin >> p;
        if(p <= big){
            count++;
            big = p;
        }
    }
    cout << count << endl;
    
    
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N,X; cin >> N >> X;
    VI m(N); int mn = INT_INF; REP(i,N){cin >> m[i]; X -= m[i]; chmin(mn, m[i]);}
    int ans = N + X/mn;
    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);

		String s = sc.next();
		int a = 0;
		int b = 0;
		int c = 0;

		for (char ch : s.toCharArray()) {
			if ('a' == ch)
				a++;
			if ('b' == ch)
				b++;
			if ('c' == ch)
				c++;
		}

		int ab = Math.abs(a - b);
		int ac = Math.abs(a - c);
		int bc = Math.abs(b - c);

		String ans = "NO";
		if (ab == 0 || ab == 1) {
			if (ac == 0 || ac == 1) {
				if (bc == 0 || bc == 1) {
					ans = "YES";
				}
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 26604
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;

int n, m;
int a[15],b[10005];
int main()
{
	scanf("%d%d", &n, &m);
	memset(a, 0, sizeof(a));
	int x;
	for(int i = 0; i < m; i++)
	{
		scanf("%d", &x);
		a[x] = 1;
	}
	for(int i = n;; i++)
	{
		int y = i;
		int flag = 0;
		while(y > 0)
		{
			int q = y % 10;
			if(a[q] == 1) {flag = 1; break;}
			y = y / 10;
		}
		if(flag == 0) {printf("%d\n", i); break;}
	}
	return 0;
}

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

int main(){
  vector<int> x(5);
  int a;
  for(int i = 0; i < 5; i++){
    cin >> x[i];
    if(x[i] == 0){
      a = i+1;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3620
/*pata hai na?*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const ld pi=acos(-1);
const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,m;
    cin>>n>>m;

    int a[n];
    mem(a,-1);

    for(int i=0;i<m;++i)
    {
        int s,c;
        cin>>s>>c;

        if(s==1 && c==0 && n!=1)
        {
            cout<<-1;
            return;
        }

        --s;
        if(a[s]==-1)
            a[s]=c;
        else
        {
            if(a[s]==c)
                ;
            else
            {
                cout<<-1;
                return;
            }
        }
    }

    for(int i=0;i<n;++i)
    {
        if(a[i]==-1)
        {
            if(!i)
            {
                if(n==1)
                    a[i]=0;
                else
                    a[i]=1;
            }
            else
                a[i]=0;
        }

        cout<<a[i];
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>g[100];
int used[100];
int solve(int a){
	used[a]=1;
	int ret=1;
	for(int i=0;i<g[a].size();i++){
		if(!used[g[a][i]]){
			ret=max(ret,1+solve(g[a][i]));
		}
	}
	used[a]=0;
	return ret;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<100;i++)g[i].clear();
		for(int i=0;i<a;i++){
			int b,c;
			scanf("%d%d",&b,&c);
			b--;c--;
			g[b].push_back(c);
			g[c].push_back(b);
		}
		int ret=0;
		for(int i=0;i<100;i++)ret=max(ret,solve(i));
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1056
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];
int n;

void preParse(int u){
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u){
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}
void postParse(int u){
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

main(){
  int i, v, l, r, root,a=0;
  a=kansu(a);
  if(a == 0){
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}
}
void kansu(int a){
 int b=0,c=1;
 if(b == 0);
  if(c == 1);
   return a;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int A,B,Q; cin >> A >> B >> Q;
    vl s(A),t(B);
    rep(i,A) cin >> s[i];
    rep(i,B) cin >> t[i];
    s.push_back(1e12);
    s.push_back(-1e12);
    t.push_back(1e12);
    t.push_back(-1e12);
    sort(all(s));
    sort(all(t));

    vl rs,rt;
    rrep(i,A+2) rs.push_back(-s[i]);
    rrep(i,B+2) rt.push_back(-t[i]);

    rep(i,Q){
        ll x; cin >> x;
        ll a = abs(x - *lower_bound(all(s), x));
        ll b = abs(x - *lower_bound(all(t), x));
        ll ra = abs(x + *lower_bound(all(rs), -x));
        ll rb = abs(x + *lower_bound(all(rt), -x));

        ll d1 = max(a, b);
        ll d2 = max(ra, rb);
        ll d3 = a + rb + min(a, rb);
        ll d4 = b + ra + min(b, ra);
        cout << min({d1,d2,d3,d4}) << endl;
    }
    return 0;
}

Measured memory_bytes: 7364
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 2000050
int n,m;
int main() {
	scanf("%d %d", &n, &m);
	if(m==1){
		printf("0\n");
		return 0;
	}
	printf("%d\n", (n-m));
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n, a[100010], sum, ans;

inline int max(int a, int b){
	return a > b ? a : b;
}

int main(){
	
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++){
		if(a[i] > a[i - 1]){
			ans = max(ans, sum);
			sum = 0;
		}
		else sum++;
	}
	ans = max(ans, sum);
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

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

   vector<int> a(n);
   rep(i,n){
      cin>>a[i];
   }
   sort(a.begin(),a.end());
   vector<int> b;
   b.push_back(0);
   b.push_back(0);
   rep(i,n-1){
      if(a[i+1]==a[i]){
         if(a[i+2]==a[i]){
            if(a[i+3]==a[i]){
               b.push_back(a[i]);
               b.push_back(a[i]);
               i+=3;
            }
            else{
               b.push_back(a[i]);
               i+=2;
            }
         }
         else{
         b.push_back(a[i]);
         }
      }
   }
   int p=0,q=0;

   

   sort(b.begin(),b.end(),greater<int>());
   cout<<(ll)b[0]*(ll)b[1];
   


   return 0;
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define endl "\n";
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

const int N = 100005;
const int MOD = 1000000007;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    ll i,n,k;
    vector<ll>vec;
    sl(n);
    rep0(i,n)
    {
        sl(k);
        vec.pb(k);
    }
    sort(all(vec));
    if(vec[0]==0)
    {
        puts("0");
        return 0;
    }
    ll tot=1,mx=1000000000000000000;
    rep0(i,n)
    {
        if(tot<=mx/vec[i])
            tot*=vec[i];
        else
        {
            tot=-1;
            break;
        }
    }
    pf("%lld",tot);
}


Measured memory_bytes: 4328
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=302,p=1000000007,inf=1047483647;
struct node { int l,x,next; } a[N];
LL an;
int head[N],f[N][N][N],i,j,k,n,m,u,x,y,z,l1,r1,l2,r2;
bool P[N][N][N];
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void plus(int &a,int b){ a+=b,a-=a<p?0:p; }

void jb(int x,int y)
{
	a[++k]=(node){y,read(),head[x]},head[x]=k;
}

void make(int i,int j,int k)
{
	if (!P[i][j][k]) return;
	z=f[i][j][k],
	plus(f[u+1][j][k],z),plus(f[u+1][i][k],z);
	if (j)
		plus(f[u+1][i][j],z);
}

void solve(int w)
{
	l1=l2=0,r1=r2=w-1;
	for (j=head[w];j;j=a[j].next)
		if (a[j].x==1)
			r1=min(r1,a[j].l-1);
		else
			if (a[j].x==2)
				l1=max(l1,a[j].l),r2=min(r2,a[j].l-1);
			else
				l2=max(l2,a[j].l);
	if (!l1&&!l2)
		P[w][0][0]=f[w][0][0]>0;
	for (j=l1;j<=r1;++j)
		for (k=min(r2,j-1);k>=l2;--k)
			P[w][j][k]=f[w][j][k]>0;
}

int main()
{
	n=read(),m=read();
	for (i=1;i<=m;++i) x=read(),jb(read(),x);
	for (j=head[1];j;j=a[j].next)
		if (a[j].x>1)
		{
			puts("0");
			return 0;
		}
	for (P[1][0][0]=f[1][0][0]=u=1;u<n;solve(++u))
		for (make(u,0,0),j=1;j<u;++j)
			for (k=0;k<j;++k)
				make(u,j,k);
	for (P[n][0][0]?an=f[n][0][0]:0,i=1;i<n;++i)
		for (j=0;j<i;++j)
			if (P[n][i][j])
				an+=f[n][i][j]<<1;
	printf("%d\n",an*3%p);
	return 0;
}

Measured memory_bytes: 133504
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    int n;
    cin >> n;
    vector<ll> values(n);
    rep(i, n) cin >> values[i];

    map<ll, int> m;
    for (ll v: values) m[v]++;

    ll sum = accumulate(values.begin(), values.end(), 0ll);

    int q;
    cin >> q;

    rep(_, q) {
        ll b, c;
        cin >> b >> c;

        ll ad = c - b;

        ll count = m[b];

        ll change = ad * count;
        sum += change;

        cout << sum << endl;

        m.erase(b);
        m[c] += count;

    }


}

Measured memory_bytes: 7956
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a); i < (b); i += (s))
#define down(i, a, b, s) for (int i = (a); (b) < i; i -= (s))

struct _solver {
  long long ls, rs, bs;
  priority_queue<int, vector<int>, less<int>> lhs;
  priority_queue<int, vector<int>, greater<int>> rhs;

  void clear() {
    ls = rs = bs = 0;
    while (!lhs.empty()) lhs.pop();
    while (!rhs.empty()) rhs.pop();
  }

  inline void push_l(int x) {
    lhs.push(x);
    ls += x;
  }

  inline void push_r(int x) {
    rhs.push(x);
    rs += x;
  }

  inline long long pop_l() {
    long long k = lhs.top();
    ls -= k;
    lhs.pop();
    return k;
  }

  inline long long pop_r() {
    long long k = rhs.top();
    rs -= k;
    rhs.pop();
    return k;
  }

  void update(int a, int b) {
    bs += b;
    push_l(a);
    if (lhs.size() > rhs.size() + 1) {
      push_r(pop_l());
    }
    while (rhs.size() > 0 && lhs.top() > rhs.top()) {
      long long ll = pop_l();
      long long rr = pop_r();
      push_l(rr);
      push_r(ll);
    }
  }

  pair<long long, long long> query() {
    long long k = lhs.top();
    long long l = k * (long long)lhs.size() - ls;
    long long r = rs - k * (long long)rhs.size();
    return mp(k, l + r + bs);
  }
} solver;

int q, a, b, c;

int main(int argc, char const *argv[]) {
  // freopen("F.txt", "r", stdin);

  while (cin >> q) {
    solver.clear();
    range(_, 0, q, 1) {
      cin >> c;
      if (c == 1) {
        cin >> a >> b;
        solver.update(a, b);
      } else {
        auto ans = solver.query();
        cout << ans.fi << " " << ans.se << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

ll d[1<<16];
ll dp[1<<16];

int main() {
  int n;
  scanf("%d",&n);
  vvi a(n,vi(n));
  cin>>a;
  int n2 = 1<<n;
  rep(i,n2) if (i) {
    int j = i&-i;
    int ni = i^j;
    d[i] = d[ni];
    j = pcnt(j-1);
    while (ni) {
      int k = ni&-ni;
      ni ^= k;
      d[i] += a[j][pcnt(k-1)];
    }
  }
  rep(i,n2) {
    dp[i] = d[i];
    for (int j = i; j; j = (j-1)&i) {
      maxs(dp[i], dp[i^j]+d[j]);
    }
  }
  cout<<dp[n2-1]<<endl;
  return 0;
}






















Measured memory_bytes: 1408
n = gets.to_i

arr = gets.split.map(&:to_i)

i = 0
flag = true
count = 0

while flag
  flag = false

  (n - 1).downto(i + 1) do |j|
    if arr[j] < arr[j - 1]
      arr[j - 1], arr[j] = arr[j], arr[j - 1]
      count += 1
      flag = true
    end
  end

  i += 1
end

puts arr.join(' ')
puts count

Measured memory_bytes: 8660
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

def make2d_arr(w,h,val =INF):
    return [[val]*w for i in xrange(h)]

def floyd_warshall(costs):
    N = len(costs)
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                costs[i][j]  = min(costs[i][j],costs[i][k]+costs[k][j])
    return costs

N = int_raw()
S = raw_input()

dp = {}

for s in S:
    if not (s in dp):
        dp[s] = 1
    else:
        dp[s]+=1

ans =1

for k,v in dp.items():
    ans*=(v+1)
    ans % DIV


print (ans-1+DIV)% DIV




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

int main()
{
    int N;
    cin >> N;
    const int MOD = 1e9 + 7;
    int64_t total = 1;
    map<int, int64_t> divisor;
    for (int i = 1; i <= N; i++)
    {
        int num = i;
        for (int j = 2; j <= i; j++)
        {
            while (num % j == 0)
            {
                divisor[j]++;
                num /= j;
            }
        }
    }
    for (auto x : divisor)
    {
        total = (total % MOD) * (x.second + 1) % MOD;
    }
    cout << total % MOD << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cctype>
using namespace std;
int main()
{
	long double a,b,c;
  cin>>a>>b>>c;
	if(a+2*sqrtl(a*b)+b<c) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N, A, B;
	cin >>N >>A >>B;
	if (1==(B-A)%2)
		cout << "Borys" <<endl;
	else
		cout << "Alice" <<endl;
	return 0;
}



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

int main() {
	int N, T, A, H;
	cin >> N >> T >> A >> H;
	T = 1000 * (T - A); // Tを平行移動することで、計算を楽にする
	int diff = abs(T - 6 * H), ans = 1; // diffは平均気温との差、これが最も小さくなる地点を探すよ
	for (int i = 2;i <= N;++ i) {
		cin >> H;
		if (diff > abs(T - 6 * H)) {
			diff = abs(T - 6 * H);
			ans = i;
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

全部1000倍します。すなわち、平均気温は1000T-6xで、これが1000Aに近い物を探します
ここで、全部の温度を1000A減らす、すなわち平均気温を1000T-1000A-6xとするとこれは0度に近いものを探すことになるね
つまり、絶対値を考えれば良いだけになる
*/

Measured memory_bytes: 256
// Author :mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second


ll const mod=1e9+7;
ll const N=5e5+5;
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return y; else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}



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);}
};
struct compare {
    bool operator()(const pair<ll, ll>& value,  const ll& key){ return (value.first < key); }
    bool operator()(const ll& key, const pair<ll, ll>& value) { return (key < value.first); }
};

bool compare1(const pair<ll,ll> &a,const pair<ll,ll> &b)
{   if(a.first<b.first) return true ;
    else if(a.first==b.first) return (a.second > b.second);
    else return false;
}


int main()
{

        ios_base::sync_with_stdio(false); cin.tie(NULL);
        

       /* #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif*/
        
        int tt=1;
        //cin>>tt;
        
        while(tt--)
        {
                ll n,m;
                cin>>n>>m;
                cout<<(n/m+(n%m>0))<<endl;
        }



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int x=max({a,b,c});
    cout<<a+b+c-x+x*pow(2,k)<<endl;
}


Measured memory_bytes: 892