akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * e.cc: 
 */

#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 = 200000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];

/* subroutines */

int countle(int n, int x) {
  int c = 0;
  for (int i = 0; i < n; i++)
    if (as[i] <= x) c++;
  return c;
}

int countge(int n, int x) {
  int c = 0;
  for (int i = 0; i < n; i++)
    if (x <= bs[i]) c++;
  return c;
}

/* main */

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

  int mina = INF, maxb = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", as + i, bs + i);
    if (mina > as[i]) mina = as[i];
    if (maxb < bs[i]) maxb = bs[i];
  }
  int h = (n + 1) / 2;
  //printf("mina=%d, maxb=%d, h=%d\n", mina, maxb, h);

  if (n & 1) {
    int l0 = mina - 1, l1 = maxb;
    while (l0 + 1 < l1) {
      int l = (l0 + l1) / 2;
      if (countle(n, l) >= h) l1 = l;
      else l0 = l;
    }

    int r0 = mina, r1 = maxb + 1;
    while (r0 + 1 < r1) {
      int r = (r0 + r1) / 2;
      if (countge(n, r) >= h) r0 = r;
      else r1 = r;
    }
    printf("%d\n", r0 - l1 + 1);
  }
  else {
    int l0 = mina - 1, l1 = maxb;
    while (l0 + 1 < l1) {
      int l = (l0 + l1) / 2;
      if (countle(n, l) >= h) l1 = l;
      else l0 = l;
    }

    int l2 = mina, l3 = maxb + 1;
    while (l2 + 1 < l3) {
      int l = (l2 + l3) / 2;
      if (countge(n, l) > h) l2 = l;
      else l3 = l;
    }

    int r0 = mina, r1 = maxb + 1;
    while (r0 + 1 < r1) {
      int r = (r0 + r1) / 2;
      if (countge(n, r) >= h) r0 = r;
      else r1 = r;
    }

    int r2 = mina - 1, r3 = maxb;
    while (r2 + 1 < r3) {
      int r = (r2 + r3) / 2;
      if (countle(n, r) > h) r3 = r;
      else r2 = r;
    }
    printf("%d\n", (l2 + r0) - (l1 + r3) + 1);
    //printf("l1=%d,l2=%d r3=%d,r0=%d\n", l1, l2, r3, r0);
  }
  return 0;
}


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

using namespace std;

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  
  if(k>=s.size()){
    cout << s << endl;
    return 0;
  }else{
    string sk;
    sk=s.substr(0,k);
    cout << sk << "..." << endl;
  }
  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b && b == c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	string s;
	cin >> n >> s;

	// '('は足りなくなったらその時点で左に加える
	// ')'は最終的に足りなかったら最後に全部右に加える
	// 辞書順も上記でクリア

	int l = 0;
	int r = 0;
	int cnt = 0;
	rep(i,n){
		char c = s[i];
		if(cnt == 0 && c == ')'){
			l++;
		}else{
			cnt += c == '(' ? 1 : -1;
		}
	}

	r = cnt;

	rep(i,l) cout << '(';
	cout << s;
	rep(i,r) cout << ')';
	cout << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
all_dish = []

for n in range(N):
    K_n_list = list(map(int, input().split()))
    del K_n_list[0]
    for K_n_list_num in K_n_list:
        all_dish.append(K_n_list_num)

prefer_dish = []
dish_kind = list(set(all_dish))
for dish_kind_num in dish_kind:
    if all_dish.count(dish_kind_num) == N:
        prefer_dish.append(dish_kind_num)

print(len(prefer_dish))

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

