akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	using G=function<Monoid(Monoid, OperatorMonoid, int)>;
	using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
	int sz;
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	const F f;
	const G g;
	const H h;
	const Monoid e1;
	const OperatorMonoid e0;

	LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
		sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
	}

	void eval(int k, int l, int r){
		if(lazy[k]!=e0){
			data[k]=g(data[k], lazy[k], r-l);
			if(k<sz-1){
				lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
			}
		}
		lazy[k]=e0;
	}

	void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
		eval(k, l, r);
		if(r<=a || b<=l) return;
		if(a<=l && r<=b){
			lazy[k]=h(lazy[k], x);
			eval(k, l, r);
		}else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			data[k]=f(data[2*k+1], data[2*k+2]);
		}
	}
	void update(int a, int b, const OperatorMonoid &x){
		return update(a, b, x, 0, 0, sz);
	}

	Monoid find(int a, int b, int k, int l, int r){
		eval(k, l, r);
		if(b<=l || r<=a) return e1;
		if(a<=l && r<=b) return data[k];
		else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
	}
	Monoid find(int a, int b){
		return find(a, b, 0, 0, sz);
	}
};
const int INF=2147483647;
int main()
{
	int n, q;
	scanf("%d %d", &n, &q);
	auto f=[](int a, int b){ return min(a, b);};
	auto g=[](int a, int x, int len){ return x;};
	auto h=[](int x, int y){ return y;};
	LazySegmentTree<int> seg(n, f, g, h, INF, INF);
	for(int z=0; z<q; z++){
		int p; scanf("%d", &p);
		if(p==0){
			int s, t, x;
			scanf("%d %d %d", &s, &t, &x);
			seg.update(s, t+1, x);
		}else{
			int s, t;
			scanf("%d %d", &s, &t);
			printf("%d\n", seg.find(s, t+1));
		}
	}
	return 0;
}


Measured memory_bytes: 4964
import sys
input = sys.stdin.readline

