akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N;
    cin >> N;
    vll a(N);
    rep(i, N){
        cin >> a[i];
    }
    ll f = 0, s = 0;
    rep(i, N){
        if(a[i]>f){
            s = f;
            f = a[i];
        }
        else if(a[i]>s){
            s = a[i];
        }
    }
    rep(i, N){
        if(a[i]==f) cout << s << endl;
        else cout << f << endl;
    }
}


Measured memory_bytes: 3200
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    @staticmethod
    def selection_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        count = 0
        for i in range(array_length):
            min_j = i
            for j in range(i, array_length):
                if unsorted_array[j] < unsorted_array[min_j]:
                    min_j = j
            unsorted_array[i], unsorted_array[min_j] = unsorted_array[min_j], unsorted_array[i]
            if i != min_j:
                count += 1

        print(" ".join(map(str, unsorted_array)))
        print(str(count))


if __name__ == '__main__':
    solution = Solution()
    solution.selection_sort()

Measured memory_bytes: 7704
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	cin >> n >> m;
	vector <ll> v[n+1];
	ll h[n+1]={0};
	for(i=0;i<m;i++)
	{
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	queue <ll> q;
	q.push(1);
	while(!q.empty())
	{
		k=q.front();
		q.pop();
		for(i=0;i<v[k].size();i++)
		{
			t=v[k][i];
			if(h[t]==0)
			{
				h[t]=k;
				q.push(t);
			}
		}
	}
	for(i=2;i<n+1;i++)
		if(h[i]==0)
		{
			cout << "No\n";
			return 0;
		}
	cout << "Yes\n";
	for(i=2;i<n+1;i++)
		cout << h[i] << "\n";
}

Measured memory_bytes: 12964
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 6e5 + 100;
using ll = long long;
const int M = 1e9 + 7;
vector<pair<int,int> >v1[maxn], v3[maxn], v2[maxn];
int tot = 0;
int vis[maxn];
void dij(int st,int en)
{
    static int dis[maxn];
    for(int i = 0;i <= tot; ++i) dis[i] = inf,vis[i] = 0;
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int>> >q;
    dis[st] = 0;
    q.push({0,st});
    while(!q.empty())
    {
        pair<int,int> tp = q.top();
        q.pop();
        vis[tp.second] = 0;
        for(auto &u:v3[tp.second])
        {
            if(dis[u.first] > dis[tp.second] + u.second)
            {
                dis[u.first] = dis[tp.second] + u.second;
                if(!vis[u.first]) 
                vis[u.first] = 1, q.push({dis[u.first],u.first});
            }
        }
    }
    int ans = dis[en];
    if(ans==inf) ans = -2;
    printf("%d\n",ans/2);
}
int main()
{
   // freopen("1.in","r",stdin);
   // freopen("1.out","w",stdout);
    int n, m;
    while (~scanf("%d%d",&n,&m))
    {
        tot = 0;
        for(int i = 1; i <= m; ++i){
            int x,y,c;
            scanf("%d %d %d",&x, &y, &c);
            v1[x].push_back({y,c});
            v2[x].push_back({c,0});
            v2[y].push_back({c,0});
        }
        tot = n;
        for(int i = 1;i <= n; ++i){
            sort(v2[i].begin(),v2[i].end());
            v2[i].erase(unique(v2[i].begin(),v2[i].end()),v2[i].end());
            for(auto &u:v2[i])
                u.second = ++tot;
        }
        for(int i = 1;i <= n; ++i){
            for(auto &u:v2[i]){
                v3[u.second].push_back({i,1});
                v3[i].push_back({u.second,1});
            }
            for(auto &u:v1[i]){
                int x = u.first,c = u.second;
                int p = lower_bound(v2[x].begin(),v2[x].end(),make_pair(c,0)) - v2[x].begin();
                p = v2[x][p].second;
                int p2 = lower_bound(v2[i].begin(),v2[i].end(),make_pair(c,0)) - v2[i].begin();
                p2 = v2[i][p2].second;
                v3[p].push_back({p2,0});
                v3[p2].push_back({p,0});
            }
        }
        dij(1,n);
        for(int i = 0;i <= tot; ++i) 
        {
            v1[i].clear();v2[i].clear();v3[i].clear();
        }
    }
    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    vector <int> ans(11);
    ans[0]=c;
    rep(i,10){
        ans[i+1]=ans[i]*a-b;
    }
    rep(i,10){
        cout << ans[i+1] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3628
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  for(ll i=1;i<=n;i++){
    if(1<=i&&i<=9)ans++;
    if(100<=i&&i<=999)ans++;
    if(10000<=i&&i<=99999)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(){
	int n,t,i,j;
	while(cin>>n,n){
		int c[10]={0};
		for(i=0;i<n;i++)cin>>t,c[t]++;
		for(i=0;i<10;i++){if(!c[i])cout<<'-';else for(j=0;j<c[i];j++)cout<<'*';cout<<endl;}
	}
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+b)>=mod)a-=mod;
  else if((a+b)<0)a+=mod;
  return a+b;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}

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

  int n;
  string s;
  cin >> n;
  cin >> s;
  multiset<char> mset;
  set<char> se;
  /*  ll num=1;
  ll kind=1;
  sort (s.begin(), s.end());*/
  rep(i,s.size()){
    mset.insert(s[i]);
    se.insert(s[i]);
  }
  ll ans=1;
  for(auto i:se){
    ans=mu((mset.count(i)+1),ans);
  }
  cout << ad(ans,-1) << endl;


  
  return 0;
    

}