int main( )
{
    string o, e;
    char ans[111];
    int i, j, k, lo, le;
    cin >> o >> e;
    lo = (int) o.size();
    le = (int) e.size();
    for (i = 0; i < lo; i++) {
        ans[2 * i] = o[i];
    }
    for (i = 0; i < le; i++) {
        ans[2 * i + 1] = e[i];
    }
    ans[lo + le] = '\0';
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

const ll DT = 24 * 60 * 60 + 1;

ll f(const string &str) {
    ll h = atoi(str.substr(0, 2).c_str());
    ll m = atoi(str.substr(3, 2).c_str());
    ll s = atoi(str.substr(6, 2).c_str());
    return h * 60 * 60 + m * 60 + s;
}

void solve(ll n) {
    vector<string> st(n), en(n);
    rep(i, n) cin >> st[i] >> en[i];
    vector<ll> dp(DT + 1, 0);
    rep(i, n) {
        dp[f(st[i])]++;
        dp[f(en[i])]--;
    }
    ll ans = dp[0];
    rep(i, DT) {
        dp[i + 1] += dp[i];
        ans = max(ans, dp[i + 1]);
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    while(true) {
        ll n;
        cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}



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

long long cnt[100005];

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

    memset(cnt, 0, sizeof(cnt));
    long long sum = 0;
    for(int i = 0; i < N; i ++){
        int x;
        scanf("%d", &x);
        cnt[x] ++;
        sum += x;
    }

    int Q;
    scanf("%d", &Q);

    while(Q --){
        int a, b;
        scanf("%d%d", &a, &b);
        sum -= cnt[a]*a;
        sum += cnt[a]*b;
        cnt[b] += cnt[a];
        cnt[a] = 0;
        printf("%lld\n", sum);
    }
}


Measured memory_bytes: 4600
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int N;
	std::string s;
	cin >> N;
	double res = 0.0;
	for (int n = 0; n < N; n++) {
		double d;
		cin >> d >> s;
		if (s[0] == 'J') {
			res += d;
		}
		else {
			res += d * 380000.0;
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int check[maxn];
int main(){
	n=read();
	check[0]=1;
	int ans=0;
	for(register int i=1;i<=n;i++){
		int x=read();
		if(check[x-1]){check[x]=1;ans=max(ans,x);}
	}
	if(ans==0)puts("-1");
	else printf("%d\n",n-ans);
	return 0;
}

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

int main(){
    long double a;
    long double b;
    cin >> a >> b;
    cout << (ll)(a * b) << endl;
    // ll b2 = b*100;
    // ll res = a * b2 / 100;
    // cout << res << endl;
    return 0;
}

Measured memory_bytes: 3676
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var input = fs.readFileSync("/dev/stdin", "utf8").split(" ");
var h = +input[0];
var a = +input[1];
console.log(Math.ceil(h / a));
//# sourceMappingURL=a-ServalvsMonster.js.map

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A1,A2,A3; cin>>A1>>A2>>A3;
    int ans=A1+A2+A3;
    if(ans>=22){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }
    return 0;
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);
    
#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

void solve(bool __attribute__((unused)) read) {
    li S;
    cin >> S;
    li x1, y1, x2, y2;
    x1 = 1e9;
    y2 = S / x1;
    li ost = S % x1;
    if (ost == 0) {
        cout << x1 << " " << 0 << " " << 0 << " " << y2 << " 0 0\n";
        return; 
    }
    ++y2;
    ost = x1 - ost;
    x2 = ost;
    y1 = 1;

    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " 0 0\n";
    return;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = Integer.parseInt(in.nextLine());
		String s = in.nextLine();
		String t = in.nextLine();
		in.close();
		int mth = 0;
		for (int i = 0; i < num; i++) {
			if (s.substring(i, num).equals(t.substring(0, num-i))) {
				mth = num - i;
				break;
			}
		}
		System.out.println(num * 2 - mth);
	}

}


Measured memory_bytes: 21844
def solver(x):
    s = 0
    for y in Query:
        if x[y[1]-1]-x[y[0]-1] ==y[2]:
            s+=y[3]
           
    return s
N,M,Q = map(int,input().split())
Query = []
for x in range(Q):
    a,b,c,d = map(int,input().split())
    Query.append([a,b,c,d])
ans = 0
for x1 in range(M):
    for x2 in range(x1,M):
        for x3 in range(x2,M):
            for x4 in range(x3,M):
                for x5 in range(x4,M) :
                    for x6 in range(x5,M):
                        for x7 in range(x6,M):
                            for x8 in range(x7,M):
                                for x9 in range(x8,M):
                                    for xa in range(x9,M):
                                        t = solver([x1,x2,x3,x4,x5,x6,x7,x8,x9,xa])
                                        if ans <t:
                                            ans =t
print(ans)

Measured memory_bytes: 71816
#include<stdio.h>
 
int main() {
  int x, y;
  
  scanf("%d %d", &x, &y);
  
  for (int i = 0; i <= x; i++) {                                                                    
    int j = x - i;
    if (2 * i + 4 * j == y) {
      printf("%s", "Yes\n");
      return 0;
    }
  }
  
  printf("%s", "No\n");
  return 0;
}

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

using namespace std;

int gcd(int a, int b) { // requires a > b
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

  int x;
  cin >> x;
  int g = x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    g = gcd(max(g, x), min(g, x));
  }
  cout << g << endl;

  return 0;
}


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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

const int M = 1e5 + 10;

struct P {
    int b;ll c;
    bool operator < (const P &rhs) const {
        return c > rhs.c;      
    }
} p[M];

int main() {
    int n = read(), m = read();
    priority_queue<ll, vector<ll>, greater<ll> > que;
    for (int i = 0; i < n; i++) {
        int x = read();
        que.push((ll)x);
    }    
    for (int i = 0; i < m; i++) p[i].b = read(), p[i].c = (ll)read();
    sort(p, p + m);
    for (int i = 0; i < m; i++) {
        int b = p[i].b;
        if (p[i].c <= que.top()) break;
        while (b--) {
            if (que.top() < p[i].c) {
                que.pop();
                que.push(p[i].c);
            } else {
                break;
            }
        }
    }
    ll sum = 0;
    while (!que.empty()) {
        int x = que.top(); que.pop();
        sum += x;
    }
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 2676
#include<iostream>
using namespace std;
struct card{char suit,value;};
void bubble(struct card A[],int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>=i+1;j--)
        {
            if(A[j-1].value>A[j].value)
                swap(A[j],A[j-1]);
        }
    }
}
void selection(struct card A[],int n)
{
    int minx;
    for(int i=0;i<n-1;i++)
    {   minx=i;
        for(int j=i;j<n;j++)
        {if(A[j].value<A[minx].value)
            minx=j;}
        swap(A[i],A[minx]);
    }
}
void print(struct card A[],int n)
{
    for(int i=0;i<n;i++)
        {if(i)cout<<" ";
        cout<<A[i].suit<<A[i].value;}
        cout<<endl;
}
bool itstable(struct card c1[],struct card c2[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(c1[i].suit!=c2[i].suit)
            return false;}
    return true;
}
int main()
{
    card c1[100],c2[100];
    int n;
    char ch;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>c1[i].suit>>c1[i].value;
        c2[i]=c1[i];
    }
    bubble(c1,n);
    selection(c2,n);
    print(c1,n);
        cout<<"Stable"<<endl;
    print(c2,n);
    if(itstable(c1,c2,n))
       {cout<<"Stable"<<endl;}
    else {cout<<"Not stable"<<endl;}
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,j,hh,ans,mx,f[500001][2],a[500001];
int main(){
	scanf("%d",&n);
	for(i=0;i<(1<<n);i++){
	 scanf("%d",&a[i]);
	 f[i][0]=a[i];
  }
    mx=1<<n;
    for(i=0;i<n;i++)
     for(j=1;j<mx;j++)if(j&(1<<i)){
     	hh=j^(1<<i);
     	if(f[hh][0]>f[j][0]){
     		if(f[hh][1]>f[j][0])f[j][1]=f[hh][1];
     		 else f[j][1]=f[j][0];
     		f[j][0]=f[hh][0];
		 }
		  else if(f[hh][0]>f[j][1])f[j][1]=f[hh][0];
	 }
	for(i=1;i<mx;i++){
		
		ans=max(ans,f[i][0]+f[i][1]);
		printf("%d\n",ans);
	}
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> node;
};

