akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
    int num;
    int a[300];
    int m;
    
int func(){
    for(int i=0;i<num;i++){
        if(a[i]%2==0){
            a[i]/=2;
        }else return 0;
    }
    return 1;
}

int main() {
    m=0;
    cin >> num;
    for(int i=0;i<num;i++){
        cin>>a[i];
    }
    
    while(func()==1){
        m++;
    }
    
    cout<<m<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int v,e,s,t,flag,a[5001]={};
  bool jud = false;
  vector<int> vec[5001];
  cin >> v >> e;
  for(int i=0;i<e;i++){
    cin >> s >> t;
    vec[s].push_back(t);
    a[t]++;
  }
  stack<int> st;
  for(int i=1;i<=v;i++){
    if(a[i] == 0) st.push(i);
  }
  while(!st.empty()){
    cout << st.top() << endl;
    int p = st.top();
    st.pop();
    flag = 0;
    for(int i=0;i<vec[p].size();i++){
      a[ vec[p][i] ]--;
      if(a[ vec[p][i] ] == 0){
	st.push( vec[p][i] );
	flag++;
      }
    }
    if(flag >= 2) jud = true;
  }
  cout << jud << endl;
  return (0);
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}
int main() {
  int a, b; cin >> a >> b;
  int cnt = 0;
  for(int i=a; i<=b; i++){
    string s = to_string(i);
    int f = 1;
    for(int j=0; j<s.size(); j++){
      if(s[j] != s[s.size()-1-j]){
        f = 0;
        break;
      }
    }
    cnt += f;
  }
  cout << cnt << endl;

  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int y1, y2, ans;
  y1 = a - b;
  ans = c - y1;
  if (ans < 0) cout << 0;
  if (ans >= 0) cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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;}

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

int main(){
    ll A,B,C,D;
    ll count=0;
    cin>>A>>B>>C>>D;
    A--;
    if(C<D){
        ll r=D;
        D=C;
        C=r;
    }
    ll g=1,c=C,d=D;
    while(g!=0){
        g=c%d;
        c=d;
        d=g;
    }
    g=c;
    ll l=(C*D)/g;
    ll sumB=B-(B/C+B/D)+(B/l);
    ll sumA=A-(A/C+A/D)+(A/l);
    cout<<sumB-sumA<<endl;
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MAX=1<<20;
int N,dat[2*MAX-1];

//初期化
void init(int n){
  N=1;
  while(N<n) N*=2; 
  for(int i=0;i<2*N-1;i++) dat[i]=0;
}

//k番目(0-index)をaに変更
void update(int k,int a){
  k+=N-1;
  dat[k]=1<<a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=dat[k*2+1]|dat[k*2+2];
  }
}

//[a,b)なので0-indexならa--,b--;
int query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l) return 0;
  if(a<=l && r<=b) return dat[k];
  int vl=query(a,b,k*2+1,l,(l+r)/2);
  int vr=query(a,b,k*2+2,(l+r)/2,r);
  return vl|vr;
}

