akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
 
int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int a[n];
  rep(i,n)cin >> a[i];
  int ans=inf,subans=0;
  rep(i,x){
    rep(j,m)if(i==a[j])subans++;
  }
  ans=min(ans,subans);
  subans=0;
  REP(i,x,n){
   rep(j,m)if(i==a[j])subans++; 
  }
  ans=min(ans,subans);
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
A = input()
N = len(A)

S, T = [0] * N, [0] * N
for i in range(N):
  if A[i] == "R":
    S[i] += S[i - 1] + 1
  else:
    S[i] = 0
#print("S:", S)

A = A[::-1]
for i in range(N):
  if A[i] == "L":
    T[i] += T[i - 1] + 1
  else:
    T[i] = 0
#print("T:", T)

tmp1, tmp2 = [0] * N, [0] * N
for i in range(N - 1):
  if S[i] and S[i + 1] == 0:
    if S[i] % 2 == 0:
      tmp1[i], tmp1[i + 1] = S[i] // 2, S[i] // 2
    else:
      tmp1[i], tmp1[i + 1] = S[i] - S[i] // 2, S[i] // 2
  if T[i] and T[i + 1] == 0:
    if T[i] % 2 == 0:
      tmp2[i], tmp2[i + 1] = T[i] // 2, T[i] // 2
    else:
      tmp2[i], tmp2[i + 1] = T[i] - T[i] // 2, T[i] // 2
tmp2 = tmp2[::-1]

answer = []
for i in range(N):
  answer.append(tmp1[i] + tmp2[i])
print(*answer)

Measured memory_bytes: 58992
import numpy as np

N, M, X = map(int,input().split())
price = np.array([None]*N)
skill = [None]*N
for i in range(N):
    tmp = list(map(int,input().split()))
    price[i] = tmp[0]
    skill[i] = np.array(tmp[1:])

ans = float('inf')
for pattern in range(1<<N):
    takahashi_level = np.array([0]*M)
    sum_of_price = 0
    #print(takahashi_level)
    for mask in range(N):
        if pattern&(1<<mask):
            sum_of_price += price[mask]
            takahashi_level += skill[mask]
    #print(takahashi_level[takahashi_level>=X])
    if len(takahashi_level[takahashi_level>=X]) == M:
        ans = min(sum_of_price,ans)

if ans < float('inf'):
    print(ans)
else:
    print(-1)

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

p = int(1e9+7)
res = 0

for i in range(60):
    zc = 0
    oc = 0
    for j in range(len(A)):
        if A[j] % 2 == 0:
            zc += 1
        else:
            oc += 1
        A[j] = A[j] >> 1

    res += zc*oc*2**i
    res %= p

print(res)

Measured memory_bytes: 122808
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
int X;

int main()
{
  int n500, n5;

  cin >> X;
  n500 = X/500;
  X -= n500*500;
  n5 = X/5;

  printf("%d\n", n500*1000+n5*5);

  return 0;
}


Measured memory_bytes: 256
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  if($k == 0){
    echo $n*$n;
    exit;
  }
  $ans = 0;
  for($i=$k+1; $i<=$n; $i++){
    $round = intdiv($n, $i);
    $ans += $round * ($i-$k);
    $mod = $n % $i;
    if($mod >= $k){
      $ans += $mod - $k + 1;
    }
//    echo $ans.PHP_EOL;
  }

  echo $ans;

Measured memory_bytes: 16140
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  vector<int> vec;

  int buf;
  rep(i, 5) {
    cin >> buf;
    vec.push_back(buf);
  }
  if (vec[0] == 0) {
    cout << vec[1] - 1;
  }
  rep(i, 4) {
    if (vec[i + 1] == 0) {
      cout << vec[i - 1] + 2;
      return 0;
    }
  }
}

Measured memory_bytes: 3612
# coding: utf-8
# Your code here!
k,t = map(int,input().split(' '))
cake = list(map(int,input().split(' ')))
sum = 0
maxCake = -1
for i in range(t):
    maxCake = max(maxCake,cake[i])
print(max(maxCake - 1 - (k - maxCake), 0))


Measured memory_bytes: 2940
n=int(input())
arr=list(map(int,input().split()))
a4=0
a2=0
a1=0
for a in arr:
    if a%4==0:
        a4+=1
    elif a%2==0:
        a2+=1
    else:
        a1+=1
if a1==0:
    print("Yes")
elif a2==0:
    if a1<=a4+1:
        print("Yes")
    else:
        print("No")
else:
    if a1<=a4:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

bool win[100010];