Vertex V[2005];
bool U[2005];

int main()
{
    ll N, K;
    cin >> N >> K;
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }

    ll min = N;
    REP(i, N)
    {
        //! iから距離K/2となる頂点の数を調べる
        ll k = K / 2;
        ll n = 0;
        {
            memset(U, 0, sizeof(U));
            U[i] = true;
            queue<pll> q;
            q.push(pll(i, 0));
            while (!q.empty())
            {
                pll t = q.front();
                q.pop();
                n++;
                if (t.second >= k)
                    continue;
                REP(j, V[t.first].node.size())
                {
                    int next = V[t.first].node[j];
                    if (U[next])
                        continue;
                    U[next] = true;
                    q.push(pll(next, t.second + 1));
                }
            }
        }

        if (K % 2 == 0)
        {
            min = std::min(min, N - n);
            continue;
        }
        //! 奇数の場合には、隣のノードからk個目の数を調べる
        memset(U, 0, sizeof(U));
        U[i] = true;
        REP(j, V[i].node.size())
        {
            int p = V[i].node[j];
            U[p] = true;
            queue<pll> q;
            q.push(pll(p, 0));
            int m = 0;
            while (!q.empty())
            {
                pll t = q.front();
                q.pop();
                if (t.second == k)
                {
                    m++;
                    continue;
                }
                REP(x, V[t.first].node.size())
                {
                    int next = V[t.first].node[x];
                    if (U[next])
                        continue;
                    U[next] = true;
                    q.push(pll(next, t.second + 1));
                }
            }
            min = std::min(min, N - (n + m));
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
def numalpha(num):
    if num <= 26:
        return chr(64+ num)
    elif num % 26 == 0:
        return numalpha(num // 26-1) + chr(90)
    else:
        return numalpha(num//26) + chr(64 + num % 26)
print(numalpha(n).lower())


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    int N;
    cin >> N;
    map<string, int> M;
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        auto itr = M.find(S);
        if( itr != M.end() ) {
            M[S] += 1;
        } else {
            M[S] = 1;
        }
    }
    int max = 0;
    for(auto itr = M.begin(); itr != M.end(); ++itr){
        if(max < itr->second){
            max = itr->second;
        }
    }
    for(auto itr = M.begin(); itr != M.end(); ++itr){
        if(max == itr->second){
            cout << itr->first << endl;
        }
    }
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mi 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		int a[3]={};
		int k=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='R')
				a[k]++;
			else
				k++;
		}
		sort(a,a+3);
		cout<<a[2]<<"\n";
	}  
	return 0;
}