h, w = sorted(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
    ans = 0
else:
    c_1 = ((w // 3 + 1) * h) - ((w - 1 - w // 3) * (h // 2))
    c_2 = ((w - w // 3) * (h - h // 2)) - (w // 3 * h)
    c_3 = h
    c_4 = ((h // 3 + 1) * w) - ((h - 1 - h // 3) * (w // 2))
    c_5 = ((h - h // 3) * (w - w // 2)) - (h // 3 * w)
    ans = min(c_1, c_2, c_3, c_4, c_5)
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#define maxn 100005
using namespace std;
int b[maxn],n,t,tcnt,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
	}
	sort(b+1,b+1+n);
	t=b[1];
	for(int i=1;i<=n;i++)
	{
		if(b[i]==t)
		{
			tcnt++;
		}
		else
		{
			if(tcnt>=t)
			{
				ans+=tcnt-t;
			}
			else
			{
				ans+=tcnt;
			}
			t=b[i];
			tcnt=1;
		}
	}
	if(tcnt>=t)
	{
		ans+=tcnt-t;
	}
	else
	{
		ans+=tcnt;
	}
	printf("%d",ans);
}

Measured memory_bytes: 512
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    Array.sort (fun (a1, b1) (a2, b2) -> compare (a2 + b2) (a1 + b1)) a;
    let rec loop i acc1 acc2 =
        if i = n then acc1 - acc2 else
            let (x, y) = a.(i) in
            if i mod 2 = 0 then loop (i + 1) (acc1 + x) acc2
                           else loop (i + 1) acc1 (acc2 + y)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define ll long long
#define MAX 100000
#define INF 1000000001

using namespace std;

int main (){
    int n,w,d1[MAX+1],d2[MAX+1],wi,vi;
    for(int i=0;i<=MAX;i++){d1[i]=INF;d2[i]=INF;}
    d1[0]=0;
    d2[0]=0;
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>wi>>vi;
        if(i%2==0){
            for(int j=0;j<vi;j++)d1[j]=d2[j];
            for(int j=0;j<MAX-vi+1;j++){
                d1[j+vi]=min(d2[j+vi],d2[j]+wi);
            }
        }else{
            for(int j=0;j<vi;j++)d2[j]=d1[j];
            for(int j=0;j<MAX-vi+1;j++)d2[j+vi]=min(d1[j+vi],d1[j]+wi);
        }
    }
    for(int i=MAX;i>=0;i--){
        if(n%2==0&&d2[i]<=w){
            cout<<i<<endl;
            break;
        }
        if(n%2==1&&d1[i]<=w){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

int main() {
    int N, A, B; cin >> N >> A >> B;
    int ma = min(A, B);
    int mi = (A + B) - N;
    if (mi < 0) mi = 0;
    cout << ma << ' ' << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 0; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
#define PI 3.14159265359
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 

int dp[205][205];

int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double theta = abs(30*h - 5.5*m)/180.0*PI;
    double c =  double(pow(a,2)) + double(pow(b,2)) - 2 * a * b * double(cos(theta));
    double d = double(sqrt(c));

    cout << fixed << setprecision(15) << d << endl;

}

Measured memory_bytes: 4228
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;
 
 
int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n); 

    long i;
    long x=n;
    long s=0;
    while(x>0) {
        s+=x%10;
        x/=10;
    }
    if( n%s==0 ) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
 
    return 0;
}


Measured memory_bytes: 128
l = io.read("*l")
t = {string.byte(l, 1, -1)} 
i, ans = 1, 0
 
for j = 2, string.len(l) do
	if t[i] ~= t[j] then
		ans = ans + 1
	end
	i = i + 1
end
print(ans)


Measured memory_bytes: 3476
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
 int n;
  cin>>n;
  vector<ll>d(n);
  for(int i=0;i<n;i++)cin>>d[i];
  ll ans = 0;
  sort(all(d));
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n-1;j++){
     ll sum = d[i]+d[j];
     int p = lb(all(d),sum)-d.begin();
     p--;
     ans+=p-j;
   }
  }
  cout<<ans;
}





Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String odd=scan.next();
        String even=scan.next();
        int i;
        String original="p";

        //System.out.println(original);

        if(odd.length()==even.length()){
            for(i=0;i<odd.length();i++){
                if(i==0){
                    original=odd.substring(i,i+1);
                    original=original+even.substring(i,i+1);
                }
                else{
                    original=original+odd.substring(i,i+1);
                    original=original+even.substring(i,i+1);
                }
                //System.out.println(odd.substring(i,i+1));
                //System.out.println(original);
            }
            original=original.substring(0,2*odd.length());
            System.out.println(original);
        }

        else if(odd.length()!=even.length()){
            for(i=0;i<odd.length();i++){
                if(i==0){
                    original=odd.substring(i,i+1);
                    original=original+even.substring(i,i+1);
                }
                else if(i!=odd.length()-1){
                    original=original+odd.substring(i,i+1);
                    original=original+even.substring(i,i+1);
                }
                else{
                    original=original+odd.substring(i,i+1);
                }
                //System.out.println(original);
            }
            original=original.substring(0,2*odd.length()-1);
            System.out.println(original);
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[500],divisor[100000];

int get_div(int tot)
{
    int tmp=0;
    for (int i=1;i*i<=tot;++i)
    if (tot%i==0)
        divisor[++tmp]=i,divisor[++tmp]=tot/i;
    return tmp;
}
int tmp_a[500];
int cmp(int o,int x){return o<x;}
long long check(int tmp_div,int n)
{
    //printf("###%d\n",tmp_div);
    long long k=0;
    for (int i=0;i<n;++i) tmp_a[i]=a[i];
    for (int i=0;i<n;++i) tmp_a[i]%=tmp_div;
    long long tot=0;
    for (int i=0;i<n;++i) tot+=(tmp_div-tmp_a[i]);
    tot/=tmp_div;
    sort(tmp_a,tmp_a+n,cmp);
    for (int i=0;i<tot;++i) k=k+tmp_a[i];
    return k;
}

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

    int num_div = get_div(tot);
    int ans=0;
    for (int i=num_div;i>0;--i)
    if (check(divisor[i],n)<=k){
        if(divisor[i]>ans) ans=divisor[i];
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int time = sc.nextInt();
    String[] inputs = new String[time * 2];
    for (int i = 0; i < time * 2; i++) {
      inputs[i] = sc.next();
    }

    for (int i = 0; i < time; i++) {
      System.out.println(LCSLength(inputs[i*2].toCharArray(), inputs[i*2+1].toCharArray()));
    }
  }

  public static int LCSLength(char[] x, char[] y) {
    int m = x.length;
    int n = y.length;
    int[][] c = new int[m+1][n+1];

    for (int i = 1; i <= m; i++) {
      c[i][0] = 0;
    }
    for (int j = 0; j <= n; j++) {
      c[0][j] = 0;
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {

        if (x[i-1] == y[j-1]) {
          c[i][j] = c[i-1][j-1] + 1;

        } else if (c[i-1][j] >= c[i][j-1]) {
          c[i][j] = c[i-1][j];

        } else {
          c[i][j] = c[i][j-1];
        }
      }
    }

    return c[m][n];
  }
}



Measured memory_bytes: 64460
import bisect
MAX_N = 120000
sieve = [0,0] + [1] * MAX_N
n = 2
primes = []
while n*n < MAX_N:
    if sieve[n]:
        primes.append(n)
        for m in range(2*n,MAX_N,n):
            sieve[m] = 0
    n += 1
for m in range(n,MAX_N):
    if sieve[m]: primes.append(m)

while True:
    N,P = map(int,input().split())
    if N == -1: break
    i = bisect.bisect_right(primes, N)
    li = []
    for p1 in range(i,i+P):
        for p2 in range(p1,i+P+1):
            li.append(primes[p1] + primes[p2])
    print(sorted(li)[P-1])

Measured memory_bytes: 7360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    priority_queue<pair<pair<ll,ll>,ll>> z;
    set<ll> q;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        z.push(make_pair(make_pair(a, b), 0));
    }
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        z.push(make_pair(make_pair(a, b), 1));
    }
    ll ans = 0;
    while (!(z.empty())) {
        ll a = z.top().first.first;
        ll b = z.top().first.second;
        ll c = z.top().second;
        if (c == 0) {
            if ((!q.empty())) {
                auto s = lower_bound(q.begin(), q.end(), b);
                if (s != q.end()) {
                    q.erase(*s);
                    ans++;
                }
            }
        }
        else {
            q.insert(b);
        }
        z.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
int gcd(int,int);
int main(){
  int x,y,r,ans;
  scanf("%d%d",&x,&y);
  if(x<y)ans = gcd(y,x);
  else ans = gcd(x,y);

  printf("%d\n",ans);
  return 0;
}
int gcd(int a, int b)
{
  int r;
  while(b>0){
    r = a%b;
    a = b;
    b = r;
  }
    return a;
}

Measured memory_bytes: 592
#include<stdio.h>

int main()
{
  int k,s;
  int x,y,z;
  int t=0;
  scanf("%d%d",&k,&s);
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      if(0<=s-x-y && s-x-y<=k) t++;
    }
  }
  printf("%d\n",t);
  return 0;
}


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

string s, t;

int main()
{
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    int dp[n + 1][m + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (s[i] == t[j])
            {
                dp[i + 1][j + 1] = 1 + dp[i][j];
            }
            else
            {
                dp[i + 1][j + 1] = max(dp[i][j + 1] , dp[i + 1][j]);
            }
        }
    }

    string str;

    int i = n, j = m;
    while (i > 0 && j > 0)
    {
        if (s[i - 1] == t[j - 1])
        {
            str.push_back(s[i - 1]);
            i--;
            j--;
        }
        else
        {
            if (dp[i][j - 1] > dp[i - 1][j])
            {
                j--;
            }
            else
            {
                i--;
            }
        }
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 38752
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
using namespace std;
ll a,b,k,ans=0;
vector<ll>v;
int32_t main(){
cin>>a;
cin>>b;
cin>>k;
for(ll i=1;i<=min(a,b);i++)
if(a%i==0&&b%i==0){
    v.pb(i);
    }
sort(v.begin(),v.end());
cout<<v[v.size()-k];
return 0;}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int ans = 0;
  
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  sort(A.begin(),A.end());
  
  for (int i=0; i<N; i++) {
    if (i == N-1) {
      ans++;
      break;
    }
    if (A[i] == A[i+1]) {
      i++;
      continue;
    }
    ans++;
  }
    
  
  cout << ans << endl;
  return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k;
string s;


// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	vll a(n);
	for(ll i=0;i<n;i++) cin>>a[i];
	ll mini = *min_element(all(a));
	ll maxi = *max_element(all(a));
	vpll ans;

	if(mini >= 0) {
		for(ll i=1;i<n;i++) {
			ans.pb({i,i+1});
		}
	}
	else if(maxi <= 0) {
		for(ll i=n;i>1;i--) {
			ans.pb({i,i-1});
		}
	}
	else if(abs(maxi) > abs(mini)) {
		ll mind = max_element(all(a)) - a.begin();
		for(ll i=0;i<n;i++) {
			if(i==mind) continue;
			ans.pb({mind+1,i+1});
		}
		for(ll i=1;i<n;i++) {
			ans.pb({i,i+1});
		}
	}
	else {
		ll mind = min_element(all(a)) - a.begin();
		for(ll i=0;i<n;i++) {
			if(i==mind) continue;
			ans.pb({mind+1,i+1});
		}
		for(ll i=n;i>1;i--) {
			ans.pb({i,i-1});
		}
	}
	cout<<ans.size();newl;
	for(auto it : ans) {
		cout<<it.f <<" "<<it.s;newl;
	}
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238056
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		int a[]=new int[N];
		long b[]=new long[N];
		long ans=-1;
		for(int i=0;i<N;i++){
			a[i]=stdIn.nextInt();
		}
		for(int i=0;i<Math.pow(2,N-1);i++){
			int x=i,cout=1;
			long sum=0,max=a[0];
			b[0]=a[0];
			for(int j=1;j<N;j++){
				b[j]=a[j];
				if(x%2==1&&max>=b[j]){
					max++;
					sum+=max-b[j];
					b[j]=max;cout++;
				}
				if(b[j]>max){
					cout++;
					max=b[j];
				}
				x/=2;
			}
			if(cout>=K&&sum<ans)
				ans=sum;
			if(cout>=K&&ans==-1)
				ans=sum;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21332
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s, t;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t;
    int len = s.length();
    int cnt = 0;
    for (int i = 0; i < len; i++) {
        if (s[i] != t[i]) cnt++;
    }
    cout << cnt << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    n=n%1000;
    if(n==0)
    {
        cout<<n;
    }
    else if(n>=0)
    {
        n=1000-n;
        cout<<n;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int N;
    map<int, int> S;
    int d;
    cin >> N;
    for(int i=0;i<N;++i){
        cin >> d;
        ++S[d];
    }

    cout << S.size() << endl;
}


Measured memory_bytes: 256
N = int(input())
v = list(map(int, input().split()))
 
 
v.sort(reverse = True)
 
for i in range(N-1):
    a = v.pop()
    b = v.pop()
    v.append((a+b)/2)
    v.sort(reverse = True)
 
print(v[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647

int main() {
  kyun;
  int a,b,c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b;
  hinata;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int N=1<<20;
inline int ksm(ll a,int b,int c=1){for(;b;b/=2,a=a*a%mod)if(b&1)c=c*a%mod;return c;}
int jc[N],jc2[N],pw3[N];
void Init(){
	pw3[0]=1;
	for(int i=1;i<N;++i)pw3[i]=(ll)3*pw3[i-1]%mod;
	jc[0]=1;
	for(int i=1;i<N;i++)jc[i]=(ll)jc[i-1]*i%mod;
	jc2[N-1]=ksm(jc[N-1],mod-2);
	for(int i=N-1;i;i--)jc2[i-1]=(ll)jc2[i]*i%mod;
}
int C(int n,int k){
	if(k<0)return 0;
	if(n<0){
		if(k&1)return(mod-C(-n+k-1,k))%mod;
		else return C(-n+k-1,k);
	}
	if(n<k)return 0;
	return (ll)jc[n]*jc2[k]%mod*jc2[n-k]%mod;
}
inline void reduce(int&x){x+=x>>31&mod;}
int a,b,c,ans;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>a>>b>>c;Init();
	for(int i=0,res=1;i<=b+c;++i){
		ans=(ans+(ll)pw3[b+c-i]*C(a+i-1,i)%mod*res)%mod;
		reduce(res=(res*2-C(i,b)-C(i,c))%mod);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 12544
import java.util.*;

class Main{
    int N;
    long[] A;

    public Main(){
        long K;
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        K = scanner.nextLong();

        A = new long[N];
        for(int i=0;i<N;i++){
            A[i] = scanner.nextLong();
        }

        Arrays.sort(A);

        long L = -1000000000000000001L,
             R =  1000000000000000001L;
        while(R-L>1){
            long mid = L + (R-L)/2;

            if(K <= totalNum(mid))
                R = mid;
            else
                L = mid;
        }

        System.out.println(R);
    }

    long totalNum(long val){
        long result = 0;
        //A[i]*T <= N となるTの数を集計する
        for(int i=0;i<N;i++){
            //A[i]が0ならば掛け算は必ず0となる
            if(A[i] == 0){
                if(val >= 0) result += N-i-1;
                continue;
            }

            int L = i, R = N;
            if(A[i] > 0) {
                while(R-L > 1){
                    int mid = L + (R-L)/2;
                    if(val < A[i]*A[mid])
                        R = mid;
                    else
                        L = mid;
                }
                result += L-i;
            } else{
                while(R-L>1){
                    int mid = L + (R-L)/2;
                    if(val >= A[i]*A[mid])
                        R = mid;
                    else
                        L = mid;
                }
                result += N-R;
            }
        }

        return result;
    }

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }
}


Measured memory_bytes: 85812
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

int n,a,b,c;
string s[MAXN];
vector<char> v;

void solve()
{
	cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		// cout<<a<<" "<<b<<" "<<c<<endl;
		if(s[i]=="AB")
		{
			if(a==1 && b==1 && c==0)
			{
				if(i<n)
				{
					if(s[i+1]=="AB" || s[i+1]=="BC") 
					{
						v.pb('B');
						a--;b++;
					}
					else if(s[i+1]=="AC")
					{
						v.pb('A');
						a++;b--;
					}
				}
				else v.pb('A');
			}
			else if(a==0 && b==0)
			{
				cout<<"No"<<endl;
				return;
			}
			else
			{
				if(a>=b)
				{
					v.pb('B');
					a--;b++;
				}
				else
				{
					v.pb('A');
					a++;b--;
				}
			}
		}
		else if(s[i]=="AC")
		{
			if(a==1 && b==0 && c==1)
			{
				if(i<n)
				{
					if(s[i+1]=="AC" || s[i+1]=="BC") 
					{
						v.pb('C');
						a--;c++;
					}
					else if(s[i+1]=="AB")
					{
						v.pb('A');
						a++;c--;
					}
				}
				else v.pb('A');
			}
			else if(a==0 && c==0)
			{
				cout<<"No"<<endl;
				return;
			}
			else
			{
				if(a>=c)
				{
					v.pb('C');	
					a--;c++;
				}
				else
				{
					v.pb('A');
					a++;c--;
				}
			}
		}
		else if(s[i]=="BC")
		{
			if(a==0 && b==1 && c==1)
			{
				if(i<n)
				{
					if(s[i+1]=="BC" || s[i+1]=="AB") 
					{
						v.pb('B');
						c--;b++;
					}
					else if(s[i+1]=="AC")
					{
						v.pb('C');
						c++;b--;
					}
				}
				else v.pb('C');
			}
			else if(c==0 && b==0)
			{
				cout<<"No"<<endl;
				return;
			}
			else
			{
				if(c>=b)
				{
					v.pb('B');
					c--;b++;
				}
				else
				{
					v.pb('C');
					c++;b--;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<v.size();i++) cout<<v[i]<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
}


Measured memory_bytes: 6924
#include <iostream>
#include<cmath>
using namespace std;
int main(){
int a,b,x,y=0;
cin>>a>>b;
x=a%b;
while(x>=0){
		if(x==0){
		
			cout<<false;
			break;
			}
		else if(x>0)  {
			if(x%b==x)
			y=1+a/b;
			cout<<abs(y-a/b);
			break;
			
				
		
		
			
		}		
				
			
		}
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        String hoge = sc.next();
        if(hoge.equals("SAT")){
            System.out.println(1);
        }else if(hoge.equals("SUN")){
            System.out.println(7);
        }else if(hoge.equals("MON")){
            System.out.println(6);
        }else if(hoge.equals("TUE")){
            System.out.println(5);
        }else if(hoge.equals("WED")){
            System.out.println(4);
        }else if(hoge.equals("THU")){
            System.out.println(3);
        }else if(hoge.equals("FRI")){
            System.out.println(2);
        }
    }     
}

Measured memory_bytes: 19796
n=int(input())
al=[]
info=[]
for i in range(n):
    a=int(input())
    al.append(a)
    temp=[]
    for j in range(a):
        x,y=map(int,input().split())
        temp.append([x,y])
    info.append(temp)

ans=0

for i in range(2**n):
    n_honest=0
    dic={}
    flag=True
    for j in range(n):
        if ((i >> j) & 1):
            n_honest+=1
            dic[j]=1
        else:
            dic[j]=0
    for j in range(n):
        if ((i >> j) & 1):
            temp=info[j]
            a=al[j]
            for k in range(a):
                l=temp[k]
                x=l[0]
                y=l[1]
                if dic[x-1]!=y:
                    flag=False
                    break
        if not flag:
            break
    if flag:
        ans=max(n_honest,ans)
print(ans)



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

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

using namespace std;

typedef long long ll;

const int MAX_N=2e5;

int N;

ll A[MAX_N],sum[1+MAX_N];

int main(){
	cin>>N;
	sum[0]=0;
	REP(i,N){
		cin>>A[i];
		sum[i+1]=sum[i]+A[i];
	}
	map<ll,int> mp;
	mp[0]=1;
	ll ans=0;
	REP(i,N){
		ans+=mp[sum[i+1]];
		mp[sum[i+1]]++;
	}
	cout<<ans<<endl;
	return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CPrison solver = new CPrison();
        solver.solve(1, in, out);
        out.close();
    }

    static class CPrison {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int max = -1;
            int min = 1000000;
            for (int i = 0; i < m; i++) {
                max = Math.max(max, in.nextInt());
                min = Math.min(min, in.nextInt());
            }
            long ans = min - max + 1;
            out.println(ans > 0 ? ans : 0);
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 40512
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define tam 500001
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define CLASSNAME WarmupWithTwins
#define FUNCNAME determineTwinsAge
using namespace std;

typedef long long       ll;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii> vii;
typedef long double lldb;
bool nop[tam];
bool entra(int num)
{
    while(num>0)
    {
        if (nop[num%10]==1)return 0;
        num/=10;
    }
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k,val;
    cin>>n>>k;
    forr(i,0,k){
        cin>>val;
        nop[val]=1;
    }
    forr(i,n,2e9)
    {
        if (entra(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c \""
  "a=range(1,8**5*int(input())+1,8**5);*b,=a[::-1];print(*a)\n"
  "for t,i in enumerate(input().split()):b[int(i)-1]+=t\n"
  "print(*b)\"";
  system(s);
  return 0;
}

Measured memory_bytes: 7532
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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 all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi a;

int main()
{
    cin >> n;
    a.resize(n); rep(i, n) cin >> a[i];
    sort(all(a), greater<int>());
    int alice = 0, bob = 0;
    rep(i, n){
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    if buf
        .chars()
        .enumerate()
        .all(|(i, c)| i % 2 == 1 && c != 'R' || i % 2 == 0 && c != 'L')
    {
        println!("Yes");
    } else {
        println!("No");
    };
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define MP make_pair
#define mod 1000000007

int main(){
    int x,y;
    cin>>x>>y;
    if(4*x<y){
        cout<<"No";
        return 0;
    }
    if(2*x>y){
        cout<<"No";
        return 0;
    }
    if(y%2){
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2592
s = gets.chomp
ans = 0
case s
when "SUN" then
  ans = 7
when "MON" then
  ans = 6
when "TUE" then
  ans = 5
when "WED" then
  ans = 4
when "THU" then
  ans = 3
when "FRI" then
  ans = 2
when "SAT" then
  ans = 1
end
puts "#{ans}"


Measured memory_bytes: 1788
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

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


int n,s;
int ans=0;


int solve(int c,int d,int s){
	if(c==n){
		if(s<=9&&s>=d){
			ans++;
		}
	}
	else{
		for(int i=d;i<10;i++){
			solve(c+1,i+1,s-i);
		}
	}
	return ans;
}
	
	

int main(){
	while(cin>>n>>s,n||s){
		//if(s>45) cout<<"0"<<endl;
		ans = 0;
		cout << solve(1,0,s) <<endl;
	}
	return 0;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< T > from(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      from[e.to] = idx;
      que.emplace(dist[e.to], e.to);
    }
  }
  return from;
}

int main() {
    int n, m;
    cin >> n >> m;
    WeightedGraph<int> G(n);

    rep (i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);
    }
    auto from = dijkstra(G, 0);
    cout << "Yes" << endl;
    rep(i, 1, n) {
        cout << from[i] + 1 << endl;
    }
}

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

int main()
{
	int n;
	double t,x;
	cin >> n >> t >> x;
	double a[n+1];
	double minn=10000;
	int mina;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		a[i]=t-a[i]*0.006;
		double xx=abs(a[i]-x);
		if(xx<minn)
		{
		   minn=xx;
		   mina=i;
		}   
	}
	cout << mina << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}

#[allow(unused_imports)]
use std::io::{stdout, Write};
fn main() {
    let strin: String = read();
    let v: Vec<i32> = strin.chars().map(|x| x.to_digit(10).unwrap() as i32).collect();
    let vv = v.clone();
    let v0: Vec<i32> = v.into_iter().filter(|x| *x == 0).collect();
    let v1: Vec<i32> = vv.into_iter().filter(|x| *x == 1).collect();
    println!("{}", if v0.len() > v1.len() {v1.len() * 2} else {v0.len() * 2});
}


Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
count=a[0]
if a.count(0)>0:
  print(0)
else:
  for i in range(1,n):
    count*=a[i]
    if count>(10**18):
      print(-1)
      break
  else:
    print(count)

Measured memory_bytes: 21776
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <climits>
#include <iomanip>

using namespace std;

const int N = 2e6 + 9;
const int INF = 2e9 + 2;
const int mod = 1e9 + 7;
const int K = 25;
const int P = 51;
const long long LONG_INF = LONG_MAX;
const int SZ = (1 << 18) - 1;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define mkp make_pair
#define all(s) s.begin(), s.end()

#define ll long long

#define int ll

int a[N], p[N];

void solve() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i];
		p[a[i]]++;
		sum += p[a[i]] - 1;
	}
	for (int i = 1; i <= n; ++ i) {
		sum -= p[a[i]] - 1;
		cout << sum << '\n';
		sum += p[a[i]] - 1;
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 7296
import sys
from collections import deque

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    A.sort()
    d = deque(A)
    min_A = d.popleft()
    max_A = d.pop()
    ans = max_A - min_A
    v1 = min_A
    v2 = max_A
    while d:
        if len(d) == 1:
            v = d.pop()
            ans += max(abs(v1 - v), abs(v2 - v))
        else:
            v_min = d[0]
            v_max = d[-1]
            diff = 0
            is_popleft = None
            if diff < abs(v1 - v_min):
                diff = abs(v1 - v_min)
                next_v1 = v_min
                next_v2 = v2
                is_popleft = True
            if diff < abs(v2 - v_min):
                diff = abs(v2 - v_min)
                next_v1 = v_min
                next_v2 = v1
                is_popleft = True
            if diff < abs(v1 - v_max):
                diff = abs(v1 - v_max)
                next_v1 = v_max
                next_v2 = v2
                is_popleft = False
            if diff < abs(v2 - v_max):
                diff = abs(v2 - v_max)
                next_v1 = v_max
                next_v2 = v1
                is_popleft = False
            if is_popleft is None:
                next_v1 = v_min
                next_v2 = v2
                is_popleft = True
            ans += diff
            v1, v2 = next_v1, next_v2
            if is_popleft:
                d.popleft()
            else:
                d.pop()

    print(ans)


if __name__ == "__main__":
    main()


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

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

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

// typedef long long ll;
#define int long long
#define double long double

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

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int N; cin >> N;
  int origN = N;
  INTV prime;
  for(int i = 2; i*i <= N; i++){
    if(N % i == 0){
      prime.eb(i);
      while(N % i == 0) N /= i;
    }
  }
  if(N != 1) prime.eb(N);
  int siz = prime.size();
  int ans = 0;
  for(int bit = 1; bit < (1<<siz); bit++){
    int popcnt = __builtin_popcount(bit);
    int mul = 1;
    REP(i, siz){
      if((bit >> i) & 1) mul *= prime[i];
    }
    if(popcnt & 1) ans += origN / mul;
    else ans -= origN / mul;
  }
  ans = origN - ans;
  cout << ans << endl;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	vector<int32> v({1, 4, 7, 9});
	vector<int32> v2(4);
	REP(i, 4) cin >> v2[i];
	sort(all(v2));
	cout << (v == v2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

      for (int i = 0; i < M; i++) {
        l = Math.max(l, sc.nextInt());
        r = Math.min(r, sc.nextInt());
      }

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, K;
    cin >> N >> K;

    ll res = 0;
    for(int b=K+1;b<=N;b++){
    	res += (N/b)*(b-K);
    	ll r = N%b;
    	if(r>=K){
    		if(K>0) res += (r-K+1);
    		else res += (r-K);
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
int a[110];
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <n; i++)
    {
        scanf("%d", &a[i]);
    }
    set<int> ans(a, a+n);
    cout << ans.size() << endl;
}


Measured memory_bytes: 256
N = list(map(int,input().split()))
ans = 0
if N [0] < 0 and N[1] > 0:
    ans = "Zero"
elif N[0] < 0:
    if (N[1] - N [0]) % 2 == 0:
        ans = "Negative"
    else:
        ans = "Positive"
elif N[0] > 0:
    ans = "Positive"
else:
    ans = "Zero"

print(ans)


Measured memory_bytes: 38256