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

int a, b;
int c[1000][1000];
bool d[1000][1000];//1 ?????£?????????
int dp[1000][1000][16];//1 ?????£???
int dx[4] = {-1,0,1,1}, dy[4] = {1,1,0,-1};
int ex[4]={-1,0,0,1},ey[4]={0,-1,1,0};
void decide(int x, int y, int z) {//z ????????§????????????
	if (d[x][y])z += c[x][y];
	bool t = true;
	for (int i = 0; i < 4; i++) {
		if (x + ex[i] >= 0 && x + ex[i] < a&&y + ey[i] >= 0 && y + ey[i] < b&&d[x + ex[i]][y + ey[i]]) {
			t = false;
			int o = z, bit = 0;
			int n[4], m[4], sum = 0;
			for (int j = 0; j < 4; j++) {
				if (i == j)continue;
				int xx = x + ex[j], yy = y + ey[j];
				if (xx >= 0 && xx < a&&yy >= 0 && yy < b&&d[xx][yy]) {
					o += c[xx][yy];
					d[xx][yy] = false;
					n[sum] = xx; m[sum] = yy;
					sum++;
				}
			}
			for (int j = 0; j < 4; j++) {
				int xx = x + dx[j], yy = y + dy[j];
				if (xx >= 0 && xx < a&&yy >= 0 && yy < b) {
					if (!d[xx][yy] && c[xx][yy]!=0) {
						bit |= (1<<j);
					}
				}
			}
			for (int j = 0; j < sum; j++) {
				d[n[j]][m[j]] = true;
			}
			dp[x][y][bit] = min(dp[x][y][bit], o);
		}
	}
	if (t) {
		int bit = 0;
		for (int j = 0; j < 4; j++) {
			int xx = x + dx[j], yy = y + dy[j];
			if (xx >= 0 && xx < a&&yy >= 0 && yy < b) {
				if (!d[xx][yy] && c[xx][yy]) {
					bit |= (1 << j);
				}
			}
		}
		dp[x][y][bit] = min(dp[x][y][bit], z);
	}
}
void kousin(int x,int y,int z) {
	for (int i = 0; i < 4; i++) {
		if (z&(1 << i)) {
			d[x + dx[i]][y + dy[i]] = false;
		}
	}
	bool S = false;
	if (c[x][y]) {
		d[x][y] = false;
		S = true;
	}
	if(x+1<a)decide(x + 1, y, dp[x][y][z]);
	if(y+1<b)decide(x, y+1, dp[x][y][z]);
	if (S) {
		d[x][y] = true;
	}
	for (int i = 0; i < 4; i++) {
		if (z&(1 << i)) {
			d[x + dx[i]][y + dy[i]] = true;
		}
	}
}
int main() {
	memset(dp, 0x3f, sizeof(dp));
	cin >> a >> b;
	for (int e = 0; e < a; e++) {
		string f; cin >> f;
		for (int g = 0; g < b; g++) {
			if (f[g] != '.') {
				c[e][g] = f[g] - '0';
				d[e][g] = true;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0; i < a + b - 2; i++) {
		for (int x = 0; x < a&&x<=i; x++) {
			int y = i - x;
			if (y < 0 || y >= b)continue;
			for (int z = 0; z < 16; z++) {
				if (dp[x][y][z] != 1061109567) {
					kousin(x, y, z);
				}
			}
		}
	}
	int MIN = 1<<29;
	for (int i = 0; i < 16; i++) {
		MIN = min(MIN, dp[a - 1][b - 1][i]);
	}
	cout << MIN << endl;
}

Measured memory_bytes: 70508
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int         nQuontity =     sc.nextInt()             ;
		int         lLength   =     sc.nextInt()             ;
		String []   sString   =     new String[nQuontity]    ;
		
		for ( int i = 0 ; i < nQuontity ; i++ ) {
			sString[i] =  sc.next()                          ;
		}
		Arrays.sort(sString);
		for ( String str : sString ) {
			System.out.print(str);
		}
		System.out.println();
	}
}

Measured memory_bytes: 10196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll N, x;
ll a[2020];
ll b[2020][2020];