int main() {
	int N, K;
	cin >> N >> K;
	vi a(N);
	rep(i, N) {
		cin >> a[i];
	}

	for (int j = 1; j <= K; ++j) {
		rep(i, N) if (j >= a[i]) {
			if (!win[j - a[i]]) {
				win[j] = true;
			}
		}
	}

	puts(win[K] ? "First" : "Second");

	return 0;
}

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

const int mod = 1e9 + 7;

int main() {
  ll N;
  int dp[62][3] = {{}};

  cin >> N;

  dp[0][0] = 1;
  for (int i = 0; i < 61; i++) {
    for (int j = 0; j < 3; j++) {
      for (int x = 0; x < 2; x++) {
        for (int y = x; y < 2; y++) {
          ll b = (N >> i & 1) - x - y - j;
          (dp[i + 1][(1 - b) >> 1] += dp[i][j]) %= mod;
        }
      }
    }
  }

  cout << dp[61][0] << endl;
}


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

int main(){
	unsigned long long a,b,n,c,d,x;
	cin>>a>>b>>n;
	x=min(n,b-1);
	c=a*x;
	c=c/b;
	d=x/b;
	
	cout<<c-a*d<<endl;
}

Measured memory_bytes: 3568
# -*- coding:utf-8 -*-

n = int(input())
k = int(input())


def double(i):
    return i*2

def add_k(i):
    return i+k

ans= 1
for j in range(n):
    if ans <= k:
        ans = double(ans)
#        print(ans)
    else:
        ans = add_k(ans)
#        print(ans)
print(ans)


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

using namespace std;

int main()
{
	string word;
	string text;
	int count = 0;

	cin >> word;
	while (cin >> text, text != "END_OF_TEXT"){
		for (int i = 0; i < text.length(); i++){
			if (isupper(text[i])){
				text[i] = tolower(text[i]);
			}
		}
		if (text == word)
			count++;
	}

	cout << count << endl;

	return 0;
}

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

