akhauriyash/Code-Regression huggingface dataset:
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

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

const ll maxn = 200010;

ll n;

ll solve(ll x) {
    return x == 1 ? 1 : 1 + solve(x / 2) * 2;
}

void MAIN() {

    cin >> n;
    cout << solve(n) << '\n';

}

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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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 (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

signed main() {
   int n;
   cin >> n;
   if (n == 1) {
      puts("Hello World");
   } else {
      int a, b;
      cin >> a >> b;
      cout << a + b << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	ll ans = 0;
	int n = s.size();
	REP(bit,(1<<n-1)){
		ll tmp = s[0] - '0';
		REP(i,n-1){
			if(bit & (1<<i)){
				ans += tmp;
				tmp = 0;
			}
			tmp = tmp*10 + (s[i+1]-'0');
		}
		ans += tmp;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } else return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } else return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int main() {
	int N, K;
	cin >> N >> K;
	puts(N % K == 0 ? "0" : "1");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;

public class Main{
 public static void main(String[] args){
  int w;
  Scanner sc = new Scanner(System.in);
  int W = sc.nextInt();
  int H = sc.nextInt();
  int x = sc.nextInt();
  int y = sc.nextInt();
  int r = sc.nextInt();
  boolean z = false;
  if ( x - r >= 0 && x + r <= W){
   if ( y - r >= 0 && y + r <= H){
    z = true;
   };
  };
  if ( z == true ){
   System.out.println("Yes");
  }else{
   System.out.println("No");
  }
 }
}   


Measured memory_bytes: 26324
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;


int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    t.erase(t.size()-1);
    if(s==t)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define sc(n) scanf("%d",&n)
#define sc1(a,b) scanf("%d %d",&a,&b)
#define sc2(x,y,z) scanf("%d %d %d",&x,&y,&z)

int main()
{
	int q;
	sc(q);
	
	list <int> lis;
	list<int>::iterator it=lis.begin();
	list<int>::iterator itr;
	
	for(int i=0;i<q;i++)
	{
		int qi;
		
	    sc(qi);
	    
	    int a;
	    if(!qi)
	    {
	    	sc(a);
	    	lis.insert(it,a);
	    	advance(it,-1);
		}
		
		else if(qi==1)
		{
			sc(a);
			advance(it,a);
		}
		
		else
		{
		   itr = it;
		   advance(it,1);
		   lis.erase(itr);
		}
	}
	
	
	for(list<int>::iterator mt= lis.begin();mt!=lis.end();mt++)
	{
		printf("%d\n",*mt);
	}
}


Measured memory_bytes: 18644
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] diff = new boolean[N]; //N not possible as max gap = N-1; N/2 is bad for even
		boolean[] used = new boolean[N+1];
		int bad = -1;
		if (N%2==0) bad=N/2;
		System.out.println(1+" "+N);
		diff[1]=true;
		diff[N-1]=true;
		used[1]=true;
		used[N]=true;
		M--;
		int START = 2;
		while (M>0) {
			for (int d = N-1; d>=1; d--) {
				int diff1 = d;
				int diff2 = N-d;
				int END = START+diff1;
				if (!diff[diff1]&&!diff[diff2]&&!used[END]&&diff1!=bad) {
					System.out.println(START+" "+END);
					diff[diff1]=true;
					diff[diff2]=true;
					used[END]=true;
					START++;
					M--;
					if (M==0) break;
				}
			}
		}
	}	
}


Measured memory_bytes: 45344
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	int n, a, b; cin>>n>>a>>b;
  cout<< min(n*a, b)<<"\n";
	
	
	
	
}