Measured memory_bytes: 3632
def examC():
    N = I()
    A = [0]*N; B = [0]*N
    for i in range(N):
        A[i], B[i] = LI()
    taka = 0; aoki = 0
    value = [[i] for i in range(N)]
    for i in range(N):
        cur = A[i]+B[i]
        value[i].append(cur)
    value.sort(key=lambda x:x[1],reverse = True)
#    print(value)
    for i in range(N):
        if i%2==0:
#            print(A[value[i][0]])
            taka += A[value[i][0]]
        else:
#            print(B[value[i][0]])
            aoki += B[value[i][0]]
    ans = taka-aoki
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 61916
import collections
n=int(input())
s=[]
num=[]
ans=[]
for i in range(n):
    s.append(input())
c = collections.Counter(s)
v=(c.most_common())
num=v[0][1]
for j in v:
    if (j[1]==num):
        ans.append(j[0])
    else:
        break
for k in sorted(ans):
	print(k)


Measured memory_bytes: 49208
import java.awt.Point;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        int D = sc.nextInt();
        int[] gridX = new int[H*W+1];
        int[] gridY = new int[H*W+1];
        int x1, y1, x2, y2;
        //Point[] grid = new Point[H*W+1];
        //Point p1, p2;
        int[] dp = new int[H*W+1];
        int k;
        
        for(int i = 1; i <= H; i++)
            for(int j = 1; j <= W; j++){
                k = sc.nextInt();
                //grid[sc.nextInt()] =  new Point(i,j);
                gridX[k] = i;
                gridY[k] = j;
            }
        
        int Q = sc.nextInt();
        int L, R;
        for(int i = 1; i <= D; i++){
            for(int j = i+D; j < dp.length; j+=D){
                //p1 = grid[j];
                //p2 = grid[j+D];
                x1 = gridX[j];
                y1 = gridY[j];
                x2 = gridX[j-D];
                y2 = gridY[j-D];
                //dp[j] = Math.abs(p2.x-p1.x) + Math.abs(p2.y-p1.y);
                dp[j] = Math.abs(x2-x1) + Math.abs(y2-y1);
                if(j > D)
                    dp[j] += dp[j-D];
            }
        }
        
        int res;
        while(Q-- > 0){
            res = 0;
            L = sc.nextInt();
            R = sc.nextInt();
            res = dp[R] - dp[L];
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 95012
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int m, n; cin >> m >> n;
    int sum = 0;
    for(int i = 0; i  < n; i++) {
        int x; cin >> x;
        sum += x;
    }
    if(sum > m) {
        cout << -1;
    }
    else {
        cout << m - sum;
    }
    return 0;
}

Measured memory_bytes: 3636
x1, x2, x3, x4, x5 = map(int,input().split())
if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9172
#include <iostream>
using namespace std;
int main(void){
    int n,t[200000],x[200000],y[200000];
    t[0] = x[0] = y[0] = 0;
    cin >> n;

    for(int i=0;i<n;i++) cin >> t[i+1] >> x[i+1] >> y[i+1];
    
    bool can = true;
    for(int i=0;i<n;i++){
        int dt1 = t[i+1] - t[i];
        int dt2 = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if (dt1 < dt2) can = false;
        if (dt1%2 != dt2%2) can = false;
    }
    
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readNM(in.readLine());
		for (; solver.hasNextLink();)
			solver.readLink(in.readLine());
		solver.readQ(in.readLine());
		for (; solver.hasNextPaint();)
			solver.readPaint(in.readLine());
		solver.solve();
	}
}