int main() {
  int l, r; cin >> l >> r;
  const int INF = 2000000005;
  int ans = INF, cnt = 0;
  for (int i=l; i<=r; i++) {
    if (i%2019==0) {
      ans = 0;
      break;
    }
    for (int j=i%2019+1; j <= r%2019;j++) {
      ans = min((i%2019 * j%2019)%2019, ans);
    }
    if (cnt == 2019) break;
    cnt++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];

vector<pair<int, int> > ans1;
vector<pair<int, int> > ans2;
ll N, X;
int x[510][510];
int main(){
    int H, W; cin >> H >> W;
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            cin >> x[i][j];
        }
    }
    int cnt=0;
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            if(x[i][j]%2!=0){
                if(x[i][j+1]%2!=0){
                    x[i][j+1]++;
                    x[i][j]--;
                    ans1.push_back({i+1, j+1});
                    ans2.push_back({i+1, j+2});
                    cnt++;
                    continue;
                }
                if(x[i+1][j]%2!=0){
                    x[i+1][j]++;
                    x[i][j]--;
                    ans1.push_back({i+1, j+1});
                    ans2.push_back({i+2, j+1});
                    cnt++;
                    continue;
                }
                if(x[i][j+1]%2==0&&j+1<W){
                    x[i][j+1]++;
                    x[i][j]--;
                    ans1.push_back({i+1, j+1});
                    ans2.push_back({i+1, j+2});
                    cnt++;
                    continue;
                }
                if(x[i+1][j]%2==0&&i+1<H){
                    x[i+1][j]++;
                    x[i][j]--;
                    ans1.push_back({i+1, j+1});
                    ans2.push_back({i+2, j+1});
                    cnt++;
                    continue;
                }
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<(int)ans1.size(); ++i) cout << ans1[i].first << " " << ans1[i].second << " " << ans2[i].first << " " << ans2[i].second << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 9964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    const int INF = 1000000000;
    int N, T;
    cin >> N >> T;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vector<vector<int>> dp0(N + 1, vector<int>(T + 1, -INF)), dp1(N + 1, vector<int>(T + 1, -INF));
    dp0[0][0] = 0;
    dp1[N][0] = 0;
    rep(i, N) rep(j, T + 1) {
        dp0[i + 1][j] = max(dp0[i + 1][j], dp0[i][j]);
        if (j + A[i] <= T) dp0[i + 1][j + A[i]] = max(dp0[i + 1][j + A[i]], dp0[i][j] + B[i]);
    }
    for (int i = N; i > 0; --i) rep(j, T + 1) {
        dp1[i - 1][j] = max(dp1[i - 1][j], dp1[i][j]);
        if (j + A[i - 1] <= T) dp1[i - 1][j + A[i - 1]] = max(dp1[i - 1][j + A[i - 1]], dp1[i][j] + B[i - 1]);
    }
    rep(i, N + 1) rep(j, T) {
        dp0[i][j + 1] = max(dp0[i][j], dp0[i][j + 1]);
        dp1[i][j + 1] = max(dp1[i][j], dp1[i][j + 1]);
    }
    int ans = 0;
    rep(i, N) {
        int res = 0;
        rep(j, T) res = max(res, dp0[i][j] + dp1[i + 1][T - 1 - j]);
        ans = max(ans, res + B[i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 70912
import math

n, m = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if n <= 1 and m >=2:
    print(combinations_count(m, 2))
elif n >= 2 and m <=1:
    print(combinations_count(n, 2))
elif n <= 1 and m <= 1:
    print(0)
else:
    print(combinations_count(n, 2) + combinations_count(m, 2))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector <int> odd(100000, 0);
  vector <int> even(100000, 0);

  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    v--;
    if (i % 2 == 0) {
      even[v]++;
    } else {
      odd[v]++;
    }
  }
  
  vector <int> odd_idx(100000);
  vector <int> even_idx(100000);
  iota(odd_idx.begin(), odd_idx.end(), 0);
  iota(even_idx.begin(), even_idx.end(), 0);
  
  sort(odd_idx.begin(), odd_idx.end(), 
       [&odd](int l, int r) {
         return odd[l] > odd[r];
       });
  sort(even_idx.begin(), even_idx.end(), 
       [&even](int l, int r) {
         return even[l] > even[r];
       });
  
  int e = 0, o = 0;
  if (even_idx[0] == odd_idx[0]) {
    cout <<
      min(n - even[even_idx[1]] - odd[odd_idx[0]], 
          n - even[even_idx[0]] - odd[odd_idx[1]])
      << endl;
  } else {
    cout << n - even[even_idx[0]] - odd[odd_idx[0]] << endl;
  }
  
  return 0; 
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
    ll N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(all(T));
    int now = 0;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cnt++;
        if (T[now] + K < T[i]) {
            ans++;
            cnt = 1;
            now = i;
        } else if (cnt > C) {
            ans++;
            cnt = 1;
            now = i;
        }
    }
    cout << ans + 1 << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <string>
#include <iostream>
using namespace std;
//constexpr long long kFiveTrillion = 500000000000;

int main() {
    string S;
    int K;
    long long cnt=0;
    char ans = '0';

    cin >> S >> K;

    for (int i = 0; i < S.length(); i++) {
        if (i + 1 == K) {
            ans = S[i];
            break;
        } else if (S[i] != '1') {
            ans = S[i];
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n;
    cin >> n;
    cout<<1-n<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K,A,B;


int main(void){
  cin >> K >> A >> B;
  if(B-A < 3) cout << K+1 << endl;
  else{
    ll k = K,num=1;
    //A枚になるまでたたく
    num += A-1;
    k = k - (A-1);
    num += (B-A)*(k/2);
    k -= k/2 * 2;
    num += k;
    k -= k;
    cout << num << endl;
  }


  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[52][52];
int cnt[26];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%s",s[i]);
  {
    REP(j,26){
      cnt[j] = count(s[0],s[0]+strlen(s[0]),'a'+j);
    }
  }
  FOR(i,1,n){
    REP(j,26){
      CHMIN(cnt[j],(int)count(s[i],s[i]+strlen(s[i]),'a'+j));
    }
  }
  REP(j,26){
    REP(_,cnt[j])putchar('a'+j);
  }
  puts("");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

typedef string::const_iterator State;
class ParseError {};

int expression(State &);
int term(State &);
int number(State &);
int factor(State &);

int main(void) {
    int N;
    cin >> N;
    cin.ignore();
    for (int i = 0; i < N; i++) {
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }

    return 0;
}

int expression(State &begin) {
    int ret = term(begin);

    while (1) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }

    return ret;
}

int term(State &begin) {
    int ret = factor(begin);

    while (1) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }

    return ret;
}

int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

int factor(State &begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
}

Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int sum = 0, quantity = 0, count = 0;

    int a, b;
    char c;
    while (cin >> a >> c >> b) {
        sum += a * b;
        quantity += b;
        count ++;
    }
    cout << sum << endl;
    cout << round(static_cast<double>(quantity) / count) << endl;

    return 0;
}

Measured memory_bytes: 1272
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
//#define =1e9 =(int)1e9
const ll mod = 1000000007;
const ll nmax=3000001;
#define int ll
int n, h[200005], a[200005], seg[800005];

void upd(int nod, int l, int r, int pos, int v){
    if(l==r) seg[nod]=v;
    else{
        int mid=(l+r)>>1;
        if(pos<=mid) upd(2*nod, l, mid, pos, v);
        else upd(2*nod+1, mid+1, r, pos, v);
        seg[nod]=max(seg[2*nod], seg[2*nod+1]);
    }

}

int qry(int nod, int l, int r, int lq, int rq){
    if(rq<l || r<lq) return 0LL;
    else if(lq<=l && r<=rq) return seg[nod];
    else{
        int mid=(l+r)>>1;
        return max(qry(2*nod, l, mid, lq, rq), qry(2*nod+1, mid+1, r, lq, rq));
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>h[i];
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=1; i<=n; i++){
        int x=qry(1, 1, n, 1, h[i]);
        upd(1, 1, n, h[i], x+a[i]);
       // cout<<"i: "; for(int j=1; j<=n; j++) cout<<qry(1, 1, n, j, j)<<" "; cout<<endl;
    }
    cout<<qry(1, 1, n, 1, n);
}


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

/********************************************************************/
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

/********************************************************************/
const double pi = 3.1415926535;
ll n, m;
const int mx = 69;
char grid[mx][mx];
ll blocked[mx][mx];
ll vis[mx][mx];
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/

ll power(ll a, ll b)
{
	ll res = 1;
	for (int i = 1; i <= b; ++i)
		res *= a;

	return res;
}
ll sum(ll x) {
	ll ans = 0;
	while (x > 0) {
		ans += (x % 10);
		x /= 10;
	}
	return ans;
}

bool opp(int x, int y)
{
    return ((x ^ y) < 0);
}


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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define N 500001
#define prob "A"
#define pb push_back
#define ll long long
#define io freopen(prob".inp","r",stdin); freopen(prob".out","w",stdout);
#define fast ios_base::sync_with_stdio(1); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
int n,h[N];
int f[N];
int main()
{
    fast
//    io
    cin>>n;
    for(int i=1;i<=n;i++) f[i]=INT_MAX;
    for(int i=1;i<=n;i++) cin>>h[i];
    f[1]=0;
    for(int i=1;i<n;i++)
    {
        f[i+1]=min(f[i+1],f[i]+abs(h[i]-h[i+1]));
        f[i+2]=min(f[i+2],f[i]+abs(h[i]-h[i+2]));
        //cout<<f[i]<<endl;
    }
    cout<<f[n];
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,k,ans=0;
	cin >> n >> k;
	while(n){
		n /= k;
		++ans;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int first = max(A, B);
  int second;
  if (first == A) {
    second = max(A-1, B);
  }
  else if (first == B) {
    second = max(A, B-1);
  }
  cout << first + second << endl;
}

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

struct UnionFind {
private :
    vector<int> data; int sz;
public :
    UnionFind(int sz) : data(sz, -1), sz(sz) { }

    bool unite(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        sz--;
        return true;
    }

    bool is_same(int x, int y) { return root(x) == root(y); }

    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

    size_t size(int x) { return (size_t)-data[root(x)]; }

    size_t size() { return (size_t)sz; }

};

int main() {
    UnionFind uf(13);
    
    uf.unite(1, 3);
    uf.unite(3, 5);
    uf.unite(5, 7);
    uf.unite(7, 8);
    uf.unite(8, 10);
    uf.unite(10, 12);
    
    uf.unite(4, 6);
    uf.unite(6, 9);
    uf.unite(9, 11);
    
    int a, b;
    cin >> a >> b;
    cout << (uf.is_same(a, b) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    long long a,b ,k;
    cin>>a>>b>>k;
    if(k>a){
        k=k-a;
        a=0;
        cout<<0<<" "<<max(a,b-k)<<endl;
    }
    else{
        cout<<a-k<<" "<<b<<endl;
    }
}

Measured memory_bytes: 256
import math
X = int(input())
flag = False
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
i = 0
while flag != True:
    flag = is_prime(X+i)
    i += 1
print(X+i-1)

Measured memory_bytes: 3060
N = int(input())
A = [0]*N
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())


S = [0]*Q
# for i in range(Q):
#     for j in range(N):
#         if A[j] == B[i]:
#             A[j] = C[i]
#     for k in range(N):
#         S[i] += A[k] 
# for i in range(Q):
#     print(S[i])

cnt = [0] * 100005 # Aの数字の数を格納する，カウント配列
for i in A:
    cnt[i]+=1 

tot = sum(A)
for i in range(Q):
    #合計値の変動
    tot -= B[i]*cnt[B[i]]
    tot -= C[i]*cnt[C[i]]
    #カウント配列の変動
    cnt[C[i]] += cnt[B[i]]
    cnt[B[i]] = 0
    #合計値の変動
    tot += B[i]*cnt[B[i]]
    tot += C[i]*cnt[C[i]]
    print(tot)



Measured memory_bytes: 22796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int A,B;
   cin>>A>>B;
   if(B%A==0){
       cout<<A+B<<endl;
   }
   else{
       cout<<B-A<<endl;
   }
}

Measured memory_bytes: 3620
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a,b  = cin()
    print(a*b)


if __name__ == '__main__':
    main()

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

int n, s, t, A, B, a[4];
int main()
{
	int i;
	cin >> n;
	cin >> A >> B;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &t);
		if (t <= A) a[1]++;
		else if (t > A && t <= B) a[2]++;
		else a[3]++;
	}
	cout << min(min(a[1], a[2]), a[3]);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N = 1e5 + 10;

int n, k, x, cnt, cnt2;
int neg[N], pos[N];

int main() {
	cin >> n >> k;
	REP(i, 1, n) {
		cin >> x;
		if (x < 0) neg[++cnt] = x;
		else if (x > 0) pos[++cnt2] = x;
		else k--;
	}

	sort(neg + 1, neg + cnt + 1);
	reverse(neg + 1, neg + cnt + 1);
	sort(pos + 1, pos + cnt2 + 1);


	int	ans = INF;
	if (k <= 0) ans = 0;
	if (cnt2>=k&&k>0) ans=min(ans, pos[k]);
	if (cnt>=k&&k>0) ans=min(ans, abs(neg[k]));

	REP(i, 1, cnt) {
		int p = k - i;
		if (p <= 0||p>cnt2) continue;
		ans = min(ans, abs(neg[i])*2+ pos[p]);
	}

	REP(i, 1, cnt2) {
		int ng = k - i;
		if (ng <= 0||ng>cnt) continue;
		ans = min(ans, abs(neg[ng]) + 2*pos[i]);
	}
	cout << ans << endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}
/*
5 5
-20 -10 -10 10 10
*/

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ret = 0;
  int d = 1;
  while (d < B) {
    d += A - 1;
    ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int a[7]={0,1,6,2,4,3,5};
int main(){
	ll x;
	cin>>x;
	ll y=x/11;
	ll z=x%11;
	if(z!=0){
		if(z<=6) z=1;
		else z=2;
	}
	ll ans=y*2+z;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,j,a[5];
	for(i=0;i<3;i++)
		scanf("%d",&a[i]);
	for(i=1;i<3;i++){
		for(j=0;j<3-i;j++){		
		if(a[j]>a[j+1])
		{int t=a[j];a[j]=a[j+1]; a[j+1]=t;
		}
		}
	}
	int z=a[2]-a[0];	
	printf("%d",z);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char c[] = S.toCharArray();
    int N = S.length();
    int a = (N-1)/2;
    if(a!=1){
      for(int i=0; i < a; i++){        
        if(c[i] == c[a-1 -i]&&c[a+1 +i] == c[N-1 -i]){
          if(c[a-1 -i] == c[a+1 +i]&&c[i] == c[N-1 -i]){
            
          } else {
            System.out.println("No");
            return;
          }
        } else {
          System.out.println("No");
          return;
        }
      }
    } else {
      if(c[0]!=c[2]) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)cout<<"1"<<endl;
    else if(x2==0)cout<<"2"<<endl;
    else if(x3==0)cout<<"3"<<endl;
    else if(x4==0)cout<<"4"<<endl;
    else if(x5==0)cout<<"5"<<endl;

}


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

const int maxn = 2e5 + 10;
int p[maxn], n;

int f(int x) { return x == p[x] ? x : p[x] = f(p[x]); }

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  vector<array<int, 2>> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1];
  vector<int> b(n + 1);
  for (int i = 0; i < n; ++i) b[a[i][0]] = a[i][1];

  stack<pair<int, int>> s;
  iota(p, p + n + 1, 0);

  for (int i = 1; i <= n; ++i) {
    int h = b[i];
    while (s.size() && b[i] > s.top().second) {
      h = min(s.top().second, h);
      p[f(i)] = f(s.top().first);
      s.pop();
    }
    s.emplace(i, h);
  }
  vector<int> sz(n + 1);
  for (int i = 1; i <= n; ++i) {
    sz[f(i)]++;
  }
  for (int i = 0; i < n; ++i) cout << sz[f(a[i][0])] << endl;

  return 0;
}



