akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main (int argc,char **argv)
{
	char s[4];
	char work;
	int b = 0;
	int i = 0,j = 0;
	scanf("%s",s);

	
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3 ; j++)
		{
			b = strcmp(&s[i],&s[j]);

			if (b < 0)
			{
				work = s[i];
				s[i] = s[j];
				s[j] = work;
			}

		}
	}

	


	if (s[0]=='a' && s[1]=='b' && s[2] == 'c')
	{
		printf("Yes\n");
	}
	else 
	{
		printf("No\n");
	}
	return 0;

}

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

int main()
{
	long long N, D;
	cin >> N >> D;
	
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		long long X, Y;
		cin >> X;
		cin >> Y;
		if (X * X + Y * Y <= D * D) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3600
#coding:utf-8
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
#heapqで最大値をとる際は一度マイナスにしてから
a = [-1 * i for i in a]

#その時買うものリストにある最高額に対して、割引券を1枚ずつ使う
#ただし愚直にやるとTLEのため、優先度付きキューを使う

#入力リストをheap化する
heapq.heapify(a)

#割引券の枚数分だけ、最高額を抽出し、割引券を使う
for i in range(0, m):
    #当時の最高額をheappopで取り出して割引後の価格を出す
    discount = (heapq.heappop(a) * (-1)) // 2
    #heappushで割引後の価格をリストに入れる
    heapq.heappush(a, discount * (-1))

print(-1 * sum(a))


Measured memory_bytes: 14180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

vi prime;
bool isP[300000];

int main() {
	for(int i=2; i*i<300000; i++) {
		if(!isP[i]) {
			for(int j=i+i; j<300000; j+=i) {
				isP[j] = true;
			}
		}
	}
	for(int i=2; i<300000; i++) {
		if(!isP[i]) {
			prime.push_back(i);
		}
	}
	int n, p;
	while(cin >> n >> p, n!=-1 && p!=-1) {
		int s = 0;
		while(prime[s] <= n) s++;
		vi adds;
		for(int i=s; i<100+s; i++) {
			for(int j=i; j<100+s; j++) {
				adds.push_back(prime[i]+prime[j]);
			}
		}
		sort(adds.begin(), adds.end());
		cout << adds[p-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1640
(defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))
  (if (<= (abs (- ng ok)) 1)
      ok
      (let ((mid (floor (+ ng ok) 2)))
        (if (funcall predicate mid)
            (lower-bound predicate mid ng)
            (lower-bound predicate ok mid)))))


(defun smaller-p (xs index b-size)
  (< (aref xs index) b-size))


(defun bigger-p (xs index b-size)
  (> (aref xs index) b-size))


(defun solve (a b c &optional (res 0))
  (declare (optimize speed))
  (declare (type (array fixnum) a b c))
  (declare (type integer res))
  (the integer
       (dotimes (j (length b) res)
         (incf res (* (lower-bound #'(lambda (x)
                                       (smaller-p a x (aref b j)))
                                   0
                                   (length a))
                      (lower-bound #'(lambda (x)
                                       (bigger-p c x (aref b j)))
                                   0
                                   (length c)))))))


(defparameter *inf* (1+ (expt 10 9)))