class Solver {

	Vertex[] Vertexes;

	class Vertex {
		int Idx;
		int[] Color;
		ArrayList<Integer> Link;

		Vertex(int i) {
			Idx = i;
			Color = new int[11];
			Link = new ArrayList<Integer>();
		}

		void AddLink(int v) {
			Link.add(v);
		}

		void Paint(int d, int c) {
			if (Color[d] != 0)
				return;
			// System.out.println(Idx + " " + d + " " + c);
			Color[d] = c;
			if (d > 0) {
				Vertexes[Idx].Paint(d - 1, c);
				for (int next : Link) {
					Vertexes[next].Paint(d - 1, c);
				}
			}
		}
	}

	int N;
	int M;
	int Q;
	int cntM;
	int cntQ;

	public void init() {
		N = 0;
		M = 0;
		Q = 0;
		cntM = 0;
		cntQ = 0;
	}

	public void readNM(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		M = Integer.parseInt(strArr[1]);
		Vertexes = new Vertex[N + 1];
		for (int i = 1; i <= N; i++)
			Vertexes[i] = new Vertex(i);
	}

	public boolean hasNextLink() {
		return cntM < M;
	}

	public void readLink(String str) {
		String[] strArr = str.split(" ");
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		Vertexes[a].AddLink(b);
		Vertexes[b].AddLink(a);
		cntM++;
	}

	int[] V;
	int[] D;
	int[] C;

	public void readQ(String str) {
		Q = Integer.parseInt(str);
		V = new int[Q];
		D = new int[Q];
		C = new int[Q];
	}

	public boolean hasNextPaint() {
		return cntQ < Q;
	}

	public void readPaint(String str) {
		String[] strArr = str.split(" ");
		V[cntQ] = Integer.parseInt(strArr[0]);
		D[cntQ] = Integer.parseInt(strArr[1]);
		C[cntQ] = Integer.parseInt(strArr[2]);
		cntQ++;
	}

	public void solve() {
		for (int i = Q - 1; i >= 0; i--) {
			// System.out.println(V[i] + " " + D[i] + " " + C[i]);
			Vertexes[V[i]].Paint(D[i], C[i]);
		}
		for (int i = 1; i <= N; i++)
			System.out.println(Vertexes[i].Color[0]);
	}
}


Measured memory_bytes: 87848
import sys
x,n=map(int,input().split())

if n == 0:
    print(x)
    sys.exit()

plist=list(map(int,input().split()))

if not x in plist:
    print(x)
    sys.exit()

for i in range(1,102):
    if not x-i in plist:
        print(x-i)
        sys.exit()
    elif not x+i in plist:
        print(x+i)
        sys.exit()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	int digit[6];
	memset(digit, -1, sizeof(digit));
	while (M--) {
		int a, b; cin >> a >> b;
		if (digit[a] != -1 && digit[a] != b) {
			cout << -1 << '\n';
			return 0;
		}
		digit[a] = b;
	}
	if (digit[1] == -1) {
		if (N != 1) digit[1] = 1;
		else digit[1] = 0;
	}
	for (int i = 2; i <= N; i++) if (digit[i] == -1) digit[i] = 0;

	if (N != 1 && digit[1] == 0) cout << -1 << '\n';
	else for (int i = 1; i <= N; i++) cout << digit[i];

	return 0;
}

Measured memory_bytes: 3616
N, A, B = map(int, input().split())
S = str(input())

countA = 0
countB = 0
count = 0

for i in range(N):
    if S[i] == 'a' and count < A + B:
        countA += 1
        count += 1
        print('Yes')
    elif S[i] =='b' and count < A + B:
        if countB < B:
            countB += 1
            count += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4016
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
char s[55][55];
int a,b,x[55][55];
const int dx[9]={0,1, 1,1, 0,0,-1,-1,-1};
const int dy[9]={0,1,-1,0,-1,1, 1, 0,-1};
int F(int q,int w)
{
	int sum=0;
	for(int i=1;i<=8;i++)if(x[dx[i]+q][dy[i]+w]==-1)sum++;
	return sum;
}
int main()
{
	scanf("%d%d\n",&a,&b);
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			s[i][j]=getchar();
			if(s[i][j]=='#')x[i][j]=-1;
		}
		char ch=getchar();
	}
	for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++)
			if(x[i][j]!=-1)x[i][j]=F(i,j);
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)putchar(x[i][j]==-1?'#':(x[i][j]+48));
		putchar('\n');
	}
	return 0;
}

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