int main(){

    cin >> N >> x;
    ll ans = 0;
    rep(i, N){
        cin >> a[i];
        ans += a[i];
    }
    rep(i, N){
        b[i][0] = a[i];
        rep(j, N)b[(i + j + 1) % N][j + 1] = b[(i + j) % N][j];
    }
    rep(i, N)rep(j, N)chmin(b[i][j + 1], b[i][j]);
    rep(i, N){
        ll sum = i * x;
        rep(j, N)sum += b[j][i];
        chmin(ans, sum);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 31872
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M-1) / 2 << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;


int main(void) {
  int a, b;
  scanf("%d%d", &a, &b);
  puts(a*b % 2 == 1 ? "Yes" : "No");
  return 0;
}



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

using namespace std;

void func_A() {

    string s, t;
    cin >> s >> t;

    string temp = t.substr(0, s.size());
    if (s == temp) cout << "Yes";
    else cout << "No";
}

void func_B() {

}

void func_C() {

}

int main() {

    func_A();
    //func_B();
    //func_C();

    return 0;

}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<29;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp(*(char **)a,*(char **)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp(*(char **)b,*(char **)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int n=in(),i,j;
    long long ans=0,a[100];
    rep(i,n)a[i]=llin();
    rep(i,n){
        rep(j,n){
            ans=max(ans,abs(a[i]-a[j]));
        }
    }
    llprint(ans);
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll A,B,ans;
  cin >> A>>B;
  if((B+A)%2==1){
    cout << "IMPOSSIBLE" << endl;
  }else{
    ans = (A+B)/2;
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int a,b;scanf("%d%d",&a,&b);
	int n;scanf("%d",&n);
	rep(i,n){
		int s,f;scanf("%d%d",&s,&f);
		if(!(b<=s||f<=a)){
			puts("1");
			return 0;
		}
	}
	puts("0");
}

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

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

  if((a+W) < b){
    cout << b-(a+W) << endl;
  }
  else if((b+W) < a){
    cout << a-(b+W) << endl;
  }
  else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long int  n;
    cin >> n;
    vector<int>adj[1000000];
    for(int i=2;i<=n;i++){
        int a;
        cin >>a;
        adj[i].push_back(a);
        adj[a].push_back(i);
    }
   for(int i=1;i<=n;i++){
       if(i==1)cout << adj[i].size() << endl;
       else cout << adj[i].size()-1 << endl;
   }
  return 0;

}


Measured memory_bytes: 33852
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX = 101;
int data[MAX];
int n;
int ans;
int wanted;

void solve(){
  int start = 0;
  int end = n-1;
  //sort(data,data+n);
  while(1){
    if(start > end) break;
    ans++;
    int now = (start+end)/2;
    //cout <<"now  "  <<now << endl;
    if(data[now] == wanted) break;
    if(data[now] > wanted) end = now-1;
    else start=now+1;
  }
}

int main(){
  while(cin >> n && n){
    ans = 0;
    for(int i = 0; i < n; i++) cin >> data[i];
    cin >> wanted;
    solve();
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[100002]={0}, arr[100002]={0};
vector<int> v[100002];
int solve(int i)
{
    //dp[i]=0;
    arr[i]=1;
    for(int j=0; j<v[i].size(); j++)
    {
        if(!arr[v[i][j]])
        {
            arr[i] = max(arr[i], solve(v[i][j]) + 1);
        }
        else
        {
            arr[i] = max(arr[i], arr[v[i][j]] + 1);
        }
    }
    return arr[i];
}
int32_t main()
{
        int n,m;
        cin>>n>>m;
        //int arr[n+1]={0};
        //vector<int> v[n];
        for(int i=0; i<m; i++)
        {
            int a,b;
            cin>>a>>b;
            if(a==b)
                continue;
            //arr[b]++;
            v[a].push_back(b);
        }
        //int dp[n]={0};
        for(int i=1; i<=n; i++)
        {
            if(!arr[i])
            {
                //cout<<i<<endl;
                solve(i);
            }
        } 
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            //cout<<arr[i]<<" ";
            ans=max(ans,arr[i]);
        }
        //cout<<endl;
        cout<<ans-1;
        return 0;
}

Measured memory_bytes: 8576
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
 
def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  return gcd(b, a % b)
 
def lcm(A, B):
  return (A // gcd(A, B)) * B
 
print(functools.reduce(lcm, T))

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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public int h { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = new List<P>();
        var ps0 = new List<P>();
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            var h = int.Parse(line[2]);
            if (h > 0) ps.Add(new P { x = x, y = y, h = h });
            else ps0.Add(new P { x = x, y = y, h = h });
        }
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++)
            {
                var t = ps[0].h + Math.Abs(ps[0].x - i) + Math.Abs(ps[0].y - j);
                if (check(ps, i, j, t) && check2(ps0, i, j, t))
                {
                    Console.WriteLine("{0} {1} {2}", i, j, t);
                    goto end;
                }
            }
        end:;
    }
    public static bool check2(List<P> ps, int cx, int cy, int t)
    {
        foreach (var x in ps)
            if (t > Math.Abs(x.x - cx) + Math.Abs(x.y - cy)) return false;
        return true;
    }
    public static bool check(List<P> ps, int cx, int cy, int t)
    {
        for (int i = 1; i < ps.Count(); i++)
        {
            var t2 = ps[i].h + Math.Abs(ps[i].x - cx) + Math.Abs(ps[i].y - cy);
            if (t != t2) return false;
        }
        return true;
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {

	bool ans = false;
	int c = 0;
	int cc = 0;
	rep(i, 3) {
		int a;
		cin >> a;
		if (a == 5)c++;
		if (a == 7)cc++;
	}
	if (c == 2 && cc == 1)ans = true;
	puts(ans ? "YES":"NO");

	return 0;
}

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

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


void multiple_of_2_and_n()
{
  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  sort(a.begin(), a.end());

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


void atcoder_crackers()
{
  int n, k;
  cin >> n >> k;

  if (n % k == 0) cout << 0 << "\n";
  else cout << 1 << "\n";
}


void garden()
{
  int a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}


void train()
{
  int n, i;
  cin >> n >> i;

  cout << n - i + 1 << "\n";
}


void Pair()
{
  int k;
  cin >> k;

  if (k % 2 == 0) cout << k / 2 * k / 2 << "\n";
  else cout << k / 2 * (k / 2 + 1) << "\n";
}


void ABC333()
{
  int a, b;
  cin >> a >> b;

  if ((a == 1 && (b == 1 || b == 3)) || (a == 3 && (b == 1 || b == 3))) cout << "Yes\n";
  else cout << "No\n";
}


void maximize_the_formula()
{
  int a, b, c;
  cin >> a >> b >> c;

  int v_max = max({ a,b,c });
  cout << a + b + c + 9 * v_max << "\n";
}


void digit_sums()
{
  int n;
  cin >> n;

  int s = 0, tmp = n;
  while (tmp > 0)
  {
    s += tmp % 10;
    tmp /= 10;
  }
  if (n % s == 0) cout << "Yes\n";
  else cout << "No\n";
}


void maximum_difference()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  sort(a.begin(), a.end());

  cout << a[n - 1] - a[0] << "\n";
}

void string_rotation() 
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); ++i)
  {
    if (s == t)
    {
      cout << "Yes\n";
      return;
    }
    char c = s.back();
    s.pop_back();
    s = c + s;
  }
  cout << "No\n";
}