Measured memory_bytes: 7088
#include<bits/stdc++.h>
using namespace std;
 
int main () {
	string s; cin >> s;
	vector<int> in(4,0);
	for (int i = 0; i < 4; i++)
		in[i] = s[i]-'0';
	int bc = 0;
	for (int i = 0; i < (1<<3); i++)
		if (in[0] + (i&(1<<2) ? 1 : -1)*in[1] + (i&(1<<1) ? 1 : -1)*in[2] + (i&1 ? 1 : -1)*in[3] == 7)
			bc = i;
	cout << in[0] << (bc&(1<<2) ? '+' : '-') << in[1] << (bc&(1<<1) ? '+' : '-') << in[2] << (bc&1 ? '+' : '-') << in[3] << "=7\n";
	return 0;
}

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

int main(){
  char str[210];
  scanf("%s", str);
  int n = strlen(str);
  for(int i = n-2; i; i-=2){
    if(strncmp(str, str+i/2, i/2)==0){
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i == 0 or i == H - 1:
                print('#'*W)
            else:
                print('#' + '.'*(W-2) + '#')
    print('')


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

int main() {
	int a, b; 
	char s;
	while(true)
	{
		cin>>a>>s>>b;
		if(s == '?') break;
		if(s == '+') cout<< a+b <<endl;
		if(s == '-') cout<< a-b <<endl;
		if(s == '*') cout<< a*b <<endl;
		if(s == '/') cout<< a/b <<endl;
	}
	return 0;
}



Measured memory_bytes: 3100
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
sm=0 
for i in range(n-1):
    if l[i]+l[i+1]<=k:
        continue 
    else: 
        sm+=l[i]+l[i+1]-k 
        req=l[i]+l[i+1]-k 
        if l[i+1]>=req: 
            l[i+1]-=req 
            req=0 
        else: 
            #l[i+1]=0 
            req-=l[i+1]
            l[i]-=req
            l[i+1]=0
print(sm)

Measured memory_bytes: 14152
//WA => CARO!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back 
#define fastcin ios::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'

void mian();

signed main(){
	int _t_; cin >> _t_;
	while(_t_--) mian();
}

ll a, b, c, d;
map<ll, ll> calculated;
map<ll, ll> values;

ll cost(ll n){
	if (n<=1) return d*n;
	if (calculated.count(n)) return calculated[n];
	ll res = d*n;
	if ((double)d*(double)n > 1.1e18)
		res = 1e18;
	for (auto x: values){
		ll p = x.first, price = x.second;
		ll uppern =  ((n-1)/p+1)*p;
		ll lowern =    (n/p)*p;
	//	cout << "for n=" << n << "upper/lower is " << uppern << " " << lowern << endl;
	//	cout << n << "called" << uppern/p << endl;
		res = min(res, d*(uppern-n) + price + cost(uppern/p));
	//	cout << n << "called" << lowern/p << endl;
		res = min(res, d*(n-lowern) + price + cost(lowern/p));
	}
	calculated[n] = res;
	return res;
}

void mian(){
	calculated.clear();
	values.clear();
	ll n;
	cin >> n >> a >> b >> c >> d;
	values[2] = a;
	values[3] = b;
	values[5] = c;
	cout << cost(n) << endl;
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<ll,ll> pll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define coutif(a,b,c) cout<<(a?b:c)

int main(){
    ll j,k=0,x=0,y=0,i,ans;
    string s1,s2;
    cin>>s1>>s2;
    ll n1=s1.size();
    ll n2=s2.size();
    bool b[26]={0};
    for(i=0;i<n1;i++) b[s1[i]-'a']=1;
    for(i=0;i<n2;i++) if(b[s2[i]-'a']==0) out(-1);
    vi a[26];
    ll bb[n2],cnt[26]={0};
    for(i=0;i<n1;i++){
        a[s1[i]-'a'].pb(i);
    }
    x=-1;
    ans=0;
    for(int i=0;i<n2;++i){
        auto it = upper_bound(a[s2[i]-'a'].begin(),a[s2[i]-'a'].end(),x);
        if(it ==a[s2[i]-'a'].end()){
            ans+=n1-1-x;
            x =-1;
            --i;
        }
        else{
            ans+=*it-x;
            x = *it;
        }
        if( x == n1 -1 )
            x = -1;
    }
    //for(i=0;i<n2;i++) cout<<bb[i]<<" ";
    cout<< ans;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,b,a) for(ll i = b;i>=a;i--)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define mp(x,y)  make_pair(x,y)
#define pb push_back
#define ins insert
#define er erase
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 2e5 + 2;

int main() {
    LAPAK
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n],b[m];
    For(i,0,n)cin>>a[i];
    For(i,0,m)cin>>b[i];
    
    vll prefb(m+2);
    For(i,0,m)prefb[i+1] = prefb[i] + b[i];
    prefb[m+1] = INF;
    
    ll timea = 0,ans = 0;
    For(i,0,n+1){
        ll to_search = k - timea;
        ll in = lower_bound(ALL(prefb),to_search) - prefb.begin();
        if(prefb[in]!=to_search)in--;
        if(timea<=k)ans = max(ans,in+i);
        if(i<n)timea += a[i];
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 7940
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int a[][]=new int[16][10];
		int i,j;
		
		//初期化
		for(i=0;i<16;i++){
			for(j=0;j<10;j++){
				if(i%4==0)a[i][j]=-1;
				else a[i][j]=0;
			}
		}
		
		int n=scan.nextInt();
		for(i=0;i<n;i++){
			int b=scan.nextInt();
			int f=scan.nextInt();
			int r=scan.nextInt();
			int v=scan.nextInt();
			
			a[4*(b-1)+f][r-1]+=v;
		}
		
		for(i=1;i<16;i++){
			for(j=0;j<10;j++){
				if(a[i][j]==-1)System.out.print("##");
				else System.out.printf(" %d",a[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 30336
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
map<int, int> a1;
map<int, int>a2;
int main() {
	int n;
	cin >> n;
	int a = 0;
	int an = 0;
	int b = 0;
	int bn = 0;
	vector<int> g;
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		g.push_back(c);
	}
	for (int i = 0; i < n; i++) {
		int k;
		k = g[i];
			if (i % 2 == 0) {
				a1[k]++;
				if (a1[k] >= an) {
					a = k;
					an = a1[k];
				}
			}
			else {
				a2[k]++;
				if (a2[k] >= bn) {
					b = k;
					bn = a2[k];
				}
			}
	}
	if (a != b) {
		cout << n - an - bn;
		return 0;
	}
	int c = 0;
	int cn = 0;
	int d = 0;
	int dn = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (g[i] == a) {
				continue;
			}
			cn = max(a1[g[i]], cn);
		}
		else {
			if (g[i] == b) {
				continue;
			}
			dn = max(a2[g[i]], dn);
		}
	}
	if (an + cn > bn + dn) {
		cout << n - (an + cn);
	}
	else {
		cout << n - (bn + dn);
	}

}

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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}

int main() {
	int a = read(), b = read();
	for (int i = 1; i <= 3; ++i) {
		if ((a * b * i) & 1) { cout << "Yes"; return 0; }
	}
	cout  << "No";
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var line1 = input[0].split(" ");
  	var n = line1[0], k = line1[1];
	var h = input[1].split(" ");
    var count = 0;
  	h.forEach((x) => {
      if (parseInt(x) >= parseInt(k)) count++;
    });
	//出力
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 16704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    vector<pll> ab(n);
    for(int i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(all(ab));

    multiset<ll> v;
    ll index = 0;
    ll ans = 0;
    for(int i = 0; i < m; i++){
        while(index < n && ab[index].first<=i+1){
            v.insert(ab[index].second);
            index++;
        }

        if(!v.empty()){
            auto itr = v.end();
            --itr;
            ans += *itr;
            v.erase(itr);
        }
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 6400
n=int(input())
a=list(map(int,input().split()))
a.append(0)
#print(a)
s_all=abs(a[0])
for i in range(n):
    s_all+=abs(a[i+1]-a[i])
#print(s_all)
#print(a[1])
#print(a[0]+abs(a[1]-a[0]))
s=[s_all-abs(a[0])-abs(a[1]-a[0])+abs(a[1])]
#print(s)
for j in range(1,n):
    c=abs(a[j-1]-a[j])+abs(a[j]-a[j+1])
    d=abs(a[j+1]-a[j-1])
    s.append(s_all-c+d)
for i in s:
    print(i)

Measured memory_bytes: 14172
#include <iostream>
using namespace std;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return 0;
  }
}
int main()
{
    char n[200000];
    for (int i = 0;i<200000;i++)
    {
        n[i]='0';
    }
    
    int a =0;
    cin>>n;

    for (int i=0;i<200000;i++)
    {
        a = a + ctoi(n[i]);
   
    }
    if(a%9==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3828
#include <stdio.h>
#include <vector>
using namespace std;
char s[100005];
int a[100005];
int dp[100005];
vector<int> v;
int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);
	scanf("%s", s);
	for(int i = 0; i <= n; i++)
	{
		a[i] = s[i] - '0';
		if(a[i] == 1)
			dp[i] = -1;
	}
	int origin = n;
	while(origin > 0)
	{
		int maxn = 0;
		for(int i = 1; i <= m; i++)
		{
			if(origin - i < 0)
				break;
			if(dp[origin - i] != -1)
			{
				dp[origin - i] = dp[origin] + 1;
				maxn = i;
			}
		}
		if(!maxn)
			break;
		v.push_back(maxn);
		origin -= maxn;
	}
	if(!dp[0])
		printf("-1");
	else
		for(int i = v.size() - 1; i >= 0; i--)
		{
			if(i != v.size() - 1)
				printf(" ");
			printf("%d", v[i]);
		}
	return 0;
}
	

Measured memory_bytes: 1784
import java.util.Scanner;

//Step Step Evolution
public class Main{

	void run(){
		int[] pos = {0,0,1,2,0,0,2,0,1,2};
		Scanner sc = new Scanner(System.in);
		while(true){
			char[] s = sc.next().toCharArray();
			if(s[0]=='#')break;
			int n = s.length;
			int[][][][] dp = new int[n+1][3][3][2];
			for(int i=0;i<=n;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++)for(int l=0;l<2;l++)dp[i][j][k][l]=1<<28;
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					for(int k=0;k<2;k++){
						dp[0][i][j][k] = i<=j?0:1<<28;
					}
				}
			}
			for(int i=0;i<n;i++){
				int p = pos[s[i]-'0'];
				for(int j=0;j<3;j++){
					for(int k=0;k<3;k++){
						for(int l=0;l<2;l++){
							if(l==0){
								if(p<=k){
									dp[i+1][p][k][1] = Math.min(dp[i+1][p][k][1], dp[i][j][k][l]);
								}
								if(j<=p){
									dp[i+1][j][p][0] = Math.min(dp[i+1][j][p][l], dp[i][j][k][l]+1);
								}
							}
							else {
								if(j<=p){
									dp[i+1][j][p][0] = Math.min(dp[i+1][j][p][0], dp[i][j][k][l]);
								}
								if(p<=k){
									dp[i+1][p][k][1] = Math.min(dp[i+1][p][k][1], dp[i][j][k][l]+1);
								}
							}
						}
					}
				}
			}
			int min = 1<<28;
			for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<2;k++)min=Math.min(min, dp[n][i][j][k]);
			System.out.println(min);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 54000
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int d;
int p[200];
int dp[1121][15][200];

int sumprime(int n,int k,int last)
{
	int i;
	int c=0;
	if(n==0 && k==0){
		return 1;
	}else if(n==0 || k==0){
		return 0;
	}
	if(dp[n][k][last] >= 0)return dp[n][k][last];
	
	for(i=last;i<d;i++){
		if(p[i]>n)break;
		c += sumprime(n-p[i],k-1,i+1);
	}
	
	dp[n][k][last] = c;
	
	return c;
}

int main(void)
{
	int i,j,l,c;
	int n,k;
	
	p[0]=2;
	d = 1;
	for(i=3;i<1121;i+=2){
		c=0;
		for(j=0;j<d;j++){
			if(p[j]*p[j]>i)break;
			if(i%p[j] == 0){
				c++;
				break;
			}
		}
		if(c==0)p[d++]=i;
	}
	
	for(i=0;i<1121;i++){
		for(j=0;j<15;j++){
			for(k=0;k<200;k++){
				dp[i][j][k] = -1;
			}
		}
	}
	
	while(1)
	{
		scanf("%d %d ",&n,&k);
		if(n==0 && k==0)break;
		
		printf("%d\n",sumprime(n,k,0));
	}
	return 0;
}
		

Measured memory_bytes: 13000
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans = "No";
    for(int i=1;i<=9;i++){
      for(int j=1;j<=9;j++){
        if(i*j == n){
          ans = "Yes";
        }
      }
    }
   System.out.println(ans); 
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp  make_pair
#define pb  push_back
void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
#define INF 1e9+5
int32_t main(){
    c_p_c();
    // int t;
    // cin>>t;
    // while(t--){
        
    // }
    int n;
    cin>>n;
    vector<int> dp(n,INF);
    int a[n];
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j :{i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 4764