Measured memory_bytes: 256
const main = (input) => {
  const args = input.split(' ').map(Number)
  const [n, k] = args
  if (n + 1 - k === 0) {
    console.log(1)
    return
  }
  const sums = [0]
  for (let i = 0; i < n + 1; i++) {
    sums.push(i + sums[i])
  }
  const sum = Array(n + 2 - k).fill(0).map((_, i) => {
    const min = sums[i + k] - sums[0]
    const max = sums[n + 1] - sums[n + 1 - i - k]
    return max - min + 1
  }).reduce((p, c) => p + c)
  console.log(sum % (10 ** 9 + 7))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
	int n;
	scanf("%d", &n);
	/*std::vector<char> a(n), b(n), c(2*n);
	for(int i=0;i<n;i++)
		scanf("%c", &a[i]);
	for(int i=0;i<n;i++)
		scanf("%c", &b[i]);
	*/
	std::string a, b, c;
	std::cin>>a>>b;
	for(int i=0;i<n;i++){
		c+=a[i];
		c+=b[i];
	}
	std::cout<<c<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> as, bs, cs;
    as.resize(a);
    for(int i=0; i<a; i++) cin >> as.at(i);
    bs.resize(b);
    for(int i=0; i<b; i++) cin >> bs.at(i);
    cs.resize(c);
    for(int i=0; i<c; i++) cin >> cs.at(i);

    sort(as.begin(), as.end(), greater<ll>());
    sort(bs.begin(), bs.end(), greater<ll>());
    sort(cs.begin(), cs.end(), greater<ll>());

    vector<ll> aps;
    for(int i=0; i<x; i++)
    {
        aps.push_back(as.at(i));
    }
    for(int i=0; i<y; i++)
    {
        aps.push_back(bs.at(i));
    }
    for(ll num : cs)
    {
        aps.push_back(num);
    }
    sort(aps.begin(), aps.end(), greater<ll>());
    ll ans = 0;
    for(int i=0; i<x+y; i++)
    {
        ans += aps.at(i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7920
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    // ダイクストラ法。計算量はO((V+E)*log(V))
    const ll sv = 0;  // 始点となる頂点。デフォルトでは0
    vl dist(MAX_N, INF);  // dist[v] : 頂点svから頂点vへの最短距離
    priority_queue<P, vector<P>, greater<P>> prQ;
    dist[sv] = 0;
    prQ.push(make_pair(sv, 0));  // (頂点番号, 頂点svからの最短距離)
    while(!prQ.empty()) {
        auto p1 = prQ.top();
        prQ.pop();
        ll v = p1.first;
        if(dist[v] < p1.second) {
            continue;
        }
        for(ll pow6 = 1; v + pow6 <= n; pow6 *= 6) {
            ll nv = v + pow6;
            if(dist[nv] > dist[v] + 1) {
                dist[nv] = dist[v] + 1;
                prQ.push(make_pair(nv, dist[nv]));
            }
        }
        for(ll pow9 = 1; v + pow9 <= n; pow9 *= 9) {
            ll nv = v + pow9;
            if(dist[nv] > dist[v] + 1) {
                dist[nv] = dist[v] + 1;
                prQ.push(make_pair(nv, dist[nv]));
            }
        }
    }

    out(dist[n]);
    re0;
}

Measured memory_bytes: 2168
N = int(input())
A = list(map(int, input().split()))
A.append(0)
    
total_normal = 0
prev = 0
for a in A:
    length = abs(a-prev)
    total_normal += length
    prev = a

prev = 0
for i in range(N):
    now = A[i]
    nex = A[i + 1]
    ans = total_normal - (abs(now - prev) + abs (nex - now)) + abs(nex - prev)
    print(ans)
    prev = now


Measured memory_bytes: 14048
N = int(input())
ans = 0
b_x = 0
b_a = 0
x_a = 0
y = 0
for _ in range(N):
  s = input()
  ans += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    b_a += 1
  elif s[0] == 'B':
    b_x += 1
  elif s[-1] == 'A':
    x_a += 1
  else:
    y += 1
if x_a >= 1 and b_x >= 1:
  ans += b_a + 1	
elif x_a >= 1 or b_x >= 1:
  ans += b_a
else:
  if b_a > 0:
    ans += b_a - 1
if x_a - 1 <= 0 or b_x -1 <= 0:
  ans += 0
else:
  ans += min(x_a - 1, b_x - 1)
print(ans)  

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    int modten=0,minnotten=INT_MAX,sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%10 ==0){
            modten++;
        }
        else{
            minnotten=min(minnotten,a[i]);
        }
        sum+=a[i];
    }
    if(modten==n){
        cout << 0 << endl;
    }
    else{
        if(sum%10){
            cout << sum << endl;
        }
        else{
            cout << sum-minnotten << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()

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

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

int main() {
  ll N;
  string ans = "";
  cin >> N;
  if (N > 0) {
    while (N != 0) {
      ll po = N % 4;
      if (po == 0)
        ans = "00" + ans;
      else if (po == 1) {
        ans = "01" + ans;
      } else if (po == 2) {
        N += 4;
        ans = "10" + ans;
      } else if (po == 3) {
        N += 4;
        ans = "11" + ans;
      }
      N /= 4;
    }
    if (ans[0] == '0') {
      ans.erase(ans.begin());
    }
  } else if (N < 0) {
    N *= -1;
    while (N != 0) {
      ll po = N % 4;
      if (po == 0)
        ans = "00" + ans;
      else if (po == 1)
        ans = "11" + ans;
      else if (po == 2)
        ans = "10" + ans;
      else if (po == 3) {
        N += 4;
        ans = "01" + ans;
      }
      N /= 4;
    }
    if (ans[0] == '0') {
      ans.erase(ans.begin());
    }
  } else {
    ans = "0";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long long a,b;
	char op;
	scanf("%lld %c %lld",&a,&op,&b);
	if(op == '+')
		printf("%lld\n",a+b);
	else if(op == '-')
		printf("%lld\n",a-b);
	
	
	return 0;
}

Measured memory_bytes: 128
def check(before, center, after, saying):
    return ([center, saying] in [["S", "o"], ["W", "x"]] and before == after)\
           or ([center, saying] in [["S", "x"], ["W", "o"]] and before != after)


def main():
    n = int(input())
    s = list(input())
    ans = "-1"
    for init in ["S", "W"]:
        if ans != "-1":
            break
        for next in ["S", "W"]:
            now_ans = ["" for _ in range(n)]
            now_ans[0] = init
            now_ans[1] = next
            for i in range(1, n - 1):
                if [now_ans[i], s[i]] in [["S", "o"], ["W", "x"]]:
                    now_ans[i + 1] = now_ans[i - 1]
                else:
                    now_ans[i + 1] = "W" if now_ans[i - 1] == "S" else "S"
            if check(now_ans[-2], now_ans[-1], now_ans[0], s[-1]) and check(now_ans[-1], now_ans[0], now_ans[1], s[0]):
                ans = "".join(now_ans)
                break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11296
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(2*n-1,0);
  for(int i=0;i<n;i++) a[n-1+i] = 1;
  for(int i=0;i<m;i++){
    int k; cin >> k;
    a[n-1+k] = 0;
  }
  int cnt = 0;
  for(int i=n-2;i>=0;i--){
    a[i] = a[2*i+1] | a[2*i+2];
    cnt += a[2*i+1] * a[2*i+2];
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3076
#include <stdio.h>

char s[128];

int last[256], max[256];

int main(void) {
	int i, len,  kotae;
	if (scanf("%127s",s) != 1) return 1;

	for (i = 0; i < 256; i++) {
		last[i] = -1;
	}

	for (i = 0; s[i] != '\0'; i++) {
		int idx = (unsigned char)s[i];
		if (i - last[idx] - 1 > max[idx]) max[idx] = i - last[idx] - 1;
		last[idx] = i;
	}

	len = i;
	for (i = 0; i < 256; i++) {
		if (len - last[i] - 1 > max[i]) max[i] = len - last[i] - 1;
	}

	kotae = len;
	for (i = 0; i < 256; i++) {
		if (max[i] < kotae) kotae = max[i];
	}

	printf("%d\n", kotae);
	return 0;
}

/*

s e r v a l
|/|/|/|/|/
s r v v l
|/|/|/|/
s v v v
|/|/|/
v v v

j a c k a l
|/|/|/|/|/
a a c a a
|/|/|/|/
a a a a

各文字は後ろへは拡散できない
ある位置の文字に統一したい → その長さになるまで待たないといけない

*/


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
vector<int> t(n);
vector<int> t2(n);

            for(int i=0;i<n;i++){
        cin >> t.at(i);
       t2.at(i)=t.at(i);
    }
    int m;
    cin >> m;
    int ch;
    int ch2;
    for(int i=0;i<m;i++){
        cin >> ch >> ch2;
    t.at(ch-1)=ch2;
      int ans;
      for(int j=0;j<n;j++){
        ans+=t.at(j);
      }
    cout << ans << endl;
    ans =0;
    t.at(ch-1)=t2.at(ch-1);
    }
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i = 0; i < n; i++) cin >> v.at(i);
  for(int i = 0; i < n; i++) cin >> c.at(i);
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += max(0, v.at(i) - c.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
inline int in() { int x; cin>>x; return x;}
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
#define dame {puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
//----------------------------------------------------------------
int main(int argc,char* argv[]){
    fileio
    vi dp(MX,INF);
    int n = in();
    int k = in();
    vi h(n);
    cin>>h;
    rep(i,k) h.pb(INF);
    dp[0] = 0;
    rep(i,n){
        rrep(j,k){
            mins(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<< endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int a = in.nextInt();
        int b = in.nextInt();
        if(Math.abs(a-b)>=2){
            if(a>b){
                out.println(a+(a-1));
            }
            else{
                out.println(b+(b-1));
            }
        }
        else{
            out.println(a+b);
        }
        out.close();
    }

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

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

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 32984
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=998244353;
const int N=3e5+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

int a[N];
int32_t main()
{
    int n=in();
    int m=0;
    int ans=1;
    for(int i=0;i<n;i++){
        int k=in();a[k]++;
        m=max(m,k);
        if(i==0&&k!=0) ans=0;
    }
    if(a[0]!=1) ans=0;
    for(int i=1;i<=m;i++){
        if(a[i]==0) ans=0;
        ans=1LL*ans*qpow(a[i-1],a[i])%mod;
    }
    pf1(ans);
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



Measured memory_bytes: 640
N,M=map(int,input().split())
A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]

for x in range(N-M+1):
  for y in range(N-M+1):
    t=1
    for i in range(M):
      for j in range(M):
        if A[x+i][y+j]!=B[i][j]:
          t=0
    if t==1:
      print("Yes")
      exit()
print("No")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {
 
  public struct City{
    public long num;
    public City(long n){
      num = n;
    }
 
  }
 
  public static void Main (string[] args) {
    var N = long.Parse(Console.ReadLine());
    var list = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
    var ans = list[0];
    /*for(var i = 0; i < N; i++){
      list.Add(Console.ReadLine().Split(' ').Select(long.Parse).ToList());
    }*/

    for(var i = 0; i < N - 1; i++){
      ans = Euclidean(ans, list[i + 1]);
    } 
    Console.WriteLine(ans);
  }
  public static long Euclidean(long a, long b){
    if(a % b == 0){return b;}
    return Euclidean(b, a % b);
  }
}

Measured memory_bytes: 20064
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<int> count(n);

    int a, b;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        count.at(a-1)++;
        count.at(b-1)++;
    }
    
    for(int x: count){
        cout << x << endl;
    }
    
    
    
    
}



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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;

    int plus = (n / 15) * 200;

    int ans = 800 * n - plus;

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

    int a,b;
    cin >> a >> b;
    int t = a + b;

    if(t >= 24){
        t -= 24;
    }

    cout << t << endl;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
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; }

const long long INF = 1LL << 60;
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    int n; cin >> n;
    vector<ll> h(n);
    REP(i,0,n) cin >> h[i];

    vector<ll> dp(n);
    REP(i,0,n) dp[i] = INF;
    dp[0] = 0;
    REP(i,1,n) {
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i >= 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std ;
int main(){
    int N,X;
    cin >> N >> X;
    int L[N];
    for(int i=0;i<N;i++)cin >> L[i];
    int NP=0;
    int count =1;
    for(int i=0;i<N;i++){
        NP+=L[i];
        if(NP<=X)count++;
        else break;
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
import sys
from heapq import*
r=sys.stdin.readline
def g(s,g):
 F=[1e7]*-~n;F[s]=0
 H=[(0,s)]
 while H:
  c,u=heappop(H)
  if u==g:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
for e in iter(r,'0 0\n'):
 n,k=map(int,e.split())
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(*map(int,f[2:].split())))
  else:
   c,d,e=map(int,f[2:].split())
   E[c]+=[(e,d)];E[d]+=[(e,c)]


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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;

    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    m1+=h1*60;
    m2+=h2*60;
    cout<<max(m2-m1-k,0ll)<<endl;
}

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

using namespace std;
vector<int> v[500005];
int floors[500005],qs[1005];
bool ch[500005];
void dfs(int i){
    ch[i]=true;
    if(v[i].empty()){
        floors[i]=1;
        return ;
    }
    int ma=-1;
    for(auto it:v[i]){
        if(!ch[it]){
            dfs(it);
        }
        if(floors[it]==-1){
            floors[i]=-1;
            return;
        }
        ma=max(floors[it]+1,ma);
    }
    floors[i]=ma;
    return ;
}
int main(){
    int n,x,y,ma=-1,a,b,sq;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        qs[i]=qs[i-1]+n-i;
    }
    for(int i=0;i<=(n*(n-1))/2;i++){
        floors[i]=-1;
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            scanf("%d",&x);
            if(j>0){
                a=min(i-1,y-1);
                b=min(i-1,x-1);
                v[qs[a]+abs(i-y)].push_back(qs[b]+abs(i-x));
                //printf("%d to %d\n",qs[a]+abs(i-y),qs[b]+abs(i-x));
            }
            y=x;
        }
    }
    for(int i=1;i<=(n*(n-1))/2;i++){
        if(!v[i].empty()&&floors[i]==-1){
            dfs(i);
            if(floors[i]==-1){
                printf("-1");
                return 0;
            }
            ma=max(floors[i],ma);
        }

    }
    printf("%d",ma);
    return 0;
}


Measured memory_bytes: 30080
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main () {
    let v = vec! [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    let k: usize = read();
    println!("{}",&v[k-1]);
}

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

using namespace std;

class Prime {
private:
  vector<long long> divisor;
  
public:
  Prime(long long n) {
    for (long long i = 0; i < n; ++i) divisor.emplace_back(i);
    for (long long i = 2; i <= n / i; ++i) if (divisor[i] == i) {
      for (long long j = i * i; j < n; j += i) divisor[j] = i;
    }
  }
  
  bool is_prime(long long n) {
    if (n <= 1) return false;
    if (n < (long long)divisor.size()) return divisor[n] == n;
    for (long long i = 2; i <= n / i; ++i) if (n % i == 0) return false;
    return true;
  }
  
  vector<long long> factor(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      while (n % i == 0) {
        res.emplace_back(i);
        n /= i;
      }
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        res.emplace_back(divisor[n]);
        n /= divisor[n];
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
  
  vector<long long> get_divisors(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      if (n % i) continue;
      res.emplace_back(i);
      while (n % i == 0) n /= i;
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        long long d = divisor[n];
        res.emplace_back(d);
        while (n % d == 0) n /= d;
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
};

int main() {
  int n;
  cin >> n;
  Prime prime(1000000);
  cout << n << ":";
  for (int f : prime.factor(n)) cout << " " << f;
  cout << endl;
}

Measured memory_bytes: 11064
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, ans;
string s;
ll a[4005];
ll d[3][4005];

int main()
{
    cin>>n>>s;
    s = ' ' + s;
    for(ll i = 1; i <= n; i++)
    {
        if(s[i] == 'R') a[i] = 0;
        else if(s[i] == 'G') a[i] = 1;
        else a[i] = 2;
        d[0][i] = d[0][i - 1];
        d[1][i] = d[1][i - 1];
        d[2][i] = d[2][i - 1];
        d[a[i]][i]++;
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = i + 1; j <= n; j++)
        {
            if(a[i] == a[j]) continue;
            ll k = 3 - a[i] - a[j];
            ans += d[k][n] - d[k][j];
            if(2 * j - i > n) continue;
            else if(a[2 * j - i] == k) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3732
import java.util.*;

public class Main {

    static final long LIMIT = 1800L;
    static final int D = 365;
    static final int[] c = new int[27];
    static final int[][] s = new int[365][27];
    static final int[] ans = new int[365];
    static final int[] last = new int[27];
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int fla = 0;
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
            fla += c[i];
        }
        for (int i = 0; i < D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        Map<Integer, TreeSet<Integer>> lastMap = new HashMap<>();
        for (int i = 1; i <= 26; i++) {
            lastMap.put(i, new TreeSet<>());
            lastMap.get(i).add(0);
            lastMap.get(i).add(D+1);
        }
        StringBuilder sb = new StringBuilder();
        int score = 0;
        for (int i = 0; i < D; i++) {
            score -= fla;
            int max = score;
            int idx = 0;
            for (int j = 1; j <= 26; j++) {
                int tmp = score + s[i][j] +  c[j] *(i - last[j] + 1);
                if(max < tmp){
                    max = tmp;
                    idx = j;
                }
            }
            score = max;
            ans[i] = idx;
            last[idx] = i+1;
            lastMap.get(idx).add(i+1);
        }

        while(System.currentTimeMillis() - start < LIMIT){
            for (int i = 0; i < D; i++) {
                int prei = ans[i];
                int idx = prei;
                int max = s[i][prei] + c[prei] * (i - lastMap.get(prei).lower(i+1) +1) * (lastMap.get(prei).higher(i+1) - i -1);
                for (int j = 1; j <= 26; j++) {
                    if(j == prei)continue;
                    int tmp = s[i][j] + c[j] * (i - lastMap.get(j).lower(i+1) +1) * (lastMap.get(j).higher(i+1) - i -1);
                    if(max < tmp){
                        idx = j;
                        max = tmp;
                    }
                }
                if(prei != idx){
                    ans[i] = idx;
                    lastMap.get(prei).remove(i+1);
                    lastMap.get(idx).add(i+1);
                }
            }
        }


        for (int i = 0; i < D; i++) {
            sb.append(ans[i] + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 61736
#include <iostream>
#include <string>

using namespace std;
int main() {
	int a, b, i;
	cin >> a >> b;
	if (a < b) {
		for (i = 0; i < b; i++) {
			cout << a;
		}
	}
	else if (b < a) {
		for (i = 0; i < a; i++) {
			cout << b;
		}
	}
	else {
		for (i = 0; i < a; i++) {
			cout << b;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> t;

  REP(i, t) {
    int n;
    cin >> n;

    ll sum = 0;
    int c = 0;
    priority_queue<P> que2;
    priority_queue<P, vector<P>, greater<P>> que;

    REP(j, n) {
      int r, a, b;
      cin >> r >> a >> b;
      int d = min(a, b);

      sum += d;
      if(a > b) {
        que.push(P(r, a - b));
        c++;
      } else {
        que2.push(P(r, b - a));
      }
    }

    priority_queue<int,vector<int>, greater<int>> que3;
    int l = 0;
    FOR(j, 0, c) {
      P p = que.top(); que.pop();
      if(p.first >= l + 1) {
        sum += p.second;
        que3.push(p.second);
        l++;
      } else if(!que3.empty()){
        int h = que3.top();
        if(h < p.second) {
          que3.pop();
          sum -= h;
          sum += p.second;
          que3.push(p.second);
        }
      }
    }

    priority_queue<int,vector<int>, greater<int>> que4;
    l = 0;
    for(int j = n; j > c; j--) {
      P p = que2.top(); que2.pop();
      if(p.first < n - l) {
        sum += p.second;
        que4.push(p.second);
        l++;
      } else if(!que4.empty()){
        int h = que4.top();
        if(h < p.second) {
          que4.pop();
          sum -= h;
          sum += p.second;
          que4.push(p.second);
        }
      }
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 6212
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

map<string, int> S;

int main() {
	string tmp, x;
	int N, max = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> tmp;
		S[tmp]++;
	}


	for (const auto& x : S) {
		if (x.second > max) {
			max = x.second;
		}
	}

	for (auto it = S.begin(); it != S.end(); it++) {
		if (it->second == max) {
			cout << it->first << "\n";
		}
	}

	return 0;
}


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

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

    std::vector<std::string> dict(n);
    std::vector<std::string> s(n);
    for(int i = 0; i < n; ++i){
        std::cin >> s.at(i);
        dict.at(i) = s.at(i);
    }

    int m;
    std::cin >> m;
    std::vector<std::string> t(m);
    for(int i = 0; i < m; ++i){
        std::cin >> t.at(i);
        dict.push_back(t.at(i));
    }

    std::sort(dict.begin(), dict.end());
    dict.erase(std::unique(dict.begin(), dict.end()), dict.end());

    std::vector<int> scores(dict.size(), 0);
    for(int i = 0; i < dict.size(); ++i){
        scores.at(i) += std::count(s.begin(), s.end(), dict.at(i));
        scores.at(i) -= std::count(t.begin(), t.end(), dict.at(i));
    }

    int ans = *std::max_element(scores.begin(), scores.end());
    if(ans > 0){
        std::cout << ans << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
a = input().split()

S = deque()

for i in range(n):
    if (i % 2 == 1):
        S.append(a[i])
    else:
        S.appendleft(a[i])
    
if (n % 2 == 0):
    S.reverse()

print(" ".join(S))



Measured memory_bytes: 26568
S = str(input())
T = str(input())
Snagasa = len(S)
Tnagasa = len(T)
saisyuicchi = 0
for i in range (Snagasa-Tnagasa+1):
 icchi = 0
 for j in range (Tnagasa):
  if S[i+j] == T[j]:
   icchi = icchi + 1
  else:
   icchi = icchi
 if icchi > saisyuicchi:
  saisyuicchi = icchi
ans = Tnagasa - saisyuicchi
print (ans)

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

int main() {
    string S;
    cin >> S;
    vector<int> total_numbers(S.size(), 0);
    int right_odd = 0;
    int right_even = 0;
    char previous_right = 'R';
    for (int i = 1; i < S.size(); i++) {
        if (previous_right == 'R'){
            swap(right_even, right_odd);
            right_odd++;
            if (S.at(i) == 'L'){
                total_numbers.at(i-1) += right_odd;
                total_numbers.at(i) += right_even;
                right_even = 0;
                right_odd = 0;
            }
        }
        previous_right = S.at(i);
    }
    int left_odd = 0;
    int left_even = 0;
    char previous_left = 'L';
    for (int i = S.size() - 2; i >= 0; i--) {
        if (previous_left == 'L'){
            swap(left_even, left_odd);
            left_odd++;
            if (S.at(i) == 'R'){
                total_numbers.at(i+1) += left_odd;
                total_numbers.at(i) += left_even;
                left_even = 0;
                left_odd = 0;
            }
        }
        previous_left = S.at(i);
    }

    for (int i = 0; i < S.size(); i++) {
        cout << total_numbers.at(i);
        if (i == S.size() - 1){
            cout << endl;
        }else{
            cout << " ";
        }
    }

}


Measured memory_bytes: 1024
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let h_size: u32 = iter.next().unwrap().parse().unwrap();
    let w_size: u32 = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let h: u32 = iter.next().unwrap().parse().unwrap();
    let w: u32 = iter.next().unwrap().parse().unwrap();

    println!("{}", h_size*w_size - h*w_size - w*(h_size-h));
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


typedef pair<int, int> p;

int main(){
  int n, m;
  scanf("%d %d", &n, &m);

  vector<p> v(m);
  REP (i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[i] = make_pair(b, a);
  }

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

  vector<bool> done(n + 1, false);

  int ans = 0;
  REP (i, m) {
    int r = v[i].first;
    int l = v[i].second;
    bool flag = true;
    FOR (j, l, r) {
      if (done[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      done[r - 1] = true;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<cmath>
using namespace std;
int n;
int w[1000];
int main(){
    cin >> n;
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> w[i];
        sum += w[i];
    }
    int min = 1000000;
    for(int i=0;i<(n-1);i++){
        sum -= 2*w[i];
        if(abs(sum) < min){
            min = abs(sum);
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256