using namespace std;
int main(){
    int N , K;
    cin >> N >> K;
    long i,j,k;
    if(K % 2 != 0){
        i = N / K;
        cout << i * i * i << endl;
    }else{
        k = K / 2;
        i = N / K;
        j = (N / k) - i;
        cout << i * i * i + j * j * j << endl;
    }
}

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

N = int(input())
points = [0] * N
rx = []
ry = []
for i in range(N):
    x, y = map(int, input().split())
    rx.append(x - y)
    ry.append(x + y)
xm = max(rx)
xn = min(rx)
ym = max(ry)
yn = min(ry)
ans = max(max(xm - x, x - xn, ym - y, y - yn) for x, y in zip(rx, ry))
print(ans)




Measured memory_bytes: 90356
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a<=5)
	{
		cout<<'0'<<endl;
	}
	else if(a<=12)
	{
		cout<<b/2<<endl;
	}
	else
	{
		cout<<b<<endl;
	}
}

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

int n;
int p[5010];
int q[5010];

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

	int ans = 1e9+7;
	for(int i=0; i<4; ++i){
		int tmp = i;
		for(int i=0; i<n; ++i) q[i] = p[i];
		q[0] -= i;
		for(int j=0; j<n-1; ++j){
			if(q[j] > 0){
				tmp += q[j] * 2;
				q[j+1] -= q[j];
			}
		}
		if(q[n-1] > 0) tmp += q[n-1];
		ans = min(ans, tmp);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2800
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO.Pipes;

public class HelloWorld
{
    static public void Main()
    {
        //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = long.Parse(Console.ReadLine());
        var A = new long[N];
        var C = new long[N];
        
        for (int i = 0; i < N; i++)
        {
            A[i] = C[i] = long.Parse(Console.ReadLine());
        }
        Array.Sort(C);
        var B = C.ToList();
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            var num = A[i];
            var Kth = B.BinarySearch(num);
            if((Kth - i +1)%2 == 0)
            {
                ans++;
            }
        }
        Console.WriteLine(ans - (ans/2));
    }
}


Measured memory_bytes: 34484
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}	 
	int min=0,max=0;
	int b[9]={0};
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++){
		if(a[i]>=1&&a[i]<=399){
			b[0]++;
		}else if(a[i]>=400&&a[i]<=799){
			b[1]++;
		}else if(a[i]>=800&&a[i]<=1199){
			b[2]++;
		}else if(a[i]>=1200&&a[i]<=1599){
			b[3]++;
		}else if(a[i]>=1600&&a[i]<=1999){
			b[4]++;
		}else if(a[i]>=2000&&a[i]<=2399){
			b[5]++;
		}else if(a[i]>=2400&&a[i]<=2799){
			b[6]++;
		}else if(a[i]>=2800&&a[i]<=3199){
			b[7]++;
		}else{
			b[8]++;
		}
	}
	for(int i=0;i<8;i++){
		if(b[i]!=0){
			min++;
		}
	}
	if(min==0){
		cout<<1<<" "<<b[8]<<endl;
	}else{
		cout<<min<<" "<<min+b[8]<<endl;
	}
	
    return 0;
}

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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};

typedef vector<P> G;

double area2(G& p) {
    double A = 0;
    for (int i = 0; i < p.size(); ++i)
        A += cross(p[i], p[(i+1)%p.size()]);
    return A;
}

int main(){
    G g;
    double n, m;
    while(scanf("%lf,%lf", &n, &m) != EOF){g.push_back(P(n, m));}
    printf("%lf\n", abs(area2(g)/2.));
}

Measured memory_bytes: 1240
import heapq

def dijkstra(s):
    inf = pow(10, 10)
    dist = [inf] * (n + 2)
    dist[s] = 0
    c = [0] * (n + 2)
    p = []
    heapq.heapify(p)
    heapq.heappush(p, (dist[s], s))
    while p:
        d, u = heapq.heappop(p)
        if dist[u] < d:
            continue
        c[u] = 1
        for g in G[u]:
            if c[g[0]] == 0 and dist[u] + g[1] < dist[g[0]]:
                dist[g[0]] = dist[u] + g[1]
                heapq.heappush(p, (dist[g[0]], g[0]))
    return dist[n + 1]

xs, ys, xt, yt = map(int, input().split())
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
s.insert(0, [xs, ys, 0])
s.append([xt, yt, 0])
G = [[] for _ in range(n + 2)]
for i in range(n + 2):
    for j in range(n + 2):
        if not i == j:
            G[i].append([j, max(0, (pow(s[i][0] - s[j][0], 2) + pow(s[i][1] - s[j][1], 2)) ** (1 / 2) - s[i][2] - s[j][2])])