void accepted()
{
  string s;
  cin >> s;

  if (s[0] != 'A')
  {
    cout << "WA\n";
    return;
  }

  int cnt = 0;
  for (int i = 1; i < s.size(); ++i)
  {
    if (i >= 2 && i <= s.size() - 2 && s[i] == 'C') ++cnt;
    else if (s[i] < 97)
    {
      cout << "WA\n";
      return;
    }
  }

  if (cnt != 1)
  {
    cout << "WA\n";
    return;
  }

  cout << "AC\n";
}


void cakes_and_donuts()
{

}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  //rated_for_me();
  //atcoder_crackers();
  //garden();
  //train();
  //Pair();
  //ABC333();
  //maximize_the_formula();

  //digit_sums();
  //maximum_difference();
  //string_rotation();
  accepted();
  //cakes_and_donuts();
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

hoge = []
m = min(A, B)

for i in range(1, m + 1):
    if A % i == 0 and A // i > 0 and B % i == 0 and B // i > 0:
        hoge.append(i)
        
fuga = sorted(list(set(hoge)))
a = len(fuga) - K
print(fuga[a])

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

happy = [[0, 0, 0] for _ in range(N)]

happy[0] = [int(x) for x in input().split()]

for i in range(1, N):
    a, b, c = [int(x) for x in input().split()]
    happy[i][0] = max(happy[i - 1][1] + a, happy[i - 1][2] + a)
    happy[i][1] = max(happy[i - 1][2] + b, happy[i - 1][0] + b)
    happy[i][2] = max(happy[i - 1][0] + c, happy[i - 1][1] + c)

ans = max(happy[N - 1])

print(ans)

Measured memory_bytes: 28776
'use strict'