(locally
  (declare (inline sort))
  (let* ((n (read))
         (a (make-array (1+ n) :element-type 'fixnum))
         (b (make-array n      :element-type 'fixnum))
         (c (make-array (1+ n) :element-type 'fixnum)))
    (declare (type fixnum n))
    (setf (aref a (1- (length a))) 0)
    (setf (aref c (1- (length c))) *inf*)
    (dotimes (i n)
      (setf (aref a i) (read)))
    (dotimes (i n)
      (setf (aref b i) (read)))
    (dotimes (i n)
      (setf (aref c i) (read)))
    (sort a #'<)
    (sort c #'>)
    (princ (solve a b c))
    (fresh-line)))



Measured memory_bytes: 78716
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,x;
  cin >> n >> x;
  rep(i,n+1) {
    rep(j,n+1) {
      int k=n-i-j;
      if(k<0) continue;
      if(i*10000+j*5000+k*1000==x) {
        pr(i,j,k);
        return;
      }   
    }
  }
  pr(-1,-1,-1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    double c=0,t=n;
    for (int i=1;i<=n;i++)
    {
        if (i%2==1)
            c++;
    }
    cout<<fixed<<setprecision(10)<<c/t<<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
def input():
    return stdin.readline().strip()

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
a, b = [], []
for _ in range(m):
    i, j = map(int, input().split())
    edge[i-1].append(j-1)
    edge[j-1].append(i-1)
    a.append(i-1)
    b.append(j-1)

# full search
# DFS
ans = 0
for i in range(m):
    seen = [True] * n
    todo = []
    start = a[i]
    goal = b[i]
    seen[start] = False
    for j in edge[start]:
        if j == goal:
            continue
        else:
            todo.append(j)
            seen[j] = False

    while len(todo) > 0 and seen[goal]:
        j = todo.pop(-1)
        for k in edge[j]:
            if seen[k]:
                todo.append(k)
                seen[k] = False

    if seen[goal]:
        ans += 1

print(ans)

Measured memory_bytes: 67884
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> t[i];
    sum += t[i];
  }
  cin >> m;
  
  for(int i = 0; i < m; i++){
    int p, x, sum_i = sum;
    cin >> p >> x;
    p--;
    sum_i -= t[p];
    sum_i += x;
    cout << sum_i << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
Alice, Bob = list(map(int,input().split()))
ans = ["Bob", "Alice", "Draw"]

if Bob == Alice:
  print(ans[2])
elif Alice == 1:
  print(ans[1])
elif Bob == 1:
  print(ans[0])
elif Bob > Alice:
  print(ans[0])
else:
  print(ans[1])

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  for(ll i = 0; i < n; ++i) cin >> a[i], b[i] = a[i];
  sort(begin(b),end(b));
  ll b1 = b[n-1],b2 = b[n-2];
  for(ll i : a){
    if(i == b1) cout << b2 << '\n';
    else cout << b1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



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


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	

	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		if (t >= k) {
			ans++;
		}
	}
	cout << ans << endl;





	

}



Measured memory_bytes: 256
n = int(input())
s = input()

max_count=0
for i in range(1,n):
    left = s[:i]
    right = s[i:]
    count = 0
    for c in "abcdefghijklmnopqrstuvwxyz":
        if c in left and c in right:
            count += 1
    max_count = max(max_count, count)

print(max_count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll INF=1000000010;
const int MAX=100011;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int m,n;
int p[10010],c[510],e[510];
int dp[510][10010];
int main(){
	int n,m;cin>>n>>m;
	int a[310][310];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	int idx[310]={};
	bool f[310]={false};
	int ans=INF;
	int co=m;
	while(co--){
		int ma=0;int id;int c[310]={};
		for(int i=0;i<n;i++){
			if(idx[i]>=m)continue;
			c[a[i][idx[i]]]++;
		}
		for(int i=1;i<=m;i++){
			if(c[i]>ma){
				ma=c[i];
				id=i;
			}
		}
		ans=min(ans,ma);
		f[id]=true;
		for(int i=0;i<n;i++){
			while(f[a[i][idx[i]]]){
				idx[i]++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int a, b, c;
	int tmpa, tmpb, tmpc;
	int ans = 0;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b&&b == c&&a % 2 == 0)
	{
		printf("-1");
		return 0;
	}

	while (a % 2 == 0&&b % 2 == 0&&c % 2 == 0)
	{
		tmpa = b / 2 + c / 2;
		tmpb = a / 2 + c / 2;
		tmpc = a / 2 + b / 2;
		a = tmpa;
		b = tmpb;
		c = tmpc;
		ans++;
	}
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
s = []
for i in range(h):
    s_ = input()
    s.append(s_)

for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            if j + 1 < h and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < w and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner.nextLine();

		System.out.println(Arrays.stream(scanner.nextLine().split(" "))
								.mapToInt(Integer::parseInt)
								.map(
									i -> {
										int count = 0;
										while (i % 2 == 0) {
											i /= 2;
											count++;
										}
										return count;
									})
								.sum());
	}
}


Measured memory_bytes: 29372
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
int main() {
  int n;
  while(cin >> n) {
    if(n == 0) break;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0LL;
    rep(i, n) sum += a[i];
    int ans = 0;
    rep(i, n) if(sum >= a[i] * n) ++ans;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3068
a, b, c, x, y = map(int, input().split())

cost = a*x+b*y

for i in range(max(x,y)):
  if min(x, y)-i-1 >=0:
    if cost > a*(x-i-1)+b*(y-i-1)+c*(i+1)*2:
      cost = a*(x-i-1)+b*(y-i-1)+c*(i+1)*2
  elif x-i-1 < 0:
    if cost > b*(y-i-1)+c*(i+1)*2:
      cost = b*(y-i-1)+c*(i+1)*2
  else:
    if cost > a*(x-i-1)+c*(i+1)*2:
      cost = a*(x-i-1)+c*(i+1)*2

print(cost)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod= 1e9+7;

int main(){
  string S;
  cin>>S;
  int a[26]={0};
  for (int i(0);i<S.size();i++){
    a[S[i]-'a']+=1;
  }
  for (int i(0);i<26;i++){
    if (a[i]==0){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)-1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT1]={0},b[LIMIT1]={0},c[1000][1000]={0};
  int d[LIMIT1]={0};
  map<ll,ll> dp;
  
  cin >> n >> m;
  rep(i,m){
    cin >> a[i] >> b[i];
    rep(j,b[i]){
      cin >> c[i][j];
      d[i] += (int)modpow(2,c[i][j]-1,0);
    }
  }
  rep(j,1<<n){
    dp[j]=1LL<<60;
  }
  dp[0]=0;
  rep(i,m){
    rep(j,1LL<<n){
      dp[j|d[i]] = min(dp[j|d[i]],dp[j]+(ll)a[i]);
    }
  }
  cout << (dp[(1<<n)-1]==1LL<<60 ? -1 : dp[(1<<n)-1]) << endl;
  return 0;
}

Measured memory_bytes: 10088
n = int(input())
A = input().rstrip().split()
B = list(map(lambda x:int(x[1]), A))
C = list(enumerate(B))
D = list(enumerate(B))

Cb = C
nums = [n - i for i in range(1, n)]
flag = 1

while flag == 1:
    flag = 0
    for j in nums:
        if Cb[j][1] < Cb[j - 1][1]:
            Cb[j], Cb[j - 1] = Cb[j - 1], Cb[j]
            flag = 1
        else:
            pass
Ab = [A[Cb[i][0]] for i in range(n)]
print(*Ab)
bstable = 1
for j in range(n - 1):
    if Cb[j + 1][1] == Cb[j][1] and Cb[j + 1][0] < Cb[j][0]:
        bstable = 0
        break
if bstable == 1:
    print("Stable")
else:
    print("Not stable")

Cs = D
for i in range(n):
    minj = i
    for j in range(i, n):
        if Cs[j][1] < Cs[minj][1]:
            minj = j
        else:
            pass
    Cs[i], Cs[minj] = Cs[minj], Cs[i]
    
As = [A[Cs[i][0]] for i in range(n)]
print(*As)
cstable = 1
for j in range(n - 1):
    if Cs[j + 1][1] == Cs[j][1] and Cs[j + 1][0] < Cs[j][0]:
        cstable = 0
        break
if cstable == 1:
    print("Stable")
else:
    print("Not stable")



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

int main(void){
 string S,T;
 cin >> S >> T;
  
  for(int i=0;i<S.size();i++){
  	if(S.at(i)!=T.at(i)){
    	cout << "No" << endl;
      	return 0;
    }
  }
  cout << "Yes" << endl;
}

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

const int N=20010,mod=998244353;
int m,n,jc[N],inv[N],f[210][8010],w[16387],p[16387];
vector<int> A,B;

int quickmi(int a,int b)
{
	int t=1;
	for (; b; b>>=1,a=1ll*a*a%mod)
		if (b&1) t=1ll*t*a%mod;
	return t;
}

void dft(vector<int> &A,int fl)
{
	int n=16384;
	for (int i=0; i<n; i++)
		if (p[i]<i) swap(A[p[i]],A[i]);
	for (int i=1; i<n; i<<=1)
		for (int j=0; j<n; j+=(i<<1))
			for (int k=0; k<i; k++)
			{
				int t1=A[j+k],t2=1ll*A[i+j+k]*w[i+k]%mod;
				A[j+k]=(t1+t2>=mod?t1+t2-mod:t1+t2);
				A[i+j+k]=(t1<t2?t1-t2+mod:t1-t2);
			}
	if (fl==-1)
	{
		int inv=quickmi(n,mod-2);
		for (int i=0; i<n; i++) A[i]=1ll*A[i]*inv%mod;
		for (int i=1; i<(n>>1); i++) swap(A[i],A[n-i]);
	}
}

int main()
{
	jc[0]=1;
	for (int i=1; i<N; i++) jc[i]=1ll*jc[i-1]*i%mod;
	inv[N-1]=quickmi(jc[N-1],mod-2);
	for (int i=N-1; i; i--) inv[i-1]=1ll*inv[i]*i%mod;
	for (int i=0; i<14; i++)
	{
		w[1<<i]=1; int wn=quickmi(3,(mod-1)>>(i+1));
		for (int j=(1<<i)+1; j<(1<<i+1); j++) w[j]=1ll*w[j-1]*wn%mod;
	}
	p[0]=0;
	for (int i=1; i<16384; i++) p[i]=(p[i>>1]>>1)|((i&1)?8192:0);
	scanf("%d%d",&n,&m),f[0][0]=1,B.resize(16384);
	for (int j=1; j<=n; j++) B[j]=inv[j+2];
	dft(B,1),A.resize(16384);
	for (int i=1; i<=m; i++)
	{
		for (int j=0; j<=n; j++) A[j]=1ll*f[i-1][j]*inv[j]%mod;
		for (int j=n+1; j<16384; j++) A[j]=0; dft(A,1);
		for (int j=0; j<16384; j++) A[j]=1ll*A[j]*B[j]%mod; dft(A,-1);
		for (int j=0; j<=n; j++) f[i][j]=1ll*A[j]*jc[j+2]%mod;
		for (int j=0; j<=n; j++) f[i][j]=(f[i][j]+f[i-1][j]*((1ll*j*(j+1)/2+1)%mod))%mod;
	}
	int ans=0;
	for (int j=0; j<=n; j++) ans=(ans+1ll*f[m][j]*jc[n]%mod*inv[j]%mod*inv[n-j])%mod;
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        java.util.Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] p = new int[200000], q = new int[200000];
        for (int i = 0; i < n; i++) {
            q[input.nextInt() - 1] = i;
        }
        int r = 0, f = 1000000, c = 0;
        for (int i = 0; i < n; i++) {
            if (f < q[i]) {
                c++;
            } else {
                c = 1;
            }
            f = q[i];
            if (r < c) r = c;
        }
        System.out.println(n - r);
    }
}


Measured memory_bytes: 85284
from collections import defaultdict

def main():
    n = int(input())
    vlst = list(map(int, input().split()))
    dd = [defaultdict(int), defaultdict(int)]
    dd[0][-1] = 0
    dd[1][-1] = 0
    for i, v in enumerate(vlst):
        dd[i % 2][v] += 1
    odd = sorted(dd[0].items(), key = lambda x:x[1], reverse = True)
    even = sorted(dd[1].items(), key = lambda x:x[1], reverse = True)
    if odd[0][0] != even[0][0]:
        minus = odd[0][1] + even[0][1]
        ans = n - minus
    else:
        minus = 0
        minus = max(minus, odd[0][1] + even[1][1])
        minus = max(minus, odd[1][1] + even[0][1])
        ans = n - minus
    print(ans)
main()

Measured memory_bytes: 102232
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VVI vector<vector<ll>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define lb(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define ub(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define pb push_back
#define pf push_front
#define m_p make_pair
#define fi first
#define se second
#define sz size()
#define sort(v) sort(v.begin(),v.end())
ll n;
VI v;
ll dp[100005]; 
ll fun(ll ind)
    {   if(ind>=n)
            return 0;
        if(dp[ind]!=-1)
            return dp[ind];
        return dp[ind]=min(abs(v[ind]-v[ind+1])+fun(ind+1),abs(v[ind]-v[ind+2])+fun(ind+2));
    }
int main()
{   cin>>n;
    v=VI(n+1);
    lf(i,1,n)
    {   cin>>v[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fun(1)<<endl;    
}

Measured memory_bytes: 4096
#include <stdio.h>
int main(void){
   int a, b;
    
   scanf("%d %d", &a, &b);
   if (a < b) printf("a < b\n");
   else if (a > b) printf("a > b\n");
   else  printf("a == b\n");
    
   return 0;
}


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

int main() {
  //input
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  rep(i,N) {
    cin >> S.at(i);
  }
  //calc
  sort(S.begin(), S.end());
  //output
  rep(i,N) {
    cout << S.at(i);
  }
  cout << endl;
}

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

#define int long long
#define reps(i,s,n) for(ll (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,n+1)
#define repst(i,s,n) reps(i,s,n+1)
#define reprt(i,n,t) for(ll (i)=(n);(i)>=t;--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb emplace_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) for(int (i)=0;i<n;++i){cout<<x[i]<<(i==n-1?'\n':' ');}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, m = inf, t, r[114514];
vpii p;

signed main() {
	cin >> n;
	p.resize(n+1);
	rep(i,n) {
		cin >> a;
		p[i] = {a,i};
	}
	// 降順ソートして手前から個数をならしていく
	// 例えば (4,3) (3,1) (2,2) (0,0)
	// 3を1個追加して3番の山から1個取る
	// -> 1番目・3番目の好きな方を2*1回追加できる
	// -> 3,1,2番目の好きなものを3*2回追加できる
	// こんな感じ 説明しにくいけど実験するとわかりやすい
	p[n] = {0,0};
	sort(p.rbegin(), p.rend());
	rep(i,n) {
		chmin(m,p[i].se);
		r[m] += (i+1)*(p[i].fi-p[i+1].fi);
	}
	rep(i,n) cout << r[i] << ln;
}

Measured memory_bytes: 3456
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, X;
	cin >> N >> X;
	vector<int>L(N), D(N + 1);
	rep(i, N)cin >> L[i];
	D[0] = 0;
	int cnt = 1;
	rep(i, N)
	{
		D[i + 1] = D[i] + L[i];
		if (D[i + 1] <= X)cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int h, m, f, r;
    char s = '\0';
    
    while (1) {
        scanf("%d %d %d", &m, &f,&r);
        if (m == -1 && f == -1 && r == -1)     break;
        
        h = m + f + r;
        
        if (m == -1 || f == -1) {
            s = 'F';
        }
        else if ((m + f) >= 80) {
            s = 'A';
        }
        else if ((m + f) >= 65 && (m + f) < 80) {
            s = 'B';
        }
        else if ((m + f) >= 50 && (m + f) < 65) {
            s = 'C';
        }
        else if ((m + f) >= 30 && (m + f) < 50) {
            if (r >= 50){
                s = 'C';
            }
            else {
                s = 'D';
            }
        }
        else if ((m + f) < 30){
            s = 'F';
        }
        
        printf("%c\n", s);
    }
    
    return 0;
}

Measured memory_bytes: 600
A,B,K = [int(x) for x in input().split()]
if B-A<K:
  c = [i for i in range(A,B+1)]
  print(*c)
  exit()
c = [i for i in range(A,A+K)]
d = [i for i in range(B-K+1,B+1)]
d =c+d
d = list(set(d))
d.sort()
print(*d)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int count = 3;
  
  if ( a == b ) count--;
  if ( a == c ) count--;
  if ( b == c ) count--;
  
  if (count == 0) cout << 1 << endl;
  else cout << count << endl;
  
 }


Measured memory_bytes: 256
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
a=1/(4*M)*sum(A)
for i in range(M):
  if(A[i]<a):
    break
  count+=1
if(count==M):
  print('Yes')
else:
  print('No')

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

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

using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  valarray<int> p = {a+b, b+c, a+c};
  cout<<p.min();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<int> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll  n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
	s = "YES";
	int n, m;
	cin >> n >> m;
	vi v(n + 1);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		v[a]++;
		v[b]++;
	}
	REP(i, n) v[i + 1] += v[i];
	REP(i, n + 1) {
		if (v[i] % 2 == 1) {
			s = "NO";
			break;
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
    int a, b, c, cnt=0;
    scanf("%d%d%d",&a,&b,&c);
    for(;a <= b;a++){
        if( c % a == 0 ){
            cnt += 1;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const int sz = 1 << 17;
vector< int > seg[2 * sz + 1];
int data[100000], n;

int query(int a, int b, int lower, int upper, int k, int l, int r)  // [a,b)でlower以上upper以下の数を求める
{
  if(a >= r || b <= l) {
    return(0);
  } else if(a <= l && r <= b) {
    return(upper_bound(seg[k].begin(), seg[k].end(), upper) - lower_bound(seg[k].begin(), seg[k].end(), lower));
  } else {
    return(query(a, b, lower, upper, 2 * k + 1, l, (l + r) >> 1) + query(a, b, lower, upper, 2 * k + 2, (l + r) >> 1, r));
  }
}
void init(int k, int l, int r)
{
  if(l + 1 == r) {
    if(l >= 0 && l < n) seg[k].push_back(data[l]);
  } else {
    init(2 * k + 1, l, (l + r) >> 1);
    init(2 * k + 2, (l + r) >> 1, r);
    seg[k].resize(seg[2 * k + 1].size() + seg[2 * k + 2].size());
    merge(seg[2 * k + 1].begin(), seg[2 * k + 1].end(), seg[2 * k + 2].begin(), seg[2 * k + 2].end(), seg[k].begin());
  }
}


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

  int Q;
  cin >> Q;
  while(Q--) {
    int l, r, e;
    scanf("%d %d %d", &l, &r, &e);
    --l, --r;
    int lower = min(data[l], data[r]) - e;
    int upper = max(data[l], data[r]) + e;
    printf("%d\n", r - l + 1 - query(l, r + 1, lower, upper, 0, 0, sz));
  }
  return(0);
}

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

#define ull unsigned long long

using namespace std;

const int N = 330;
const int base = 233;

char s[N << 1][N << 1];
ull Lhash[N << 1][N << 1], Hhash[N << 1][N << 1], Pow[N];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			s[i + n][j] = s[i][j + n] = s[i + n][j + n] = s[i][j];
	for(int i = 1; i <= 2 * n; i++)
		for(int j = 1; j <= 2 * n; j++)
			Lhash[i][j] = Lhash[i - 1][j] * base + s[i][j] - 'a' + 1;
	for(int j = 1; j <= 2 * n; j++)
		for(int i = 1; i <= 2 * n; i++)
			Hhash[i][j] = Hhash[i][j - 1] * base + s[i][j] - 'a' + 1;
	Pow[0] = 1;
	for(int i = 1; i <= n; i++)
		Pow[i] = Pow[i - 1] * base;
	int ans = 0;
	for(int A = 0; A < n; A++)
		for(int B = 0; B < n; B++)
		{
			int flag = 1;
			for(int k = 1; k <= n; k++)
			{
				int x1 = A + k, y1 = B + k, x2 = A + n, y2 = B + n;
				ull hash1 = Lhash[x2][y1] - Lhash[x1 - 1][y1] * Pow[n - k + 1];
				ull hash2 = Hhash[x1][y2] - Hhash[x1][y1 - 1] * Pow[n - k + 1];
				if(hash1 != hash2)
				{
					flag = 0;
					break;
				}
			}
			ans += flag;
		}
	printf("%d\n", ans);
}

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

#define X first
#define Y second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

/*#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
                         tree_order_statistics_node_update>;*/

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	int k = 0;
	for (int i = 0; i < n; ++i) {
		k += a[i] * 4 * m >= sum;
	}
	cout << (k >= m ? "Yes\n" : "No\n");
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	// cin >> tt;
	while (tt--) solve();
	return 0;
}


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

bool Binary(int x,int s[],int n){
  int b=0;
  int t=n-1;

  while(b<=t){
    int mid=(b+t)/2;

    if(s[mid]==x){
      return true;
    }else if(s[mid]<x){
      b=mid+1;
    }else{
      t=mid-1;
    }
  }

  return false;
}

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

  int s[n];
  for(int i=0; i<n; i++){
    cin >> s[i];
  }

  int q;
  cin >> q;

  int t[q];
  for(int i=0; i<q; i++){
    cin >> t[i];
  }

  int count=0;
  for(int i=0; i<q; i++){
    if(Binary(t[i],s,n)!=false){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int n = Integer.parseInt(str);
		str = input.readLine( );
		String[] strlist = str.split(" ");
		int[] list = new int[n];
		for(int i=0; i<n; i++){
			list[i] = Integer.parseInt(strlist[i]);
		}
		Arrays.sort(list);
		System.out.println(list[n-1]-list[0]);
	}
}




Measured memory_bytes: 21076
#include<cstdio>
int n,a,b;
int main()
{
    for(int i=1;i<=3;i++)
    {
        scanf("%d",&n);
        if(n==7)
            a++;
        if(n==5)
            b++;
    }
    if(a==1 && b==2)
        printf("YES");
    else
        printf("NO");
    return 0;
}

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

#define TASK ""
#define openfile ({freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);})

char s[20];

int main() {
	// openfile
	cin >> s + 1;
	int n = strlen(s + 1);
	if (n < 4) return cout << "No", 0;
	if (s[1] == 'Y' && s[2] == 'A' && s[3] == 'K' && s[4] == 'I') return cout << "Yes", 0;
	cout << "No";
	return 0;
}


Measured memory_bytes: 256
/*  ex9_2
    suuxxu  */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100000

typedef struct node{ // スタック内のデータの定義
    char data; // データの要素
    struct node *next; // 次のノードを表すポインタ
} node;

void push(node **head, char data); // スタックのpush操作
char pop(node **head); // スタックのpop操作

int main(void){
    int i, ans;
    char add, tmp, input[SIZE+1];

    // 先頭ノードをNULLに
    node *head = NULL;

    // 入力をinputに格納
    scanf("%s", input);

    ans = 0; // 答えを初期化
    for(i = 0; i < strlen(input); i++){
        add = input[i];
        if(head == NULL){ // 先頭ノードがNULLなら
            // 要素を追加
            push(&head, add);
        }else{
             // 今の先頭要素を取り出す
            tmp = pop(&head);
            if(add != tmp){ // 隣り合った要素が異なるなら
                // 要素は取り出したまま
                // 答えに2を追加
                ans += 2;
            }else{ // 隣り合った要素が等しいなら
                // 取り出した要素を戻す
                push(&head, tmp);
                // 次の要素を追加
                push(&head, add);
            }
        }
    }

    // 答えを出力
    printf("%d\n", ans);

    return 0;
}

// スタックのpush操作
void push(node **head, char data){
    node *new;

    // 追加する要素の領域を確保
    new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);

    new->data = data; // newにノードの要素を格納
    new->next = *head; // newの次のノードを今の先頭ノードに
    *head = new; // 新しい先頭ノードをnewに
}

// スタックのpop操作
char pop(node **head){
    char data;

    node *tmp = *head;
    if(tmp == NULL) exit(1);

    data = tmp->data; // ノードの要素を取得
    *head = tmp->next; // 先頭ノードを次のノードにずらす

    // 取り出したノードのメモリを解放
    free(tmp);

    return data;
}

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

int main()
{
	std::string s;
	std::cin >> s;

	int a = 200000, z = 0;
	int i;
	for( i = 0; i < s.length(); i++ ){
		if ( s[i] == 'A' ){
			a = std::min( a, i );
		}
		if ( s[i] == 'Z' ){
			z = std::max( z, i );
		}
	}
	
	std::cout << z - a + 1 << std::endl;

	return 0;
}

Measured memory_bytes: 640
import heapq

s = input()
K = int(input())

h = []
l = set()

for i in range(len(s)):
  m = min(len(s),i+K)
  for j in range(i,m):
    heapq.heappush(h, s[i:j+1])
    
while h:
  p = heapq.heappop(h)
  l.add(p)
  if len(l) == K:
    print(p)
    exit()

Measured memory_bytes: 71248
def test_case():
    for i in range(1, 3001):
        li = list(map(int, input().split()))
        if li[0] == 0 and li[1] == 0:
            break

        if li[0] > li[1]:
            li[0], li[1] = li[1], li[0]
        print(li[0], li[1])


if __name__ == "__main__":
    test_case()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  
  int ans =1e9;
  for(int i=-100;i<=100;i++){
    int res=0;
    rep(j,n){
      res+=pow(i-a[j],2);
    }
    ans=min(ans,res);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int mod=1e9+7;
signed main()
{
  int h,w,i,j;
  cin>>h>>w;
  int dp[h][w];
  for (int i=0;i<h;++i)
  {
    for (int j=0;j<w;++j)
    {
      char a;
      cin>>a;
      if (a=='#')
      	dp[i][j]=-1;
      else
        dp[i][j]=0;
    }
  }
  for (int i=0;i<h;++i)
  {
    if (dp[i][0]==-1)
      {
        break;
      }
    dp[i][0]=1;
  }
    for (int j=0;j<w;++j)
    {
      if (dp[0][j]==-1)
      {
        break;
      }
    dp[0][j]=1;
    }
  for (int i=1;i<h;++i)
  {
    for (int j=1;j<w;++j)
    {
      if (dp[i][j]==-1)
        continue;
      if (dp[i-1][j]!=-1 )
        dp[i][j]=dp[i-1][j]%mod;
      if (dp[i][j-1]!=-1)
        dp[i][j]=(dp[i][j]%mod+dp[i][j-1]%mod)%mod; 
    }
  }
  if (dp[h-1][w-1]==-1)
    dp[h-1][w-1]=0;
  cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int a[10], b[10], per[10];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        per[i] = i + 1;
    }
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) cin >> b[i];
    int ans_a = 1;
    do{
        bool found = 0;
        for(int i = 0; i < n; i++){
            if(a[i] != per[i]){
                found = 1;
                break;
            }
        }
        if(!found) break;
        ans_a++;
    }while(next_permutation(per, per + n));
    sort(per, per + n);
    int ans_b = 1;
    do{
        bool found = 0;
        for(int i = 0; i < n; i++){
            if(b[i] != per[i]){
                found = 1;
                break;
            }
        }
        if(!found) break;
        ans_b++;
    }while(next_permutation(per, per + n));
    cout << abs(ans_a - ans_b);

    return 0;
}


Measured memory_bytes: 3624
N=int(input())
L=[input() for i in range(N)]
c=[0,0,0]
ans=0
for st in L:
  ans+=st.count("AB")
  if st[-1]=="A":
    if st[0]=="B":
      c[0]+=1
    else:
      c[1]+=1
  elif st [0]=="B":
    c[2]+=1
if c[0]!=0:
  ans+=c[0]-1
  if c[1]!=0:
    ans+=1
    c[1]-=1
  if c[2]!=0:
    ans+=1
    c[2]-=1
ans+=min(c[1:])
print(ans)

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

int main(){
    int N,K,Q;
    int seikai;
    
    cin >> N >> K >> Q;
    long long int A[N+1];
    //初期化
    for(int i=1;i<N+1;i++) A[i]=K;
    
    //解答反映
    for(int i=0;i<Q;i++){
        cin >> seikai;
        A[seikai]++;
    }
    //output
    for(int i=1;i<N+1;i++){
        if(A[i]-Q < 1) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

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

int stot(string s){
  int h=0,m=0;
  h = (s[0]-'0')*10 + s[1]-'0';
  m = (s[3]-'0')*10 + s[4]-'0';
  return h*60 + m;
}

int main(){
  int n,t;
  string d[10],a[10];
  string name[11];

  cin >> n >> t;
  for(int i=0;i<n;i++){
    cin >> d[i] >> name[i] >> a[i] >> name[i+1];
  }

  int cnt = 0;
  for(int i=1;i<=n;i++){
    int len = stot(d[i]) - stot(a[i-1]); 
    if(len>=t)cnt++;
  }

  cout << cnt << endl;
  for(int i=1;i<=n;i++){
    int len = stot(d[i]) - stot(a[i-1]); 
    if(len>=t)cout << name[i] << " " << len << endl;
  }
}

Measured memory_bytes: 1216
H, W, K = map(int, input().split())
arr = [input() for i in range(H)]

ans = 0
for ib in range(1<<H):
  for jb in range(1<<W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        #print(i, j, arr[i][j])
        if (ib>>i&1): continue
        if (jb>>j&1): continue
        if arr[i][j] == "#": cnt+=1
    if cnt == K: ans += 1
print(ans)

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

typedef long long int ll; 
#define MOD 1000000007
#define ON 200000
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define FF first
#define SS second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define MK make_pair
#define PB push_back
#define PO pop_back
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
///// This part below is only for debug, not used /////
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
///// END /////



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

  ll ans = 0;

  ans += (n/500)*1000;

  n%=500;

  ans += (n/5)*5;

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

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

int main()
{
    int A, B, C, D;
    cin>>A>>B>>C>>D;

    vector<vector<long long>> T(C+1, vector<long long>(D+1));
    long long M = 998244353LL;
    T[A][B] = 1;
    for (int y=A; y<=C; y++)
        for (int x=B; x<=D; x++)
            if (y>=A || x>=B)
            {
                if (y<C)
                    T[y+1][x] += T[y][x]*x,
                    T[y+1][x] %= M;
                if (x<D)
                    T[y][x+1] += T[y][x]*y,
                    T[y][x+1] %= M;
                if (y<C && x<D)
                {
                    T[y+1][x+1] -= T[y][x]*x%M*y%M,
                    T[y+1][x+1] = (T[y+1][x+1]%M+M)%M;
                }
            }
    cout<<T[C][D]<<endl;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    reverse(all(a));
    if(a[0] != 2){
        cout << -1 << endl;
        return;
    }
    ll l=2, r=3;
    rep1(i, N-1){
        l = (l+a[i]-1)/a[i]*a[i];
        r = r/a[i]*a[i]+a[i]-1;
        if(l >= r){
            cout << -1 << endl;
            return;
        }
    }
    cout << l << " " << r << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5120
X,Y=map(int,input().split())
ans=0
if X==3:
    ans+=100000
elif X==2:
    ans+=200000
elif X==1:
    ans+=300000
if Y==3:
    ans+=100000
elif Y==2:
    ans+=200000
elif Y==1:
    ans+=300000
if X==1 and Y==1:
    ans+=400000
print(ans)


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

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

using namespace std;

int main() {

    long int n,k,diff;
    cin >> n >> k;

    diff = min(n%k, k-n%k);

    cout << diff << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(int argc, char **argv)
{
	int i, k, a, b;
	scanf("%d", &k);
	scanf("%d %d", &a, &b);

	for (i = a; i <= b; ++i)
			{
		if (i % k == 0)
				{
			printf("OK");
			return 0;
		}
	}
	printf("NG");
	return 0;
}


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

using namespace std;

int main(){
  string s;
  int flag=1;
  
  cin >> s;
  
  for(int i=0;i<s.size();i++){
    if((i+1)%2==1){
      if(s[i] == 'L')flag = 0;
    }
    else{
      if(s[i] == 'R')flag = 0;
    }
  }
  
  if(flag == 0)cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}
    

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <fstream>
#include <climits>
#include <cstdio>
#include <vector>
#include <string>
#include <memory>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>


using namespace std;

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


int main()
{
    int mm=1000,mx=0;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        mm=min(mm,a);
        mx=max(mx,a);
    }
    cout<<mx-mm<<endl;
    return 0;
}


Measured memory_bytes: 256
n,a=map(int,input().split())
X=list(map(int,input().split()))
m=max(X)
Y=map(lambda x:x-a,X)
DP=[[0]*(2*m*n+1) for _ in range(n+1)]
DP[0][m*n]=1
for i,y in enumerate(Y):
    for j in range(2*m*n+1):
        DP[i+1][j]=DP[i][j]
        if 0<=j-y<=2*m*n:
            DP[i+1][j]+=DP[i][j-y]
print(DP[n][m*n]-1)

Measured memory_bytes: 5616