Measured memory_bytes: 5072
#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" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x, 0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
int n,m;
int a[100005];
int dp[100005];

int minCost (int i)
{
    if (i == n - 1) return 0;
    if (i >= n) return mod;

    int &ret = dp[i];

    if (ret != -1) return ret;

    int choice1 = minCost(i + 1) + abs(a[i] - a[i + 1]);
    int choice2 = minCost(i + 2) + abs(a[i] - a[i + 2]);

    return ret = min (choice1, choice2);
}

void solve()
{
    cin >> n;
    f (i, n) cin >> a[i];
    f (i, n) dp[i] = -1;
    cout << minCost(0);
}  
 
signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 9788
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x,k,d,a,b,c;
  cin >> x >> k >> d;
  a = abs(x/d);
  if (k-a > 0)
  {
    
    b = abs(x)-a*d;
    c = d-b;
    if ((k-a)%2 == 0)
    {
      cout << b <<endl;
    }else
    {
      cout << c << endl;
    }
  }else
  {
    cout << abs(x)-k*d <<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
using namespace std;

int main(void)
{
	int face_val[6], i, j, face_num[6] = { 0,1,2,3,4,5 }, tmp[6];
	string direction;

	for (i = 0; i < 6; i++) {
		cin >> face_val[i];
	}

	cin >> direction;

	for (i = 0; i < direction.length(); i++) {

		for (j = 0; j < 6; j++) {
			tmp[j] = face_num[j];
		}

		switch (direction[i]) {
		case 'N':
			face_num[0] = tmp[1];
			face_num[1] = tmp[5];
			face_num[5] = tmp[4];
			face_num[4] = tmp[0];
			break;
		case 'E':
			face_num[0] = tmp[3];
			face_num[3] = tmp[5];
			face_num[5] = tmp[2];
			face_num[2] = tmp[0];
			break;
		case 'W':
			face_num[0] = tmp[2];
			face_num[2] = tmp[5];
			face_num[5] = tmp[3];
			face_num[3] = tmp[0];
			break;
		case 'S':
			face_num[0] = tmp[4];
			face_num[4] = tmp[5];
			face_num[5] = tmp[1];
			face_num[1] = tmp[0];
			break;
		default:
			break;
		}
	}

	cout << face_val[face_num[0]] << endl;
}


Measured memory_bytes: 3160
def mainFunc():
    n = int(input())
    tesMat = [0] * (n + 1)
    
    for i in range(1, n + 1):
        tesMat[i] = [-1] * (n + 1)
        a = int(input())
        for j in range(a):
            x, y = list(map(lambda x: int(x), input().split(" ")))
            tesMat[i][x] = y
    
    ans = 0
    flag = False
    for i in range(2 ** n):
        flag = True
        honest = list(map(lambda x: int(x), list(format(i, "b").zfill(n + 1))))
        for j in range(1, n + 1):
            if honest[j] == 1:
                for k in range(1, n + 1):
                    if tesMat[j][k] == 1 and honest[k] == 0 or tesMat[j][k] == 0 and honest[k] == 1:
                        flag = False
                        break

            if not flag:
                break
        
        if flag:
            honestNumber = len(list(filter(lambda x: x == 1, honest)))
            ans = honestNumber if ans < honestNumber else ans
    
    print(ans)

mainFunc()

Measured memory_bytes: 3064
n = int(input())
word = []
for i in range(n):
  word.append(input())
  
  
s_word = set(word)
ans = 'No' 
siri = word[0][-1]
s_size = len(s_word)
w_size = len(word)
del word[0]

if s_size == w_size:
  for i in word:
    if siri == i[0]:
      ans = 'Yes'
      siri = i[-1]
    else:
      ans = 'No'
      break
      
print(ans)      

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<vector<int>,int> P;

int n, d, idx;

ll Vtoll(vector<int> V){
  
  ll res=0;
  
  for(int i=0;i<V.size();i++) res=res*10+V[i];
  
  return res;
  
}

unordered_map<ll,int> memo[2];

queue<P> q;

void bfs(vector<int> s){
  
  q.push(P(s,0));

  memo[idx][Vtoll(s)]=0;
  
  while(!q.empty()){

    P t=q.front(); q.pop();

    int cost=t.second;
    vector<int> S=t.first;
    
    if(cost==d) continue;
    
    for(int i=0;i<n-1;i++)
      for(int j=i+2;j<=n;j++){
	
	vector<int> nS=S;
	reverse(nS.begin()+i,nS.begin()+j);
	
	if(memo[idx].count(Vtoll(nS))) continue;
	memo[idx][Vtoll(nS)]=cost+1;
	
	q.push(P(nS,cost+1));
      }
    
  }
  
}

int main(){
  
  cin>>n;
  
  vector<int> A;
  
  A.resize(n);
  
  for(int i=0;i<n;i++) cin>>A[i],A[i]--;
  
  d=(n-1)/2;
  
  idx=0;
  
  bfs(A);
  
  d=(n-1)/2;
    
  idx=1;
  
  for(int i=0;i<n;i++) A[i]=i;
  
  bfs(A);

  int ans=n-1;
  
  unordered_map<ll,int>::iterator ite=memo[0].begin();

  while(ite!=memo[0].end()){
    
    if(memo[1].count((*ite).first))
      ans=min(ans,(*ite).second+memo[1][(*ite).first]);
    
    ite++;
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}

/*

SAK

*/

Measured memory_bytes: 42868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vp vec(n);
    REP(i,n){
        cin>>vec[i].fi;
        vec[i].se=i;
    }
    sort(all(vec));
    vi ans(n);
    REP(i,n){
        if(i<n/2){
            ans[vec[i].se]=vec[n/2].fi;
        }else{
            ans[vec[i].se]=vec[n/2-1].fi;
        }
    }
    REP(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <array>

using namespace std;
typedef long long ll;

int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a.at(i).at(j);
        }
    }

    vector<array<ll, 4>> moves;
    for(int y = 0; y < h; ++y){
        if(y % 2 == 0){
            for(int x = 0; x < w; ++x){
                if(a.at(y).at(x) % 2 != 0){
                    a.at(y).at(x) -= 1;
                    if(x < w - 1){
                        a.at(y).at(x + 1) += 1;
                        moves.push_back({y, x, y, x + 1});
                    }else if(y < h - 1){
                        a.at(y + 1).at(x) += 1;
                        moves.push_back({y, x, y + 1, x});
                    }
                }
            }
        }else{
            for(int x = w - 1; x >= 0; --x){
                if(a.at(y).at(x) % 2 != 0){
                    a.at(y).at(x) -= 1;
                    if(x > 0){
                        a.at(y).at(x - 1) += 1;
                        moves.push_back({y, x, y, x - 1});
                    }else if(y < h - 1){
                        a.at(y + 1).at(x) += 1;
                        moves.push_back({y, x, y + 1, x});
                    }
                }
            }
        }
    }

    cout << moves.size() << endl;
    for(array<ll, 4>& a : moves){
        cout << a.at(0) + 1 << ' ' << a.at(1) + 1 << ' ' <<
            a.at(2) + 1 << ' ' << a.at(3) + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 8304
h, w, m = map(int, input().split())
H = [0] * (h+1)
W = [0] * (w+1)
bombs = set()
for _ in range(m):
    hh, ww = map(lambda x: int(x)-1, input().split())
    H[hh] += 1
    W[ww] += 1
    bombs.add((hh, ww))

mh = max(H)
mw = max(W)
mhis = [i for i, x in enumerate(H) if x == mh]
mwis = [i for i, x in enumerate(W) if x == mw]

duplicated = True
for mhi in mhis:
    for mwi in mwis:
        if not (mhi, mwi) in bombs:
            duplicated = False
            break
            
ans = mh + mw - duplicated
print(ans)


Measured memory_bytes: 83420
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
long long a;
long double b;

signed main()
{
	scanf("%lld %llf", &a, &b);
	
	ll ans=floor((long double)a*b);
	printf("%lld",ans);
	 
	return 0;
} 


Measured memory_bytes: 3828
#include <stdio.h>
 
int main(void){
  int i,j,n,taro_p=0,hana_p=0;
  char taro[101], hana[101];
 
  scanf("%d", &n);
 
  for(i=0;i<n;i++){
    scanf("%s %s", taro, hana);
 
    for(j=0;;j++){
      if(taro[j] > hana[j]){
        taro_p += 3;
        break;
      }else if(taro[j] < hana[j]){
        hana_p += 3;
        break;
      }else if(taro[j] + hana[j] == 0){
        hana_p++;
        taro_p++;
        break;
      }
    }
  }
 
  printf("%d %d\n", taro_p , hana_p);
  return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
long f(long t1,long t2){
    stringstream ss1,ss2;
    ss1<<t1;
    ss2<<t2;
    string s1,s2;
    s1=ss1.str();
    s2=ss2.str();
    return max(s1.size(),s2.size());
}

int main(){
    long n;
    cin>>n;
    long root=sqrt(n);
    unsigned long min=-1;
    for(int i=1; i <=root; i++){
        if(n%i!=0)
            continue;
        else{
            long t=n/i;
            t=f(i,t);
            if(t<min)
                min=t;
        }
    }
    cout<<min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int a[100010];

int ans;
int res;

bool r[64];

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
    res ^= a[i];
    REP( j , 32 ){
      if( a[i] & PW(j) ){
        r[j] = true;
        break;
      }
    }
  }
  
  for( int i = 30; i >= 0; i-- ){
    if( res & PW(i) ){
      if( r[i] ){
        ans++;
        res = res ^ ( PW(i) - 1 );
      } else {
        puts( "-1" );
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {

  int N,flag;
  cin >> N;
  vector<int> A(N);
  flag=1;//1なら承認
  
// A入力
for (int i = 0; i < N; i++) {
  cin >> A.at(i);
}
  
// A入力
for (int i = 0; i < N; i++) {
  if (A.at(i)%2 ==0){
    if (A.at(i)%3!=0 && A.at(i)%5!=0 ){
      flag=0;
    }    
  }
//  cout<<A.at(i)<<endl;
////  cout<<"/2 "<<A.at(i)%2<<' '<<endl;
//  cout<<"/3 "<<A.at(i)%3<<' '<<endl; 
//  cout<<"/5 "<<A.at(i)%5<<' '<<endl;
//  cout << endl;
}
 
//flag=1のままだったらAPPROVED
if (flag ==1){
  cout<<"APPROVED"<<endl;
} else {cout<<"DENIED"<<endl;}

  
}


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

int main()
{
ll k , a , b ;
cin >> k >> a >> b ;
rep(i,5000){
if(a<=i*k&&i*k<=b)ans="OK";
}
cout << ans << endl;
return 0;
}

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

int main(){
    int N;
    int h[110000];
    cin >> N;
    for(int i=0;i<N;++i) cin >> h[i];
    
    // dp (i(~N)への最短コスト)
    int dp[110000];
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<N;++i){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2]));
    }

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

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	ll H, W;
	int N;
	cin >> H >> W >> N;

	map<ll, vector<ll>> m;
	for (auto i = 0; i < N; ++i)
	{
		ll a, b;
		cin >> a >> b;
		--a;
		--b;
		m[b].push_back(a);
	}

	for (auto& p : m)
	{
		sort(p.second.begin(), p.second.end());
	}

	vector<ll> ans(10);

	for (auto& p : m)
	{
		auto x = p.first;
		for (auto y : p.second)
		{
			for (auto i = -2; i <= 0; ++i)
			{
				for (auto j = -2; j <= 0; ++j)
				{
					auto baseX = x + i;
					auto baseY = y + j;
					if (baseX < 0 || baseY < 0 || baseX + 2 >= W || baseY + 2 >= H)
					{
						continue;
					}

					auto valid = true;
					auto num = 1;
					for (auto k = 0; k < 3; ++k)
					{
						for (auto l = 0; l < 3; ++l)
						{
							auto tempX = baseX + k;
							auto tempY = baseY + l;
							if (tempX == x && tempY == y)
							{
								continue;
							}

							auto it = m.find(tempX);
							if (it == m.end())
							{
								continue;
							}

							auto it2 = lower_bound(it->second.begin(), it->second.end(), tempY);
							if (it2 == it->second.end()
								|| *it2 != tempY)
							{
								continue;
							}

							++num;
							if (tempX < x
								|| (tempX == x && tempY < y))
							{
								valid = false;
								break;
							}
						}
						if (!valid)
						{
							break;
						}
					}

					if (valid)
					{
						++ans[num];
					}
				}
			}
		}
	}

	auto sum = 0ll;
	for (auto i = 1; i < 10; ++i)
	{
		sum += ans[i];
	}
	ans[0] = (H - 2) * (W - 2) - sum;

	for (auto i = 0; i < 10; ++i)
	{
		cout << ans[i] << endl;
	}

	return 0;
}

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

typedef long long int lli;
#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define REP(i,n) for(lli(i)=0;(i)<(lli)(n);(i)++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;


typedef pair<lli, lli> ii;
typedef pair<ii, lli> iii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef long double C;
typedef complex<C> P;
#define X real()
#define Y imag()
C EPS=1e-9;
C pi=acos(-1.0);
const int N=1e5+9;
const int INF=1100000;

int main(){
	fastio;
	int dp[N];
	vi v;
	int n; cin>>n;
	REP(i,n){
		int num; cin>>num;
		v.pb(num);
	}
	dp[0]=0; dp[1]=abs(v[0]-v[1]);
	rep(i,2,sz(v)) dp[i]=min( dp[i-1]+abs(v[i]-v[i-1]) , dp[i-2]+abs(v[i]-v[i-2]) );
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1524
n,m,c=gets.chomp.split(" ").map(&:to_i)
arr_b = gets.chomp.split(' ').map(&:to_i)
ans = 0
n.times do 
  arr_a = gets.chomp.split(' ').map(&:to_i)
  sum = c
  m.times do |k|
  sum += arr_a[k] * arr_b[k]
  end
  if sum > 0
    ans += 1
  end
end

puts ans

Measured memory_bytes: 14308
from sys import stdin

N, A, B = map(int, stdin.readline().split())


def sum_each(N):
    N_10000 = N // 10000
    N_1000 = N % 10000 // 1000
    N_100 = N % 1000 // 100
    N_10 = N % 100 // 10
    N_1 = N % 10
    return N_10000 + N_1000 + N_100 + N_10 + N_1


ans = 0
for a in range(N + 1):
    this = sum_each(a)
    if A <= this <= B:
        ans += a

print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define int long long

signed main() {
  int a, b, n;
  cin>>a>>b>>n;
  int x = b-1 < n ? b-1 : n;
  int val = ((a*x) / b) - (a * (x / b));
  cout<<val<<"\n";
  return 0;
}

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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	rep(i, 19) {
		char c; cin >> c;
		cout << (c == ',' ? ' ' : c);
	}
	cout << endl;
	system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;


int main() {
 int N;
  in(N);
  vl A(N);
  rep(i,N) in(A[i]);
  int ans =0;
  rep(i,N) ans += A[i];
  out(ans-N);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 300000


ll fact[MAX];
ll power(ll a,ll b){
	if(b==0) return 1;
	ll temp = power(a,b/2)%Mod;
	if(b%2==0){
		return (temp*temp)%Mod;
	}else{
		return (a*((temp*temp)%Mod))%Mod;
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	fact[0]=1;
	For(i,1,MAX) fact[i]=(fact[i-1]*i)%Mod;
	ll n,m,k;cin>>n>>m>>k;

	ll ans=0;
	ll z = ((fact[n*m-2])*power((fact[n*m-2-(k-2)]*fact[k-2])%Mod,Mod-2))%Mod;

	vector<ll> X,Y;
	For(i,0,n) For(j,0,m) {
		X.pb(i+1);
		Y.pb(j+1);
	}	
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	ll p1 = 0 , p2=0;
	For(i,0,X.size()){
		ll t1 = (X[i]*i)%Mod;
		ll t2 = (Y[i]*i)%Mod;
		ans+=(t1-p1+Mod);
		ans%=Mod;
		ans+=(t2-p2+Mod);
		ans%=Mod;
		p1+=X[i];
		p1%=Mod;
		p2+=Y[i];
		p2%=Mod;
	}

	cout<<(ans*z)%Mod<<endl;
	











	
}

Measured memory_bytes: 5988
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef struct{
	int fir;											//first
	int sec;											//second
}w;

int s[20000],  sizes = 0, sizet = 0;
w t[20000];

void push_s(int x)
{
	s[sizes++] = x;
}

int pop_s()
{
	sizes--;
	return s[sizes];
}

void push_t(int fir, int sec)
{
	w x;
	x.fir = fir;
	x.sec = sec;

	t[sizet++] = x;
}

w pop_t()
{
	sizet--;
	return t[sizet];
}

w k_t(){
	return t[sizet - 1];
}

int main(void)
{
	int i, j, sum = 0, a;
	char c[20000];

	scanf("%s", c);

	for(i = 0; i < strlen(c); i++){
		if(c[i] == '\\'){
			push_s(i);
		}
		else if(c[i] == '/' && sizes > 0){
			j = pop_s();
			sum += i - j;
			a = i - j;
			while(sizet > 0 && k_t().fir > j){
				a += pop_t().sec;
			}
			push_t(j, a);
		}
	}

	printf("%d\n", sum);
	printf("%d", sizet);

	for(i = 0; i < sizet; i++){
		printf(" ");
		printf("%d", t[i].sec);
	}

	printf("\n");
	return 0;
}



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

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

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

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int N;
	cin >> N;
	long long int sum = 0;
	long long int a = 0;
	long long int b = 0;
	long long int ba = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 1; j < s.size(); j++) {
			if (s[j] == 'B') {
				if (s[j - 1] == 'A') {
					sum++;
				}
			}
		}
		if (s[s.size() - 1] == 'A'&& s[0] == 'B') {
			ba++;
			continue;
		}
		if (s[0] == 'B') {
			b++;
		}
		if (s[s.size()-1] == 'A') {
			a++;
		}
	}
	if (ba != 0) {
		sum = sum + ba - 1;
		if (a + b != 0) {
			cout << sum + min(a, b) + 1;
			return 0;
		}
		cout << sum;
		return 0;
	}
	cout << min(a, b) + sum;
}

Measured memory_bytes: 256
from functools import reduce
import operator as op

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = list(map(int, ds_str))

for m in range(n, 100000):
    mlist = map(int, list(str(m)))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; ++i) { cin >> x[i]; y[i] = x[i]; }
    sort(y.begin(), y.end());

    int left = y[N/2-1];
    int right = y[N/2];

    for(int i=0; i<N; ++i){
        if(x[i] <= left) cout << right << endl;
        else cout << left << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(H, W, inputs):
    delete_row = []
    i = 0
    while len(inputs) != 0 and i < len(inputs):
        is_all_white = True
        for c in inputs[i]:
            is_all_white = is_all_white and c == '.'
        if is_all_white:
            inputs.pop(i)
        else:
            i += 1
    blank_columns = {i for i in range(len(inputs[0]))}
    for row in inputs:
        for i, c in enumerate(row):
            if c != '.' and i in blank_columns:
                blank_columns.remove(i)
    for row in inputs:
        for i, c in enumerate(row):
            if i not in blank_columns:
                print(c, end='')
        print('')

    # return inputs


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [H, W] = string_to_int(input())
    ret = solve(H, W, inputs(H))
    # print(ret)


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



int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	long long n, a, b;
   	cin>>n>>a>>b;


   	if(!(abs(a-b) & 1)) { // even diff 
   		cout<<(abs(a-b)/2);
   		return 0;
   	}
   	else {
   		long long ans = min(a-1, n-b) + 1 + (b-a-1)/2;
   		cout<<ans;
   		
   	}
	return 0;		
}


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

int main(){
  string T;
  cin >> T;
  for(int i=0;i<T.size();i++){
    if(T.at(i)=='?'){
      cout << 'D';
    }else{
      cout << T.at(i);
    }
  }
  cout << endl;
  return 0;
}


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


int dp__[100];

//最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp__[n] = 1;
  if(dp__[n] != -1) return dp__[n];
  return dp__[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> v(n);
  rep(i, n){
    string s;
    int p;
    cin >> s >> p;
    v[i] = make_pair(make_pair(s, -p), i+1);
  }
  sort(v.begin(), v.end());
  rep(i, n) cout << v[i].second << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1==m2)
    {
    	cout<<0<<endl;
    }
    else
    {
    	cout<<1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = input().split()
list = []

N = int(N[0])
for i in range(1,N+1,1):
    list.append(input())

list.sort(reverse = False)

ans = ""
for i in range(1,N+1,1):
    ans = ans + list[0]
    list.pop(0)

print(ans)


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

int main()
{
  int n;
  cin >> n;
  valarray<int> v(n), c(n);
  for (auto&& e : v) cin >> e;
  for (auto&& e : c) cin >> e;
  cout << (v - c).apply([](int e){return e > 0 ? e : 0;}).sum() << endl;
}


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

if __name__ == '__main__':
    H, W, M = list(map(lambda x: int(x), sys.stdin.readline().split()))

    dic = {}
    # h = [0 for i in range(H)]
    # w = [0 for i in range(W)]
    h = np.zeros(H, dtype=np.int64)
    w = np.zeros(W, dtype=np.int64)
    for i in range(M):
        # P.append(list(map(lambda x: int(x), sys.stdin.readline().split())))
        x, y = list(map(lambda x: int(x), sys.stdin.readline().split()))
        x -= 1
        y -= 1
        h[x] += 1
        w[y] += 1
        dic[x*H+y] = 1
    
    lh = np.where(h == h.max())
    lw = np.where(w == w.max())

    mx = np.max(h)
    my = np.max(w)
    # print(mx, my)

    # print(lh[0])
    # print(lw[0])


    tmp = mx + my
    for i in lh[0]:
        for j in lw[0]:
            if i*H+j not in dic:
                print(tmp)
                exit()
    print(tmp-1)
    exit()

Measured memory_bytes: 60900
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <ll> v;

int main(){
    int n;
    sf(n);

    while(n--){
        ll a;
        scanf("%lld",&a);
        v.push_back(a);
    }

    int len=v.size();
    for(int i=0; i<len; i++){
        if(v[i]==0){
            pf("0\n");
            return 0;
        }
    }

    ll sum=1,ans=1e18;
    for(int i=0; i<len; i++){
        if(v[i]<=ans/sum){
            sum*=v[i];
        }
        else{
            pf("-1\n");
            return 0;
        }
    }
    pf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;

vector<P> prime_factorize(ll N){
	vector<P> ans;
	for(ll a = 2; a*a <= N; a++){
		if(N%a == 0){
			ll ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
  int n; cin >> n;
  vector<int> data(98, 0);
  for(int i = 2; i <= n; i++){
    vector<P> vec = prime_factorize(i);
    for(int j = 0; j < vec.size(); j++) data[vec[j].first] += vec[j].second;
  }  
  int c74 = 0, c14 = 0, c24 = 0, c4 = 0, c2 = 0;
  for(int i = 0; i < 98; i++){
    if(data[i] >= 74) c74++;
    if(data[i] >= 14) c14++;
    if(data[i] >= 24) c24++;
    if(data[i] >= 4) c4++;
    if(data[i] >= 2) c2++;
  }
  int ans = c4 * (c4 - 1) * (c2 - 2) / 2 + c24 * (c2 - 1) + c74 + (c4 - 1) * c14;
  cout << ans << endl;
}

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

using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)
		cout << (a + b) / 2 << endl;
	else
		cout << (a + b) / 2 + 1 << endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

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

  cout << 2*M_PI*r << "\n";
  return 0;
}


Measured memory_bytes: 3820
n = int(input())
mod = 10 ** 9 + 7
def prime(n):
    number = [i+2 for i in range(n-1)]
    while len(number) > 0:
        yield min(number)
        number = [x for x in number if x % min(number) != 0]

prime_number = []
for i in prime(n):
    prime_number.append(i)
prime_factor = {}
for i in prime_number:
    prime_factor[i] = 0

for i in range(1, n + 1):
    for j in prime_number:
        if i == 1:
            break
        else:
            while i % j == 0:
                i //= j
                prime_factor[j] += 1
num = 1
for i in prime_factor.values():
    num *= i + 1
    num %= mod
print(num)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int x;
		int i = 0;

		while ( 0 !=  ( x = sc.nextInt() ) ) {
			i++;
			sb.append("Case " + i + ": " + x + "\n");
		}

		System.out.print(sb);
	}

}

Measured memory_bytes: 43344
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int p = sc.nextInt();
			list.add(p);
		}

		Collections.sort(list);

		int sum = 0;
		for (int i = 0; i < k; i++) {
			sum += list.get(i);
		}

		System.out.println(sum);

		sc.close();
	}
}

