akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
ls = []
for j in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    if ct.get(c) is None:
        ct[c] = 0
    ls.append((b, c))
    ct[c] += b
ls.sort(key=lambda x:x[1], reverse=True)
cnt = 0
for b, c in ls:
    if cnt + b < n:
        a_ls += [c] * b
        cnt += b
    else:
        a_ls += [c] * (n - cnt)
        break
a_ls.sort()
print(sum(a_ls[-n:]))

Measured memory_bytes: 41040
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,H,W;
	cin >> N >> H >> W;
	vector<int> A(N),B(N);
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i];
	}
	
	int cnt = 0;
	for(int i=0;i<N;i++){
		if(H <= A[i] && W <= B[i]) cnt++;
	}
	
	cout << cnt << endl;
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll dp[1010][10100],H,N;

ll min(ll a, ll b){
    if(a>b) return b;
    else return a;
}

int main(){
    cin>>H>>N;
    ll A[N],B[N];
    rep(i,N){
        cin>>A[i]>>B[i];
    }
    rep(i,N)rep(j,10010)if(j)dp[i][j]=10000000;
    repi(j,1,H+1){
        if(j<A[0])dp[0][j]=B[0];
        else dp[0][j] = dp[0][j-A[0]]+B[0];
    }
    repi(i,1,N){
        rep(j,H+1){
            if(j<A[i])dp[i][j]=min(dp[i-1][j],B[i]);
            else dp[i][j] = min(min(dp[i-1][j],dp[i-1][j-A[i]]+B[i]),dp[i][j-A[i]]+B[i]);
        }
    }
    out(dp[N-1][H]);
}

Measured memory_bytes: 79104
#include<iostream>
using namespace std;
int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if((x >= r && x <= W-r) && (y >= r && y <= H-r)) cout << "Yes\n";
	else cout << "No\n";
	return 0;

}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;


signed main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, 0, n)
        cin >> v[i];
    vector<vector<int>> dp(n, vector<int>(60, 0));
    for (int i = n - 2; i >= 0; i--)
        for (int j = 0; j < 60; j++)
        {
            dp[i][j] = dp[i+1][j];
            if ((v[i+1] & (1LL << j)) > 0)
                dp[i][j]++;
        }
    int res = 0;
    int MOD = 1e9+7;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < 60; j++)
        {
            if ((v[i] & (1LL << j)) > 0)
                res += (((n - i - 1 - dp[i][j]) % MOD) * ((1LL << j) % MOD)) % MOD;
            else 
                res += ((dp[i][j] % MOD) * ((1LL << j) % MOD)) % MOD;
            res %= MOD;
        }
    }
    cout << endl << res % MOD;
    return 0;
}

Measured memory_bytes: 157952
import sys
inf = float('inf')

n = int(sys.stdin.readline().rstrip())
res = zip(*[map(int, sys.stdin.read().split())] * 2)
res = sorted(zip(res, [1] * n + [0] * n))

def main():
    cnt = 0
    confirmed = [0] * n * 2
    for i in range(n * 2 - 2, -1, -1):
        if not res[i][1]: continue
        yr = res[i][0][1]
        yb = inf
        k = None
        for j in range(i + 1, n * 2):
            if res[j][1] or confirmed[j]: continue
            y = res[j][0][1]
            if y > yr and y < yb:
                yb = y; k = j
        if not k: continue
        confirmed[k] = 1
        cnt += 1
    print(cnt)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
int n,sum=0,div=10,temp;
scanf("%d",&n);
temp=n;
while(n>0)
{
	
sum+=(n%div);
n=n/div;
}

if(temp%sum==0)
printf("Yes");
else
printf("No");
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  if(s.size()==3){
    reverse(s.begin(),s.end());
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int ans=0;
  int i=0;
  while(true){
    if(a[i]%2==1)break;
    a[i]/=2;
    if(i==n-1)ans++;
    i++;
    i%=n;
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int[] ab = ReadAndParseIntArr();
            int a = ab[0];
            int b = ab[1];

            int s = a * b + 1 - b - a;
            Console.WriteLine(s);
        }
        
    }
}


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