int main(){
  int n,q;
  string s;
  cin>>n>>s>>q;
  init(n);
  
  rep(i,n){
    update(i,s[i]-'a');
  }
  
  int c,a,b;
  char d;
  rep(i,q){
    cin>>c;
    if(c==1){
      cin>>a>>d;
      a--;
      update(a,d-'a');
    }
    else{
      cin>>a>>b;
      a--,b--;
      cout<<__builtin_popcount(query(a,b+1,0,0,N))<<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 7968
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

ll dp[3005][3005][5];

int main(void){
  ll r, c, k;
  cin >> r >> c >> k;
  vector<vector<ll>> g(r, vector<ll>(c, 0));
  REP(i, k){
    ll a, b, v;
    cin >> a >> b >> v;
    a--; b--;
    g[a][b] = v;
  }

  REP(i, r){
    REP(j, c){
      REPr(k, 4){
        chmax(dp[i][j][k+1], dp[i][j][k]+g[i][j]);
      }
      REP(k, 4){
        chmax(dp[i][j+1][k], dp[i][j][k]);
        chmax(dp[i+1][j][0], dp[i][j][k]);
      }
    }
  }
  ll ans = 0;
  REP(i, 4) chmax(ans, dp[r-1][c-1][i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 426036
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
s = [input() for _ in range(n)]
xys = []
# 最小費用流
"""nodeにdemand属性
edgeにcapacity, weight属性を指定
f以下の任意の流量について考えたければ、s->tにcapacity無限、weight=0の枝を追加すれば良い
"""
import networkx as nx
g = nx.DiGraph() # 必要に応じてMultiDiGraphにする
num = 0
for i in range(n):
    for j in range(m):
        u = i*m+j
        if s[i][j]=="o":
            num += 1
            g.add_node(u, demand=-1)
            xys.append(u)
        elif s[i][j]==".":
            g.add_node(u)
            xys.append(u)
        else:
            pass
        if i>=1:
            if s[i-1][j]!="#":
                v = (i-1)*m + j
                g.add_edge(v, u, capacity=100, weight=-1)
        if j>=1:
            if s[i][j-1]!="#":
                v = i*m + j-1
                g.add_edge(v, u, capacity=100, weight=-1)
g.add_node(n*m, demand=num)
for u in xys:
    g.add_edge(u,n*m,capacity=1,weight=0)
val, d = nx.network_simplex(g)
ans = -val
print(ans)

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

int main() {

	int A, B, C;

	cin >>A >>B >>C;
	if (A < B && A < C && C < B)	//A,C,Bの順
		cout << "Yes";

	else if (A > B && A > C && C > B)		//B,C,Aの大きさ
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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 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;
    cout << u << endl;
    return u;
}


int main() {
    ll n;
    cin >> n;
    FOR(i,1, n+1){
        ll ans = 0;
        //cout << i << endl;
        FOR(a, 2, sqrt(2 * n)){
            FOR(b, a,sqrt(2 * n)){
                ll c = sqrt(2 * i - a*a - b * b);
                //cout << "a= " << a <<" b= " << b << " c= " << c <<endl;
                if(c * c == 2 * i - a*a - b * b && c >= b){
                    //cout << "yea" << endl;
                    if((a+b+c)%2 == 0 && (a+b+c)/2 > a && (a+b+c)/2 > b && (a+b+c)/2 > c){
                        if(a == b){
                            if(b == c){
                                ans += 1;
                            } else {
                                ans += 3;
                            }
                        } else {
                            if(b != c && a != c){
                                ans += 6;
                            } else if (b == c){
                                ans += 3;
                            }
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	int n; cin >> n;
	string s;
	cin >> s;
	stack<char> bkt;
	string s_head = {}, s_tail = {};
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '(')bkt.push('(');
		else if(s[i] == ')' && bkt.size() != 0)bkt.pop();
		else if(s[i] == ')' && bkt.size() == 0)s_head += '(';
	}
	for(int i = 0; i < bkt.size(); i++){
		s_tail += ')';
	}
	cout << s_head << s << s_tail << endl;
}



Measured memory_bytes: 256
import sys
n=int(input())
ans=0
for i in range(n):
    d1,d2=map(int,input().split())
    if ans==3:
        continue
    if d1==d2:
        ans+=1
    else:
        ans=0
if ans==3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9044
class UnionFindVerSize():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループのサイズ（個数）
        self._size = [1] * N
        self._even = [i%2 for i in range(0,N)]
        self._odd =[(i+1)%2 for i in range(0,N)]

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属するグループを併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
            self._even[gy] += self._even[gx]
            self._odd[gy] += self._odd[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]
            self._even[gx] += self._even[gy]
            self._odd[gx] += self._odd[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        """ グループ数を計算して返す """
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans

    def calc_comb(self):
        N=len(self._parent)
        ans=0
        for i in range(N):
            if self.find_root(i) ==i:
                ans+=self._even[i]*self._odd[i]
        return ans


import sys

N,M=map(int,input().split())
uf=UnionFindVerSize(2*N)
for i in range(M):
    a,b=map(int,input().split())
    uf.unite(2*a-2,2*b-1)
    uf.unite(2*b-2,2*a-1)

ans=uf.calc_comb()
for i in range(N):
    if uf.is_same_group(2*i,2*i+1):
        ans-=1

ans//=2
print(ans-M)

Measured memory_bytes: 135032
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("sumsqr.in");ofstream out("sumsqr.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<ll> m(a);
    for(int q=0; q<a; q++) cin>>m[q];
    map<ll, ll> mp;
    ll o = 0;
    for(int q=a-2; q>=0; q--){
        mp[m[q+1]+(a-1-q-1)]++;
        o += mp[-m[q]+1+a-1-(q+1)];
    }
    cout<<o;
}

Measured memory_bytes: 27424
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int t;
  cin >> t;
  rep(soz,t){
    int n;
    cin >> n;
    priority_queue<pair<int,ll>, vector<pair<int,ll>>, greater<pair<int,ll>>> q;
    priority_queue<pair<int,ll>, vector<pair<int,ll>>, greater<pair<int,ll>>> p;
    ll ans=0;
    rep(i,n){
      int k;
      ll l,r;
      cin >> k >> l >> r;
      ans+=min(l,r);
      if(l>=r)q.push(make_pair(k,l-r));
      else p.push(make_pair(-1*k,r-l));
    }
    //cout << ans << endl;
    int y=q.size();
    priority_queue<int, vector<int>, greater<int>> a;
    priority_queue<int, vector<int>, greater<int>> b;
    rep(i,y){
      pair<int,ll> l=q.top();
      //cout << l.first << endl;
      q.pop();
      ans+=l.second;
      a.push(l.second);
      if(a.size()>l.first){
        ans-=a.top();
        a.pop();
      }
    }
    //cout << ans << endl;
    rep(i,n-y){
      pair<int,ll> l=p.top();
      p.pop();
      ans+=l.second;
      b.push(l.second);
      if(b.size()>(n-l.first*-1)){
        ans-=b.top();
        b.pop();
      }
    }
    cout << ans << endl;
  }
}


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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    IOS;

     ll c;
    cin >> c;

    string str;

    while (c > 0) 
    {
        ll rem = c % 26;
        if (rem == 0) 
        {
            str += 'z';
            c = (c / 26) - 1;
        } 

        else 
        {
            str += (char) ((rem - 1) + 'a');
            c = c / 26;
        }
    }
    
    reverse(str.begin(), str.end());
    cout << str;

    return 0;
}


Measured memory_bytes: 3620
N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))
mod=998244353

#print(A)

DP=[[0 for i in range(S+1)]for j in range(N+1)]

DP[0][0]=1

for i in range(1,N+1):
    for j in range(S+1):
        if j-A[i]>=0:
            DP[i][j]=(DP[i-1][j]*2+DP[i-1][j-A[i]])%mod
        else:
            DP[i][j]=(DP[i-1][j]*2)%mod
print(DP[-1][-1])

Measured memory_bytes: 147152
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

int main(){
  int n;cin>>n;
  long long a[200005];
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)a[i] = a[i]-((long long)i+1LL);

  sort(a,a+n);
  long long ans = 0;
  for(int i=0;i<n;i++){
    ans += abs(a[i]-a[n/2]);
  }
  cout<<ans<<endl;

  return 0;
}


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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    VI A(4);
    string S; cin>>S;
    int n = stoi(S);
    REP(i,4)
    {
        A.at(3-i) = n %10;
        n /= 10;
    }
    
    int res;
    //bit全探索
    for (int bit=0; bit < (1<<3); ++bit)
    {
        res=A.at(0);
        REP(i, 3)
        {
            if (bit & (1<<i))
            {
                //dump(bit &(1<<i));
                res += A.at(i+1);
            }
            else
            {
                //dump(bit &(1<<i));
                res -= A.at(i+1);
            }
        }

        //dump(bit);
        //cout << res << endl;
            
        
        if (res==7)
        {
            cout << A.at(0);
            REP(i, 3)
            {
                if (bit & 1<< i)
                {
                    cout << '+' << A.at(i+1);
                }
                else cout << '-' << A.at(i+1);
            }
            cout << "=7" << endl;
            
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#main
h = Hash.new
h.default = 0
arr = Array.new
while n = gets
  arr << n.to_i
end
arr.each do |i|
  h[i] += 1
end
g = h.to_a.sort{|a, b| b[1] <=> a[1]}
i = 0
f = Array.new
while g[0][1] == g[i][1]
  f << g[i][0]
  i += 1
end
puts f.sort.join("\n")

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

int main() {
	string o, e;
	cin >> o >> e;
	if (o.length() == e.length()) {
		for (int i = 0; i < o.length(); i++) {
			cout << o[i] << e[i];
		}
	}
	else {
		for (int i = 0; i < e.length(); i++) {
			cout << o[i] << e[i];
		}
		cout << o[o.length() - 1];
	}
	cout << endl;
	system("pause");
	return 0;
}


Measured memory_bytes: 504
# coding: utf-8
N=int(input())

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

sA=[A[0]]
siA=[A[-1]]

for i in range(N-1):
    sA.append(sA[i]+A[i+1])
    siA.append(siA[i]+A[-(i+2)])

ans=10**15

for i in range(N-1):
    ans=min(ans,abs(sA[i]-siA[-(i+2)]))

# print(sA,siA)

print(ans)



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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b)a=b;};

struct Dice{
  Int s[6];
  void roll(char c){
    Int b;
    if(c == 'E'){
      b = s[0];
      s[0] = s[3];
      s[3] = s[5];
      s[5] = s[2];
      s[2] = b;
    }

    if(c == 'W'){
      b = s[0];
      s[0] = s[2];
      s[2] = s[5];
      s[5] = s[3];
      s[3] = b;
    }

    if(c == 'N'){
      b = s[0];
      s[0] = s[1];
      s[1] = s[5];
      s[5] = s[4];
      s[4] = b;
    }

    if(c == 'S'){
      b = s[0];
      s[0] = s[4];
      s[4] = s[5];
      s[5] = s[1];
      s[1] = b;
    }

    if(c == 'R'){
      b= s[1];
      s[1] = s[2];
      s[2] = s[4];
      s[4] = s[3];
      s[3] = b;
    }
    
    if(c == 'L'){
      b = s[1];
      s[1] = s[3];
      s[3] = s[4];
      s[4] = s[2];
      s[2] = b;
    }
  }
};


vector<Dice> makeDices(Dice d){
  vector<Dice> res;
  for(Int i=0;i<6;i++){
    Dice t(d);
    if(i == 1) t.roll('N');
    if(i == 2) t.roll('S');
    if(i == 3) t.roll('S'), t.roll('S');
    if(i == 4) t.roll('L');
    if(i == 5) t.roll('R');
    for(Int k=0;k<4;k++){
      res.push_back(t);
      t.roll('E');
    }
  }
  return res;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  while(cin>>n,n){
    vector<Dice> vs;
    Int sz=0;
    map<string, Int> cm;
    for(Int i=0;i<n;i++){
      vs.emplace_back();
      for(Int j=0;j<6;j++){
	string s;
	cin>>s;
	if(!cm.count(s)) cm[s]=sz++;
	vs[i].s[j]=cm[s];
      }     
    }
    
    if(n==1){
      cout<<0<<endl;
    }else if(n==2){
      auto A = makeDices(vs[0]);
      auto B = makeDices(vs[1]);
      Int ans=1e9;      
      for(auto &a:A){
	for(auto &b:B){
	  Int res=0;
	  for(Int j=0;j<6;j++){
	    map<Int, Int> x;
	    x[a.s[j]]++;
	    x[b.s[j]]++;
	    Int y=0;
	    for(auto p:x) chmax(y,p.second);
	    res+=2-y;
	  }	  
	  chmin(ans,res);
	}
      }      
      cout<<ans<<endl;
    }else if(n==3){
      auto A = makeDices(vs[0]);
      auto B = makeDices(vs[1]);
      auto C = makeDices(vs[2]);
      Int ans=1e9;
      
      for(auto &a:A){
	for(auto &b:B){
	  for(auto &c:C){
	    Int res=0;
	    for(Int j=0;j<6;j++){
	      map<Int, Int> x;
	      x[a.s[j]]++;
	      x[b.s[j]]++;
	      x[c.s[j]]++;
	      Int y=0;
	      for(auto p:x) chmax(y,p.second);
	      res+=3-y;
	    }	  
	    chmin(ans,res);
	  }
	}
      }
      cout<<ans<<endl;
    }else{
      auto A = makeDices(vs[0]);
      auto B = makeDices(vs[1]);
      auto C = makeDices(vs[2]);
      auto D = makeDices(vs[3]);
      Int ans=1e9;      
      for(auto &a:A){
	for(auto &b:B){
	  for(auto &c:C){
	    for(auto &d:D){
	      Int res=0;
	      for(Int j=0;j<6;j++){
		map<Int, Int> x;
		x[a.s[j]]++;
		x[b.s[j]]++;
		x[c.s[j]]++;
		x[d.s[j]]++;
		Int y=0;
		for(auto p:x) chmax(y,p.second);
		res+=4-y;
	      }	  
	      chmin(ans,res);
	    }
	  }
	}
      }
      cout<<ans<<endl;
    }    
  }
}



Measured memory_bytes: 3100
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
	ll a;
	cin>>a;
	ll s=(a/500)*1000;
	a=a%500;
	s=s+(a/5)*5;
	cout<<s;
}

Measured memory_bytes: 256
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

ll f(int x, int y, int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

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

  vector<int> ans(1e4 + 1, 0);
  for (int x = 1; x < 1e2; x++) {
    for (int y = 1; y < 1e2; y++) {
      for (int z = 1; z < 1e2; z++) {
        if (f(x, y, z) > 1e4) continue;
        ans.at(f(x, y, z))++;
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 3588
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a-lin bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

//dp[i][j]:i桁目まで見た時、Lと一致している→j=1
long long dp[100005][2];

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    string L;cin >> L;int N = L.size();
    for(int i = 0;i<100005;i++) for(int j = 0;j<2;j++) dp[i][j] = 0;
    dp[0][1] = 1;
    for(int i = 0;i<N;i++){
        if(L.at(i) == '0'){
            dp[i+1][1] = dp[i][1];
            dp[i+1][0] = dp[i][0]*3;

            dp[i+1][1] %= MOD;
            dp[i+1][0] %= MOD;
        }
        if(L.at(i) == '1'){
            dp[i+1][1] = dp[i][1]*2;
            dp[i+1][0] = dp[i][1] + dp[i][0]*3;
            
            dp[i+1][1] %= MOD;
            dp[i+1][0] %= MOD;
        }
    }
    cout << (dp[N][0] + dp[N][1]) % MOD << endl;
}

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

int main()
{
    string s, ss;
    ll t, n=1, m, x;
    cin>>t;

    for(int i=1; i<=t; i++)
    {
        cin>>x;
        if(x==n)
        {
            n++;
        }
    }
    if(n==1)cout<<-1<<endl;
    else cout<<t-n+1<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
int n;
char s[1000000];
int main(void){
scanf("%s",s);
int k=0,j=0,o=0,i=0;
int a=0;
while(1){
for(;s[k]!='J' && s[k]!=0;k++);
if(s[k]==0)break;
for(;s[k]=='J';k++)j++;
for(;s[k]=='O';k++)o++;
for(;s[k]=='I';k++)i++;
if(j>=o&&o<=i)a=(a<o)?o:a;
j=0;o=0;i=0;}
printf("%d\n",a);
return 0;}

Measured memory_bytes: 1944
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	recC(IntArray(n), 0, 0)
}

fun recC(arr: IntArray, n: Int, m: Int){
	if (arr.lastIndex == n){
		println(buildString { arr.forEach {append(char(it))} })
		return
	}
	for (i in 0 .. m+1){
		arr[n+1] = i
		recC(arr, n+1, Math.max(m, i))
	}
}

fun char(n: Int) = 'a' + n

Measured memory_bytes: 41992
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

vector<int> divisors(int x) {
  vector<int> v;
  for (int i = 1; i*i <= x; i++) {
    if (x % i == 0) {
      v.push_back(i);
      if (i*i != x) v.push_back(x/i);
    }
  }
  return v;
}

int main() {
  int N, M;
  cin >> N >> M;
  int maxv = INT_MIN;
  for (auto x : divisors(M)) {
    if (x >= N) {
      maxv = max(M/x, maxv);
    }
  }
  cout << maxv << endl;
  return 0;
}


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

int main(){

	long long int a,b;
	cin >> a >> b;
	if( a == 0 || b == 0 ){
		cout << "Zero" << endl;
		return 0;
	}
	if(a <= 0 && b >= 0 ){
		cout << "Zero" << endl;
		return 0;
	}
	if( a > 0 ){
		cout << "Positive" << endl;
		return 0;
	}

	if( a == b && b < 0){
		cout << "Positive" << endl;
		return 0;
	}

	if( (b-a)%2 == 0 ){
		cout << "Negative" << endl;
	}else{
		cout << "Positive" << endl;
	}
	// -5 -4 -3 -2 -1

	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,x;
    cin>>a;
    for(int i=0; i<=100; i++)
    {
        x=pow(i,5);
        if(x-i>a)
        {
            x=i-1;
            break;
        }
    }
    ll x1=pow(x,5);
    ll x3=a-x1;
    if(x1==a)
    {
        cout<<x<<" "<<0<<endl;
    }
    else
    {
        for(int i=-150; i<=150; i++)
        {
            for(int j=-150; j<=150; j++)
            {
                ll x2=pow(i,5)-pow(j,5);
                //cout<<x2<<endl;
                if(x2==a)
                {
                    cout<<i<<" "<<j<<endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 4040
#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 n;
    cin >> n;
    string ans;
    if(n==0)
    {
        ans = '0';
    }
    while(n){
        if(n%2 != 0){
            n--;
            ans = ('1' + ans);
        }
        else
            ans = ('0' + ans);
        n /= -2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long n,m,X,Y,x[200],y[200];
  cin>>n>>m>>X>>Y;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<m;i++){
    cin>>y[i];
  }
  sort(x,x+n);
  sort(y,y+m);
  if(x[n-1]<Y &&  X<y[0] && x[n-1]<y[0] )
    cout<<"No War"<<endl;
  else
    cout<<"War"<<endl;
  return(0);
}
    

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int p,q,r;
	cin>>p>>q>>r;
	int sum1=p+q;
	int sum2=q+r;
	int sum3=r+p;
	if(sum1<=sum2&&sum1<=sum3)
	{
		cout<<sum1<<endl;
	}
	else if(sum2<=sum1&&sum2<=sum3)
	{
		cout<<sum2<<endl;
	}
	else if(sum3<=sum1&&sum3<=sum2)
	{
		cout<<sum3<<endl;
	}
	else if(sum1==sum2==sum3)
	{
		cout<<sum1<<endl;
	}

	return 0;

}



Measured memory_bytes: 256
N, M = map(int, input().split())
a = min(N, M)
b = max(N, M)

if a == 1:
    if b == 1:
        print(1)
    else:
        print(b - 2)
elif a == 2:
    print(0)
else:
    print((a - 2) * (b - 2))



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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using ch = char;
using vll = V<ll>;
using vvll = V<V<ll>>;
using vvvll = V<V<V<ll>>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vvpll = V<vpll>;
using vtpll = V<tpll>;
using vst = V<str>;
using vch = V<ch>;
using vvch = V<vch>;
using qll = queue<ll>;
using vqll = V<qll>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin() 
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a) //
/*vvll v(n,vll(m)) n行m列  continue
A.erase(A.begin()+i); 配列Aのi番目を消せる
std::binary_search(v.bgn,v.en,a); 二分探索
abs(a,b)   pow(a,n)  to_string  stoll
auto Iter=lower_bound(v.bgn,v.en,a); v[i]>=aとなる初のv[i]
v.insert(lower_bound(v.bgn,v.en,a),b); bを入れられる
lower upper  co(*Iter) co(Iter-v.bgn) v[i]>=aとなる初のi
vvll v(100001,vll(0)); v[a].pb(b); v[b].pb(a);
priority_queue<ll> pque; pque.push(ai); pque.top(); pque.pop();
priority_queue<ll,vll,greater<ll>> pque; 昇順
vqll q(3);  q[0].push(0); q[0].push(2); q[0].push(1);
q[0].front()→0 q[0].back()→1 q[0].pop(); q[0].front()→2
que.pop() que.sz while(!que.empty())
ll a=1,b=2,c=4,xo; xo=a^b^c; if(a^b^c==0)co(xo)→7 if(xo==0)co(xo)→なし
*/

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll pow_mod(ll a,ll n,ll mod){
  ll res=1;
  for(;n>0;n/=2){
    if(n%2==1)res=(res*a)%mod;
    a=(a*a)%mod;
  }
  return res;
}
ll digit_sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0)break;
  }
  return m;
}
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}

int main(){
  ll n;
  cin>>n;
  vll v(n);
  FOR(i,0,n){
    cin>>v[i];
  }
  ll c=0,ans=0;
  FOR(i,1,n){
    if(v[i-1]>=v[i]){
      c++;
      if(ans<c){
        ans=c;
      }
    }
    else{
      c=0;
    }
  }
  co(ans);
}
  

Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))
tl=[l[0]]
for i in range(1,n):
    if l[i]!=l[i-1]:
        tl.append(l[i])


a=[]
ma=False

for i in range(len(tl)):
    if len(tl)==1:
        break
    if i==0:
        if tl[i]>tl[i+1]:
            ma=True
            a.append(tl[i])
        else:
            ma=False
            a.append(tl[i])
    elif i==len(tl)-1:
        if tl[i]>tl[i-1]:
            a.append(tl[i])
        else:
            a.append(tl[i])
    else:
        if tl[i-1]<tl[i] and tl[i+1]<tl[i]:
            a.append(tl[i])
        elif tl[i-1]>tl[i] and tl[i+1]>tl[i]:
            a.append(tl[i])

if ma:
    a.pop(0)


num=0
ans=1000

for i in range(0,len(a)-1,2):
    
    thing1=(ans//(a[i]))*a[i+1]
    thing2=num*a[i+1]
    if thing1>thing2:
        ans=thing1+ans%a[i]
        num=0
        
    elif thing2>thing1:
        ans=thing2

print(ans)
            
            
        

    


Measured memory_bytes: 62064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "No"; return;}

vector <int> z_f(string s) {
    int n = s.length(), L = 0, R = 0;
    s += ".";
    vector <int> z(n);
    loop1(i, n - 1) {
        z[i] = max(0, min(R - i, z[i - L]));
        while (s[z[i]] == s[i + z[i]])
            z[i]++;
        if (i + z[i] > R) {
            L = i;
            R = i + z[i];
        }
    }
    return z;
}

void solve() {
    int n, ans = 0; cin >> n;
    string s; cin >> s;
    loop(i, n) {
        vector <int> z = z_f(s);
        loop(j, z.size())
            ans = max(ans, min(z[j], j));
        s.erase(s.begin());
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
void trozen()
{
    int n;
    cin>>n;
    vector<int> v1(n);
    for(auto &i:v1) cin>>i;
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(v1[i]<v1[i-1])
        {
            ans+=abs(v1[i]-v1[i-1]);
            v1[i]=v1[i-1];
        }
    }
    cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 4716
N = int(input())

MAXNUM = 10 ** 6 + 10
a = [i for i in range(1, MAXNUM)]

def calc(i):
    l, r = 0, MAXNUM
    while r-l > 1:
        mid = (l+r)//2
        if mid * i < N:
            l = mid
        else:
            r = mid
    return l

cnt = 0
for i in range(1, MAXNUM):
    cnt += calc(i)

print(cnt)


Measured memory_bytes: 142124
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
multiset<int>m;
void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		auto it = m.lower_bound(x);
		if (it == m.begin())
			m.insert(x);
		else
		{
			it--;
			m.erase(it);
			m.insert(x);
		}
	}
	cout << m.size();
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <stack>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int R, C, N;
bool onedge(int x, int y) {
	return (x == 0 || x == R) || (y == 0 || y == C);
}
int score(int x, int y) {
	if (y == 0) return x;
	if (x == R) return R + y;
	if (y == C) return R + C + R - x;
	return R + C + R + C - y;
}

int main() {
	 R = in();
	 C = in();
	 N = in();
	int M = 0;
	vpint p;
	rep(i,N) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (!onedge(x1, y1) || !onedge(x2, y2)) {
			continue;
		}
		//pr(score(x1, y1));
		//pr(score(x2, y2));
		p.pb(mp(score(x1, y1), M));
		p.pb(mp(score(x2, y2), M));
		M++;
	}
	sort(p.begin(), p.end());
	vint found(M, 0);
	stack<int> st;
	st.push(-1);
	bool ok = true;
	rep(i,M*2) {
		int a = p[i].second;
		if (found[a]) {
			int t = st.top();
			if (a != t) {
				ok = false;
				break;
			}
			st.pop();
		}
		else {
			found[a] = 1;
			st.push(a);
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 2420
t=0
x=0
y=0
n=int(input())
for i in range(n):
    ti,xi,yi=map(int,input().split())
    t=ti-t
    x=xi-x
    y=yi-y
    if t%2!=(abs(x+y))%2:
        print('No')
        exit()
    elif t<abs(x)+abs(y):
        print('No')
        exit()
print('Yes')

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<int> left(N), right(N);
    for(int i = 1; i < N; i++){
        if(S[i-1] == 'E') left[i] = left[i-1] + 1;
        else left[i] = left[i-1];
    }
    for(int i = N - 2; i >= 0; i--){
        if(S[i+1] == 'W') right[i] = right[i+1] + 1;
        else right[i] = right[i + 1];
    }
    int M = 0;
    for(int i = 0; i < N; i++){
        int cnt = 0;
        if(i == 0) cnt = right[i];
        else if(i == N - 1 ) cnt = left[i];
        else cnt = right[i] + left[i];
        M = max(cnt, M);
    }
    cout << N - M - 1 << endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define ll int long long
#define mp make_pair
//#define for(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define N 1000000007
#define pq priority queue
#define pb push_back
#define mt make_tuple
#define prec(a) fixed<<setprecision(9)<<a
#define endl "\n"
#define fast_set s.max_load_factor(0.25);s.reserve(500);
const long double PI = (long double)(3.1415926535897932384626433832795);
int parity_check(int n)
{
	int par=n;
	par = par ^ (par >> 1); 
    par = par ^ (par >> 2); 
    par = par ^ (par >> 4); 
    par = par ^ (par >> 8); 
    par = par ^ (par >> 16); 
  
    if(par%2==1)
    {
    	return 1;
    }
    else
    {
    	return 0;
    }
    // true means odd parity
    // false means even parity
}
ll gcd(ll a,ll b)
{
	if(a==0)
	{
		return b;
	}
	return gcd(b%a,a);
}
int sz[100001];
ll lcm(ll a,ll b)
{
	ll pro=a*b;
	ll ans=gcd(a,b);
	pro=pro/ans;
	return pro;
}
ll fast_power(ll a,ll b,ll p)
{
	if(b==0)
	{
		return (1%p);
	}
	ll t=fast_power(a,b/2,p);
	ll ans=(t*t)%p;
	if(b%2)
	{
		ans=(ans*(a%p))%p;
	}
	return ans;
}

void dfs(ll s,vector<ll>vert,map<ll,ll>&visited,set<pair<ll,ll> >se)
{
	visited[s]=1;
	for(ll i=0;i<vert.size();i++)
	{
		if(!visited[vert[i]]&&se.find(mp(s,vert[i]))!=se.end())
		{
			visited[vert[i]]=1;
			dfs(vert[i],vert,visited,se);
			//sz[s] = sz[v[s][i]]+sz[s];
		}
	}
	//sz[s]=sz[s]+1;
}


ll connec(vector<ll> vert,map<ll,ll>visited,set<pair<ll,ll> >s)
{
	ll count=0;
	for(ll i=0;i<vert.size();i++)
	{
		if(!visited[vert[i]])
		{
			dfs(vert[i],vert,visited,s);
			count++;
		}
	}
	return count;
}
int main()
{
	fast;
	
	ll n,a,b,i,j,k;
	
	cin>>n;
	ll arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	ll zero[62]={0};
	ll one[62]={0};
	ll ans=0,maxi=0;
	for(i=0;i<n;i++)
	{
		ll count=0;
		while(count<62)
		{
			if(arr[i]%2==0)
			{
				zero[count]++;
			}
			else
			{
				one[count]++;
			}
			arr[i]/=2;
			maxi=max(maxi,count);
			count++;
		}
	}
	for(i=0;i<=maxi;i++)
	{
		ans=(ans+(((zero[i]*one[i])%N)*fast_power(2,i,N))%N)%N;
		//cout<<ans<<" "<<zero[i]<<" "<<one[i]<<endl;
	}
	cout<<ans;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  vi v(n);
  fi(0, n)
    cin >> v[i];
  sort(all(v), greater<int>());
  ll total = sum(v);
  ld th = (ld)total / 4 / m;
  if(v[m - 1] < th)
    cout << "No\n";
  else
    cout << "Yes\n";
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256