function Main(input) {
  input = input.trim().split('\n')
  const array = input[0].split(' ')
  const res = input[1].split(' ').map(s => parseInt(s))

  const S = array[0]
  const T = array[1]
  let A = res[0]
  let B = res[1]

  const U = input[2]

  if (U === S) {
    A -= 1
  } else {
    B -= 1
  }

  console.log(`${A} ${B}`)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int a[]=new int[n];
        int b[]=new int[n];
        int c[]=new int[m];
        int d[]=new int[m];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
        }
        for(int i=0;i<m;i++){
            c[i]=sc.nextInt();
            d[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            int min=Math.abs(a[i]-c[0])+Math.abs(b[i]-d[0]);
            int ans=1;
            for(int j=1;j<m;j++){
                int len=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
                if(min>len){
                    ans=j+1;
                    min=len;
                }
            }
            System.out.println(ans);
        }


    }
}


Measured memory_bytes: 21460
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int R=sc.nextInt();
        if(N>=10){
            System.out.println(R);
        }else{
            System.out.println(R+100*(10-N));
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; ++i)

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	int ans = 0;
	int backANum = 0, frontBNum = 0, frontBbackANum = 0;
	REP(i, N)
	{
		string s; cin >> s;
		REP(j, s.length() - 1)
		{
			if (s[j] == 'A' && s[j + 1] == 'B') ++ans;
		}
		if (s.front() == 'B') {
			if (s.back() == 'A') ++frontBbackANum;
			else ++frontBNum;
		}
		else if (s.back() == 'A') ++backANum;
	}
	if (frontBbackANum == 0)
	{
		ans += min(frontBNum, backANum);
	}
	else if(frontBNum + backANum != 0)
	{
		ans += frontBbackANum + min(frontBNum, backANum);
	}
	else
	{
		ans += frontBbackANum - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3588
/*  -*- coding: utf-8 -*-
 *
 * 2816.cc: Alphabet Block
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int cs[26];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);

  for (int i = 0; s[i]; i++) cs[s[i] - 'a']++;
  //for (int i = 0; i < 26; i++) printf("%d ", cs[i]); putchar('\n');

  int cnt = 0;
  for (int i = 0; i < 26; i++)
    cnt += (cs[i] & 1);

  printf("%d\n", cnt / 2);
  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P= pair<ll,ll>;
const ll INF = ll(1e18)+5;
const ll MAXN = ll(1e5) +5;
vector<vector<ll>> G(3*MAXN);
vector<ll> d(3*MAXN,INF);

int main() {
    ll N,M;
    cin >> N >>M;
    
    for(int i=0;i<M;i++){
        ll u,v;
        cin >> u >> v;
        --u;--v;
        G[u*3].push_back(v*3+1);
        G[u*3 +1].push_back(v*3+2);
        G[u*3+2].push_back(v*3);
    }
    ll S,T;
    cin >> S >>T;
    --S;--T;
    
    d[3*N]=0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(P(0,3*S));
    while(!pq.empty()){
        P p= pq.top();
        pq.pop();
        if(d[p.second] <p.first){
            continue;
        }
        for(ll child:G[p.second]){
            if(d[child] > p.first+1){
                d[child] = p.first+1;
                pq.push(P(d[child],child));
            }
        }
    }
    if(d[T*3]==INF){
        cout << -1<<endl;
        return 0;
    }
    cout << d[T*3]/3 << endl;


    return 0;
}

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

int main()
{
  int n, t;
  cin >> n >> t;
  
  int minc = -1;
  for(int i = 0; i < n; i++)
  {
    int c, ct;
    cin >> c >> ct;
    if(ct > t)
    {
      continue;
    }
    if(minc == -1 || minc > c)
    {
      minc = c;
    }
  }
  if(minc == -1)
  {
    cout << "TLE" << endl;
  }
  else
  {
    cout << minc << endl;
  }
}

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

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

int weight[110];
int value[110];
long dp[100010];

int main(){
	int n, w;
	scanf("%d%d", &n, &w);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &weight[i], &value[i]);
	}
	for(int i = 0; i < n; i++) {
		for(int j=w; j >= 0; j--) {
			if(j + weight[i] <= w)
				chmax(dp[j+weight[i]], dp[j] + value[i]);
		}
	}
	long ret = 0;
	for(int i=0; i <= w; i++) {
		chmax(ret, dp[i]);
	}
	printf("%ld", ret);
}


Measured memory_bytes: 1024
n=int(input())
V=list(map(int,input().split()))

A=[V[i] for i in range(0,n,2)]
B=[V[i] for i in range(1,n,2)]

import collections
  
C = collections.Counter(A)
D = collections.Counter(B)
  
if C.most_common()[0][0] != D.most_common()[0][0]:
  print(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1])
else:
  if len(C)!=1 and len(D)!=1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[1][1],
            len(A)+len(B)-C.most_common()[1][1]-D.most_common()[0][1]) )
  elif len(C)!=1 and len(D)==1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1],
            len(A)+len(B)-C.most_common()[1][1]-D.most_common()[0][1]) )
  elif len(C)==1 and len(D)!=1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[1][1],
            len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1]) )
  else:
    print(min(len(A),len(B)))

Measured memory_bytes: 77444
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int ase=(n*(n+1))/2;
    long long int three=n/3;
    long long int five=n/5;
    long long int fifteen=n/15;
    cout<<ase- 3*((three)*(three+1))/2 - 5*((five)*(five+1))/2 + 15*((fifteen)*(fifteen+1))/2<<endl;
}


Measured memory_bytes: 3640
function main(arg) {
    
    let n = Number(arg.split("\n")[0])
    let a = arg.split("\n")[1].split(" ").map(x=>Number(x))
    
    let i=0, max=a[i], sum=0
    for(i=1; i<n; i++) {
        sum += Math.max(max-a[i], 0)
        max = Math.max(max, a[i])
    }
    console.log(sum)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

		int[][] A = new int[4][4];
		for( int i=1; i<=3; i++ ){
			for( int k=1; k<=3; k++ ){
				A[i][k] = sc.nextInt();
			}
		}
		int N = sc.nextInt();
		int[] B = new int[N];
		for( int i=0; i<N; i++ ){
			B[i] = sc.nextInt();
			loop:for( int j=1; j<=3; j++ ){
				for( int k=1; k<=3; k++ ){
					if( B[i]==A[j][k] ){
						A[j][k] = 0;
						break loop;
					}
				}
			}
		} 
		int ans = 0;
		if( A[1][1]==A[1][2] && A[1][2]==A[1][3] ){
			ans = 1;
		}
		if( A[2][1]==A[2][2] && A[2][2]==A[2][3] ){
			ans = 1;
		}
		if( A[3][1]==A[3][2] && A[3][2]==A[3][3] ){
			ans = 1;
		}
		if( A[1][1]==A[2][1] && A[2][1]==A[3][1] ){
			ans = 1;
		}
		if( A[1][2]==A[2][2] && A[2][2]==A[3][2] ){
			ans = 1;
		}
		if( A[1][3]==A[2][3] && A[2][3]==A[3][3] ){
			ans = 1;
		}
		if( A[1][1]==A[2][2] && A[2][2]==A[3][3] ){
			ans = 1;
		}
		if( A[1][3]==A[2][2] && A[2][2]==A[3][1] ){
			ans = 1;
		}
		System.out.println(ans==1?"Yes":"No");
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
ll d[300][300],v, n, c, e, u, k, sum = 0,ans;
int main(void) {
    ll a, b, c, sum = 0;
    cin >> a >> b >> c;
    if (a + b + 1 < c) {
        cout << a + b + 1 + b << endl;
    }
    else cout << b + c << endl;
}

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

using namespace std;
using ll = long long;


int main()
{
	vector<vector<int>> hen(3, vector<int>(3));
	for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++)cin >> hen[i][j];
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		int t; cin >> t;
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(hen[j][k] == t)hen[j][k] = -1;
			}
		}
	}
	bool res = false;
	for(int i = 0; i < 3; i++) {
		int cnt = count(hen[i].begin(), hen[i].end(), -1);
		if(cnt == 3)res = true;
	}
	for(int i = 0; i < 3; i++) {
		int cnt = 0;
		for(int j = 0; j < 3; j++) {
			if(hen[j][i] == -1)cnt++;
		}
		if(cnt == 3)res = true;
	}

	if(hen[0][0] == -1 && hen[1][1] == -1 && hen[2][2] == -1 )res = true;
	if(hen[0][2] == -1 && hen[1][1] == -1 && hen[2][0] == -1)res = true;


	cout << (res ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;#include <stdio.h>
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;

ll gcd(ll a, ll b);
ll N, X;
vector<ll> x;

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	cin >> N >> X;

	for (int i = 0; i < N; i++) {
		ll temp;
		cin >> temp;
		x.emplace_back(abs(temp - X));
	}

	if (N > 1) {
		ll ans = gcd(x[0], x[1]);
		for (int i = 0; i < N; i++) {
			ans = gcd(ans, x[i]);
		}

		cout << ans;
	}
	else {
		cout << x[0];
	}





}

//---最大公約数を求める---
ll gcd(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int i,x,sum;
  sum=0;
  for (i=0; i<N; i++){
    cin >> x;
    if(x<K-x)
      sum+=x*2;
    else
      sum+=(K-x)*2;
  }
  cout << sum << endl;
}


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

int main() {
    int a, b, d; cin >> a >> b >> d;
    vector<int> v = {a, b, d};
    sort(v.begin(), v.end());
    vector<int> v2 = {5, 5, 7};
    
    if (v == v2) {
        cout << "YES" << endl;
    }

    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,m;
  cin >> n >> m;
  if (n==m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
while True:
    n,x = map(int, raw_input().split())
    count = 0
    if(n != 0 or x != 0):
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if(i+j+k == x):
                        count += 1
        print count
    else:
        break 

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n;
    cin>>n;
    ll H[n];
    for(int i=0;i<n;i++)
        cin>>H[i];
    ll Up[n];
    string ans = "Yes";
    Up[0] = H[0];
    for(int i=1;i<n;i++){
        int diff = H[i]- Up[i-1];
        if(diff<0){
            ans = "No";
            break;
        }
        else if(diff==0)
            Up[i] = H[i];
        else
            Up[i] = H[i]-1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int A,B,T,s=0;
	scanf("%d%d%d",&A,&B,&T);
	s=(int)T/A;
	if(s>0)
	printf("%d\n",s*B);
	else 
	printf("0\n");
	return 0;
}

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

int main()
{
  int64_t x;
  cin >> x;
  
  int64_t sum = 100;
  int year = 0;
  while(sum < x){
    sum += sum / 100;
    year++;
  }
  
  cout << year << endl;
}

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

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

using namespace std;

ll gcd(ll x, ll y)
{
	if (y == 0){
		return x;
	}
	return gcd(y, x%y);
}

int main(void)
{
	ll n, cur;
	cin >> n;
	vector<ll> a(n);
	rep(i, n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cur = a[0];
	rep(i, n){
		cur = gcd(cur, a[i]);
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		int l = s[i]-'A'+n;
		l=l%26;
		s[i]=char(l+'A');
	}
	cout<<s;
}

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

/// ----------------------------- (Debug) ------------------------------
#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 {
#ifndef ONLINE_JUDGE
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
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
void solve (int test_case) {
	int n , m , k ;
	cin >> n >> m >> k ;
	vector< vector <char> > g(n , vector<char> (m)) ;
	vector<int> r(n , 0 ) , c(m , 0) ;
	int cnt = 0 ;
	for (int i = 0 ; i <n ; ++i) {
		for (int j = 0 ; j < m ; ++j) {
			cin >> g[i][j] ;
			if (g[i][j] == '#') {
				++r[i] ;
				++c[j] ;
				++cnt ;
			}
		}
	}
	long long ways = 0 ;
	for (int maskr = 0 ; maskr < (1 <<n) ; ++maskr) {
		for (int maskc = 0 ; maskc < (1 <<m) ; ++maskc) {
			int sum = 0 ;
			dbg(maskr,maskc);
			for (int i = 0 ; i < n ; ++i) {
				if (maskr & (1 << i)) {
					sum += r[i] ;
				}
			}
			for (int i = 0 ; i < m ; ++i) {
				if (maskc & (1 << i)) {
					sum += c[i] ;
				}
			}
			for (int i = 0 ; i < n ; ++i) {
				for (int j = 0; j < m ; ++j) {
					if ((maskr & (1 << i)) && (maskc & (1 << j)) && g[i][j] == '#') --sum ;
				}
			}
			if (cnt - sum == k) ++ways ;
		}
	}
	cout << ways << "\n" ;
}

int main() {
	ios_base :: sync_with_stdio (false) ;
	cin.tie(0) ;
	cout.tie(0) ;
	int tc = 1 ;
	//cin >> tc ;
	while (tc--) {
		solve (tc) ;
	}
	return 0 ;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int n,int r){
  int a[100];
  rep(i,n){
    a[i+1]=n-i;
  }

  rep(i,r){
    int p,c;
    cin>>p>>c;
    int b[100];
    rep(j,p-1){
      b[j]=a[j+1];
    }
    rep(j,c){
      a[j+1]=a[p+j];
    }
    rep(j,p-1){
      a[j+c+1]=b[j];
    }
  
    
  }

  cout<<a[1]<<endl;

}

int main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0) break;
    f(n,r);
  }

  return 0;
}


Measured memory_bytes: 3080
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}

int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin>>n;
        if(n%1000==0){
            cout<<0<<endl;
        }
        else
        cout<<1000-(n%1000)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3672
def main():
    from itertools import groupby
    from collections import deque
    N, K = (int(i) for i in input().split())
    S = input()
    ans = 0
    cur_0 = 0
    cur_sum = 0
    que = deque()
    for k, g in groupby(S):
        len_g = len(list(g))
        # print(k, len(list(g)))
        if k == "0":
            cur_0 += 1
            cur_sum += len_g
            que.append((0, len_g))
        else:
            cur_sum += len_g
            que.append((1, len_g))

        if K < cur_0:
            cur_0 -= 1
            key, val = que.popleft()
            while key != 0:
                cur_sum -= val
                key, val = que.popleft()
            cur_sum -= val
        ans = max(ans, cur_sum)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45532
from heapq import heapify, heappop, heappush

K, T = map(int, input().split())
A = [-a for a in map(int, input().split())]

heapify(A)
while len(A) > 1:
    a, b = -heappop(A), -heappop(A)
    heappush(A, -(a - b))

print(max(0, -A[0] - 1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

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

	ll b = 0;
	rep(i,n) b ^= a[i];

	rep(i,n){
		if(a[i] != (b ^ a[i])){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

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

int main()
{
  long N;
  cin>>N;
  long ans=N-1;
  long pack;
  for(int i=2;i<=1000000;i++){
    if(N%i==0){
      if(ans>=i+N/i-2) ans=i+N/i-2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

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

  int w, h, n;
	cin >> w >> h >> n;
	int x[1000], y[1000];
	rep(i, n) cin >> x[i] >> y[i];
	int ans = 0;

	rep(i, n - 1) {
		int dx = x[i + 1] - x[i];
		int dy = y[i + 1] - y[i];
		if(dx > 0 && dy > 0) {
			ans += max(dx, dy);
		} else if(dx < 0 && dy < 0) {
			ans += max(abs(dx), abs(dy));
		} else {
			ans += abs(dx) + abs(dy);
		}
	}
	cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define MN 25000
string s,S[MN+5];
int main()
{
	int k,i,j,l,cnt=0;
	cin>>s>>k;
	for(i=0;i<s.size();++i)
	{
		for(j=0;j<k&&i+j<s.size();++j)
		{
			++cnt;
			for(l=0;l<=j;++l)S[cnt]+=s[i+l];
		}
	}
	sort(S+1,S+cnt+1);
	for(i=1;i<=cnt;++i)if(k&&S[i]!=S[i-1])if(!--k)cout<<S[i]<<endl;
}

Measured memory_bytes: 1664
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

using namespace std;
typedef long long ll;
 
int main() {
  int n,m,a,b,ans;
  cin >> n >> m;
  int box[n+1]={};
  int num[n+1]={};
  rep(k,n+1){
  	num[k]=1;
  }
  box[1]=1;
  rep(i,m){
  	cin >> a >> b;
	num[a]--;
  	num[b]++;
	
  	if(box[a]==1){
  		box[b]=1;
  	}
  	if(num[a]==0){
  		box[a]=0;
  	}

  }
  ans = 0;
  rep(j,n+1){
  	if(box[j]==1){
  		ans++;
  	}
  }
	cout << ans << endl;

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int H, W;

	while (1){
		cin >> H >> W;
		for (int i = 0; i < H; i++){
			for (int i = 0; i < W; i++){
				cout << "#";
			}
			cout << endl;
		}
		if (H == 0 && W == 0){
			break;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  string N;
  cin >> N;
  ll K;
  cin >> K;

  vector<vector<vector<ll>>> dp(201, vector<vector<ll>>(5, vector<ll>(2, 0)));
  dp.at(0).at(0).at(0) = 1;
  for (ll i = 0; i < N.size(); i++)
  {
    for (ll j = 0; j <= 3; j++)
    {
      for (char d = '0'; d <= '9'; d++)
      {
        ll nj = ((d == '0') ? j : j + 1);

        if (d < N.at(i))
        {
          dp.at(i + 1).at(nj).at(1) += dp.at(i).at(j).at(0);
          dp.at(i + 1).at(nj).at(1) += dp.at(i).at(j).at(1);
        }
        else if (d == N.at(i))
        {
          dp.at(i + 1).at(nj).at(0) += dp.at(i).at(j).at(0);
          dp.at(i + 1).at(nj).at(1) += dp.at(i).at(j).at(1);
        }
        else
        {
          dp.at(i + 1).at(nj).at(1) += dp.at(i).at(j).at(1);
        }
      }
    }
  }

  ll ans = dp.at(N.size()).at(K).at(0) + dp.at(N.size()).at(K).at(1);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <set>
#include <string>
#include <queue>
using namespace std;

#define pub push_back
#define pob pop_back
#define PI (3.141592)
#define L (100)
# define U(v) cer <<< #v << ": " <<(v)<<endl;

typedef long long ll;
typedef pair<int, int> P;

int dh[] = { 0, 0, 1, -1 };
int dw[] = { 1, -1, 0, 0 };
const ll MOD = 1000000007;
const ll INF = 1000000000;
const int MAX = 10000000;
const int MAXH = 100;
const int MAXW = 100;


const int MAX_N = 100000;

int par[MAX_N];
int dep[MAX_N];

void init(int n){
    for (int i = 0; i < n; i++){
        par[i] = i;
        dep[i] = 0;
    }
}

int find(int x){
    if (par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (dep[x] < dep[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if (dep[x] == dep[y]) dep[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

int main(void){

    int p[MAX_N];
    int n, m;
    int ans = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    init(n);
    for (int i = 0; i < m; i++){
        int s, t;
        cin >> s >> t;
        s--; t--;
        unite(s, t);
    }

    for (int i = 0; i < n; i++){
        if (same(i, p[i])) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
string MAP[2222];
ll ruiy[2222][2222];
ll ruit[2222][2222];
ll ruiy2[2222][2222];
ll ruit2[2222][2222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  for(int i=0;i<n;i++)cin>>MAP[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(MAP[i][j]!='#'){
	ruiy[i][j+1]+=ruiy[i][j]+1;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=m-1;j>=0;j--){
      if(MAP[i][j]!='#'){
	ruiy2[i][j]+=ruiy2[i][j+1]+1;
      }
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(MAP[j][i]!='#'){
	ruit[j+1][i]+=ruit[j][i]+1;
      }
    }
  }
  for(int i=0;i<m;i++){
    for(int j=n-1;j>=0;j--){
      if(MAP[j][i]!='#'){
	ruit2[j][i]+=ruit2[j+1][i]+1;
      }
    }
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(MAP[i][j]!='#'){
	//if(i==1&&j==1)
	// cout<<ruiy[i][j+1]<<" "<<ruiy2[i][j+1]<<" "<<ruit[i+1][j]<<" "<<ruit2[i+1][j]<<endl;
	ll hoge=ruiy[i][j+1];
	hoge+=ruiy2[i][j+1];
	hoge+=ruit[i+1][j];
	hoge+=ruit2[i+1][j];
	ans=max(ans,hoge);
      }
    }
  }
  cout<<ans-1<<endl;
  return 0;
}


Measured memory_bytes: 149888
#include<bits/stdc++.h>
using namespace std;
#define repeat(i, n) for(int i = 0; i < (n); i++)
#define Would
#define you
 
int main() {
	int N, M, Q;
	int L[200000], R[200000];
	int nijigen[501][501] = {};
	scanf("%d%d%d", &N, &M, &Q);
	//cin >> N >> M >> Q;
	repeat(i, M) {
		scanf("%d%d", L + i, R + i);
		//cin >> L[i] >> R[i];
		nijigen[L[i]][R[i]] += 1;
	}
	int p[100000], q[100000];
	repeat(i, Q) {
		scanf("%d%d", p + i, q + i);
		//cin >> p[i] >> q[i];
	}
 
 
	int ruikei[502][502] = {};
 
	repeat(i, N) {
		repeat(ii, N) {
			ruikei[i + 1][ii + 1] = ruikei[i + 1][ii] + nijigen[i + 1][ii + 1];
		}
	}
 
	repeat(ii, N) {
		repeat(i, N) {
			ruikei[N - i][ii + 1] = ruikei[N - i + 1][ii + 1] + ruikei[N - i][ii + 1];
		}
	}
 
	repeat(i, Q) {
		printf("%d\n", ruikei[p[i]][q[i]]);
	}
	Would you return 0;
}

Measured memory_bytes: 5248