akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

N,X = map(int, input().split())
min_req = 0
for i in range(N):
    m = int(input())
    min_req += m
    if i==0:
        m_min = m
    else:
        if m_min > m:
            m_min = m

num = N + ((X - min_req) // m_min)
print(num)

Measured memory_bytes: 9080
import math
A, B, N = map(int, input().split())
ans = []
if B-1<N:
    sahen = math.floor(A*(B-1)//B)
    uhen = math.floor((B-1)//B)
    uhen = uhen*A
    ans.append(sahen-uhen)

sahen = math.floor(A*N//B)
uhen = math.floor(N//B)
uhen = uhen*A
ans.append(sahen-uhen)

print(max(ans))


Measured memory_bytes: 8948
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int t;cin>>t;while(t--)
#define N 100003
#define M 103
#define inf LLONG_MAX
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n,k;
    cin>>n>>k;
    cout<<n-k+1;



    return 0;
}


Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
num1=0
num2=0
num3=0
for i in range(n):
    if p[i]<=a:
        num1+=1
    elif p[i]<=b:
        num2+=1
    else:
        num3+=1
print(min(num1,num2,num3))


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

const int N = 1 << 20;

namespace POLY {
    const int mo = 998244353;
    const double PI = acos(-1.0);
    int fpm(int x, int y) {
        int ans = 1;
        for (; y > 0; y >>= 1) {
            if (y & 1)
                ans = 1ll * ans * x % mo;
            x = 1ll * x * x % mo;
        }
        return ans;
    }

    int n;
    void init(int _n) {
       n = _n;
       while(n > (n & -n)) n += (n & -n);
    }

    void dft(complex<double> *x, int t) {
        for(int i = 0, j = 0; i < n; ++i) {
            if(i < j) swap(x[i], x[j]);
            for(int l = n >> 1; (j ^= l) < l; l >>= 1);
        }

        for(int l = 1; l < n; l <<= 1) {
            complex <double> wn(cos(t * PI / l), sin(t * PI / l));

            for(int i = 0; i < n; i += (l << 1)) {
                complex <double> w(1, 0);

                for(int j = 0; j < l; ++j) {
                    complex <double> a = x[i + j];
                    complex <double> b = x[i + j + l] * w;

                    w = w * wn;
                    x[i + j] = a + b;
                    x[i + j + l] = a - b;
                }
            }
        }

        if(!~t) {
            for(int i = 0; i < n; ++i) { x[i] = x[i] / (double) n; }
        }
    }
}

const int mo = 2e5 + 3;

int n;
int a[N + 5], _exp[mo + 5], _log[mo + 5];
complex<double> x[N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
#endif

    int t = 1;
    for (int i = 0; i < mo-1; ++i) {
        _log[_exp[i] = t] = i;
        t = 2 * t % mo;
    }

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);

        if (a[i]) x[_log[a[i]]] += 1;
    }

    POLY::init(2 * mo);
    POLY::dft(x, +1);

    for (int i = 0; i < POLY::n; ++i) x[i] = x[i] * x[i];

    POLY::dft(x, -1);

    long long ans = 0;
    for (int i = 1; i <= n; ++i) if (a[i]) x[2 * _log[a[i]]] -= 1;
    for (int i = 0; i < 2 * mo; ++i) {
        ans += 1ll * _exp[i % (mo-1)] * ((long long) std::round(x[i].real()));
    }
    ans/=2;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 14640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000



int main() {
	int n, k, s;
	int a[100];
	int c[100];
	vector<int>b;
	vector<int>d;
	int x, y, z;
	scanf("%d %d", &n, &k);
	f(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	if (n == 1) {
		if (a[0] > 0) {
			printf("1\n1\n");
			return 0;
		}
		else {
			printf("-1\n");
			return 0;
		}
	}
	s = 0;
	f(i, n) {
		if (a[i] < 0) {
			printf("-1\n");
			return 0;
		}
		c[i] = k - a[i];
      if(c[i]<0)c[i]=0;
		s += c[i];
		if ((2 * c[i]) > (k + 1)) {
			printf("-1\n");
			return 0;
		}
	}
	if (s > k) {
		printf("-1\n");
		return 0;
	}
	b.push_back(-1);
	z = -1;
	f(i, k) {
		x = -1;
		y = -1;
		f(j, n) {
			if ((c[j] > y) && (j != z)) {
				x = j;
				y = c[j];
			}
		}
		b.push_back(x);
		if(c[x]>0)c[x]--;
		z = x;
	}
	f(i, k) {
		f(j, n) {
			if ((j != b[i]) && (j != b[i + 1])) {
				d.push_back(j);
			}
		}
		d.push_back(b[i + 1]);
	}
	f(i, n) {
		if (i != b[k])d.push_back(i);
	}
	printf("%d\n", d.size());
	f(i, d.size()) {
		printf("%d", d[i]+1);
		if (i < (d.size() - 1))printf(" ");
		else printf("\n");
	}

	return 0;
}

Measured memory_bytes: 256
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
## math
DIVC = lambda x, y: -(-x//y)
DIVF = lambda x, y: x//y

def main():
    n = II()
    for i in range(8):
        if 2**i > n:
            print(2**(i-1))
            return None

if __name__ == '__main__':
    main()

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

bool compare(tuple<string, int, int>, tuple<string, int, int>);

int main()
{
  int n;
  cin >> n;
  
  string s;
  int p;
  vector<tuple<string, int, int>> t_list(n);
  for (int i = 0; i < n; i++) {
    cin >> s >> p;
    get<0>(t_list.at(i)) = s;
    get<1>(t_list.at(i)) = p;
    get<2>(t_list.at(i)) = i + 1; // 1-origin の番号
  }
  
  sort(t_list.begin(), t_list.end(), compare);
  
  for (tuple<string, int, int> t : t_list) {
    cout << get<2>(t) << endl;
  }
}

bool compare(tuple<string, int, int> left, tuple<string, int, int> right)
{
  if (get<0>(left) != get<0>(right)) {
    return get<0>(left) < get<0>(right);
  }
  
  // 異なる2個に同じ点数がついていることはない
  return get<1>(left) > get<1>(right);
}

Measured memory_bytes: 3496
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (x >= a[i]) {
      x -= a[i];
      ans++;
    }
  }
  if (x == a[n - 1]) {
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define G vector<vll >
#define F first
#define S second
#define pll pair<ll,ll>
#define FOR1(i,a) for(i=0;i<=a;i++)
#define FOR2(i,a,b) for(i=a;i<=b;i++)
#define endl '\n'
#define clr(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
typedef long long ll;


int main()
{
	ll n;cin>>n;
	ll csum=0,dsum=0;
	ll t;
	ll smt=INT_MAX;
	while(n--)
	{
		cin>>t;
		if(t%10&&smt>t)
			smt=t;
		dsum+=t;
	}
	if(!(dsum%10)&&smt!=INT_MAX)
	    cout<<dsum-smt<<endl;
	else if(dsum%10)
		cout<<dsum;
	else
		cout<<'0';
	return 0;
}

Measured memory_bytes: 256
people=int(input())
vector=list(map(int,input().split()))
min_cordination=min(vector)
max_cordination=max(vector)
sum_squared_list=[]
for i in range(min_cordination,max_cordination+1):
  tmp_sum_squared=0
  for one_person in vector:
    tmp_sum_squared+=(i-one_person)**2
  sum_squared_list.append(tmp_sum_squared)
print(min(sum_squared_list))

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int num_bag, num_trk;
llong sum_bag=0;
llong arr[MAX];

int check(llong P){
	int i = 0;
	for(int j = 0; j < num_trk; j++){
		llong s = 0;
		while(s + arr[i] <= P){
			s += arr[i];
			i++;
			if( i == num_bag ) return num_bag;
		}
	}
	return i;
}

int solve(){
	llong left = 0;
	llong right = sum_bag;
	llong mid;
	while(right - left > 1){
		mid = (right + left) /2;
		int v = check(mid);
		if(v == num_bag) right = mid;
		else left = mid;
	}
	return right;
}

int main(){
	cin >> num_bag >> num_trk;
	for(int i = 0; i < num_bag; i++){
		int bag;
		cin >> bag;
		arr[i] = bag;
		sum_bag += bag;
	}
	llong P = solve();
	cout << P << endl;
	return 0;
}



Measured memory_bytes: 3880
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.List (foldl')
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe

modular :: Int
modular = 1000000007

solve :: Int -> B.ByteString -> B.ByteString -> Int
solve !n !s1 !s2 = (\(_,_,acc) -> acc) $ foldl' (\(!pre1,!pre2,!acc) i ->
  let ch1 = s1 `B.index` i; ch2 = s2 `B.index` i in
  if ch1 == pre1  -- skip if letters are same as previous
    then (pre1,pre2,acc)
    else
      if pre1 == pre2 then (ch1,ch2,2 `times` acc)
      else if ch1 == ch2 then (ch1,ch2,acc)
      else (ch1,ch2,3 `times` acc)
  ) (let ch1 = B.head s1; ch2 = B.head s2 in (ch1,ch2,if ch1 == ch2 then 3 else 6)) [1..n-1]
  where
    times !x !y = (x * y) `mod` modular

main = do
  let readInt = fmap (second B.tail) . B.readInt

  Just (n,_) <- readInt <$> B.getLine
  s1 <- B.getLine
  s2 <- B.getLine
  print $ solve n s1 s2


Measured memory_bytes: 380
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int x,a,b;
	cin >> x >> a >> b;

  	if(abs(x-a)<abs(x-b)){
		cout << "A" << endl;
    }else{
		cout << "B" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int nextplayer(char s[3][128], int p[3], int player, int *winner) {
	char temp;
	temp = s[player][p[player]];
	p[player] += 1;

	if(temp == '\n' || temp == '\0') {
		*winner = player;
	}
	if(temp == 'a') {
		return 0;
	} else if(temp == 'b') {
		return 1;
	} else {
		return 2;
	}
}

int main(void) {
	int p[3];
	int winner = -1;
	int player;
	char buf[128], *ch;
	char s[3][128];

	fgets(s[0], sizeof(buf), stdin);//a's card
	fgets(s[1], sizeof(buf), stdin);//b
	fgets(s[2], sizeof(buf), stdin);//c
	p[0] = 0;
	p[1] = 0;
	p[2] = 0;

	player = 0;
	while(winner == -1) {
		player = nextplayer(s, p, player, &winner);
	}

	if(winner == 0) {
		printf("A\n");
	} else if(winner == 1) {
		printf("B\n");
	} else {
		printf("C\n");
	}

	return 0;
}


Measured memory_bytes: 1848
from bisect import bisect_left,bisect_right

N=int(input())
A=list(map(int,input().split()))
C=[0]*N
for i in range(N):
  C[i]=[i+1,A[i],i+1-A[i],A[i]-(i+1),A[i]+(i+1)]
  
#ID/身長/ID-身長/身長-ID/合計
C.sort(key=lambda x:x[4])
D=[C[i][4] for i in range(N)]

#print(C)
cnt=0
for num in C:
  s=bisect_left(D,num[2])
  t=bisect_right(D,num[2])
  #print(num,s,t)
  cnt += t-s
print(cnt)

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

using namespace std;

int main()
{
    string s,t;
    int flg = 0;

    cin>>s>>t;

    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] != t[i])
        {
            flg++;
        }
    }
    cout<<flg;

    cout<<endl;
    return 0;
}

Measured memory_bytes: 3904
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int main(){
	int n;
	ll a,b;
	cin>>n>>a>>b;
  ll h[n];
	REP(i,n)cin >> h[i];
	ll mi=0,ma=1000000000,mid;
	while(ma-mi>1){
		mid=(mi+ma)/2;
		long long int cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>b*mid){
				cnt+=(h[i] - b * mid + a - b - 1) / (a-b);
			}
		}
		if(cnt>mid){
			mi=mid;
		}
		else{
			ma=mid;
		}
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
 
int main(void){
  int A,B;
  if(scanf("%x %x",&A,&B) == 1);
  if(A >=10 && B >=10 && A <= 15 && B <= 15){
    if (A>B)
      printf(">");
    else if (A<B)
      printf("<");
    else
      printf("=");
  }
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  int n, m, p;
  while(cin >> n >> m >> p, n) {
    int sum = 0, mm = 0;
    rep(i, n) {
      int x;
      cin >> x;
      sum += x;
      if (i == m - 1) mm = x;
    }

    if (mm) mm = (sum * (100 - p)) / mm;
    cout << mm << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;
  string S_without_x;
  for(int i=0; i<S.length(); i++)
    if(!(S[i] == 'x'))
      S_without_x += S[i];

  string S_without_x_copy = S_without_x;
  int ret = 0;
  reverse(S_without_x.begin(), S_without_x.end());
  if(!(S_without_x_copy == S_without_x)){
    ret = -1;
  } else {
    int begin = 0, end = S.length()-1;
    while(!(begin >= end)){
      if(S[begin] != 'x' && S[end] != 'x'){
        begin++;
	end--;
      }
      else if(S[begin] == 'x' && S[end] != 'x'){
	begin++;
	ret++;
      }
      else if(S[begin] != 'x' && S[end] == 'x'){
	end--;
	ret++;
      }
      else if(S[begin] == 'x' && S[end] == 'x'){
	begin++;
	end--;
      }
    }
  }

  cout <<  ret << endl;

  return 0;
}


Measured memory_bytes: 640
from collections import Counter

def get_prime_factors(x):
    out = []
    if x < 1:
        return out
    while not x%2:
        out.append(2)
        x //= 2
    i = 3
    while i*i <= x:
        if not x%i:
            out.append(i)
            x //= i
        else:
            i += 2
    if x != 1:
        out.append(x)
    return out
    
def main():
    n = int(input())
    primes = Counter(get_prime_factors(n))
    ans = 0
    for prime, num in primes.items():
        i = 1
        while num >= i:
            ans += 1
            num -= i
            i += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9368
def getDistance( x, y, n, pow )
	dxy = 0
	for i in ( 0 .. n )
		dxy += ( x[i].to_f - y[i].to_f ).abs**pow
	end
	return dxy**(1/pow.to_f)
end
		

n = gets.to_i
x = gets.split( " ").map { |val| val.to_f }
y = gets.split( " ").map { |val| val.to_f }

puts( getDistance( x, y, n, 1 ) )
puts( getDistance( x, y, n, 2 ) )
puts( getDistance( x, y, n, 3 ) )
dxy = []
for i in ( 0 .. n )
	dxy[i] = ( x[i].to_f - y[i].to_f ).abs
end
puts( dxy.max )

Measured memory_bytes: 6204
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll sum = accumulate(all(A), 0LL);
    ll removed = N * (N + 1) / 2;
    if (sum % removed) {
        cout << "NO" << endl;
        return 0;
    }
    ll k = sum / removed;
    ll cnt = 0;
    rep(i, 0, N) {
        ll diff = A[(i + 1) % N] - A[i] - k;
        if (diff < 0) {
            if (diff % N) {
                cout << "NO" << endl;
                return 0;
            }
            else {
                cnt -= diff / N;
            }
        }
        else if (diff > 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (cnt == k) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int max_num = -INF;
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(x == 1) cnt++;
        else cnt = 0;
        max_num = max(cnt, max_num);
    }
    cout << max_num + 1 << endl;
    return 0;
}




Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

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

    string s, t;
    cin >> s >> t;
    t += s;
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> H.at(i);
    }

    sort(H.begin(), H.end());
    ll sum = 0;
    for (ll i = 0; i < N - K; i++)
    {
        sum += H.at(i);
    }

    cout << sum << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdbool.h>
#include<set>
#define N 1000000007
using namespace std;
typedef long long ll;
int num[100001];
int main(void) {
	int n, a, ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a;
		if (a >= 100001)ans++;
		else num[a]++;
	}
	for (int i = 1;i < 100001;i++) {
		if (num[i]!=0&&num[i] > i)ans += num[i] - i;
		if (num[i] != 0 && num[i] < i)ans += num[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#
n = int(input())
dic  = {}
a = [None] * n

for i in range(n):
    c, key, val = (input() + " 0").split()[:3]
    if c == "0":
        dic[key] = val
    elif c== "1":
        a[i] = dic.get(key,0)
    else:
        try:
            del dic[key]
        except KeyError:
            pass

[print(x) for x in a if x is not None]



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int k;
    cin >> k;

    int x = k / 2, y = k - k / 2;
    int ans = x * y;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

fun main (args: Array<String>) {
  val s = Scanner(System.`in`).next()
  var a = ""
  s.forEach { c ->
    if (c == 'B') {
      if (a.length > 0) {
        a = a.substring(0, a.length - 1)
      }
    }
    else a += c
  }
  println(a)
}

Measured memory_bytes: 29476
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> A(n), B(n), C(n - 1);
    for (auto & a : A) {
        cin >> a;
    }
    for (auto & b : B) {
        cin >> b;
    }
    for (auto & c : C) {
        cin >> c;
    }
	int res = 0;
	for (int i = 0; i <= B.size() - 1; i++) {
		res += B[i];
	}
	for(int j = 0; j < n-1; j ++){
		if (A[j] + 1 == A[j + 1]) {
			res += C[A[j] - 1];
		}
	}
    cout << res << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

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

const ll mx = 105;
const ll mod = 998244353;


vector<vector<int>> adj;


void solve(){
     
     ll a, b, n, i, j, k;

     cin>>a>>b>>n;

    ll te = min(b-1, n);
    cout<<(a*te)/b<<"\n";
  
}


int main(){

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

    ll t = 1;
    
   // cin>>t;

    while(t--){
        solve();
    }
   
}




Measured memory_bytes: 3640
#include<stdio.h>

int main()
{
	char S[110000];
	scanf("%s",S);
	int a = 0;
	int b = 0;
	int i;
	for(i=0;S[i]!='\0';i++);
	int L = i;
	for(i=0;i<=L-1;i++){
		if(S[i] == '1') a++;
		else if(S[i] == '0') b++;
	};
	if(a >= b)	printf("%d",2*b);
	else printf("%d",2*a);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}
double getangle(P a, P b){
    return abs(arg(a/b));
}

void inputXY(P &p){
    double x,y;
    cin >> x >> y;
    p = P(x,y);
}

bool in_sector(P s, P g, double w, double d, double a){
    g -= s;
    double wrad = w/180 *PI;
    P dir = rotate(P(1, 0), wrad);
    double drad = (d/2)/180 *PI;
    double angle = getangle(g, dir);
    return abs(g) < a +EPS && -drad < angle +EPS && angle < drad +EPS;
}

int main(){
    while(1){
        int h,r;
        cin >> h >> r;
        if(h==0 && r==0) break;

        VP house(h);
        for(int i=0; i<h; i++) inputXY(house[i]);

        int u,m,s, du,dm,ds;
        cin >> u >> m >> s >> du >> dm >> ds;
        VP pu(u), pm(m), ps(s);
        for(int i=0; i<u; i++) inputXY(pu[i]);
        for(int i=0; i<m; i++) inputXY(pm[i]);
        for(int i=0; i<s; i++) inputXY(ps[i]);
        vector<int> w(r), a(r);
        for(int i=0; i<r; i++) cin >> w[i] >> a[i];
        
        vector<int> reach(h, 0);
        for(int i=0; i<h; i++){
            for(int j=0; j<r; j++){
                if(!in_sector(P(0,0), house[i], w[j], du, a[j])){
                    continue;
                }
                bool only = true;
                for(int k=0; k<u && only; k++){
                    if(in_sector(pu[k], house[i], w[j], du, a[j])){
                        only = false;
                    }
                }
                for(int k=0; k<m && only; k++){
                    if(in_sector(pm[k], house[i], w[j], dm, a[j])){
                        only = false;
                    }
                }
                for(int k=0; k<s && only; k++){
                    if(in_sector(ps[k], house[i], w[j], ds, a[j])){
                        only = false;
                    }
                }
                if(only){
                    reach[i]++;
                }
            }
        }

        int max = *max_element(reach.begin(), reach.end());
        if(max == 0){
            cout << "NA" << endl;
        }else{
            vector<int> ans;
            for(int i=0; i<h; i++){
                if(reach[i] == max){
                    ans.push_back(i+1);
                }
            }
            for(int i=0; i<(int)ans.size()-1; i++){
                cout << ans[i] << " ";
            }
            cout << ans.back() << endl;
        }
    }
    return 0;
}


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

using namespace std;

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

  int N; cin>>N;
  string S; cin>>S;
  vector<vector<int>> dp(N, vector<int>(N, 0));
  for (int i = 1; i < N; i++) {
    if (S[0] == S[i])
      dp[0][i] = 1;
  }
  for (int l = 1; l < N-1; l++) {
    for (int r = l+1; r < N; r++) {
      if (r - dp[l-1][r-1] > l)
        dp[l][r] = dp[l-1][r-1];
      else
        dp[l][r] = 0;
      if (S[l] == S[r]) {
        dp[l][r]++;
      } else {
        dp[l][r] = 0;
      }
    }
  }
  int ans = 0;
  for (auto& v : dp) {
    ans = max(ans, *max_element(v.begin(), v.end()));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 98304
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef long long ll;
 
int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;
using ld = long double;
int const nmax = 500000;
int v[1 + nmax];

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++)
    if(s[i] == '<')
      v[i + 1] = max(v[i + 1], v[i] + 1);
  for(int i = s.size() - 1; 0 <= i; i--)
    if(s[i] == '>')
      v[i] = max(v[i], v[i + 1] + 1);
  ll result = 0;
  for(int i = 0; i <= s.size(); i++)
    result += v[i];

  cout << result;
  return 0;
}


Measured memory_bytes: 2820
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var n = next();
  var s = nexts(n,1);
  var map = {};
  var mx = 1;
  for(var i = 0; i < n; i++){
    var t = s[i];
    if(map[t]){
      map[t]++;
      if(mx < map[t])mx = map[t];
    }else map[t] = 1;
  }
  var ans = [];
  for(var i in map){
    if(map[i] === mx)ans.push(i);
  }
  return ans.sort().join("\n");
}

Measured memory_bytes: 102372
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
typedef long long ll;
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  int A[3][3]={};
  rep(i,3) rep(j,3) cin >> A[i][j];
  int N;
  cin >> N;
  vector<int> b(N);
  rep(i,N) cin >> b[i];

  int map[3][3] = {0};
  rep(i,3){
    rep(j,3){
      rep(k,N){
	if(A[i][j] == b[k]) map[i][j]++;
      }
    }
  }
  
  int ans=0;
  if(map[0][0] && map[0][1] && map[0][2]) ans++;
  else if(map[1][0] && map[1][1] && map[1][2]) ans++;
  else if(map[2][0] && map[2][1] && map[2][2]) ans++;
  else if(map[0][0] && map[1][0] && map[2][0]) ans++;
  else if(map[0][1] && map[1][1] && map[2][1]) ans++;
  else if(map[0][2] && map[1][2] && map[2][2]) ans++;  
  else if(map[0][0] && map[1][1] && map[2][2]) ans++;
  else if(map[0][2] && map[1][1] && map[2][0]) ans++;
  if(ans>0) cout << "Yes" << endl;
  else cout << "No" << endl;  
}


Measured memory_bytes: 256
x = int(input())
if x / 11 < 0:
    if x <= 6:
        print(1)
    else:
        print(2)
else:
    a = x // 11
    b = x % 11
    if b == 0:
        print(2 * a)
    elif b <= 6:
        print(2 * a + 1)
    else:
        print(2 * a + 2)

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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"

#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define tr(c, it) for (auto it = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

const int INF = 9e18;
// const int N = 1e9 + 7;
const int N = 998244353;
const double eps = 1e-9;

const auto start_time = std::chrono::high_resolution_clock::now();

void zark() {
	#ifdef ZARK
		auto end_time = std::chrono::high_resolution_clock::now();
		std::chrono::duration<double> diff = end_time - start_time;
		cerr << "Time Taken: " << diff.count() << "s\n";
	#endif
}

#ifdef ZARK
  #include "/home/aranjan/Desktop/CP/header.h"
  #else
  #define debug(args...) 42
#endif
 
/* ------------------ Actual Coding Starts ------------------ */

void solve() {
	int h1,h2,m1,m2,k;
	cin >> h1>>m1>>h2>>m2>>k;
	int ans = (h2-h1)*60;
	ans += m2-m1;
	cout << ans - k << endl;
}

int32_t main() {
	fastio;
	#ifdef ZARK
		freopen("input.in", "r", stdin);
	#endif

	// freopen("txt.in", "r", stdin);
	// freopen("txt.out", "w", stdout);
	// cout << fixed << setprecision(10);

	solve();
	zark();
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

    public static int minBus(int maxPassenger, int timeLimit, int[] arriveTime) {
        int result = 1;
        int curPassenger = 0;
        Arrays.sort(arriveTime);
        int busTime = arriveTime[arriveTime.length-1];
        for (int i = arriveTime.length-1; i >= 0; i--) {
            if (curPassenger == maxPassenger || arriveTime[i]+timeLimit < busTime) {
                result++;
                busTime = arriveTime[i];
                curPassenger = 0;
            }
            curPassenger++;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int numPassengers = in.nextInt();
        int maxPassenger = in.nextInt();
        int timeLimit = in.nextInt();
        int[] arriveTime = new int[numPassengers];
        for (int i = 0; i < numPassengers; i++) {
            arriveTime[i] = in.nextInt();
        }

        System.out.print(minBus(maxPassenger, timeLimit, arriveTime));
    }
}


Measured memory_bytes: 49948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n ;
    vi d(n);
    rep(i,n) cin >> d[i];
    ll ans=0;
    rep(i,n){
        repk(j,i+1,n){
            ans += d[i]*d[j];
        }
    }
    cout << ans <<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll x;
  cin >> x;
  vector<pair<ll,ll>> v;
  for(ll i = -1000; i<=1000; i++) {
    ll k = i;
    ll m = k*k*k*k*k;
    v.push_back(make_pair(k,m));
  }
  int n = v.size();
  for(ll i = 0; i<n; i++) {
    for(ll j = 0; j<n; j++) {
      if(v[j].second-v[i].second==x) {
        cout << v[j].first << " " << v[i].first << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

void chmax(int& a, int b) {
	if (a < b) {
		a = b;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<vector<ll>> dp(n + 1, vector<ll>(2));
	dp[0][1] = -inf;
	rep(i, n) {
		dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
		dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
	}
	cout << dp[n][0] << endl;
	return 0;
}


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

int main() {
  
  int x; cin>>x;
  string s; cin >> s;
  
  int w = 0;
  int e = 0;
  for(int i=0; i<s.size(); i++){
    if (s.at(i) == 'E') e++;
  }
  
  int m = s.size();
  for(int i=0; i<s.size(); i++){
    
    if (s.at(i) == 'E') e--;
    
    int c = e + w;
    if (c < m) m = c;
    
    if(s.at(i) == 'W') w++;
    
  }  
  
  cout << m << endl;

}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; i++) cin >> l[i];
  sort(l.begin(),l.end());
  int sum = 0;
  for (int i = N - K; i < N; i++) sum += l[i];
  cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int ans = 0;
        bool ok = false;
        int a[n];
        for(int i = 0; n > i; i++){
            cin>>a[i];
            if(a[i] > 0)ans++;
            if(a[i] > 1)ok = true;
        }
        if(ok)cout << ans+1 << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 3132
import java.util.*;
class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),cn=n;
		int rn=0;
		while(cn!=0) {
			rn*=10;
			rn+=cn%10;
			cn/=10;
		}
		System.out.println(rn==n?"Yes":"No");
	}
}

Measured memory_bytes: 21844
n = int(input())
p = list(map(int,input().split()))

p_sort = sorted(p)

cnt = 0

for i in range(n):
    if p_sort[i] != p[i]:
        cnt += 1
    else:
        pass
    
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	vector<int> d(n);
	rep(i, n) cin >> d[i];

	sort(ALL(d));

	int count = 0;
	for (int i = 1; i <= 100000; i++)
	{
		if (lower_bound(ALL(d), i) - d.begin() == d.size() / 2) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main(){
	string s;
	while(getline(cin, s)){
		if(s == ".") break;
		stack<char> st;
		for(int i = 0;i < s.length();++i){
			if(s[i] == '(' || s[i] == '[') st.push(s[i]);
			else if(s[i] == ')') {
				if(st.size() && st.top() == '(') st.pop();
				else { 
					st.push(s[i]); 
					break; 
				}
			}
			else if(s[i] == ']') {
				if(st.size() && st.top() == '[') st.pop();
				else{
					st.push(s[i]); 
					break; 
				}
			}
		}
		if(!st.size()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, m, k, r1, c1, r2, c2, bl[N], best[N], ur[N], uc[N];
set<int> rr[N], cc[N];

struct T {
  int r;
  int c;
};

queue<T> q;

void know(int i, int j) {
  rr[i].erase(j);
  cc[j].erase(i);
  q.push({i, j});
}

bool oker(int r, int c1, int c2) {
  return uc[r * m + c1] > c2;
}

bool okec(int c, int r1, int r2) {
  return ur[r1 * m + c] > r2;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k >> r1 >> c1 >> r2 >> c2;
  r1--;
  c1--;
  r2--;
  c2--;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] != '.') {
        bl[i * m + j] = 1;
      } else {
        rr[i].insert(j);
        cc[j].insert(i);
      }
      best[i * m + j] = (int) 1e9;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (bl[i * m + j] == 0) {
        if (i == n - 1) ur[i * m + j] = n; else ur[i * m + j] = ur[(i + 1) * m + j];
        if (j == m - 1) uc[i * m + j] = m; else uc[i * m + j] = uc[i * m + j + 1];
      } else {
        ur[i * m + j] = i;
        uc[i * m + j] = j;
      }
    }
  }
  best[r1 * m + c1] = 0;
  know(r1, c1);
  while (!q.empty()) {
    auto it = q.front();
    q.pop();
    int r = it.r, c = it.c;
    while (!rr[r].empty()) {
      auto it = rr[r].lower_bound(c);
      if (it == rr[r].end() || *it - c > k || !oker(r, c, *it)) {
        break;
      }
      best[r * m + *it] = best[r * m + c] + 1;
      know(r, *it);
    }
    while (!rr[r].empty()) {
      auto it = rr[r].lower_bound(c);
      if (it == rr[r].begin()) break;
      it--;
      if (c - *it > k) break;
      if (!oker(r, *it, c)) break;
      best[r * m + *it] = best[r * m + c] + 1;
      know(r, *it);
    }
    while (!cc[c].empty()) {
      auto it = cc[c].lower_bound(r);
      if (it == cc[c].end() || *it - r > k || !okec(c, r, *it)) {
        break;
      }
      best[*it * m + c] = best[r * m + c] + 1;
      know(*it, c);
    }
    while (!cc[c].empty()) {
      auto it = cc[c].lower_bound(r);
      if (it == cc[c].begin()) break;
      it--;
      if (r - *it > k) break;
      if (!okec(c, *it, r)) break;
      best[*it * m + c] = best[r * m + c] + 1;
      know(*it, c);
    }
  }
  int sol = best[r2 * m + c2];
  if (sol == (int) 1e9) {
    sol = -1;
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 205840
#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() {
	
	int n;
	cin >> n;
	vector<int> t(n + 1), x(n + 1), y(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> t[i] >> x[i] >> y[i];
	}
	bool ok = true;
	for(int i = 1; i <= n; i++){
		if(abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]) > abs(t[i] - t[i-1])){
			ok = false;
			break;
		}
		if((abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) % 2 != abs(t[i] - t[i-1]) % 2){
			ok = false;
			break;
		}
	}
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1408
n=gets.to_i

edges=Array.new(n){Array.new}
weight={}
ans=Array.new(n)
done=Array.new(n,false)
ans[0]=0
done[0]=true

(n-1).times{
  u,v,w=gets.split.map(&:to_i)
  u-=1
  v-=1
  edges[u]<<v
  edges[v]<<u
  weight[[u,v]]=weight[[v,u]]=w%2
}

q=[0]
until q.empty?
  u=q.shift
  edges[u].each{|v|
    next if done[v]
    done[v]=true
    ans[v]=(ans[u]+weight[[u,v]])%2
    q << v
  }
end

puts ans

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

using p_res = pair<string, int>;

struct guide {
    int id;
    string name;
    int point;
};

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

    int N;
    cin >> N;
    vector<guide> res;
    for (int i = 1; i <= N; ++i) {
        string S;
        int P;
        cin >> S >> P;
        res.push_back(guide{ i, S, P});
    }

    stable_sort(res.begin(), res.end(), [](guide x, guide y){
        return x.point > y.point;
    });
    stable_sort(res.begin(), res.end(), [](guide x, guide y){
        return x.name < y.name;
    });

    for (auto& r: res) {
        cout << r.id  << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
int h[100001], memo[100001];
int rec(int i) {
    if (memo[i] != -1) return memo[i];
    if (i == 2) return abs(h[1] - h[2]);
    if (i == 1) return 0;
    return memo[i] = min(rec(i - 1) + abs(h[i] - h[i - 1]), rec(i - 2) + abs(h[i] - h[i - 2]));
}
int main() {
    cin >> n;
    reps(i, n) { cin >> h[i]; }
    memset(memo, -1, sizeof(memo));
    cout << rec(n) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
  else cout << min(a * b, min(b * c, a * c)) << endl;
}

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

signed main(void)
{
	string s;
	long long ans;
	deque<char> dq;

	cin >> s;
	rep(i, s.size())
	{
		dq.push_back(s[i]);
	}
	ans = 0;
	while(!(dq.size() <= 1))
	{
		char f = dq.front(); 
		char b = dq.back(); 
		if (f == b)
		{
			dq.pop_front();
			dq.pop_back();
		}
		else if (f == 'x') 
		{
			ans++;
			dq.push_back('x');
		}
		else if (b == 'x')
		{
			ans++;
			dq.push_front('x');
		}
		else if (f != 'x' && b != 'x')
		{
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,m,n,c=0;
    cin>>n;
    long long int v[n+10],u[n+10];
    u[0]=0;
    for(long long int i=1; i<=n; i++)
    {
        cin>>v[i];
        u[i]=u[i-1]+v[i];
        c+=v[i];
    }
    long long int mn=0x7fffffff;
    for(long long int i=1;i<n;i++)
    {
        mn=min(mn,abs(2*u[i]-c));
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 3328
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main(){
int N,M;
cin>>N>>M;
pair<int,int> req[M];
rep(i,M){
    int a,b;
    cin>>a>>b;
    req[i]=make_pair(b,a);
}
sort(req,req+M);
int now=0,count=0;
rep(i,M){
    if(req[i].second>=now){
        now=req[i].first;
        count++;
    }

}
cout<<count<<endl;





return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<fstream>
#include <string>
using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int A,B,C;
  cin>>A>>B>>C;

  if(A==B && B!=C){
    cout<<"Yes"<<endl;
  }else if(B==C && C!=A){
    cout<<"Yes"<<endl; 
  }else if(C==A && A!=B){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
void swap(int x, int y, int z)
{
    int temp1, temp2;
    temp1 = x;
    x = y;
    y = temp1;
    temp2 = x;
    x = z;
    z = temp2;
    printf("%d %d %d\n", x, y, z);
}
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    swap(a, b, c);
    return 0;
}


Measured memory_bytes: 128