int main(void){
int a,b,k;
cin >>a>>b>>k;

if((a+k-1)>= (b-k+1)){
  for(int i = a;i < b+1;i++){
    cout << i <<endl;
  }
}
else{
  for(int i = a;i < a+k;i++){
    cout << i <<endl;
  }
  for(int i = b-k+1;i < b+1;i++){
    cout << i <<endl;
  }
}
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for ( int i = 0; i <= m; i++ ) c[i][0] = 0;
  for ( int j = 1; j <= n; j++ ) c[0][j] = 0;

  for ( int i = 1; i <= m; i++ )
    for ( int j = 1; j <= n; j++ ) {
      if ( X[i] == Y[j] )
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      maxl = max(maxl, c[i][j]);
    }

  return maxl;
}

int main() {
  string s1, s2;
  int n; cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}


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

const int maxn=1e5+7;
int a[maxn];

int main (){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	if(n==1) {
		puts("0");
		return 0;
	}
	int pre=a[0];
	int cnt=1,ans=0;
	for(int i=1;i<n;i++){
		if(pre==a[i]) cnt++;
		else {
			pre=a[i];
			ans+=cnt/2;
			cnt=1;
		}
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	return 0;
}


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

int main(void) {
  string s;
  cin >> s;
  int K;
  cin >> K;
  
  set<string> ss;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      ss.insert(s.substr(i, j));
    }
  }

  auto it = ss.begin();
  for(int i = 0; i < K - 1; i++) {
    it++;
  }

  cout << *it << endl;
  
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;
//2だけの増加もOK
int main(){
    int A[3],ans=0;
    cin>>A[0]>>A[1]>>A[2];
    sort(A,A+3);
    if(A[0]==A[1]&&A[1]==A[2]){
        cout<<ans<<endl;
        return 0;
    }
    for(int i=0; ; i++){
        if(A[1]-A[0]>1){
            A[0]+=2;
            ans++;
        }else{
            A[0]++;
            A[1]++;
            ans++;
        }
        sort(A,A+3);
        if(A[0]==A[1]&&A[1]==A[2]){
            cout<<ans<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ld = long double;
int main() {
	ll a,b;
	cin >> a >> b;
	char dot;
	cin >> dot;
	ll d;
	cin >> d;
	b*=100;
	b+=d;
	ll out = a*b;
	out/=100;
	cout<<out;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(){

int A,B,AB,X,Y;
int calc_1,calc_2,ans;
scanf("%d%d%d%d%d",&A,&B,&AB,&X,&Y);

ans = A*X + B*Y;

if (A+B > 2*AB)
{
  if (X<Y)
  {
    calc_1 = 2*AB*X+B*(Y-X);
    calc_2 = 2*AB*Y;
    if(calc_1 < calc_2){ans = calc_1;}
    else{ans = calc_2;}
  }else
  {
    calc_1 = 2*AB*Y+A*(X-Y);
    calc_2 = 2*AB*X;
    if(calc_1 < calc_2){ans = calc_1;}
    else{ans = calc_2;}
  }
}

printf("%d",ans);


return 0;

}

Measured memory_bytes: 1732
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    if(a[n-1]-a[0]>1){
        cout << "No" << endl;
        return 0;
    }
    int x=0, y=0;
    REP(i,n){
        if(a[i]==a[0]){
            x++;
        }else{
            y++;
        }
    }
    //cout << x << " " << y << endl;
    if(x==1){
        if(y>=2*a[0]){
            cout << "Yes" << endl;
            return 0;
        }
    }else{
        if(y==0){
            if(n>=a[0]*2||a[0]==n-1){
                cout << "Yes" << endl;
                return 0;
            }
        }else if(y>=2){
            if(y>=(a[0]-x+1)*2&&a[0]-x+1>=1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 768
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = []
o = [-1] * (n + 1)  # ord 訪れた箇所, v が1スタートなので注意
c, l = 1, 0  # 周期, 例外

v = 1
while o[v] == -1:
    o[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - o[v]
l = o[v]

if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l + k])


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

int main()
{
    // get a string
    string s;
    int i;
    cin >> s;

    // output
for(i=0; i<12; i++)
{
    if (i==4)
    {cout<<' ';}
cout<<s[i];
}
cout<<endl;

    return 0;
}


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

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


Measured memory_bytes: 3636
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

S=one_str()
T=one_str()

count=0
for s,t in zip(S,T):
    if s!=t:
        count+=1
print(count)

Measured memory_bytes: 9412
#include <iostream>

using namespace std;

int main(){
  long long s, c, cc, ans=0;
  cin >> s >> c;
  cc = c/2;
  if(s>cc){
    ans += cc;
  }else{
    ans += s;
    c -= s*2;
    ans += c/4;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    rr = []

    def f(hi,hm):
        n,m = LI()
        a = [S() for _ in range(n)]
        t = I()
        d = {}
        for _ in range(t):
            c,i = LS()
            d[c] = int(i)
        t = I()
        mv = [LS() for _ in range(t)]
        t = I()
        p = [I() for _ in range(t)]
        b = [[d[c] for c in s] for s in a]
        cu = [0,0]
        dms = []
        for c,i in mv:
            i = int(i)
            for _ in range(i):
                if c == 'D':
                    cu[0] += 1
                elif c == 'U':
                    cu[0] -= 1
                elif c == 'R':
                    cu[1] += 1
                else:
                    cu[1] -= 1
                dm = b[cu[0]][cu[1]]
                if dm > 0:
                    dms.append(dm)
        dl = len(dms)
        fm = {}
        sh = hi
        si = dl
        for i in range(dl):
            if dms[i] >= sh:
                si = i
                break
            sh -= dms[i]

        pl = len(p)

        def ff(k):
            if k == 0:
                return (si,sh)
            if k in fm:
                return fm[k]
            r = (0,sh)
            for i in range(pl):
                if k & (1<<i):
                    ti,th = ff(k-(1<<i))
                    th += p[i]
                    if th > hm:
                        th = hm
                    tj = dl
                    for j in range(ti,dl):
                        if dms[j] >= th:
                            tj = j
                            break
                        th -= dms[j]
                    t = (tj,th)
                    if r < t:
                        r = t
            fm[k] = r
            return r

        r = ff(2**pl-1)

        # print('b',b)
        # print('hi,hm',hi,hm)
        # print('dms',dms)
        # print('p',p)
        # print('fm',fm)

        if r[0] == dl:
            return 'YES'

        return 'NO'

    while True:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str, rr))


print(main())



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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

ll v[N];

bool valid(ll a, ll b, ll c){
    return ((a < (b+c)) and (b < (a+c)) and (c < (a+b)));
}

int main(){
	fastio;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> v[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(v[i] != v[j] and v[j] != v[k] and v[i]!=v[k]){
                    ans += valid(v[i], v[j], v[k]);
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#define Max 2000000
using namespace std;
int size,A[Max+1];
void maxHeapify(int i)
{
    int l=2*i;
    int r=2*i+1;
    int largest=i;
    //cout<<l<<' '<<r<<' '<<i<<endl;
    if(l<=size && A[i]<A[l])
        largest=l;
    if(r<=size && A[largest]<A[r])
        largest=r;
    int temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    if(largest!=i)
        maxHeapify(largest);
}

void insert(int k){
    size++;
    A[size]=k;
    int i=size;
    while(i/2>0 && A[i]>A[i/2])
    {
        swap(A[i],A[i/2]);
        i=i/2;
    }
}

int extractMax(){
    int max=A[1];
    A[1]=A[size--];
    maxHeapify(1);
    return max;
}
int main()
{
    size=0;
    string com;
    int k;
    while(1){
        cin>>com;
        if(com=="insert"){
            cin>>k;
            insert(k);
        }
        if(com=="extract"){
            int max=extractMax();
            cout<<max<<endl;
        }
        if(com=="end")
            break;
    }
    return 0;
}


Measured memory_bytes: 7060
#include<stack>
#include<iostream>
using namespace std;
int main(){
	stack<int> train;
	int n;
	while(cin >> n){
		if(n != 0)
			train.push(n);
		else{
			cout << train.top() << endl;
			train.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 0
from collections import Counter
d = [Counter(), Counter()]
n = int(input())
v = list(map(int, input().split()))
for i, vi in enumerate(v):
    d[i&1][vi] += 1
a = []
for i in range(2):
    a.append(sorted(d[i].keys(), key=lambda k: d[i][k], reverse=True))
c = [ai[:2] for ai in a]
if len(c[0]) == len(c[1]) == 1 and c[0][0] == c[1][0]:
    print(n // 2)
else:
    ans = 1001001001
    for ci in c[0]:
        for cj in c[1]:
            if ci == cj:
                continue
            cnt = sum(v for k, v in d[0].items() if k != ci) + sum(v for k, v in d[1].items() if k != cj)
            ans = min(ans, cnt)
    print(ans)


Measured memory_bytes: 17440
import java.util.*;
import java.util.Map;
import java.util.TreeMap;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        System.out.println(Z + " " + X + " " + Y);
    }
}

Measured memory_bytes: 22228
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	char s[100000];
	int a,len;
	cin>>s;
	len=strlen(s);
	for(a=0;a<len;a+=2){
		cout<<s[a];
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
bool notprime[1001];
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin >> n;
  LL ans = 1;
  for (int i = 2; i <= n; i++) {
    if (notprime[i]) continue;
    for (int j = 2 * i; j <= n; j += i) notprime[j] = true;
    int res = 1;
    for (int m = n / i; m > 0; m /= i) res += m;
    ans = (ans * res) % MOD;
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
vector<string> ans;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		int it[25];
		int bl[25];
		
		int sindex[25];
		
		for(int i = 0;i < n;i++) {
			cin >> it[i] >> bl[i];
			sindex[i] = i;
		}
		
		for(int i = 0;i<n;i++){
			for(int j = i+1;j < n;j++){
				if(bl[sindex[i]] > bl[sindex[j]]){
					int tind = sindex[i];
					sindex[i] = sindex[j];
					sindex[j] = tind;
				}
			}
		}
		
		int tsum = 0;
		bool tans = true;
		for(int i =0;i<n;i++){
			tsum += it[sindex[i]];
			if(tsum > bl[sindex[i]]) tans = false;
		}
		
		if(tans){
			ans.push_back("Yes");
	 	}else{
	 		ans.push_back("No");
	 	}
	}
 	
 	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
 	
	return 0;
}

Measured memory_bytes: 3084
s=gets.chomp.split("")
c1=s[0]
s.delete_at(0)
flag=true
idx=s.index(c1)
if(idx!=nil)
	s.delete_at(idx)
else
	flag=false
end
c2=s[0]
if(c1==c2)
	flag=false
end
s.shift(1)
idx=s.index(c2)
if(idx==nil)
	flag=false
end
print (flag) ? "Yes" : "No"

Measured memory_bytes: 1788
n=int(input())
a=list(map(int,input().split()))
#a=[10**5 for _ in range(10**5)]
ans=[0 for _ in range(10**5+3)]
for i in a:
    ans[i+1]+=1
    ans[i+2]+=1
    ans[i]+=1

print(max(ans))

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

long long a[102];

long long lcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	else {
		return lcd(b, a%b);
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		long long t;
		t = lcd(ans, a[i]);
		ans = (ans / t)*a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int n;
const int MAX_N = 100;
int z[MAX_N];
int sw = 0;

int selectionSort(int a[], int n){
  for(int i = 0; i < n; i++){
    int minj = i;
    for(int j = i + 1; j < n; j++){
      if (a[minj] > a[j])
        minj = j;
    }
    swap(a[minj], a[i]);
    if (minj != i) sw++;
  }
  return sw;
}

int main(){
  cin >> n;
  for(int i = 0; i < n; i++) cin >> z[i];
  int ans = selectionSort(z, n);
  for(int i = 0; i < n; i++){
    if (i) printf(" ");
    printf("%d", z[i]);
  }
  puts("");
  printf("%d\n",ans);
}

Measured memory_bytes: 1152
<?php
    fscanf(STDIN, "%s", $a);
    fscanf(STDIN, "%s", $b);
    fscanf(STDIN, "%s", $c);
    
    function del($s) {
        return substr($s, 1, 100);
    }
    
    $winner = [
        "a" => "A",
        "b" => "B",
        "c" => "C"
    ];
    
    
    
    $next = "a";
    while (true) {
        if (${$next} == "") {
            break;
        }
        $temp = substr(${$next}, 0, 1);
        ${$next} = del(${$next});
        $next = $temp;
    }
    
    echo $winner[$next];
?>

Measured memory_bytes: 4728
h, w = [int(n) for n in input().split()]

B = [['.'] * (w + 2)]
for i in range(h):
    s = ['.'] + list(input()) + ['.']
    B.append(s)
B.append(['.'] * (w + 2))

for i in range(1, h+1):
    for j in range(1, w+1):

        if B[i][j] == '#':
            continue
        else:
            
            B[i][j] = str((B[i-1][j-1:j+2] + [B[i][j-1]] + [B[i][j+1]] + B[i+1][j-1:j+2]) .count('#'))

#print(B)

for i in range(1, h+1):
    print(''.join(B[i][1:w+1]))
    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

void input()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(0, min(d,b)- max(a,c) );
}

void solve()
{

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
   // freopen(TASK".inp","r",stdin);
   // freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main() {FIN
    
    int i, j, k, n;
    cin >> n;
    vi ns(n + 1);
    for (i = 1; i <= n; i++) {
		j = 1;
		while (i * j + i * i + j * j <= n) {
			k = 1;
			while (i*i + j*j + k*k + i*j + i*k + j*k <= n) {
				ns[i*i + j*j + k*k + i*j + i*k + j*k]++;
				k++;
			}
			j++;
		}
	}
	
	for (i = 1; i <= n; i++) {
		cout << ns[i] << "\n";
	}
    
    return 0;
}


Measured memory_bytes: 3652
def factorize(n):
  ret = [1, n]
  for i in xrange(2, n):
    if i * i > n:
      break
    if n % i == 0:
      ret.append(i)
      if i * i != n:
        ret.append(n / i)
  return ret

n = input()
a = {}

for k in map(int, raw_input().split()):
  for f in factorize(k):
    if not f in a:
      a[f] = 0
    a[f] += 1

for k in sorted(a):
  if a[k] == n:
    print k

Measured memory_bytes: 4248
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int w = 0, s = 0;
    for(int ai = 0; 100 * ai * a <= f; ai++) {
        for(int bi = 0; 100 * bi * b + 100 * ai * a <= f; bi++) {
            for(int ci = 0; 100 * bi * b + 100 * ai * a + ci*c <= f; ci++) {
                int A = 100 * ai * a;
                int B = 100 * bi * b;
                int C = ci*c;
                int W = A + B;
                if(W == 0) continue;
                int D = min(((f - (100 * bi * b + 100 * ai * a + ci*c))/d) * d, ((e * W / 100 - C)/d) * d);
                if(D < 0) continue;
                int S = C + D;
                if(S > e * W / 100) continue;
                if(W + S == 0) continue;
                if((W+S)*s < (w+s)*S || (w == 0 && s == 0)) s = S, w = W;
            }
        } 
    }
    cout << w + s<< " " << s << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
sList = []
tLsit = []
result = 0
count = 0
Bool = False
for _ in range(n) :
    s, t = map(str, input().split())
    sList += [s]
    tLsit += [int(t)]
x = input()

for S in sList :
    if Bool :
        result += tLsit[count]
    if S == x :
        Bool = True
    count += 1

print(result)





Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
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;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll W,H,x,y,r;cin>>W>>H>>x>>y>>r;
    if(0<=x-r and x+r<=W and 0<=y-r and y+r<=H)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3112
# include<iostream>
using namespace std;
int main(){
string a , b ;
cin>>a>>b;
if(a.size() > b.size()){
    cout<<"GREATER";
}
else if (a.size()<b.size()){
    cout<<"LESS";
}
else if (a.size() == b.size()){
     if(a[0]>b[0]){
        cout<<"GREATER";
     }
     else if (a[0]<b[0]){
        cout<<"LESS";
     }
     else {
        cout<<"EQUAL";
     }
}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int a,b;
   char op;
   
   for(;;){
   scanf("%d %c %d",&a,&op,&b);
   
   if(op=='+'){
       printf("%d",a+b);
   }else if(op=='-'){
       printf("%d",a-b);
   }else if(op=='*'){
       printf("%d",a*b);
   }else if(op=='/'){
       printf("%d",a/b);
   }else{
       break;
   }
   printf("\n");
   
   }
    return(0);
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    if (l > 0) cout << (2 * l + n) * (n - 1) / 2 << endl;
    else if (l + n - 2 < 0) cout << (2 * l + n - 2) * (n - 1) / 2 << endl;
    else cout << (2 * l + n - 1) * n / 2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
const ull mod =1e9+7;
inline void solve(void){
  int N,K;
  in(N,K);
  ull ans=0,u=0,d=0,du=0,dd=0;
  rep(i,K){
    d+=i;u+=(N-i);
    if(i==K-1){
      dd=i+1;
      du=(N-i-1);
    }
  }
  ans=u-d+1;
  up(i,K+1,N+1){
    d+=dd;
    u+=du;
    dd++;
    du--;
    ans+=u-d+1;
  }
  out(ans%mod);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;
typedef long long ll;
#define maxn 100005
ll a[maxn];

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    int n;
    cin >> n; 
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, cmp);
    ll len[2] = {0};
    ll cnt = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == a[i + 1]) {
            len[cnt++] = a[i];
            i++;
            if(cnt == 2) {
                break;
            }
        }
    }
    cout << len[0] * len[1] << endl;
    return 0;
}


Measured memory_bytes: 1024
program dm
    implicit none
    integer::N
    integer(16)::K
    integer,allocatable,dimension(:)::A
    integer,allocatable,dimension(:)::num,town
    integer::now
    integer::loop
    integer::S
    integer::ans
    read*,N,K
    allocate(A(N))
    read*,A
    allocate(num(N),town(N))
    num=-1
    num(1)=1
    now=1
    town(1)=1
    do
        if(num(A(now))<0)then
            num(A(now))=num(now)+1
            town(num(now)+1)=A(now)
            now=A(now)
        else
            exit
        endif
    end do
    loop=num(now)-num(A(now))+1
    S=num(A(now))-1
    if(K>S)then
        K=K-S
        K=mod(K,loop)
        ans=town(1+S+K)
    else
        ans=town(K+1)
    endif
    print"(i0)",ans
contains
end program dm

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

int main() {
  int  N,  A,  a;
  cin  >>  N  >>  A;
  a  =  N  %  500;

  if (a  <= A) {
    cout  <<  "Yes"  <<  endl;
  }
  else {
    cout  <<  "No"  <<  endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int inf = 0x3f3f3f3f;
bool ok; char ch;
void read(int& x) {
	for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') ok = 1;
	for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if (ok) x = -x;
}
void write(int x)
{
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
string s;
int fuc(int n, int k) {
	if (n < k)return 0;
	if (k == 0)return 1;
	if (k == 3) {
		int ans = 0;
		for (int i = 3; i <= n; i++) {
			for (int j = 2; j < i; j++) {
				for (int k = 1; k < j; k++) {
					ans += 9 * 9 * 9;
				}
			}
		}
		return ans;
	}
	if (k == 2)return n * (n - 1) * 81 / 2;
	/*if (k == 2) {
		int ans = 0;
		for (int j = 2; j < n; j++) {
			for (int k = 1; k < j; k++) {
				ans += 9 * 9 ;
			}
		}
		return ans;
	}*/
	return 9 * n;
}
int dp(int i, int k) {
	while (s[i] == '0')i++;
	if (i >= (signed)s.size()) {
		return 0;
		//return k ? 0 : 1;
	}
	if (k <= 0)return 0;
	//if ((signed)s.size() - i - 1 < k)return 0;
	return dp(i + 1, k - 1) + (s[i] - '1') * fuc((signed)s.size() - i - 1, k - 1) + fuc((signed)s.size() - i - 1, k) + (k == 1);
}
int main() {

	cin >> s;
	int k;
	cin >> k;
	cout << dp(0, k);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

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

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

const int INF=1001001001;

#define pb push_back
#define mp make_pair

struct Taxi{
	int C,R;
	vint edges,edges2;
	bool flag;
	int ans;
	Taxi()
			: flag(false),ans(INF){
	}
}taxis[5010];

int main(){
	int N,K;
	N=in();//町の数
	K=in();//道路の本数
	for(int i=0;i<N;i++){
		taxis[i].C=in();//タクシー会社iの移動値段
		taxis[i].R=in();//タクシー会社の通ることが出来る道路の本数
	}
	for(int i=0;i<K;i++){
		int to,from;
		//町toと町fromをつなぐ道路
		to=in()-1;
		from=in()-1;
		taxis[to].edges.pb(from);
		taxis[from].edges.pb(to);
	}
	
	//make a graphdefaults
	//タクシー会社をすべて見ていく
	for(int i=0;i<N;i++){
		queue<int> q;
		//指標となるタクシー会社を定義
		q.push(i);
		//指標としたタクシー会社の通れる道路の本数だけ繰り返す。
		for(int k=0;k<taxis[i].R;k++){
			queue<int> q2;
			//町qから一つ移動することだけでできる町がなくなるまで繰り返す
			while(! q.empty()){
				int n=q.front();
				q.pop();
				
				//町nから1回で移動できる町をすべて繰り返す
				for(int j=0;j<taxis[n].edges.size();j++){
					int to=taxis[n].edges[j];//toに町nから移動できる街の場所を代入する
					//taxis[to].flagがfalseでなければ
					if(! taxis[to].flag){
						//trueにする
						taxis[to].flag=true;
						//taxis(to)の町を次の指標にする
						q2.push(to);
					}
				}
			}
			//次の指標に切り替える
			q=q2;
		}
		//町iから1回で移動できる街の個数すべてつなげる
		for(int k=0;k<N;k++){
			if(i!=k&&taxis[k].flag){
				taxis[i].edges2.pb(k);
			}
			//次のためにすべてfalseに戻す
			taxis[k].flag=false;
		}
	}
	
	//Dijkstra
	//
	priority_queue<pint> pq;
	pq.push(mp(0,0));
	while(pq.size()){
		pint a=pq.top();
		pq.pop();
		int cost=-a.first;
		int n=a.second;
		
		if(cost<taxis[n].ans){
			taxis[n].ans=cost;
			if(n==N-1){
				break;
			}
			for(vint::iterator iter=taxis[n].edges2.begin();iter!=taxis[n].edges2.end();++iter){
				if(taxis[*iter].ans==INF){
					pq.push(mp(-(cost+taxis[n].C),*iter));
				}
			}
		}
	}
	
	cout<<taxis[N-1].ans<<endl;
	return 0;
}


Measured memory_bytes: 71480
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int dpx[8]={1,1,1,-1,-1,-1,0,0};
int dpy[8]={-1,1,0,1,-1,0,-1,1};

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	int x = 1000; 
	while(x < n)
		x += 1000; 
	cout << (x - n); 
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
    int m, nmin, nmax;
    while(cin >> m >> nmin >> nmax, m){
        vector<int> p(m);
        for(int i = 0 ; i < m ; i++){
            cin >> p[i];
        }
        sort(p.begin(), p.end());

        pair<int, int> ans = make_pair(-1, -1);
        for(int n = nmin ; n <= nmax ; n++){
            ans = max(ans, make_pair(p[m - n] - p[m - n - 1], n));
        }

        cout << ans.second << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j,a[10010],b,c,y,m,d;
  char s[4][110],t[110][110],o[110][110];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s %d/%d/%d",t[i],o[i],&y,&m,&d);
    a[i]=y*10000+m*100+d;
  }
  scanf("%d",&m);
  while(m--){
    for(i=0;i<4;i++)scanf("%s",s[i]);//printf("%s %s %S %s\n");
    for(i=0;i<n;i++){
      if(s[0][0]-'*'&&strstr(t[i],s[0])==NULL)continue;
      if(s[1][0]-'*'&&strstr(o[i],s[1])==NULL)continue;
      for(j=b=0;s[2][j];j++)b=s[2][j]-'/'?b*10+s[2][j]-'0':b;
      if(s[2][0]=='*')b=0;
      for(j=c=0;s[3][j];j++)c=s[3][j]-'/'?c*10+s[3][j]-'0':c;
      if(s[3][0]=='*')c=1e9;
      if(b<=a[i]&&a[i]<=c)printf("%s\n",t[i]);
    }
    if(m)printf("\n");
  }
  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
int main()
{
	int S,h,m,s;//设出时分秒 
	scanf("%d",&S);//输入秒数数值 
	h=S/3600;//小时数 
	m=(S-3600*h)/60;//分钟数 
	s=S-3600*h-60*m;//秒数 
	printf("%d:%d:%d\n",h,m,s);//打印结果 
	return 0;
}



Measured memory_bytes: 2064
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextLong();
		}
		long[] kbin = new long[40];
		long[] xbin = new long[40];
		int kdigit = 0;
		long kcopy = k;
		while(kcopy>0){
			if(kcopy%2==1){
				kbin[kdigit] = 1;
			}
			kdigit++;
			kcopy /= 2;
		}
		long[] abin = new long[40];
		for(int i=0; i<n; i++){
			long acopy = a[i];
			int adigit = 0;
			while(acopy>0){
				if(acopy%2==1){
					abin[adigit]++;
				}
				adigit++;
				acopy /= 2;
			}
		}
		for(int i=0; i<40; i++){
			if(abin[i] >= n-abin[i]){
				xbin[i] = 0;
			}
			else{
				xbin[i] = 1;
			}
		}
		for(int i=39; i>=0; i--){
			if(kbin[i]==1 && xbin[i]==0)break;
			if(kbin[i]==0 && xbin[i]==1)xbin[i] = 0;
		}
		long x = 0;
		for(int i=0; i<40; i++){
			x += (long)Math.pow(2, i) * xbin[i];
		}
		long ans = 0;
		for(int i=0; i<n; i++){
			ans += x ^ a[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 60456
/* created   : 2019-09-24 00:14:34
 * accepted  : 2019-09-24 00:33:27
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

int n;
string s;

bool check(int md) {
  for (int i = 0; i + md <= n; i++) {
    string x = s.substr(i, md);
    if ((int) s.find(x, i + md) != -1) {
      return true;
    }
  }
  return false;
}

void solve() {
  cin >> n >> s;
  int lo = -1;
  int hi = n + 1;
  while (hi - lo > 1) {
    int md = lo + (hi - lo) / 2;
    if (check(md)) {
      lo = md;
    }
    else {
      hi = md;
    }
  }
  cout << lo << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()

l = l%2019
r = r%2019

if l >= r:
    print(0)
else:
    ans = float('inf')
    for left in range(l, r):
        for right in range(left+1, r+1):
            ans = min(ans, (left*right)%2019)
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(ll i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define MOD 998244353
#define sec setprecision
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return pow(x * x % m, n / 2, m);
	else
		return x * pow(x, n - 1, m) % m;
}
ll pow(ll x, ll n) {
	if (n == 0)
		return 1;
	else if (x == 1)return(1);
	else if (n % 2 == 0)
		return pow(x * x, (n / 2));
	else
		return x * pow(x, n - 1);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll 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;
	}
}

// 二項係数計算
long long com(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;
}

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	rip(i, n) {
		cin >> a[i];
	}
	ll kotae = 1;
	ll gennkai = pow(10, 18);
	int count = 0;
	rip(i, n) {
		if (a[i] == 0)count++;
	}
	rip(i, n) {
		if (kotae == 0 || a[i] == 0) {
			kotae = 0;
			break;
		}
		else if (a[i] > (gennkai / kotae)) {
			kotae = -1;
			break;
		}
		else {
			kotae *= a[i];
		}
	}
	if (count == 0)cout << kotae << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 4052
n, a, b = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

def power(x, n)
    return 1 if n == 0
    (n.even? ? 1 : x) * power(x ** 2 % MOD, n / 2) % MOD
end

def mul(s, t)
    (s..t).each.inject(1) {|r, v| r * v % MOD}
end

def comb(a, b)
    mul(a - b + 1, a) * power(mul(1, b), MOD - 2) % MOD 
end

puts (power(2, n) - 1 - comb(n, a) - comb(n, b)) % MOD


Measured memory_bytes: 1788
#include<stdio.h>
int N=100;

int main(){
  int M[N][N];
  int n, u, k, v, i, j;

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) {
M[i][j] = 0;
  }}
  
  for ( i = 0; i < n; i++ ){
    scanf("%d%d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ){
      if ( j ) printf(" ");
      printf("%d", M[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  } else if (a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if (a == b) {
    cout << "EQUAL" << endl;
    return 0;
  }
  cout << (a < b ? "LESS" : "GREATER") << endl;
  return 0;
}


Measured memory_bytes: 256