akhauriyash/Code-Regression huggingface dataset:
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

n, as = ili()

max = as.max
max_index = as.index{|a| a == max}
min = as.min
min_index = as.index{|a| a == min}


if min >= 0
  puts n-1
  (n-1).times{|i|
    puts (i+1).to_s + " "+ (i+2).to_s
  }
elsif max <= 0
  puts n-1
  (n-1).times{|i|
    puts (n-i).to_s + " " +(n-i-1).to_s
  }
else
  res = []
  if max.abs >= min.abs
    n.times{|i|
      if as[i] < 0
        res << [max_index+1, i+1]
      end
    }
    puts n-1+res.length
    res.each{|r|
      puts r.join(" ")
    }
    (n-1).times{|i|
      puts (i+1).to_s + " "+ (i+2).to_s
    }
  else
    n.times{|i|
      if as[i] > 0
        res << [min_index+1, i+1]
      end
    }
    puts n-1+res.length
    res.each{|r|
      puts r.join(" ")
    }
    (n-1).times{|i|
      puts (n-i).to_s + " "+ (n-i-1).to_s
    }
  end
end


Measured memory_bytes: 1788
# 当初理解が及ばずできなかったが、後日リベンジできた！
# B問題とは思えない！

def dis(d, x, y): #d次元、2点間の距離の関数
    a = 0
    for i in range(d):
        a += (x[i] - y[i])**2
    return a**0.5
    
n, d = map(int,input().split())

l = [] # n個の座標を2次元リストで取得
for j in range(n):
    l.append(input().split())
 
c=[]
for j in l:
    b=[]
    for k in j:
        b.append(int(k))
    c.append(b)

z = []
for e in range(n):
    for f in range(e,n): #重複（逆の組み合わせ）無し
        g = dis(d, c[e], c[f]) #各座標間の距離を関数で取得
        if g == int(g) and g != 0: #距離が整数かつゼロでないか確認
            z.append(g) # 上の条件をpassした値をリスト'z'へappend
            
print(len(z))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var k = Integer.parseInt(br.readLine());
      final var ab = Arrays.stream(br.readLine().split(" "))
        .mapToInt(Integer::parseInt)
        .toArray();

      final var cand = (ab[0] / k) * k;
      if (cand >= ab[0] && cand <= ab[1]) {
        System.out.println("OK");
      } else if (cand + k >= ab[0] && cand + k <= ab[1]) {
        System.out.println("OK");
      } else {
        System.out.println("NG");
      }
    }
  }
}


Measured memory_bytes: 34296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);


	string s;
	cin >> s;

	int cnt = 0;
	s += "?";

	for(int i = 0; i + 1 < s.size(); i++)
		if(s[i] != s[i + 1])
			cnt++;
	
	cout << cnt - 1 << endl;

	return 0;
}


Measured memory_bytes: 3752
# ABC136 C-City Savers
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0

for i in range(N):
    if B[i] < A[i]:
        ans += B[i]
    elif A[i] <= B[i] <= A[i] + A[i+1]:
        ans += B[i]
        A[i+1] -= (B[i] - A[i])
    elif A[i] + A[i+1] <B[i]:
        ans += A[i] + A[i+1]
        A[i+1] = 0
