akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
#define INF 1e9

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X,N;
    cin >> X >> N;

    int A[N+2];
    rep(i,N){
        cin >> A[i];
    }
    int min_val = 150;
    int ans = 0;
    for(int i = 101; i >= 0; i--){
        int flag = 0;
        rep(j,N)if(A[j] == i) flag = 1;
        
        if(flag == 0){
            if(min_val >= abs(i-X)){
                min_val = abs(i-X);
                ans = i;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define N 10005
using namespace std;

int cal(int x){
  int res=x,a=x%10;
  x/=10;
  while(x){
    if(a-1==x%10)a=x%10;
    else res=-1;
    x/=10;
  }
  return res;
}

int main(){
  int n,a[N],ans=-1;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      ans=max(ans,cal(a[i]*a[j]));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3108
n=gets.strip.to_i

ta=readlines.map {|line| line.split(' ').map(&:to_i) }

coefficient = 1
(n-1).times do |index|
  before = ta[index]
  after = ta[index+1]
  coefficient = [((before.first + after.first - 1)/after.first), ((before.last+after.last-1)/after.last)].max

  ta[index+1] = [after.first*coefficient, after.last*coefficient]
end

result = ta.last.inject(:+)

p result


Measured memory_bytes: 1916
import sys
#入力する数N
N = input()

I = N[-1]   #ここでint→strに代わってる
#print(type(I))
#print(I)

if I in ["2", "4", "5", "7", "9"]:   #""はstrになってるから必要
    print("hon")
    sys.exit()
elif I in ["0", "1", "6", "8"]:
    print("pon")
    sys.exit()
else :
    print("bon")
    sys.exit()


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

using namespace std;

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

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

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

ll A[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll s = 0;
    REP(i, N) {
        cin >> A[i];
        s += A[i];
    }

    ll a = 0;
    REP(i, N) {
        if (s <= A[i] * 4 * M)
            a++;
    }
    if (a >= M)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int l=a+b;
  int r=c+d;
  if(l<r){
    cout<<"Right"<<endl;
  }else if(l>r){
    cout<<"Left"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
    
#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
//#define int long long int
    
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_mset = tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
    
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
//const ll INFLL = (ll)1e17;
const int MAXN = 112345;
const double pi = 3.14159265359;
const double eps = 0.00000001;

int dp[MAXN], h[MAXN];

int main() {
    int n, k, mx;
    scanf("%d %d %d", &n, &k, &h[0]);
    for (int i = 1; i < n; ++i) {
        scanf("%d", &h[i]);
        mx = INF;
        for (int j = 1; j <= k && j <= i; ++j) {
            mx = min(mx, dp[i - j] + abs(h[i - j] - h[i]));
        }
        dp[i] = mx;
    }
    printf("%d\n", dp[n - 1]);
}

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

int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	debt := 100.0 // 100千円
	for i := 1; i <= n; i++ {
		debt = math.Ceil(1.05 * debt)
	}
	fmt.Println(int(math.Ceil(debt)) * 1000)
}



Measured memory_bytes: 1064
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main(){
  int n, q;
  cin >> n >> q;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  for(int i = 0; i < q; i++){
    ll x;
    cin >> x;

    ll count = 0;
    int r = 0;
    ll tmp_sum = 0;
    for(int l = 0; l < n; ++l){
      while(r < n && tmp_sum + a[r] <= x){
        tmp_sum += a[r];
        ++r;
      }

      count += r - l;

      if(l == r)++r;
      else tmp_sum -= a[l];
    }

    cout << count << endl;
  }

}



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

int main(){
    int A,B;
    cin >> A >> B;
    for(int i=1;i<=10000;i++){
        int a = floor((double)i * 0.08);
        int b = floor((double)i * 0.1);
        if(a == A && b == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var x1, y1, x2, y2, x3, y3, x4, y4 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	x3 = x2 + y1 - y2
	y3 = y2 + x2 - x1
	x4 = x1 + y1 - y2
	y4 = y1 + x2 - x1
	fmt.Println(x3, y3, x4, y4)
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/dp/tasks/dp_a
#include <bits/stdc++.h>
using namespace std;

#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;

int main() {
    // 入力
    ll N; cin >> N;
    vector<ll> height(N);
    vector<ll> dp(100001);
    for( ll i = 0; i < N; i++ ) cin >> height.at(i);

    dp.at(0) = 0; dp.at(1) = abs(height.at(0) -height.at(1));
    for (int i = 2; i < N; ++i) {
        dp.at(i) = min(dp.at(i-2)+abs(height.at(i) - height.at(i-2)),
                       dp.at(i-1)+abs(height.at(i) - height.at(i-1)));
    }

    cout << dp[N-1] << endl;

    return 0;
}



Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int ans = c - a + b;
    if(ans < 0){
        cout<<0;
    }
    else{
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N;cin>>N;
  struct rate{int a,b;};
  std::vector<rate> v(3);
  std::vector<int> w(6); for(int i=0;i<6;i++)cin>>w[i];
  for(int i=0;i<3;i++)v[i]={w[i],w[i+3]};
  for(int i=0;i<3;i++)if(v[i].a==v[i].b)v[i]={LINF+1,LINF};

  if(v[1].a<v[1].b)swap(v[0],v[1]);
  if(v[2].a<v[2].b)swap(v[2],v[1]);
  if(v[1].a<v[1].b)swap(v[0],v[1]);

  int s=0;  for(int i=0;i<3;i++)if(v[i].a<v[i].b)s=i+1;
  int ans=0;

  //i,j,kがそれぞれ v[0],v[1],v[2]の金属をいくつ作るかを表す
  int o=0;

  if(s==0){//全部Bでお金にしてAでどんぐりにする
    for(int i=0;i*v[0].b<=N;i++){
      int res1=N-i*v[0].b;
      for(int j=0;j*v[1].b<=res1;j++){
        int res2=res1-j*v[1].b;
        int k=res2/v[2].b; res2+=k*(v[2].a-v[2].b);
        res2+=i*v[0].a+j*v[1].a;
        ans=max(ans,res2);
      }
    }
  }
  if(s==1){//v[0]はAでお金にしてBでどんぐりに、v[1],v[2]はBでお金にしてAでどんぐりに
    int i=N/v[0].a;  N+=i*(v[0].b-v[0].a);
    for(int j=0;j*v[1].b<=N;j++){
      int res=N;
      res-=j*v[1].b;
      int k=res/v[2].b;  res+=k*(v[2].a-v[2].b);
      res+=j*v[1].a;
      ans=max(ans,res);
    }
  }
  if(s==2){//v[0],v[1]はAでお金にしてBでどんぐりに、v[2]はBでお金にしてAでどんぐりに
    for(int i=0;i*v[0].a<=N;i++){
      int res=N-i*v[0].a;
      int j=res/v[1].a;  res+=j*(v[1].b-v[1].a);
      res+=i*v[0].b;
      int k=res/v[2].b;  res+=k*(v[2].a-v[2].b);
      ans=max(ans,res);
    }
  }
  if(s==3){//全部Aでお金にしてBでどんぐりに
    for(int i=0;i*v[0].a<=N;i++){
      int res1=N-i*v[0].a;
      for(int j=0;j*v[1].a<=res1;j++){
        int res2=res1-j*v[1].a;
        int k=res2/v[2].a;  res2+=k*(v[2].b-v[2].a);
        res2+=i*v[0].b;
        res2+=j*v[1].b;
        ans=max(ans,res2);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
// contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include "bits/stdc++.h"
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#define YES "Yes"
#define NO "No"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define eb emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair < ut, ut > pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5 * 1e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 400;
const int SIZE = 1<<18;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut D,F,T,N, M, K, X, L, Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
LL vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////
//LL L;
string s;
VI v[2];
Vpr anses[2];
int  A[SIZE];
LL solve(){
	cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N) {
		v[i % 2].PB(A[i]);
	}
	int ans = 0;
	REP(i, 2) {
		int maxim = 0;
		sort(ALL(v[i]));
		v[i].PB(-1);
		int last = 0;
		REP(j, v[i].size()) {
			if (v[i][last] == v[i][j]);
			else {
				anses[i].eb(j - last,v[i][j-1]);
				last = j;
			}
		//	cout << v[i][j] << endl;
		}
		anses[i].eb(0, 0);
		sort(ALL(anses[i]),greater<pr>());
	//	cout << anses[i].size() << endl;
	}
	REP(i,2)
		REP(j, 2) {
		if (anses[0][i].second != anses[1][j].second) {
			MX(ans, anses[0][i].first + anses[1][j].first);
			}
	}
	return N-ans;
}
signed main() {
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 6128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <vector>
typedef long long unsigned int ll;
using namespace std;

int main() {
    int n;
    int h;
    cin>>n>>h;
    int a[100005],b[100005];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    
    sort(b,b+n,greater<int>());
    int A=1;
    for(int i=0;i<n;i++){
        if(a[i]>A) A=a[i];
    }
    int c=0;
    for(int i=0;i<n&&b[i]>A&&h>0;i++){
        h-=b[i];
        c++;
        
    }

    if(h>0){
        c+=(h-1)/A+1;
    }
    cout<<c<<endl;
    return 0;

 }


Measured memory_bytes: 1024
import collections
N=int(input())
a=collections.Counter(map(int, input().split())).items()
b=sorted([n for n in a if n[1] > 3], reverse=True)
c=sorted([n for n in a if n[1] > 1], reverse=True)
print(max([b[0][0] ** 2 if len(b) > 0 else 0, c[0][0] * c[1][0] if len(c) > 1 else 0]))


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

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

int main(){

	int n;
	cin>>n;

	int ans=0,count=0;
	for(int i=1;i<=n;i+=2){
		count=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)count++;
		}
		if(count==8)ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

string s;

bool judge(int l,int r)
{   
    int len = (r-l);
    //cout<<l<<' '<<r<<endl;
    for(int i = 0; i <= len/2; i++) 
    {   
        //cout<<i<<' '<<s[l+i]<<' '<<s[r-i]<<endl;
        if(s[l+i] != s[r-i]) return false;
    }
    return true;
}

signed main()
{   
    cin>>s;
    n = s.size();
    ok = 1;
    if(!judge(0,n-1)) ok = 0;
    //cout<<ok<<endl;
    if(!judge(0,n/2-1)) ok = 0;
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int cnt4 = 0;
    int cnt1 = 0;
    int cnt2 = 0;
    rep(i,n){
        if(a[i] % 4 == 0)cnt4++;
        else if(a[i] % 2 == 1)cnt1++;
        else cnt2++;
    }
    bool ans = true;
    if(cnt4<cnt1-1)ans = false;
    if(cnt2 != 0 && cnt4-cnt1<0)ans = false;
    if(cnt2 == 1 && cnt4 == 0)ans = false;
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s,ans;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='1')ans=ans+"1";
        else if(s[i]=='0')ans=ans+"0";
        else if(ans!="")ans.erase(ans.end()-1);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-04-04.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, M;
vector<int> A;

int main() {
    cin >> N >> M;
    A.assign(N, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.rbegin(), A.rend());
    if (A[M-1] * M * 4 >= accumulate(A.begin(), A.end(), 0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    if N == 1:
        print(0)
        return

    M = N

    ps = []

    d = 2
    cnt = 0
    while N % d == 0:
        N //= d
        cnt += 1
    if cnt:
        ps.append(cnt)
        # ps.append((d, cnt))

    d = 3
    while d * d <= M:
        cnt = 0
        while N % d == 0:
            N //= d
            cnt += 1
        if cnt:
            ps.append(cnt)
            # ps.append((d, cnt))
        d += 2

    if N > 1:
        ps.append(1)
        # ps.append((N, 1))

    ans = 0
    for x in ps:
        t = 1
        while x >= t:
            x -= t
            t += 1
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, y; cin >> n >> y;
    rep(man, n+1) for (int gosen=0; man+gosen<=n; ++gosen) {
        ll sen = n-man-gosen;
        if ((ll)((ll)man*10000+(ll)gosen*5000+(ll)sen*1000) == y) {
            cout << man << " " << gosen << " " << sen << endl;
            return 0;
        }
    }
    cout << "-1" << " " << "-1" << " " << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 10:13:10 2020

@author: Kanaru Sato
"""

N = int(input())
H = list(map(int, input().split()))
ans = 0
count = 0

for i in range(0,N-1):
    if H[i] >= H[i+1]:
        count += 1
        ans = max(ans,count)
    else:
        count = 0

print(ans)

Measured memory_bytes: 14252
#include <stdio.h>

int main()
{
	int i, N, a[200001], sum = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(a[i]));
		sum ^= a[i];
	}
	for (i = 1; i < N; i++) printf("%d ", sum ^ a[i]);
	printf("%d\n", sum ^ a[N]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)

pair<int,int> MIN(vector<int>& num,int skip){
    pair<int,int> tmp;
    tmp = MP(num[0],0);
    rep(i,num.size()){
        if(i == skip) continue;
        if(tmp.first >= num[i]){
            tmp.first = num[i];
            tmp.second = i;
        } 
    } 
    return tmp;
}

int main(){
    int N; cin>>N;
    vector<int> even(100100,N/2),odd(100100,N/2);

    rep(i,N){
        int v; cin>>v;
        i%2?--even[v]:--odd[v];
    }

    pair<int,int> e,o;
    e = MIN(even,0);
    o = MIN(odd,0);

    if(e.second == o.second){
        if(e.first > o.first) e = MIN(even,e.second);
        else if(e.first < o.first) o = MIN(odd,o.second);
        else e = min(MIN(even,e.second),MIN(odd,o.second));
    }
    
    cout<<e.first + o.first<<endl;
}

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

int main() {
  
  int a,b,c,x;
  cin >> a >> b >> c;
  
  for ( int i = 1; i < 10000; i++){
    x = a * i;
    if ( x % b == c ){
      cout << "YES" << endl;
      return 0;
    }   
  }
  
  cout << "NO" << endl;
  return 0; 
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  const [N,K] = input[0].split(' ').map((n) => {
    return parseInt(n, 10);
  });
  const hn = input[1].split(' ').map((n) => {
    return parseInt(n, 10);
  });
  const h_max = Math.pow(10,9);
  console.log(dp(N,K,hn,h_max));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function dp(N,K,hn,h_max) {
  const dp = [];
  let dp_work = [];
  dp[0] = 0;
  for (var i = 1; i < N; i++) {
    dp.push(h_max);
    dp_work = [];
    dp_work.push(dp[i]);
    for (var dp_work_i = 1; dp_work_i <= K; dp_work_i++) {
      if (i-dp_work_i < 0) continue;
      dp_work.push(dp[i-dp_work_i] + Math.abs(hn[i-dp_work_i] - hn[i]));
    }
    dp[i] = Math.min(...dp_work);
  }
  return dp[N-1];
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

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

    int i,k,m,n,x,ans=0;
    bool mark[102]={0};
    cin >> n >> k;
    for(i=0;i<k;i++)
    {
        cin >> m;
        while(m--)
        {
            cin >> x;
            mark[x]=true;
        }
    }
    for(i=1;i<=n;i++)
    {
        if(!mark[i])++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3644
while True:
    n = int(input())
    a = []
    b = 0
    if n == 0:
        break
    n2 = 1
    for i in range(n,1,-1):
        n2 *= i
    c = str(n2)
    for j in range(len(c)-1,-1,-1):
        if c[j] == "0":
            b += 1
        else:
            break
    print(b)



Measured memory_bytes: 5708
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

a = (A // 10 + math.ceil((A % 10) / 10)) * 10
b = (B // 10 + math.ceil((B % 10) / 10)) * 10
c = (C // 10 + math.ceil((C % 10) / 10)) * 10
d = (D // 10 + math.ceil((D % 10) / 10)) * 10
e = (E // 10 + math.ceil((E % 10) / 10)) * 10

X = a + b + c + d + e

Y = [A % 10, B % 10, C % 10, D % 10, E % 10]
Y = [i for i in Y if i > 0]

if len(Y) >= 1:
    X = X - 10 + min(Y)

print(X)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 1000 - n % 1000;
	if(n%1000 == 0) ans = 0;
	cout << ans << endl;
	return 0;
}

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

int solvePlus(vector<int> v) {
  int cnt = 0, sum = 0;

  for (int i = 0; i < v.size(); i++) {
    sum += v[i];
    if (i % 2 == 1) {
      cnt = (sum < 0) ? cnt : (cnt + abs(sum) + 1);
      sum = (sum < 0) ? sum : -1;
    } else if (i % 2 == 0) {
      cnt = (sum > 0) ? cnt : (cnt + abs(sum) + 1);
      sum = (sum > 0) ? sum : 1;
    }
  }
  return cnt;
}

signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& w : a) cin >> w;
  int ans1, ans2;
  ans1 = solvePlus(a);
  for (auto&& w : a) w *= -1;
  ans2 = solvePlus(a);

  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
#define forp(x,a,b) for(int x=a; x<b; x++)

using namespace std;


int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
     
     int l,r,d;
     cin>>l>>r>>d;
     int x=r/d-(l-1)/d;
     cout<<x;
    
    
    return 0;}

Measured memory_bytes: 3416
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// Author : Koushal Bhat
// arraysum : count of subarrays with sum k
#define forr(i,p,n) for( ll i=p; i<n; i++)
#define forn(i,p,n) for(ll i=p; i<=n; i++)
#define rev(i,n,p) for(ll i=n; i>=p; i--)
#define PI 3.14159265358979323846

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    ll count=0;
    ll ans=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='R')
        {
            count++;
            continue;
        }
        else
        {
            ans=max(ans,count);
            count=0;
        }
        
    }
    ans=max(ans,count);
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/abc116/tasks/abc116_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,K; cin >> N >> K;
    vector<pll> td(N);
    for(auto& in:td){ cin >> in.first >> in.second; in.first--;}
    sort(td.begin(),td.end(),[](const pll& l,const pll& r){return l.second > r.second; });
    vector<int> used(N);
    ll S = 0;
    for(int i = 0; i < K;i++){
        used[td[i].first]+=1;
        S += td[i].second;
    }

    vector<int> checked(N);
    queue<pll> q;
    for(int i = K; i < N;i++){
        if(checked[td[i].first]) continue;
        if(used[td[i].first]) continue;
        q.push(td[i]);
        checked[td[i].first] = 1;
    }
    
    ll x = N - count(used.begin(),used.end(),0);
    res = S + x*x;
    
    for(int i = K-1; i >= 0; i--){
        if(q.empty()) break;
        if(used[td[i].first]<=1) continue;
        pll p = q.front(); q.pop();
        S -= td[i].second;
        S += p.second;
        
        x++;
        used[td[i].first]--;
        
        res = max(res,S + x*x);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

#define ll long long

vector<vector<int>> d;
vector<pair<int, int>> a;

int calc(int x, int i) {
    if (x <= 0) return 0;
    if (i == 0) return INT32_MAX;

    if (d[x][i] == -1) {
        d[x][i] = min(calc(x, i - 1), calc(x - a[i - 1].first, i) + a[i - 1].second);
    }
    return d[x][i];
}

int main() {
    cin.tie();
    ios_base::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;

    a.resize(n);

    for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;

    d.assign(h + 1, vector<int>(n + 1, -1));

    cout << calc(h, n);

    return 0;
}

Measured memory_bytes: 39808
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let hs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun h -> h in
  Array.sort compare hs;
  Printf.printf "%d\n" @@ 
  Array.fold_left ( + ) 0 @@
  Array.init (max 0 (n - k)) @@ fun i -> hs.(i)


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

dp = [0] * n
for i in range(n):
  dp[i] = p[i] / 2 + 0.5
  
m = sum(dp[0:k])
max = m
for i in range(1,n-k + 1):
  m = m - dp[i-1] + dp[i+k-1]
  if m > max:
    max = m
print(max)

Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <map>
using namespace std;

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		int* word = new int[N];
		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		long long ans = 0;
		map<int, int> bubblehist;

		for (int i = 0; i < N-1; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.find(word[i] - 1);

			if (it != bubblehist.end()){
				bubblenum = it->second + 1;
			}
			else {
				it = bubblehist.find(word[i] + 1);
				if (it != bubblehist.end()){
					bubblenum = it->second;
				}
				else{
					bubblenum = 0;
					for (int j = 0; j < i; j++){
						if (word[j] < word[i]) bubblenum++;
					}
				}
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(it, p);
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}

		delete[] word;
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << endl;
	}

	delete[] factmodary;
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n;
  cin >> n;
  vector<ll> c(n),s(n),f(n);
  REP(i,n-1)cin >> c[i] >> s[i] >> f[i];
  for(int i = 0;i < n;i++){
    ll now = 0;
    for(int j = i+1;j < n;j++){
      if(now <= s[j-1]){
        now = s[j-1] + c[j-1];
      }else{
        now = ((now - s[j-1] + f[j-1] -1)/f[j-1])*f[j-1]+ c[j-1] + s[j-1];
      }
      if(j == n-1)cout << now << endl;


    }
  }
  cout << 0 << endl;






  

  return 0;
}


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

int	main()
{
  int	n, min_v, max_v, temp;
  
  cin >> n;
  cin >> min_v;
  max_v = min_v;
  for (int i = 1; i < n; i++)
  {
    cin >> temp;
    if (temp < min_v)
      min_v = temp;
    else if (max_v < temp)
      max_v = temp;
  }
  cout << max_v - min_v << endl;
  return (0);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int x = 0, ans = 0;
    rep(i, n) {
        if (s[i] == 'I')
            x++;
        else
            x--;
        chmax(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0, abs(h[0]-h[1])] + [float('inf')]*(n-2)
for i in range(2,n):
    dp[i] = min(dp[i], dp[i-1]+abs(h[i-1]-h[i]))
    dp[i] = min(dp[i], dp[i-2]+abs(h[i-2]-h[i]))
print(dp[-1])

Measured memory_bytes: 52808
def f_single_dot():
    # https://atcoder.jp/contests/abc168/submissions/13368489
    import sys
    from collections import deque
    input = sys.stdin.readline
    N, M = [int(i) for i in input().split()]

    X, Y = set([0]), set([0])
    A, B, C = [0] * N, [0] * N, [0] * N
    for i in range(N):
        A[i], B[i], C[i] = map(int, input().split())
        X.add(A[i])
        X.add(B[i])
        Y.add(C[i])
    D, E, F = [0] * M, [0] * M, [0] * M
    for i in range(M):
        D[i], E[i], F[i] = map(int, input().split())
        X.add(D[i])
        Y.add(E[i])
        Y.add(F[i])
    UX = list(X)
    UY = list(Y)
    UX.sort()
    UY.sort()
    dictx, dicty = {n: i * 2 for i, n in enumerate(UX)}, {n: i * 2 for i, n in enumerate(UY)}
    LX = [UX[i // 2 + 1] - UX[i // 2] if i % 2 else 0 for i in range(len(UX) * 2 - 1)]
    LY = [UY[i // 2 + 1] - UY[i // 2] if i % 2 else 0 for i in range(len(UY) * 2 - 1)]
    c = [[0] * (len(UX) * 2 - 1) for _ in range(len(UY) * 2 - 1)]
    for i in range(N):
        y = dicty[C[i]]
        for x in range(dictx[A[i]], dictx[B[i]] + 1):
            c[y][x] = 1
    for i in range(M):
        x = dictx[D[i]]
        for y in range(dicty[E[i]], dicty[F[i]] + 1):
            c[y][x] = 1
    que = deque()
    used = [[0] * len(UX) * 2 for _ in range(len(UY) * 2)]
    dy = [1, 1, -1, -1]
    dx = [1, -1, 1, -1]
    for k in range(4):
        nny, nnx = dicty[0] + dy[k], dictx[0] + dx[k]
        if 1 <= nny < len(UY) * 2 - 1 and 1 <= nnx < len(UX) * 2 - 1:
            que.append((nny, nnx))
            used[nny][nnx] = 1
    ans = 0
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    while que:
        y, x = que.popleft()
        if y % 2 and x % 2:
            ans += LY[y] * LX[x]
        for k in range(4):
            ny, nx = y + dy[k], x + dx[k]
            nny, nnx = ny + dy[k], nx + dx[k]
            if c[ny][nx] == 0:
                if nny < 0 or nny >= len(UY) * 2 - 1 or nnx < 0 or nnx >= len(UX) * 2 - 1:
                    return 'INF'
                if not used[nny][nnx]:
                    que.append((nny, nnx))
                    used[nny][nnx] = 1
    return ans

print(f_single_dot())

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

static const int NIL = -1;

struct Node {
	int parent;
	int left;
	int right;
	Node(int parent = NIL, int left = NIL, int right = NIL): parent(parent), left(left), right(right) {}
};

vector<Node> T;

void prePerse(int u)
{
	if (u == NIL) return;
	printf(" %d", u);
	prePerse(T[u].left);
	prePerse(T[u].right);
}

void inPerse(int u)
{
	if (u == NIL) return;
	inPerse(T[u].left);
	printf(" %d", u);
	inPerse(T[u].right);
}

void postPerse(int u)
{
	if (u == NIL) return;
	postPerse(T[u].left);
	postPerse(T[u].right);
	printf(" %d", u);
}

int main()
{
	int n;
	scanf("%d", &n);
	
	T.resize(n);
	
	for (int i = 0; i < n; i++){
		int v, l, r;
		scanf("%d %d %d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if (l != NIL) T[l].parent = v;
		if (r != NIL) T[r].parent = v;
	}
	
	int root;
	for (int i = 0; i < n; i++){
		if (T[i].parent == NIL) root = i;
	}
	
	printf("Preorder\n");
	prePerse(root);
	printf("\n");
	
	printf("Inorder\n");
	inPerse(root);
	printf("\n");
	
	printf("Postorder\n");
	postPerse(root);
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		int[]B = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(Console.ReadLine());
			B[i] = A[i];
		}
		Array.Sort(B);
		for(var i=0;i<N;i++){
			if(A[i]==B[N-1]){
				Console.WriteLine(B[N-2]);
			} else {
				Console.WriteLine(B[N-1]);
			}
		}
	}
}

Measured memory_bytes: 19924
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct study{
	int x;
	int y;
	int h;
}c[110];
int main()
{
	int n,p=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x>>c[i].y>>c[i].h;
	}
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int flag=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					flag=1;
					break;
				}
			}
			if(!flag)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
}

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

using namespace std;

ll n;
ll ans = 0;

void rec(ll s, bool have3, bool have5, bool have7){
  if (s > n){return;}
  if (have3 && have5 && have7){ans++;}
  rec(10*s+3, true, have5, have7);
  rec(10*s+5, have3, true, have7);
  rec(10*s+7, have3, have5, true);
}

int main(){
	cin >> n;
	rec(0, false, false, false);
	cout << ans << endl;
}


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

int main()
{    
   int n;
   cin >> n;
   vector<int> p(n),q(n),a(n);
   rep(i,n) cin >>  p[i];
   rep(i,n) cin >>  q[i];
   rep(i,n) a[i] = i+ 1;

   map<vector<int>,int> mp;

   do{
      mp[a] = mp.size();
   }while(next_permutation(a.begin(), a.end()));

   int ans = abs(mp[p] - mp[q]);

   cout << ans << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> baseNums;
    baseNums.push_back(1);
    ll temp = 6;
    while (temp <= N)
    {
        baseNums.push_back(temp);
        temp *= 6;
    }
    temp = 9;
    while (temp <= N)
    {
        baseNums.push_back(temp);
        temp *= 9;
    }
    sort(baseNums.begin(), baseNums.end(), greater<ll>());
    priority_queue<tll, vector<tll>, greater<tll>> que;
    que.push(make_tuple(0, N, 0));
    ll answer = 1e12;
    while (!que.empty())
    {
        ll count, remain, baseNumIndex;
        tie(count, remain, baseNumIndex) = que.top();
        que.pop();
        ll baseNum = baseNums.at(baseNumIndex);
        if (count >= answer)
        {
            break;
        }
        if (remain % baseNum == 0)
        {
            answer = min(answer, count + remain / baseNum);
            continue;
        }
        ll currentCount = 0;
        while (baseNum * currentCount < remain)
        {
            if((baseNum % 2 == 1 && currentCount == 9) || (baseNum % 2 == 0 && currentCount == 6))
            {
                break;
            }
            que.push(make_tuple(count + currentCount, remain - baseNum * currentCount, baseNumIndex + 1));
            currentCount++;
        }
    }
    cout << answer << endl;
    return 0;
}


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

int main(){
    int64_t n, b, r, tb, x;
    cin >> n >> b >> r;
        x = n % (b+r);
        if(x <= b){
            tb = n/(b+r)*b + x;
        }else {
            tb = n/(b+r)*b + b;
        }
        cout << tb << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    max = A[N - 1]
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
        if count == M:
            break
    A.sort()
    
ans = int(sum(A))

print(ans)

Measured memory_bytes: 23096
#include<bits/stdc++.h>
using namespace std; 
int main(){
	int a;
	bool s=false;
	cin>>a;
	int b[a];
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	for(int i=0;i<a;i++){
		if(b[i]%2!=0)continue;
		if(b[i]%3!=0&&b[i]%5!=0){ 
		cout<<"DENIED";
		return 0; 
	}
	}
	cout<<"APPROVED";
	return 0;
} 

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

using namespace std;

#define MOD 1000000007
#define N 1003
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int grid[N][N];
int dp[N][N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, i, j;
    cin>>n>>m;
    char ch;
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            cin>>ch;
            if(ch == '#') grid[i][j] = 1;
        }
    }
    dp[1][1] = (grid[1][1] == 0);
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            if(grid[i-1][j] == 0){
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            }
            if(grid[i][j-1] == 0){
                dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
            }
        }
    }
    cout<<dp[n][m];
    return 0;
}

Measured memory_bytes: 8064
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    n = int(input().strip())
    ans = 0
    for i in range(1, n):
        j = n - i
        if i == j:
            continue
        ans += 1
    print(ans // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
while True:
 h,w = map(int, input().split())
 if w==0 and h==0:
  break
 for i in range(h):
    for j in range(w):
        if i == 0 or i == h-1 or j == 0 or j == w-1:
            print("#", end="")
        else:
            print(".", end="")
    print()
 print()


Measured memory_bytes: 7004
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i] != s[s.size()-i-1])
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int m;
	while (cin >> m) {
		int z1 = m / 1000;
		int z4 = m % 10;
		int z3 = (m % 100 - z4) / 10;
		int z2 = m / 100 - z1 * 10;
		if (z1 == z2 && z2 == z3) cout << "Yes";
		else if (z2 == z3 && z4 == z3) cout << "Yes";
		else cout << "No";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll k,a,b;
cin>>k>>a>>b;
ll count=1;
ll memo=k;
if(k>=a-1){
if(b-a>=2){
if((k-(a-1))%2==0){
cout<<a+(k-(a-1))/2*(b-a);
}
else{
cout<<a+(k-(a-1))/2*(b-a)+1;
}
}
else{
cout<<1+k;
}
}
else
cout<<1+k;
  return 0;
 
}
 

Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define INF 1000000
#define WHITE 1
#define BLACK 0

int main(){

  int d[N], color[N], w[N][N];
  int i, j, v, c;
  int n, u, k;
  int mincost;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
	for(j = 0; j  < n; j++){
	  w[i][j] = -1;
	}
  }

  for(i = 0; i < n; i++){
	scanf("%d %d",&u, &k);
	for(j = 0; j < k; j++){
	  scanf("%d %d", &v, &c);	 
	  w[i][v] = c;
	}
  }

  for(i = 0; i < n; i++){
	d[i] = INF;
	color[i] = WHITE;
  }

  d[0] = 0;
  
  while(1){
	mincost = INF;
	for(i = 0; i < n; i++){
	  if(d[i] < mincost && color[i] ==WHITE){
		mincost = d[i];
		u = i;
	  }
	}
	
	if(mincost == INF)break;
	color[u] = BLACK;
	
	for(v = 0; v < n; v++){
	  if(w[u][v] == -1) continue;
	  if(d[v] >  d[u] + w[u][v]) d[v] = d[u] + w[u][v];
	}
  }   
  for(i = 0; i < n; i++){ 
	printf("%d %d\n",i, d[i]);
  }

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535
 
int main() 
{
    FAST;
    ll n;
    cin>>n;
    ve<ll> v;
    while(n>0)
    {
        v.pb(n%10);
        n=n/10;
    }
    if(v[0]==7 || v[1]==7 || v[2]==7)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;

 
 int  main() {
        
       
       ll a,b,n;
       cin>>a>>b>>n;
       
       ll x=min(b-1,n);
       
       ll ans=(a*x)/b-a*(x/b);
       cout<<ans<<endl;
       
       
    
       
      
    return 0;
}

Measured memory_bytes: 3592
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

vector<int> num;
vector<int> sofa;
vector<int> vals;
int n;
int k;
void search(int i)
{
	if(sofa.size()==k){
		int order[4]={0,1,2,3};
		do{
			int v=0;
			for(int i=0;i<k;i++){
				int a=vals[sofa[order[i]]];
				if(a>=10){
					v*=100;
				}
				else
				{
					v*=10;
				}
				v+=a;
			}
			//cout << v << endl;
			num.push_back(v);
		}while(next_permutation(order,order+k));
	}
	else if (i==vals.size()){
		return;
	}
	else{
		sofa.push_back(i);
		search(i+1);
		sofa.pop_back();
		search(i+1);
	}
}
int main() {
while(1){
	cin >> n >> k;
	if(n==0&&k==0){
		return 0;
	}
	num.clear();
	vals.clear();
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		vals.push_back(a);
	}
	search(0);
	sort(num.begin(),num.end());
	int ret=unique(num.begin(),num.end())-num.begin();
	cout << ret << endl;

}
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256