ans = dijkstra(0)
print(ans)

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

int main() {
  
  int N;
  cin >> N;
  
  int D1, D2;
  int dou = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> D1 >> D2;
    if (D1 == D2) {
      dou++;
    }
    else {
      dou = 0;
    }
    if (dou >=3) {
      cout << "Yes" << endl;
      goto jail;
    }
  }
  
  cout << "No" << endl;
  
  jail:
  

return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define fs first
#define sc second

int main(){
	int n,m;
	while(cin>>n>>m){
		vector<pii> ud(n,pii(0,0));
		vector<pii> xy(m);
		rep(i,m) cin>>xy[i].fs>>xy[i].sc;
		sort(all(xy));
		for(auto p:xy){
			int i=p.sc;
			ud[i-1].sc=max(ud[i-1].sc,ud[i].sc+1);
			ud[i].fs=max(ud[i].fs,ud[i-1].fs+1);
		}
		rep(i,n){
			cout<<ud[i].fs+ud[i].sc+1;
			if(i+1==n) cout<<endl;
			else cout<<" ";
		}
	}
	return 0;
}



Measured memory_bytes: 5204
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll D[100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> D[i];
    ll tol = 0;
    ll crt = 0;
    for (int i = 0;i < N;i++) {
    	tol += abs(D[i] - crt);
    	crt = D[i];
    }
    tol += abs(crt);
    cout << tol + abs(D[1]) - abs(D[0]) - abs(D[1] - D[0]) << endl;
    for (int i = 1;i < N - 1;i++) {
    	ll d = abs(D[i + 1] - D[i - 1]) - abs(D[i + 1] - D[i]) - abs(D[i] - D[i - 1]);
    	cout << tol + d << endl;
    }
    cout << tol + abs(D[N - 2]) - abs(D[N - 1]) - abs(D[N - 1] - D[N - 2]) << endl; 
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a == b) {
			cout << "Draw" << endl;
		}
	if (a == 1)
	{
		if (a < b) {
			cout << "Alice" << endl;
		}
	}
	if (b == 1) {
		if (a > b) {
			cout << "Bob" << endl;
		}
	}
	if (a != 1 && b != 1) {
		if (a > b) {
			cout << "Alice" << endl;
		}
		if (a < b) {
			cout << "Bob" << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<limits>
#include<string>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
const static ll MOD = 1e9 + 7;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

ll divceil(ll N, ll x) {
    if (N % x == 0) {
        return N / x;
    }
    else {
        return N / x + 1;
    }
}
int main() {
    ll N; cin >> N;
    vector<pair<ll, ll>> vec(6);
    for (int i = 0; i < 5; i++) {
        cin >> vec[i+1].first;
    }
    vec[0] = { ll_INF,0 };
    for (int i = 0; i < 5; i++) {
        if (vec[i + 1].first >= vec[i].first) {
            vec[i + 1].second = vec[i].second + 1;
            vec[i + 1].first = vec[i].first;
        }
        else {
            ll zero = 0;
            vec[i + 1].second = vec[i].second + 1 + max(zero, divceil(N, vec[i + 1].first) - divceil(N, vec[i].first));
        }
    }

    cout << vec[5].second << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;
ll s=0;
while(m--)
{
	ll x;
	cin>>x;
	s+=x;
}
if(s>n)ol("-1");
else ol(n-s);
return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))

using namespace std;


int main(){
	int n,m;
	while(cin>>n>>m&&(n||m)){
		int t=1000,h=1000;
		int sumt=0,sumh=0;
		int taro[101],hanako[101];
		REP(i,0,n){
			cin>>taro[i];
			sumt+=taro[i];
		}
		REP(i,0,m){
			cin>>hanako[i];
			sumh+=hanako[i];
		}

		REP(i,0,n){
			REP(j,0,m){
				if(2*(taro[i]-hanako[j])==sumt-sumh){
					if(t+h>taro[i]+hanako[j]){
						t=taro[i];
						h=hanako[j];
					}
				}
			}
		}
		if(t==1000) cout<<"-1"<<endl;
		else cout<<t<<" "<<h<<endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: u64 = sc.cin();
    if n % 2 == 1 {
        put!(0);
    } else {
        let mut f5: u64 = n / 10;
        let mut m = n / 10;
        while m > 0 {
            f5 += m / 5;
            m /= 5;
        }
        put!(f5);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a + 3,greater<>());
    cout << a[0] * 10 + a[1] + a[2] << endl;
    return 0;
}

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

amaris = [N//K] * K
for i in range(N%K +1):
  amaris[i] += 1
amaris[0] -= 1

if K%2 == 1:
  print(amaris[0]**3)
else:
  print(amaris[0]**3 + amaris[K//2]**3)


Measured memory_bytes: 4596
S = input()
Stack = []
for i in range(len(S)):
  if S[i] == "S":
    Stack.append("S")
  elif S[i] == "T" and len(Stack) == 0:
    Stack.append("T")
  elif S[i] == "T" and Stack[-1] == "T":
    Stack.append("T")
  elif S[i] == "T" and Stack[-1] == "S":
    Stack.pop()
print(len(Stack))
    

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

int main() {
    int N,flag = 0;
    int A = 0;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
      if (vec.at(i) % 2 == 0) {
        if (vec.at(i) % 3 == 0) A=1;
        else if (vec.at(i) % 5 == 0) A=1;
        else flag = 1;
      }
      
    }
    
   if(flag) cout << "DENIED" << endl;
   else cout <<"APPROVED" << endl;
}

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

int main() {
	double l;
	cin >> l;
	
	double ans = (l/3.0)*(l/3.0)*(l/3.0);
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = 0
for i, a in enumerate(A):
    m += B[a-1]
    if i > 0:
        if A[i-1] + 1 == A[i]:
            m += C[a-2]
print(m)

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

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.7f\n", ans); 相対誤差

int main() {
  int n,k,num;
  cin >> n >> k;
  int cnt = 0;

  rep(i,n) {
    cin>>num;
    if (num >= k) cnt+=1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 888
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    long N;
    cin >> N;

    vector<long> As = {};
    for (long i=0; i < N; i++){
        long a = 0;
        cin >> a;
        As.push_back(a);
    }
    
    long ans = 0;
    long expect = 1;
    for (long i=0; i < N; i++) {
        if (As.at(i) == expect) {
            expect++;
        } else {
            ans++;
        }
    }
    if (expect == 1) {
        ans = -1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include<cmath>
using namespace std;
long long a,b;

int main()
{

    cin>>a>>b;
                                 if(a>0 && b>0)
       {
            if(a>b)
            cout<<abs(a-b)+2;
           else
           if(a<b)
           cout<<b-a;

       }

    else
      if(a+b==0)
        cout<<1;
    else
                                if(a>0&&b<0||a<0&& b>0)
    {
        if((a+b)>0)
            cout<<a+b+1;
        else
            if((a+b)<0)
            cout<<abs(a+b)+1;

    }
    else
                                                if(a<0&&b<0)
    {

        if(a>b)
            cout<<a-b+2;
        else
            if(a<b)
                cout<<abs(a-b);


    }
    else
    if(a==b)
    cout<<0;
    else
        if(a==0)

    {
       if(b>0)
        cout<<b;
       else
        if(b<0)
        cout<<abs(b)+1;
    }
    else
        if(b==0)
    {
        if(a>0)
            cout<<a+1;
        else
            if(a<0)
            cout<<abs(a);

    }



}


Measured memory_bytes: 256
n,m,k=map(int,input().split())
board=[list(input()) for _ in range(n)]
cnt=[0]*n
for i in range(n):
  tmp=0
  for j in range(m):
    if board[i][j]=='#':
      tmp+=1
  cnt[i]=tmp
ans=[[0]*m for _ in range(n)]
num=1
for i in range(n):
  if cnt[i]==0:
    continue
  tmp=0
  for j in range(m):
    ans[i][j]=num
    if board[i][j]=='#':
      tmp+=1
      if tmp>=2:
        ans[i][j]+=1
        num+=1
  num+=1
for i in range(1,n):
  if cnt[i]==0:
    for j in range(m):
      ans[i][j]=ans[i-1][j]
for i in range(n-2,-1,-1):
  if cnt[i]==0:
    for j in range(m):
      ans[i][j]=ans[i+1][j]
for i in range(n):
  print(*ans[i])

Measured memory_bytes: 8272
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(B) > sum(A):
    print(-1)
else:
    C = []
    for i, j in zip(A, B):
        C.append(i-j)
    C.sort()
    
    cnt = 0
    s = 0
    for i in C:
        if i < 0:
            cnt += 1
            s += i
        else:
            break
    if s == 0:
        print(0)
    else:
        for i in C[::-1]:
            s += i
            cnt += 1
            if s >= 0:
                print(cnt)
                break

Measured memory_bytes: 18708