print(ans)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s,t;
    cin >> s >> t;
    int ans = 10000;

    for(int i = 0; i + t.size() <= s.size(); i++){
        int cnt = 0;
        rep(j,t.size()){
            if (t.at(j) != s.at(j+i))cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9+9;



int main()
{
    int n,i;
    cin>>n>>i;
    cout<<(n+1)-i<<endl;


    return 0;
}
    // gotcha;


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n;
    int ans;
    int maxv = -1;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        int div = i;
        while (div % 2 == 0 && div != 0) {
            cnt++;
            div /= 2;
        }

        if (maxv < cnt) {
            maxv = cnt;
            ans = i;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, read().split())
print(min(a, k) if a + b >= k else 2 * a + b - k)


Measured memory_bytes: 9168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void){
  int w,h;
  scanf("%d %d",&w,&h);
  int a[w],b[h],c[h];
  FOR(w)scanf("%d",&a[i]);
  FOR(h)scanf("%d",&b[i]);
  qsort(a,w,sizeof(int),d);
  qsort(b,h,sizeof(int),d);
  FOR(h)c[i]=b[i];
  FOR(w){
    FORJ(a[i]){
      if(!b[j]){
        PRN(0);
        return 0;
      }
      b[j]--;
    }
    qsort(b,h,sizeof(int),d);
  }
  FOR(h){
    FORJ(c[i]){
      if(!a[j]){
        PRN(0);
        return 0;
      }
      a[j]--;
    }
    qsort(a,w,sizeof(int),d);
  }
  PRN(1);
  return 0;
}



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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  // MARCHから始まる人の数をmapでカウントする（それぞれをmarchとする）
  // 種類が2種類未満だったら０を返す
  // ３種類のうち二つを選んで、カウントを掛け合わせたものの和
  int N;cin>>N;
  set<char> march{'M','A','R','C','H'};
  map<char,ll> mp;
  REP(i,N) {
    string s;cin>>s;
    if (march.find(s[0]) != march.end()) mp[s[0]]++;
  }
  ll mp_size = mp.size();
  if (mp_size<=2) {
    OUT(0);
    return 0;
  }

  ll ans = 0;
  vector<char> keys;
  for (auto x:mp) keys.push_back(x.first);

  for (int i=0;i+2<mp_size;i++) {
    for (int j=i+1;j+1<mp_size;j++) {
      for (int k=j+1;k<mp_size;k++) {
        ans += mp[keys[i]]*mp[keys[j]]*mp[keys[k]];
      }
    }
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

const double eps = 1e-1;
void solve()
{
    ll a;
    double b;
    scanf("%lld%lf", &a, &b);
    ll bb = (ll)(b * 100 + eps);
    ll c = a * bb;
    printf("%lld\n", c/100);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1752
H, W, N = map(int, raw_input().split())
lst = {}
for i in range(N):
  a, b = map(int, raw_input().split())
  for x in range(-2, 1):
    if x + a < 1 or H - 2 < x + a:
      continue
    for y in range(-2, 1):
      if y + b < 1 or W - 2 < y + b:
        continue
      xkey = x + a
      ykey = y + b
      if xkey not in lst:
        lst[xkey] = {}
      lst2 = lst[xkey]
      if ykey not in lst2:
        lst[xkey][ykey] = 1
      else:
        lst[xkey][ykey] += 1

answer = [0 for i in range(10)]
count = 0
for l1 in lst.values():
  for l2 in l1.values():
    answer[l2] += 1
    count += 1
answer[0] = (H-2) * (W-2) - count

for i in range(10):
  print answer[i]

Measured memory_bytes: 134180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath> 
using namespace std;

const int MAX_N = 1000;
const int INF = 1e+8;

struct Point{
	int x, y;
	Point(int x_, int y_){
		x = x_; y = y_;
	}
	Point(){}
};

int H, W, sy, sx, gy, gx, cnt[5];
Point P[5][MAX_N];

int dist(int x1, int y1, int x2, int y2){
	return abs(x1-x2) + abs(y1-y2);
}  

pair<int,int> solve(){
	int t;
	pair<int,int> result;
	result.second = INF;
	
	int dp[5][MAX_N];
	for(int s=0 ; s < 5 ; s++ ){  
		for(int i=0 ; i < 5 ; i++ ){
			for(int j=0 ; j < cnt[i] ; j++ ){
				dp[i][j] = INF;
			}
		}
		t = (s+1) % 5;
		for(int j=0 ; j < cnt[t] ; j++ ){
			dp[t][j] = dist(sx, sy, P[t][j].x, P[t][j].y );
		}
		for(int i = s+1 ; i < s + 5 ; i++ ){  
			int b = i % 5;
			int e = (i+1) % 5;
			for(int k=0 ; k < cnt[b] ; k++ ){
				for(int l=0 ; l < cnt[e] ; l++ ){
					int d = dist(P[b][k].x, P[b][k].y, P[e][l].x, P[e][l].y);
					dp[e][l] = min( dp[e][l] , dp[b][k] + d );
				}
			}
		}
		t = (s+4) % 5;
		for(int j=0 ; j < cnt[t] ; j++ ){
			int d = dist(gx, gy, P[t][j].x, P[t][j].y );
			if( dp[t][j] + d < result.second ){
				result.second = dp[t][j] + d;
				result.first = s;
			}
		}
	}
	return result; 
}

int main(){
	while( cin >> W >> H , W || H ){
		for(int i=0 ; i < 5 ; i++ ){
			cnt[i] = 0;
		}
		for(int y=0 ; y < H ; y++ ){
			for(int x=0 ; x < W ; x++ ){
				char ch;
				cin >> ch;
				if( ch == '.' ) continue;
				
				if( ch == 'S' ){
					sy = y; sx = x;  
				}else if( ch == 'G' ){
					gy = y; gx = x;
				}else{
					int k = ch -'0' - 1;
					P[k][ cnt[k] ] = Point(x,y);
					cnt[k]++;
				}
			}
		}
		pair<int,int> ans = solve();
		if( ans.second == INF ){
			cout << "NA" << endl;
		}else{
			cout << ans.first+1 << " " << ans.second << endl;
		}
	}  
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define MAX 20000005
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

ll vis[MAX], cycle[MAX];
map<ll, ll>ttime;
map<ll, ll>inverstime;

void solve(){
	ll n, k;
	cin >> n >> k;
	
	ll v[n+1];
	
	for(int i=1; i<=n; i++) cin >> v[i];
	
	ll j=1, t=0;
	while(vis[j] == 0){
		ttime[t] = j;
		inverstime[j] = t;
		vis[j] = 1;
		j = v[j];
		t++;
	}	
	
	if(k < t){
		cout << ttime[k] << endl;
		return;		
	}
	
	ll init = j, d = t-inverstime[j];
	cycle[0] = init;
	j = v[init];
	
	for(int i=1;;i++){
		if(j == init) break;
		cycle[i] = j;
		j = v[j];
	}
	
	k -= inverstime[init];
		
	cout << cycle[k%d] << endl;
}

int main(){

	fastcin
	solve();      
	return 0;
}

Measured memory_bytes: 31396
#include <iostream>

using namespace std;

static const int MAX=100;

void push (int x);
int pop (void);

int stack[MAX] = {0};
int n = 0;

int main () {
	int v, op1, op2;
	string op;

        while (cin >> op) {
		switch ( *(op.c_str()) ) {
		case '+':
			op2 = pop();
			op1 = pop();
			push(op1 + op2);
			break;
		case '-':
			op2 = pop();
			op1 = pop();
			push(op1 - op2);
			break;
		case '*':
			op2 = pop();
			op1 = pop();
			push(op1 * op2);
			break;
		// case ' ':
		// 	break;
		default:
			push( stoi(op) );
			break;
		}
	}
	v = pop();

	cout << v << endl;

	return 0;
}

void push (int x) {
	int i;

	for (i = n - 1; i >= 0; i--)
		stack[i + 1] = stack[i];
	stack[0] = x;
	n++;
}

int pop (void) {
	int i, x;

	x = stack[0];
	for (i = 0; i < n; i++)
		stack[i] = stack[i + 1];
	n--;

	return x;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        a *= -1;
        ++mp[a];
    }
    
    int len1 = 0, len2 = 0;
    for(auto it : mp){
        if(it.second == 1)  continue;
        if(len1 == 0){
            len1 = it.first;
            if(it.second >= 4){
                len2 = it.first;
                break;
            }
        }
        else if(len2 == 0){
            len2 = it.first;
            break;
        }
    }
    cout << (ll)len1 * len2 << "\n";
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 1000100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int dp[110][110];
char m[110][110];
int32_t main(){
	fastio;
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>m[i][j];
		}
	}

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i==1 && j==1){
					dp[1][1] = (m[1][1]=='#' ? 1 : 0);
					continue;
			}
			if(i==1){
				dp[i][j] = (dp[i][j-1]);
				if(m[i][j]=='#' && m[i][j-1]=='.')dp[i][j]++;
			}else if(j==1){
				dp[i][j] = dp[i-1][j];
				if(m[i][j]=='#' && m[i-1][j]=='.')dp[i][j]++;
			}else{
				dp[i][j] = (dp[i][j-1]);
				if(m[i][j]=='#' && m[i][j-1]=='.')dp[i][j]++;
				int op2 = dp[i-1][j];
				if(m[i][j]=='#' && m[i-1][j]=='.')op2++;
				dp[i][j] = min(dp[i][j],op2);	
			}
			
		}
	}
	cout<<dp[h][w]<<endl;
	
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var xs = Console.ReadLine().Split()
            .Select(x => long.Parse(x))
            .ToArray();

        var adjust = new long[2];
        var sum = new long[2];
        var sign = new[] { Math.Sign(1), Math.Sign(-1) };
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < 2; ++j)
            {
                var t = sum[j] + xs[i];
                var k = t * sign[j];
                if (k >= 0)
                {
                    adjust[j] += k + 1;
                    sum[j] = -1 * sign[j];
                }
                else
                {
                    sum[j] = t;
                }
                sign[j] = Math.Sign(sum[j]);
            }
        }
        
        Console.WriteLine(adjust.Min());
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    vector<vi> cnt(3,vi(n+1));
    rep(i,n) cnt[0][i+1]=cnt[0][i]+(s[i]=='R');
    rep(i,n) cnt[1][i+1]=cnt[1][i]+(s[i]=='G');
    rep(i,n) cnt[2][i+1]=cnt[2][i]+(s[i]=='B');
    ll ans=0;
    char text[] = {'R','G','B'};
    rep(i,n){
        rep(j,i){
            if (s[i]==s[j]) continue;
            int c=3;
            if (s[i]=='G') c-=1;
            if (s[i]=='B') c-=2;
            if (s[j]=='G') c-=1;
            if (s[j]=='B') c-=2;
            ans+=cnt[c][n]-cnt[c][i+1];
            if (s[2*i-j]==text[c]) ans--;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005;
const ll INF=1LL<<60;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    ll A,B;cin>>A>>B;
    ll ans=INF;
    
    if(A>B) swap(A,B);
    
    if((B-A)%2==0){
        ans=min(ans,(B-A)/2);
        ll a=A,b=B;
        
        ll left=A-1;
        a-=left;
        b-=left;
        
        left+=(b-a)/2;
        ans=min(ans,left);
        
        a=A;
        b=B;
        
        ll right=N-b;
        
        a+=right;
        b+=right;
        
        right+=(b-a)/2;
        ans=min(ans,right);
    }else{
        ll a=A,b=B;
        
        ll left=A-1;
        a-=left;
        b-=left;
        
        left++;
        b--;
        
        left+=(b-a)/2;
        ans=min(ans,left);
        
        a=A;
        b=B;
        
        ll right=N-b;
        
        a+=right;
        b+=right;
        
        right++;
        a++;
        
        right+=(b-a)/2;
        ans=min(ans,right);
    }
    
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

// s = "112223" -> [[1,2],[2,3],[3,1]]
vector<pair<int,int>> rle (vector<int> x) {
  vector<pair<int,int>> res;
  int n = (int)x.size();
  for (int i = 0; i < n;) {
    int j = i;
    int cnt = 0;
    while (j < n && x[j] == x[i]) {
      ++j;
      ++cnt;
    }
    //res.emplace_back(x[i], cnt);
    res.emplace_back(cnt, x[i]);
    i = j;
  }
  return res;
}

int main () {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.begin(), a.end());
  auto x = rle(a);
  sort(x.begin(), x.end());
  //rep(i,x.size()) printf("%d %d\n", x[i].fi, x[i].se);
  int ans = 0;
  for (int i = 0; i < sz(x)-k; ++i) {
    ans += x[i].fi;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int n,a,b;
int main(){
  cin>>n>>a>>b;
  if (a>b) swap(a,b);
  if ((b-a)&1) puts("Borys");
  else puts("Alice");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int MOD = 998244353;
const int MX = (int)1e6 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

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

vector<int> read(int n, int k){
	vector<int> vec(n);
	for(int i = 0; i < k; ++i) cin >> vec[i];
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = k; i < n; ++i)
		vec[i] = (a * 1ll * vec[i - 2] + b * 1ll * vec[i - 1] + c) % d;
	return vec;
}

void solve(){
	int n, k;
	cin >> n >> k;
	vector<array<int, 2>> vec(k);
	for(auto &[x, y] : vec) cin >> x >> y;

	vector<int> dp(n + 1);
	dp[1] = 1;

	for(int i = 2; i <= n; ++i){
		for(auto [x, y] : vec){
			int mn = max(0, i - y - 1);
			int mx = max(0, i - x);
			add_self(dp[i], sub(dp[mx], dp[mn]));
		}
		add_self(dp[i], dp[i - 1]);
	}

	cout << sub(dp[n], dp[n - 1]) << "\n";
	
	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3984
import java.util.*;
import java.io.*;
public class Main{
  public static void main(String [] args) throws IOException{
	  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	  int n=Integer.parseInt(br.readLine().trim());
	  Map<String,Integer> map=new HashMap<>();
	  while(n-->0){
		  map.put(br.readLine().trim(),1);
	  }
	  System.out.println(map.size());
  }

}

Measured memory_bytes: 59048
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
yoyuu=0
husai=0
for i in range(n):
	if a[i]<yoyuu:
		yoyuu=b[i]
	else:
			
		if a[i]>(b[i]+yoyuu):
			husai+=a[i]-(b[i]+yoyuu)
			yoyuu=0
		else:
			yoyuu=(b[i]+yoyuu)-a[i]
if a[n]>yoyuu:
	husai+=a[n]-yoyuu
print(sum(a)-husai)



Measured memory_bytes: 18624
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    col = {"R": 0, "G": 1, "B": 2}
    B = [[0, 0, 0] for _ in range(N)]
    B[N-1][col[S[N-1]]] = 1
    for i in reversed(range(N-1)):
        for j in range(3): B[i][j] = B[i+1][j]
        B[i][col[S[i]]] += 1

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            if set((S[i], S[j])) == {"R", "G"}: 
                ans += B[j+1][2]
                if 2 * j - i < N and S[2 * j - i] == "B": ans -= 1
            elif set((S[i], S[j])) == {"B", "G"}: 
                ans += B[j+1][0]
                if 2 * j - i < N and S[2 * j - i] == "R": ans -= 1
            elif set((S[i], S[j])) == {"B", "R"}: 
                ans += B[j+1][1]
                if 2 * j - i < N and S[2 * j - i] == "G": ans -= 1
            
    print(ans)
            

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 75220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];   // 頂点間の辺の情報
int id[MAXN][MAXN];     // 試合のid=DAGの頂点番号

int toId(int i, int j) {    // 選手idから試合idを返す関数
	if (i > j) swap(i,j);   // i,jが逆になっても試合idは同じ
	return id[i][j];
}

bool visited[MAXV];     // 訪問済み
bool calculated[MAXV];  // 計算済み
int dp[MAXV]; // max length of path from v   Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

int dfs(int v) {
	if (visited[v]) {
		if (!calculated[v]) return -1;  // 計算が終わっていない頂点を2度訪れるのはループがあるということ
		return dp[v];
	}
	visited[v] = true;
	dp[v] = 1;
	for (int u : to[v]) {   // 全ての辺をなめる
		int res = dfs(u);
		if (res == -1) return -1;   // ループがあれば-1を返す
		dp[v] = max(dp[v], res+1);  // メモ化再帰っぽいこと(トポロジカルソートが同時にできる)
	}
	calculated[v] = true;
	return dp[v];
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n-1));
	rep(i,n) {
		rep(j,n-1) {
			cin >> a[i][j];
			a[i][j]--;  // 選手idを0始まりに変換
		}
	}
	int V = 0;
	rep(i,n)rep(j,n) {
		if (i < j) {
			id[i][j] = V++; // 0から順に各試合にidを割り振る
		}
	}
	rep(i,n) {
		rep(j,n-1) {
			a[i][j] = toId(i,a[i][j]);  // 選手idを試合id(頂点番号)に置き換える
		}
		rep(j,n-2) {    // 頂点間の依存関係はn-2個
			to[a[i][j+1]].push_back(a[i][j]);
		}
	}
	int ans = 0;
	rep(i,V) {
		int res = dfs(i);
		if (res == -1) {
			cout << -1 << endl;     // ループがあれば-1を返す（問題文の指示）
			return 0;
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 38528
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

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

    VI a(3); REP(i,3) cin >> a[i]; SORT(a);
    if(a[0]!=a[1]) out(a[0]);
    else out(a[2]);

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll MOD = 1e9+7;

ll amt[102][100100];
ll delt[102][100100];

int N, K;

inline void addDelt(int i, int j, ll d) {
	if(j <= K) {
		delt[i][j] = (delt[i][j]+MOD+d)%MOD;
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> K;
	vector<int> a(N);
	for(auto& x : a) cin >> x;
	amt[0][0] = 1;
	for(int i=0;i<N;++i) {
		ll b = 0;
		for(int j=0;j<=K;++j) {
			b = (b+delt[i][j])%MOD;
			amt[i][j] += b;
			addDelt(i+1, j, amt[i][j]);
			addDelt(i+1, j+a[i]+1, -amt[i][j]);
		}
	}
	ll b = 0;
	for(int i=0;i<=K;++i) {
		b = (b+delt[N][i])%MOD;
		amt[N][i] = b;
	}
	cout << amt[N][K] << endl;
    return 0;
}


Measured memory_bytes: 158208
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		char[] a = line.toCharArray();

		for (int i = 0; i < a.length; i += 2) {
			System.out.print(a[i]);
		}
		System.out.println("");
	}
}


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

int main(){
	int n;
    cin>>n;
    int a[n],b[n],c[n],dp[3][n];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(int i=1;i<n;i++){
    	dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
    }
    int ans=max(dp[0][n-1],dp[1][n-1]);
  	ans=max(ans,dp[2][n-1]);
  	cout<<ans;
    return 0;
}


Measured memory_bytes: 5900
from collections import defaultdict
def primefactor(x):
    fac=defaultdict(int)
    for i in xrange(2,int(x**0.5)+1):
        while x%i==0:
            fac[i]+=1
            x=x/i
    if x!=1:
        fac[x]+=1
    return fac

n=int(raw_input())
mod=10**9+7
ans=1
cnt=defaultdict(int)
for i in xrange(1,n+1):
    tmp=primefactor(i)
    for j,k in tmp.items():
        cnt[j]+=k
for i,j in cnt.items():
    ans=ans*(j+1)%mod
print(ans%mod)


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//---------------------------------------------------------------------------------------------------
ll MOD = 1000000007;
ll f[201010], rf[201010];
ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    for(int i = 1; i < 201010; i++) f[i] = (f[i - 1] * i) % MOD;
    for(int i = 0; i < 201010; i++) rf[i] = inv(f[i]);
}
ll C(int n, int k) {
    if(n < k) return 0;
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % MOD;

    return (a * bc) % MOD;
}
//---------------------------------------------------------------------------------------------------
ll add(ll &a, ll b)
{
    a = (a+b) % MOD;
}
int main()
{
    init();
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> p(n+1);
    p[0] = 0, p[1] = 1;
    for(int i = 2; i <= n; i++)
    {
        p[i] = p[i-1] + inv(i);
        add(p[i], MOD);
    }
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        ll v = p[i+1] + p[n-i] - 1;
        add(v, MOD);
        v = (v * a[i]) % MOD;
        add(ans, v);
    }
    for(int i = 2; i <= n; i++)
    {
        ans = ans * i % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
num = gets.split.map(&:to_f)
W = num[0]
H = num[1]
x = num[2]
y = num[3]

if x == W / 2 && y == H / 2
    print (W * H / 2).to_f
    puts " 1"
else
    print (W * H / 2).to_f
    puts " 0"
end


Measured memory_bytes: 1916
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := Scan(), Scan(), Scan()
	t := 0
	x, y, z := 0, 0, 0
	for {
		p := ""
		if t == 0 {
			if x == len(a) {
				fmt.Println("A")
				break
			}
			p = string(a[x])
			x++
		} else if t == 1 {
			if y == len(b) {
				fmt.Println("B")
				break
			}
			p = string(b[y])
			y++
		} else {
			if z == len(c) {
				fmt.Println("C")
				break
			}
			p = string(c[z])
			z++
		}
		if p == "a" {
			t = 0
		} else if p == "b" {
			t = 1
		} else {
			t = 2
		}
	}
}


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

bool solve() {
  int N; cin >> N;
  map<int, int> ma;
  rep(i, 0, N) {
    int d; cin >> d;
    ma[d]++;
  }
  int M; cin >> M;
  rep(i, 0, M) {
    int t; cin >> t;
    if(ma[t] == 0) return false;
    ma[t]--;
  }
  return true;
}

int main() {
  cout << (solve() ? "YES" : "NO") << endl;
  return 0;
}


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

C=[]
S=[]
F=[]
for i in range(N-1):
    c,s,f=map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

def func(n):
    t=0
    for i in range(n,N-1):
        if t < S[i]:
            t = S[i]
        else:
            if t%F[i]!=0:
                t += F[i] - (t % F[i])
        t += C[i]
    return t

for i in range(N):
    print(func(i))


Measured memory_bytes: 3064
def init(n)
  n.times do |i|
    Parent[i] = i
    Size[i] = 1
  end
end

def find(x)
  if Parent[x] == x
    return x
  else
    return Parent[x] = find(Parent[x])
  end
end

def unite(x,y)
  x,y = find(x),find(y)
  return if x==y

  x,y = y,x if Size[x] < Size[y]
  Size[x] += Size[y]  
  Parent[y] = x
end

n,m = gets.split.map(&:to_i)
edge = []
m.times do
  edge << gets.split.map(&:to_i)
end

Parent,Size = [],[]
init(n+1)

ans = [n*(n-1)/2]
edge.reverse.each do |arr|
  a,b = arr
  pa,pb = find(a),find(b)
  if pa == pb
    ans.unshift(ans[0])
  else
    ans.unshift(ans[0]-Size[pa]*Size[pb])
    unite(a,b)
  end
end
1.upto(ans.length-1) do |i|
  p ans[i]
end


Measured memory_bytes: 19168
#include <iostream>
#include <queue>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int N,M;
    cin>>N;cin>>M;
    long A[N];
    priority_queue<int> pque;
    for(int i=0;i<N;i++){
        long num;
        cin>>num;
        pque.push(num);
    }
    for(int i=0;i<M;i++){
        long num = pque.top()/2;
        pque.pop();
        pque.push(num);
    }
    long ans=0;
    for(int i=0;i<N;i++){
        long num = pque.top();
        pque.pop();
        ans = ans + num;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 892
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();

		List<Integer> towerList = new ArrayList();
		int gap = b-a;
		int height = 1;
		for(int i=2; i<1000; i++) {
			towerList.add(height);
			height = height + i;
		}

		System.out.println(towerList.get(gap-2)- a);
	}

}



Measured memory_bytes: 21972
#include <stdio.h>
#define N_max 100000

int main(int argc, char const *argv[]) {
  int N, K;
  int A[N_max];
  //入力
  scanf("%d%d", &N, &K);
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &A[i] );
  }
  //最小値の位置の計算
  /*
  int min_position = 0;
  int i = 0;
  while ( i < N ) {
    if ( A[i] == 1) {
      break;
    }
    min_position ++;
  }
  */
  //計算
  int answer;
  if ( (N-1)%(K-1) == 0 ) { //操作回数の最小値
    answer = (N-1)/(K-1);
  } else {
    answer = (N-1)/(K-1) + 1;
  }
  /*
  int g;
  g = min_position/(K-1);
  */

  //出力
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 512
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M; cin >> N >> M;
    veci p(M);
    vector<vector<int>> S(M,vector<int>());
    REP(i,M) {
        int k; cin >> k;
        REP(j,k) {
            int s; cin >> s;
            S.at(i).push_back(s-1);
        }
    }
    REP(i,M) cin >> p.at(i); 
    int ans = 0;   
    for(int bit = 0; bit < (1<<N); bit++) {
        bool ok = true;
        for(int i = 0; i < M; i++) {
            int cnt = 0;
            for(int j = 0; j < S.at(i).size(); j++) {
                if(bit & (1<<S.at(i).at(j))) cnt++;
            }
            if(cnt%2 != p.at(i)) {
                ok = false;
                break;
            } 
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a, b, c;
int main() {
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
}


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


/// this question translates into finding a binary tree whose leaves are the n slimes, and the sum of all internal nodes is minimum

const int nax = 405;
ll dp[nax][nax];
/// dp[i][j] = min cost of combining interval a[i...j]

void min_self(ll &a, ll b){
    a = min(a, b);
}

const ll inf = 1e18L + 5;

void solve(){
    int n;
    cin>>n;
    vector<int> a(n);

    fr(i, n) {
        cin>>a[i];
    }

    /// inline function
    auto sum = [&](int L, int R){
        ll s = 0;
        for(int i = L; i <= R; i++)
            s += a[i];
        return s;
    };

    for(int L = n - 1; L >= 0; L--){
        dp[L][L] = 0ll;
        for(int R = L + 1; R < n; R++){
            dp[L][R] = inf;
            ll s = sum(L, R);
            for(int K = L; K < R; K++){
                min_self(dp[L][R], dp[L][K] + dp[K+1][R] + s);
            }
        }
    }

    cout<<dp[0][n-1];
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

int main(){
    int L;
    string S;
    cin >> L >> S;
    int ans = 0;
    for(int i=0;i<L;i++){
        if(S[i]!='.') continue;
        string T = S;
        T[i] = 'W';
        bool ok = true;
        for(int j=0;j<L;j++){
            if(T[j]!='B') continue;
            bool white = false;
            bool semiok = true;
            for(int k=j+1;k<L;k++){
                if(T[k]=='W') white = true;
                if(T[k]=='.'){
                    white = false;
                    break;
                }
                if(T[k]=='B'){
                    if(white) semiok = false;
                    break;
                }
            }
            ok &= semiok;
        }
        if(!ok) continue;
//        cerr << i << "in" << endl;
        for(int j=0;j<L;j++){
            ok = false;
            if(T[j]!='W') continue;
            int cnt = 0;
            for(int k=j+1;k<L;k++){
                if(T[k]=='B') cnt++;
                if(T[k]=='.'){
                    break;
                }
                if(T[k]=='W'){
                    ok = true;
                    break;
                }
            }
            if(ok) ans = max(ans,cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

double n, m, d, ans;

int main() {
  cin >> n >> m >> d;
  if (d == 0) {
    ans = (m-1) / n;
  } else {
    ans = (m-1) * 2*(n-d) / n / n;
  }
  printf("%.10lf\n", ans);
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];

        int maxValue = 1;
        int secondMaxValue = 0;
        int cntMaxValue = 0;
        int currentValue;

        for(int i = 0; i < N; i++) {
            currentValue = int.Parse(Console.ReadLine());
            A[i] = currentValue;

            if(maxValue == currentValue) { 
                cntMaxValue++;
            } else if(maxValue < currentValue) {
                secondMaxValue = maxValue;
                maxValue = currentValue;
                cntMaxValue = 1;
            } else if(secondMaxValue < currentValue) {
                secondMaxValue = currentValue;
            }
        }

        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        
        for(int i = 0; i < N; i++) {
        
            if(cntMaxValue > 1) {
                Console.WriteLine(maxValue);
                continue;
            }
            
            if (A[i] == maxValue) {
                Console.WriteLine(secondMaxValue);
            }
            else {
                Console.WriteLine(maxValue);
            }

        }

        Console.Out.Flush();
    }
}

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

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





using ll = long long;

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




int n,k,c;
string s;
int premax[maxn];
set<int> valid[maxn];

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

    cin>>n>>k>>c;
    cin>>s;

    for (int i=0; i<n; i++) {
	if (s[i]=='x') {
	    if (i > 0) premax[i] = premax[i-1];
	} else {
	    premax[i] = (i-c-1>=0 ? 1+premax[i-c-1] : 1);
	}
    }

    if (*max_element(premax,premax+n) != k) {
	exit(0);
    }

    for (int i=n-1; i>=0; i--) {
	if (s[i] == 'o') {
	    int at = premax[i];
	    if (at==k) {
		valid[at].insert(i);
	    } else {
		if (!valid[at+1].empty() && *valid[at+1].rbegin() >= i+c+1) {
		    valid[at].insert(i);
		}
	    }
	}
    }

    // for (int i=1; i<=k; i++) {
    // 	watch(i);
    // 	for (int x: valid[i]) cout<<x+1<<" ";
    // 	cout<<endl;
    // }
    // cout<<endl;

    for (int i=1; i<=k; i++) {
	if ((int)valid[i].size() == 1) {
	    cout<<*valid[i].begin()+1<<"\n";
	}
    }

    
    return 0;
}


Measured memory_bytes: 60568
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val K = in.next().toLong
  val A = new Array[Int](N+1)
  for (i <- 1 to N)
    A(i) = in.next().toInt

  //
  val dp = Array.fill[Int](N+1)(-1)
  var now = A(1)
  var cnt = 0
  var vol = -1
  breakable {
    while (true) {
      if (dp(now) == -1) {
        cnt += 1
        dp(now) = cnt
        now = A(now)
      }
      else {
        vol = dp(now) - 1
        break
      }
    }
  }


  if (K < cnt) {
    val k = K
    for (i <- 1 to N) {
      if (dp(i) == k)
        println(i)
    }
  }
  else {
    val m = (cnt-vol)
    var k = (K-cnt) % m
    if (k == 0) k = m
    for (i <- 1 to N) {
      if (dp(i) - vol == k)
        println(i)
    }
  }

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 64980