Measured memory_bytes: 30180
import itertools
N,M,X = map(int,input().split())
A=[]
ANS=[]
for i in range(N):
    A.append(list(map(int,input().split())))
A.sort()
for n in range(1,len(A)+1):
    for conb in itertools.combinations(A, n):
        S=[0]*(M+1)
        for L in conb:
            for i in range(M+1):
                S[i] += L[i]
        if min(S[1:])>=X:
            ANS.append(S)
if ANS==[]:
    print(-1)
else:
    ANS.sort()
    print(ANS[0][0])

Measured memory_bytes: 68284
string=raw_input()
allist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans='None'
for i in range(len(allist)):
    if allist[i] not in string:
        ans=allist[i]
        break
print ans
           

Measured memory_bytes: 2692
n=int(input())
a=list(map(int,input().split()))
dict={}
for i in a:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1

ans=0
for i in dict.keys():
  count=dict[i]
  if count>i:
    ans+=count-i
  elif count<i:
    ans+=count

print(ans)


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

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

Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 19:58:50 2020

@author: liang
"""
"""
【三角形の面積の公式】
S = 1/2 * a * b
"""
import math
a, b, x = map(int, input().split())
L = math.sqrt((x/a/b)**2 + b**2)
if x >= a**2*b/2:
    ans = math.degrees(math.atan((b-x/a**2)/a*2))
else:
    ans = math.degrees(math.atan((a*b**2)/x/2))
    #ans = math.degrees(math.asin(b/L))
print(ans)

Measured memory_bytes: 9180
from collections import deque
n = input()
k = int(input())
c = list(n)
d = deque(c)
ans=0
while len(d) > 0:
    a = d.popleft()
    i = int(a)
    if i==1:
        k = k-1
        if k==0:
            ans = 1
            break
    else:
        ans = i
        break


print(ans)

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  bool flag = true; //正順のときtrue
  deque<char> s;
  rep(i, S.size()){
    s.push_back(S.at(i));
  }
  rep(i, Q){
    int T;
    cin >> T;
    if(T == 1){
      flag = !flag;
    }else{
      int F;
      char C;
      cin >> F >> C;
      if((F == 1 && flag) || (F == 2 && !flag)){
        s.push_front(C);
      }else{
        s.push_back(C);
      }
    }
  }
  int n = s.size();
  if(flag){
    rep(i, n){
      cout << s.front();
      s.pop_front();
    }
    cout <<endl;
  }else{
    rep(i, n){
      cout << s.back();
      s.pop_back();
    }
    cout <<endl;
  }
}
    

Measured memory_bytes: 896
#include<stdio.h>
int main(void){
  
  int A,P,p,q;
  
  scanf("%d",&A);
  scanf("%d",&P);
  
  p = A*3+P;
  
  if(p%2==0){
    printf("%d",p/2);
  }
  else{
    
    q = (p-1)/2;
    printf("%d",q);
  }
  
}
  

Measured memory_bytes: 128
#3問目
N, M = map(int, input().split())
A = set({})
MAX = 1000000007
for i in range(M):
    a = int(input())
    A.add(a)
dp = [0] * (N+1)
dp[0] = 1
if 1 in A:
    dp[1] = 0
else:
    dp[1] = 1
    
for i in range(2, N+1):
    if i in A:
        dp[i] = 0
    else:
        #あきがなかったら
        dp[i] = (dp[i-2] + dp[i-1])%MAX
print(dp[N])

Measured memory_bytes: 86284
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    if (n % 10 == 3)
        cout << "bon\n";
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
        cout << "pon\n";
    else
        cout << "hon\n";
    return 0;
}

Measured memory_bytes: 3652
from collections import*
h,w,n=map(int,input().split())
d=defaultdict(int)
for x in[0]*n:
  a,b=map(int,input().split())
  for i in[a-1,a,a+1]:
    for j in[b-1,b,b+1]:d[(i,j)]+=1
c=[0]*10;c[0]=(w-2)*(h-2)
for i in d:
  a,b=i
  if 1<a<h and 1<b<w:c[d[i]]+=1;c[0]-=1
for i in c:print(i)

Measured memory_bytes: 148148
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int dp[310][310];

int main()
{
	int n;
	
	while(cin >> n,n)
	{
		REP(i,310)REP(j,310)dp[i][j] = 0;
		
		vector<int> v(n);
		REP(i,n)cin >> v[i];
		
		REP(i,n-1)if(abs(v[i]-v[i+1]) < 2)dp[i][i+1] = 2;
		
		for(int k = 2;k < n;k++)
		{
			for(int i = 0;i+k < n;i++)
			{
				for(int j = 0;j < k;j++)
				{
					dp[i][i+k] = max(dp[i][i+k],dp[i][i+j]+dp[i+j+1][i+k]);
				}
				if(dp[i+1][i+k-1] == k-1)
				{
					int tmp = 0;
					if(abs(v[i]-v[i+k])<2)tmp = 2;
					dp[i][i+k] = max(dp[i][i+k],k-1+tmp);
				}
			}
		}
		
		cout << dp[0][n-1] << endl;
		
	}
	
	
	return 0;
}


Measured memory_bytes: 3460
/// ITNOG :)))
/// SAliB
#include <bits/stdc++.h>

using namespace std;

#define pb                      push_back
#define pp                      pop_back
#define mp                      make_pair
#define fi                      first
#define sec                     second
#define xmax(x,y)               ((x) = max((x),(y)))
#define xmin(x,y)               ((x) = min((x),(y)))
#define all(x)                  (x).begin(),(x).end()
#define mem(x , y)              memset(x , y , sizeof(x))
#define _                       ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug1(a)               cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n';
#define debug2(a , b)           cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n';
#define debug3(a , b , c)       cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n';
#define debug4(a , b , c , d)   cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n' << #d << " ---> " << d << '\n';
#define connect(a , b , c)      a[b].pb(c) , a[c].pb(b)
//
typedef long long int ll            ;
typedef unsigned long long int ull  ;
typedef unsigned int uint           ;
typedef long double ld              ;
typedef string str                  ;
typedef pair < int , int > pii      ;
typedef pair < pii , int > ppi      ;
typedef pair < int , pii > pip      ;
typedef pair < ll , ll> pll         ;
typedef pair < ll , pll> plp        ;
typedef pair < pll , ll> ppl        ;
typedef vector < ll > vl            ;
typedef vector < ld > vld           ;
typedef vector < int > vi           ;
typedef vector < str > vs           ;
//
inline int   iin()  { int x   ; scanf("%d" , &x)   ;  return x; }
inline ll    lin()  { ll  x   ; scanf("%lld" , &x) ;  return x; }
inline ll    Lin()  { ll  x   ; scanf("%I64d" , &x);  return x; }
//
inline int   iout(int  x)  { printf("%d" , x)   ;  }
inline ll    lout(ll   x)  { printf("%lld" , x) ;  }
inline ll    Lout(ll   x)  { printf("%I64d" , x);  }
//
const int maxn4 = 1e4 + 85 , maxn5 = 1e5 + 69 , maxn6 = 1e6 + 85 , maxn7 = 1e7 + 69 , maxn8 = 1e8 + 85 , maxn9 = 1e9 + 69 , modi1 = 1e7 + 7 , modi2 = 1e9 + 7;
const ll mod1 = 1e7 + 7 , mod2 = 1e9 + 7;
int mn = INT_MAX , mx = INT_MIN;
//

int main()
{_
    string n; cin >> n;
    for(int i = 0 ; i < n.size() ; i++)
      if(n[i] == '1')
        n[i] = '9';
 	  else if(n[i] == '9')
        n[i] = '1';
 	cout << n;
    return 0;
}

Measured memory_bytes: 256