akhauriyash/Code-Regression huggingface dataset:
n = int(input())
sp = {}
ids = {}

for i in range(n):
    tmp = input().split()

    if tmp[0]in ids:
        ids[tmp[0]][int(tmp[1])] = i+1
    else:
        ids[tmp[0]] = {}
        ids[tmp[0]][int(tmp[1])] = i+1

    if tmp[0] in sp:
        sp[tmp[0]].append(int(tmp[1]))
    else:
        sp[tmp[0]] = [int(tmp[1])]

ks = list(sp.keys())
ks.sort()

for k in ks:
    sp[k].sort(reverse=True)
    # print(sp[k])
    for i in range(len(sp[k])):
        print(ids[k][sp[k][i]])
# print(ids)


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


int main() {
    int n,a[100];
    cin>>n;

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

    double ave=(double)sum/n;

    double d=101;
    int ans;
    for (int i = 0; i < n; ++i){
        if(abs(a[i]-ave)<d){
            ans=i;
            d=abs(a[i]-ave);
        }
    }

    cout<<ans<<endl;
}


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

int main(){
  int K,S,count=0;
  cin >> K >> S;
  for(int i=0;i<K+1;i++){
    for(int j=0;j<K+1;j++){
      if(0<=S-i-j && S-i-j<K+1){
          count++;
        }
    }
  }
  cout << count << endl;
} 

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int h , n ;
	cin >> h >> n ;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll sum = 0 ;
	rep(i,n) sum += a[i];
	if( sum >= h ) coY();
	else coN();
}


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

int main() {
  int N;
  cin>>N;
  vector<int>x(N);
  for(int i=0;i<N;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  vector<int>t(N,0);
  vector<int>a(x.at(N-1)+1,0);
  for(int i=1;i<=x.at(N-1);i++){
    for(int j=0;j<N;j++){
      t.at(j)=(x.at(j)-i)*(x.at(j)-i);
      a.at(i)=a.at(i)+t.at(j);
    }
  }
  sort(a.begin(),a.end());
  cout<<a.at(1)<< endl;
}
      
      
      
  


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
        int a,b;
        cin>>a>>b;
        int d,r;
        double f;
        d=a/b;
        r=a%b;
        f=(double)a/(double)b;
        printf("%d %d %lf",d,r,f);
        return 0;
}



Measured memory_bytes: 3216
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string.h>

using namespace std;

#define BUF_SIZE 1024

int count = 0;

void insertionSort(int array[],int n,int g){
	int v,j;
	for(int i = g;i < n; i++){
		v = array[i];
		j = i - g;
		while(j >= 0 && array[j] > v){
			array[j+g] = array[j];
			j = j - g;
			count++;
		}
		array[j+g] = v;
	}
}

void shellSort(int array[],int n){
	int m = 0;
	int s = 1;

	while((n/s) > 0){
		s *= 2;
		m++;
	}

	int G[20];

	for(int k = 0,t = 1; k < m; k++){
		G[k] = n/t;
		t *= 2;
	}

	for(int i = 0; i < m;i++){
		insertionSort(array,n,G[i]);
	}

	printf("%d\n",m);
	for(int i = 0; i < m; i++){
		if(i != m-1){
			printf("%d ",G[i]);
		}else{
			printf("%d\n",G[i]);
		}
	}
	printf("%d\n",count);
	for(int i = 0; i < n; i++){
		printf("%d\n",array[i]);
	}

}

int main(int argc,char* argv[]){
	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[1000000];

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

	shellSort(array,n);

}



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

int cost(vector<int> v, int t){
  int temp=0;
  for(int i=0; i<v.size(); i++){
    temp+=(v[i]-t)*(v[i]-t);
  }
  return temp;
}
 
int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++) cin >> v[i];
  
  sort(v.begin(), v.end());
  int ans=-1;
  for(int i=v[0]; i<=v[N-1]; i++){
    int temp=cost(v, i);
    if (ans==-1) ans=temp;
    ans=min(ans, temp);
  }
  cout << ans <<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll N; cin >> N;
    ll A, B, C, D, E; cin >> A >> B >> C >> D >> E;
    ll ans = 4;
    ll m = 0;
    m = max(m, (N+A-1)/A);
    m = max(m, (N+B-1)/B);
    m = max(m, (N+C-1)/C);
    m = max(m, (N+D-1)/D);
    m = max(m, (N+E-1)/E);
    cout << ans+m << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int a,b,c,d;
int main (){
	scanf("%d %d %d %d",&a,&b,&c,&d);
  	if(a+b>c+d){
      	printf("Left");
    }else if(a+b==c+d){
      	printf("Balanced");
    }else if(a+b<c+d){
      	printf("Right");
}
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(){
  int N,K;
  scanf("%d %d", &N, &K);
  
  int H[N];
  for(int i=0; i<N; i++){
    scanf("%d", &H[i]);
  }
  
  int canRide = 0;
  for(int j=0; j<N; j++){
    if(H[j] >= K) canRide++;
  }
  
  printf("%d", canRide);
}

Measured memory_bytes: 512
import java.util.Scanner;

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

                int N = scan.nextInt();

                int[] L = new int[N];

                for (int i = 0; i < N; i++) {
                	L[i] = scan.nextInt();
                }

                if (N == 1 || N == 2) {

                	System.out.println(0);

                } else {

                	int count = 0;

                	for (int i1 = 0; i1 < N-2; i1++) {
                		for (int i2 = i1+1; i2 < N-1; i2++) {
                			for (int i3 = i2+1; i3 < N; i3++) {
                				if (L[i1] != L[i2] && L[i2] != L[i3] && L[i3] != L[i1] && L[i1] + L[i2] > L[i3] && L[i2] + L[i3] > L[i1] && L[i3] + L[i1] > L[i2]) {
                					count++;
                				}
                			}
                		}
                	}

                	System.out.println(count);

                }

                scan.close();

        }

}

Measured memory_bytes: 36984
def main():
    n = int(input())
    ac = 0
    wa = 0
    tle = 0
    re = 0
    for i in range(n):
        s = input()
        if s == "AC":
            ac += 1
        elif s == "WA":
            wa += 1
        elif s == "TLE":
            tle += 1
        elif s == "RE":
            re += 1
    print(f"AC x {ac}")
    print(f"WA x {wa}")
    print(f"TLE x {tle}")
    print(f"RE x {re}")

if __name__ == "__main__":
    main()


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

using namespace std;
#define int long long
const int maxn=200005;
int t[4*maxn];
void build(int node,int tl,int tr)
{
    t[node]=0;
    if((tr-tl)==1)
    {
        return;
    }
    int tm=(tl+tr)>>1;
    build(2*node+1,tl,tm);build(2*node+2,tm,tr);
}
void pl(int node,int tl,int tr,int l,int r)
{
    if(tl>=l && tr<=r)
    {
        t[node]++;
        return;
    }
    if(tl>=r || tr<=l)
    {
        return;
    }
    int tm=(tl+tr)>>1;
    pl(2*node+1,tl,tm,l,r);pl(2*node+2,tm,tr,l,r);
}
int get(int node,int tl,int tr,int pos)
{
    if(tl>pos || tr<=pos)
    {
        return 0;
    }
    if((tr-tl)==1)
    {
        return t[node];
    }
    int tm=(tl+tr)>>1;
    return t[node]+get(2*node+1,tl,tm,pos)+get(2*node+2,tm,tr,pos);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;++i) cin>>a[i];
    for(int cyc=0;cyc<min(50LL,k);++cyc)
    {
        build(0,0,maxn);
        for(int i=0;i<n;++i)
        {
            int x=a[i];
            pl(0,0,maxn,max(0LL,i-x),min(n,i+x+1));
        }
        for(int i=0;i<n;++i)
        {
            a[i]=get(0,0,maxn,i);
        }
    }
    for(int i=0;i<n;++i) cout<<a[i]<<' ';
    return 0;
}


Measured memory_bytes: 9184
#include<stdio.h>
int main(){
int a,b,c=1,i,d;
while(scanf("%d %d\n",&a,&b)!=EOF){
if(a>b){
c=a;
a=b;
b=c;
c=1;
}
if(a!=b){
for(i=2;i<=a && i<=b/2+1;i++){
if(a%i==0 && b%i==0){
c=i;
}
}
}
else{
c=a;
}
d=(a/c)*(b/c)*c;
printf("%d %d\n",c,d);
c=1;
}
return 0;
}


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

int n, a[45];

int main() {
    cin >> n;
    a[0] = 1; a[1] = 1;
    for (int i=2; i<=n; i++) a[i]= a[i-1] + a[i-2];
    cout << a[n] << endl;
}


Measured memory_bytes: 3132
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);  // duration
  std::vector<long long> B(N);  // dead line
  for (int i = 0; i < N; ++i)
    std::cin >> A[i] >> B[i];

  // Main

  // dead line が小さい順にソート
  std::vector<long long> idx(N);
  for (int i = 0; i < N; ++i)
    idx[i] = i;
  std::stable_sort(idx.begin(), idx.end(),
                   [&](int k, int l) { return B[k] < B[l]; });
  std::vector<long long> duration(N);
  std::vector<long long> deadLine(N);
  for (int i = 0; i < N; ++i) {
    duration[i] = A[idx[i]];
    deadLine[i] = B[idx[i]];
  }
  // std::cout << duration << std::endl;
  // std::cout << deadLine << std::endl;

  std::string res = "Yes";
  int t = 0;
  for (int i = 0; i < N; ++i) {
    t += duration[i];
    if (t > deadLine[i]) {
      res = "No";
      break;
    }
  }

  // Output
  std::cout << res << std::endl;

  return 0;
}


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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T vec_max(auto & , string);
template <class T>
T vec_min(auto & , string);

int main(){
  faster();
  int n,cnt=0,cnt_p=0,cnt_q=0;
  cin >> n;
  vi p(n),q(n),vec(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  rep(i,n) vec[i]=(i+1);
  do{
    cnt++;
    bool flagp=true,flagq=true;
    rep(i,n){
      if(vec[i]!=p[i]) flagp=false;
      if(vec[i]!=q[i]) flagq=false;
    }
    if(flagp) cnt_p = cnt;
    if(flagq) cnt_q = cnt;
  }while(next_permutation(vec.begin(),vec.end()));
  cout << abs(cnt_p-cnt_q) << endl;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//配列内の最大要素の添え字取得or要素取得
template <class T>
T vec_max(auto &v, string s){
  auto itr = max_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

//配列内の最小要素の添え字取得or要素取得
template <class T>
T vec_min(auto &v, string s){
  auto itr = min_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

pq = [(-a[0]-b[0]-c[0], 0, 0, 0)]
f = set()
for i in range(k):
    s, p, q, r = heappop(pq)
    print(-s)
    # print(-s, p, q, r, f)
    if p + 1 < x and (p+1, q, r) not in f:
        heappush(pq, (-a[p+1]-b[q]-c[r], p+1, q, r))
        f.add((p+1, q, r))
    if q + 1 < y and (p, q+1, r) not in f:
        heappush(pq, (-a[p]-b[q+1]-c[r], p, q+1, r))
        f.add((p, q+1, r))
    if r + 1 < z and (p, q, r+1) not in f:
        heappush(pq, (-a[p]-b[q]-c[r+1], p, q, r+1))
        f.add((p, q, r+1))


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

#define ll long long
#define MOD 1000000007

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

	int n;
	cin>>n;
	int r;
	while(n>0) {
		r=n%10;
		if(r==7) {
			break;
		}
      n/=10;
	}
	if(n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll GCD(ll a, ll b){
    if(b==0) return a;
    else return GCD(b,a%b);
}

int main(){
    string s; cin >> s;
    ll acount=0;
    ll ans=0;
    if(s.size() < 3) cout << 0 << endl;
    else{
        for(ll i=0; i<s.size()-2; i++){
            //cout << i << endl;
            if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
                ans += acount + 1;
                //cout << "acount : " << acount << endl;
                //cout << "ans : " << ans << endl;
                s[i+2] = 'A';
                i++;
            }else{
                if(s[i] == 'A') acount++;
                else acount=0;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n;
	vector<long long int> v[n+1];
	for(int i=0;i<n-1;i++)
	{
		long long x;
		cin>>x;
		v[x].push_back(i+2);
	}
	for(int i=1;i<n+1;i++)
	{
		cout<<v[i].size()<<endl;
	}
	return 0;
}



  


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

int main(){
  int Y, X; cin >> Y >> X;
  vector<vector<char>> A(Y, vector<char>(X));
  rep(i, Y){
    rep(j, X){
      cin >> A[i][j];
    }
  }
  
  int dx[9] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
  int dy[9] = {0, 1, -1, 1, 0, -1, 1, 0, -1};
  rep(i, Y){
    rep(j, X){
      if (A[i][j] == '#') cout << '#';
      else {
        int count = 0;
        for (int k=0; k < 9; ++k){
          int nx = j + dx[k];
          int ny = i + dy[k];
          if (nx < 0 || ny < 0 || nx >= X || ny >= Y) continue;
          if (A[ny][nx] == '#') count++;
        }
        cout << count;
      }
    }
    cout << endl;
  }
  
  
}


Measured memory_bytes: 256
/* ex6_2
    sak_Citrus*/

#include <stdio.h>

int main(void){
    //|S|の最大値は100なのでnull文字を考慮して101枠確保
    char string[101];
    char *pointer = string;
    //挟まれた文字数をカウント
    int counter = 0;
    scanf("%s",pointer);

    //1文字目を出力してポインタをズラす
    putchar(*pointer++);
    //ポインタをずらしてもnull文字じゃなければカウントを増やす（2文字目を数えずに最後の文字をカウントすることにする）
    while(*(++pointer) != '\0')counter++;

    printf("%d",counter);
    //ポインタがnull文字の所を指しているので1文字分戻してから出力
    putchar(*(--pointer));
    printf("\n");

    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n,d,x;cin >> n >> d >> x;
   vector<int> a(n);
   rep(i,n)cin >> a[i];
   int ans = x;
   rep(i,n){
      ans += (d + a[i] - 1) / a[i];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    writeln(min(lread(), lread()) + min(lread(), lread()));
}


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

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

	int h, w;
	vector<string> a;
	string s;
	cin >> h >> w;
	for (int i = 0; i < h; ++i){
		cin >> s;
		a.push_back(s);
	}
	for (int i = 0; i < w+2; ++i){
		cout << "#";
	}
	cout << "\n";
	for (int i = 0; i < h; ++i){
		cout << "#" << a[i] << "#" << "\n";
	}
	for (int i = 0; i < w+2; ++i){
		cout << "#";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};


int main(void) {
    ll N;
    cin >> N;
    ll cx, cy;
    ll x[100], y[100], h[100];
    ll i;
    
    for(i=0; i<N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    
    ll def;
    ll tmp=0;
    bool flag;
    for(cx=0; cx<=100; cx++) {
        for(cy=0; cy<=100; cy++) {
            def=-1;
            flag=true;
            for(i=0; i<N; i++) {
                if(h[i]==0) continue;
                tmp=h[i]+abs(x[i]-cx)+abs(y[i]-cy);
                
                if(def==-1) {
                    def=tmp;
                }else if(def!=tmp) {
                    flag=false;
                    break;
                }
            }
            
            if(!flag) continue;
            
            for(i=0; i<N; i++) {
                if(h[i]!=0) continue;
                ll dist=abs(x[i]-cx)+abs(y[i]-cy);
                if(tmp>dist) {
                    flag=false;
                }
            }
            
            if(!flag) continue;
            
            cout << cx << " " << cy << " " << tmp << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int n, tmp = -1, cnt = 0;
    int p[50];
    std::cin >> n;
    for (int i=0; i<n; ++i) std::cin >> p[i];

    for (int i=0; i<n-1; ++i) {
        if (p[i] > p[i+1]) {
            tmp = i;
            break;
        }
    }
    if (tmp == -1) {
        std::cout << "YES" << std::endl;
        return 0;
    }

    for (int i=0; i<n; ++i) {
        cnt = 0;
        std::swap(p[tmp], p[i]);
        for (int j=0; j<n-1;j++) {
            if (p[j] > p[j+1]) ++cnt;
        }
        std::swap(p[tmp], p[i]);
        if (cnt == 0) {
            std::cout << "YES" << std::endl;
            return 0;
        }
    }
    std::cout << "NO" << std::endl;

    return 0;
}


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

int main(int argc, char const *argv[])
{
	string s,t;
	cin>>s>>t;
	s+=s;
	int f=0;
	for (int i = 0; i < t.size(); ++i)
	{
		int g=1;
		for (int j = 0; j < t.size(); ++j)
		{
			if (s[i+j]!=t[j])
			{
				g=0;
				break;
			}
		}
		if (g)
		{
			f=1;
			break;
		}
	}
	if (f)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


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

#define pb push_back
#define loop(i,l,r) for(int i = (l); i < (r); i++)
#define rloop(i,r,l) for(int i = (r-1); i >= (l); i--)
#define refloop(x, v) for(auto& x : (v))
#define exists(m,e) if((m).find(e) != (m).end())
#define nexists(m,e) if((m).find(e) == (m).end())
#define sortaka(v) sort((v).begin(), (v).end())
#define rsort(v) sort((v).rbegin(), (v).rend())
#define lower_bound_index(v, x) (lower_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] >= x
#define upper_bound_index(v, x) (upper_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] > x
#define scanint(x) scanf("%d", &(x))
#define scanfloat(x) scanf("%f", &(x))
#define scanll(x) scanf("%lld", &(x))
#define scanchar(x) scanf("%c", &(x))
#define scanstring(x) scanf("%s", &(x))
#define printint(x) printf("%d", x)
#define printfloat(x) printf("%.9f", x)
#define printll(x) printf("%lld", x)
#define printchar(x) printf("%c", x)
#define printstring(x) printf("%s", x)
#define printintnewline(x) printf("%d\n", x)
#define printfloatnewline(x) printf("%.9f\n", x)
#define printllnewline(x) printf("%lld\n", x)
#define printcharnewline(x) printf("%c\n", x)
#define printstringnewline(x) printf("%s\n", x)
#define square(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))

typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<string> vs;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<vector<pair<long long, long long>>> vvpll;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);

    int n; cin >> n;

    vl sums(n);
    vl diffs(n);

    loop(i, 0, n){
        int s, t;
        cin >> s >> t;

        sums[i] = s+t;
        diffs[i] = s-t;
    }

    sortaka(sums);
    sortaka(diffs);

    cout<<max(sums[n-1]-sums[0], diffs[n-1]-diffs[0])<<endl;
}

Measured memory_bytes: 6412
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
8.是否可以记录两个值之间的关系 CSPday2 meal
9.括号-》数组or栈
10.是否可以先构造
11.网络流奇偶构图
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	LL n,a,b;
	cin>>n>>a>>b;
	if((b-a-1)&1ll){
		cout<<((b-a))/2;
	}
	else{
		LL A,B;
		A=a;
		B=b;
		LL res=0;
		res+=a-1;
		b-=(a-1);
		b--;
		res++;a=1;
		res+=((b-a))/2;
		a=A;
		b=B;
		LL res2=0;
		res2+=n-b;
		a+=res2;
		a++;
		res2++;
		b=n;
		res2+=((b-a))/2;
		cout<<min(res,res2);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,k,m,x;
bool has[100005];
int main()
{
  cin>>n>>k;
  for(int i=1;i<=k;++i){
    cin>>m;
    for(int j=1;j<=m;++j){
      cin>>x;
      has[x]=1;
    }
  }
  int ans=0;
  for(int i=1;i<=n;++i) if(!has[i]) ans++;
  cout<<ans<<endl;
  return 0;
}

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

int main(){
	int h, w;
  	cin >> h >> w;
  	
    string board[50];
    
    for(int i=0; i<h; i++) cin >> board[i];
  
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if(board[i][j] == '#') continue;
        
        int num = 0;
        for(int d=0; d<8; ++d){
          const int ni = i + dy[d];
          const int nj = j + dx[d];
          
          if (ni<0 or h<=ni) continue;
          if (nj<0 or w<=nj) continue;
          if (board[ni][nj] == '#') num++;
        }
        
        board[i][j] = char(num + '0');
      }
    }
  
  for(int i=0; i<h; i++) cout << board[i] << endl;
  
  return 0;
}

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

int main(void) {
    long long int N, M, all, tmp1;
    long double tmp2;
    all = 0;
    cin >> N >> M;

    long long int A[N];
    memset(A, 0, N);

    for(int i = 0; i < N; i++) {
        cin >> A[i];
        all += A[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = N - 1; j > i; j--) {
            if(A[j] < A[j - 1]) {
                tmp1 = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp1;
            }
        }
    }

    tmp2 = (long double)all / 4 / (long double)M;

    if((long double)A[N - M] >= tmp2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i, j;
    int dat[10];
        for(i=0; i<10; i++)
            scanf("%d", &dat[i]);
    for (i=0; i<10; i++)
        for (j=9; j>i; j--)
            if (dat[j] > dat[j-1]){
                int tmp = dat[j];
                dat[j] = dat[j-1];
                dat[j-1] = tmp;
            }
    for (i=0; i<3; i++)
        printf("%d\n", dat[i]);
    return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }

    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());

    cout << d.size() << endl;

    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<pair<string,int>> music(N);
  for(int i=0;i<N;i++){
    cin>>music.at(i).first>>music.at(i).second;
  }
  string X;
  cin>>X;
  bool asleep=false;//寝たかどうか
  int time=0;//寝てからの時間
  for(int i=0;i<N;i++){
    if(asleep){
      time+=music.at(i).second;
    }
    if(music.at(i).first==X){asleep=true;}
  }
  cout<<time<<endl;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);

    int d = 0;
    int A_okashi = 0;
    for(int i = 0; i < K; i++){
        cin >> d;
        for(int j = 0; j < d; j++){
            cin >> A_okashi;
            A.at(A_okashi-1)++;
        } 
    }

    int count = 0;
    for(int num : A){
        if(num == 0){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3584
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 5e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pll pair<ll, ll>
#define F first
#define S second

ll n, a[maxn], b[maxn], ans;

string s;

int main(){
	fast_io;
	
	cin >> s;
	
	n = s.size();
	
	for(ll i = 1; i <= n; i++){
		if(s[i - 1] == '<'){
			a[i] = a[i - 1] + 1;
		}
	}
	
	for(ll i = n - 1; i > -1; i--){
		if(s[i] == '>'){
			b[i] = b[i + 1] + 1;
		}
	}
	
	for(ll i = 0; i <= n; i++){
		ans += max(a[i], b[i]);
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 8732
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define inf                1e18L+1
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  100005
multiset <ll> s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests=1;
//    cin>>tests;
    while(tests--)
{
    ll n;
    cin>>n;
    vii v;
    rep(i,0,n)
    {
      ll a;
      cin>>a;
      v.pb({a,i+1});
    }
    sort(v.rbegin(),v.rend());    s.insert(0);
    s.insert(0);
    s.insert(n+1);
    s.insert(n+1);
    ll ans=0;
    rep(i,0,sz(v))
    {
        ll val=v[i].F;
        auto itr=s.lower_bound(v[i].S);
        ll itr4=*itr;
        itr++;
        ll itr3=*itr;itr--;itr--;
        ll itr2=*itr;
        itr--;
        ll itr1=*itr;
        if(itr3>itr4){
          ans+=val*(-itr4+itr3)*(v[i].S-itr2);
        //  dbg(ans);
        }
        if(itr2>itr1){
          ans+=val*(itr2-itr1)*(itr4-v[i].S);//dbg(ans);
        }
        s.insert(v[i].S);
    }
    cout<<ans<<endl;
}
    return 0;
}

Measured memory_bytes: 7024
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int ans = 0;
	int n;

	cin >> n;


	int min = 10000000;



	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if (min >= a)
		{
			min = a;
			ans++;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
	cout<<"a < b"<<endl;
	}else if(a>b){
	cout<<"a > b"<<endl;
	}else if(a=b){
	cout<<"a == b"<<endl;
	}
	return 0;

}

Measured memory_bytes: 3088
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"

using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

int main(void) {
	int a, b;
	cin >> a >> b;
	int ans = a;
	if (a > b) ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i
min_cnt = [A,B,C,D,E].min
ans = 0
if (N <= min_cnt) then
    ans = 5
else
    ans = 5 + (N - min_cnt) / min_cnt
    ans = (N % min_cnt) === 0 ? ans : ans + 1
end

puts ans


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

int main() {
	long x,y,n,m,i,j,k,ans,cur;
	cin >> n >> x >> y;
	x--; y--;
	vector<long> p(n);
	
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			cur=abs(j-x)+1+abs(y-i);
			cur=min(cur,abs(j-y)+1+abs(x-i));
			cur=min(cur,abs(j-i));
			p[cur]++;
		}
	}
	for(i=1; i<n; i++){
		cout << p[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, W;
  ll dp[SIZE] = {};

  scanf("%d%d", &n, &W);

  for(int i=0;i<=100000;i++) dp[i] = LLINF;
  dp[0] = 0;

  for(int i=0;i<n;i++){
    int w, v;
    scanf("%d%d", &w, &v);

    for(int j=100000-v;j>=0;j--){
      dp[j+v] = min(dp[j+v], dp[j]+w);
    }
  }

  ll ans = 0;

  for(int i=0;i<=100000;i++){
    if (dp[i] <= W) ans = i;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int l;
  l=0;
  for (int i=0; i<N;i++){
    int xi;
    cin >> xi;
    if (xi > (K-xi))
        l+= (K-xi);
    else
        l+= xi;
        
      
        
    
    
      }
  cout << 2*l << endl;



    
    
    
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


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

   int a;string  b; cin >>a >> b;
   for(int i = 0; i < b.size(); i++)
   {
      a = a*10 +b[i]-'0';
   }
   int tmp = pow(a, 0.5);
   if(tmp*tmp == a)
      cout << "Yes" << nl;
   else
      cout << "No" << nl;


   return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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 int MOD = 1000000007;


int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int t = 0;
    int a;
    REP(i, n) {
        cin >> a;
        int c = 0;
        int j = 0;
        while (1 + a * j <= d) {
            c++;
            j++;
        }
        t += c;
    }
    cout << t + x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
using namespace std;
int N;
vector<int> t;
map<int,string> change;
int cnt[38][38];
 
int check(char ch,char ch2){
  string s="";
  s.push_back(ch);
  s.push_back(ch2);
  for(int i=26;i<38;i++){
    if(change[i]==s){
      return i;
    }
  }
  return -1;
}
 
void make_table(){
  string s="a";
  for(int i=0;i<26;i++){
    change[i]=s;
    s[0]++;
  }
  change[26]="ld";
  change[27]="mb";
  change[28]="mp";
  change[29]="nc";
  change[30]="nd";
  change[31]="ng";
  change[32]="nt";
  change[33]="nw";
  change[34]="ps";
  change[35]="qu";
  change[36]="cw";
  change[37]="ts";
  for(int i=0;i<38;i++)
    for(int j=0;j<38;j++)
      cnt[i][j]=0;
}
 
void add(string &tmp){
  int len=tmp.size();
  for(int i=0;i<len;i++){
    if(i+1<len){
      int x=check(tmp[i],tmp[i+1]);
      if(x==-1){
    t.push_back(tmp[i]-'a');
      }else{
    t.push_back(x);
    i++;
      }
    }else{
      t.push_back(tmp[i]-'a');
    }
  }
}
 
int main(){
  make_table();
  string str,tmp;
  cin>>N;
  cin.ignore();
  for(int i=0;i<N;i++){
    getline(cin,str);
    stringstream ss(str);
    while(ss>>tmp){
      add(tmp);
      t.push_back(-1);
    }
     
  }
  for(int i=1;i<(int)t.size();i++){
    int x=t[i-1],y=t[i];
    if(x==-1||y==-1)continue;
    cnt[x][y]++;
  }
   
  for(int i=0;i<38;i++){
    int key=0;
    for(int j=1;j<38;j++)
      if(cnt[i][key]<cnt[i][j])
    key=j;
    cout<<change[i]<<" "<<change[key]<<" "<<cnt[i][key]<<endl;
     
  }
  return 0;
}

Measured memory_bytes: 1540
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,A,B=pin()
    tt=abs(A-B)
    if tt%2==0:
        print(tt//2)
        return
    else:
        s= max(A,B)-1
        t=N-min(A,B)
        print(min(s,t,(tt-1)//2+1)+min(min(A,B)-1,N-max(A,B)))
#%%submit!
resolve()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <stack>
#include <deque>
#include <cassert>
#include <list>
#include <cstdio>
#include <numeric>
#define EPS 1e-7
#define INF (int)(1e+9)
#define LINF (long long)(1e+18)
#define PI acos(-1)
#define mp make_pair
#define MOD 1000000007
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define N 999999


using namespace std;

#define NAME "test"
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

void solve(int test_number);


void pre() {
    cout.setf(ios::fixed);
    cout.precision(20);
    cerr.setf(ios::fixed);
    cerr.precision(3);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
}

void post() {
    fprintf(stderr, "\n");
    fprintf(stderr, "Execution time: %Lf", (ld) clock());
}

const int MAXN = 100100;

int a[999];

inline void solve(int test_number) {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 2 * n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + (2 * n));
	int ans = 0;
	for (int i = 0; i < 2 * n - 1; i += 2) {
		ans += min(a[i], a[i + 1]);
	}
	printf("%d", ans);

}



int main()
{
#ifdef DEBUG
    freopen(NAME ".in", "r", stdin);
    freopen(NAME ".out", "w", stdout);
#endif
    //freopen(NAME ".in", "r", stdin);
    //freopen(NAME ".out", "w", stdout);
    pre();

    int n = 1;
    for (int i = 0; i < n; i++) {
            solve(i + 1);
    }

    post();
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, n;
	cin >>h >>w >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	vector<VI> ba(h, VI(w));
	int cy=0,cx=0;
	rep(i, n){
		rep(j, a[i]){
			ba[cy][cx] = i+1;
			if(cy%2==0){
				if(cx==w-1) cy++;
				else cx++;
			}else{
				if(cx==0) cy++;
				else cx--;
			}
		}
	}
	for(auto xl: ba){for(auto x :xl) cout<<x <<" "; cout<<"\n";}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;
	pair<ll, ll> p[n];
	rep(i, n) cin >> p[i].second >> p[i].first;
	sort(p, p + n, greater<pair<ll, ll>>());
	ll now = 0;
	set<ll> s;
	priority_queue<ll, vector<ll>, greater<ll>> que;
	rep(i, k) {
		now += p[i].first;
		if (s.count(p[i].second)) que.push(p[i].first);
		s.insert(p[i].second);
	}
	ll S = s.size();
	now += S * S;
	priority_queue<ll> Que;
	repl(i, k, n) {
		if (s.count(p[i].second) == 0) {
			Que.push(p[i].first);
			s.insert(p[i].second);
		}
	}
	ll ans = now;
	while (true) {
		if (Que.empty() or que.empty()) break;
		now += Que.top() - que.top();
		Que.pop(), que.pop();
		now += (S + 1) * (S + 1) - S * S;
		S++;
		ans = max(ans, now);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9864
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
// 104, 
// 169, 
// 180, 
// 171, 
// 45, 
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	long long ret=0;
	long long ks=1;
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		printf("? %d %d %d %d\n",i,j,i,j);
		fflush(stdout);
		int t;
		scanf("%d",&t);
		if(t)ret=(ret+ks)%d;
		ks=ks*2%d;
	}
	int sz=ret/200%200;
	char *p = new char[sz*1000000];
	for(int i=0;i<sz*1000000;i++)p[i]='e';
	printf("! %lld\n",ret);
}

Measured memory_bytes: 130640
#include <iostream>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    if(N==1 && M==0){
        cout << 0 <<endl;
        return 0;
    }

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

    bool fl = true;
    for(int i=0; i<M; i++){
        if(N != 1 && c[i] == 0 && s[i] == 1) fl = false;
        for(int j=i+1; j<M; j++){
            if(s[i]==s[j] && c[i] != c[j]) fl = false;
        }
    }

    if(!fl){
        cout << -1 << endl;
        return 0;
    }

    int a[N];
    for(int i=0; i<N; i++) {
        a[i] = -1;
    }

    for(int i=0; i<M; i++){
        a[s[i]-1] = c[i];
    }

    if(a[0] == -1) cout << 1;
    else cout << a[0];
    for(int i=1; i<N; i++){
        if(a[i] == -1) a[i]=0;
        cout << a[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100009
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<long long> vl;



int main() {
    ll n, d;

    cin >> n >> d;
    d = 2*d+1;

    ll ans = n/d;
    if(n%d)
        ++ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import combinations, permutations

import sys
def input():
	return sys.stdin.readline().strip()


N = int(input())
xy1 = []
xy2 = []
for i in range(N):
	x, y = list(map(int, input().split()))
	xy1.append((x, i))
	xy2.append((y, i))
xy1.sort()
xy2.sort()

edge_list = [[] for _ in range(N)]

for i in range(N - 1):
	edge_list[xy1[i][1]].append((xy1[i + 1][0] - xy1[i][0], xy1[i + 1][1]))
	edge_list[xy1[i + 1][1]].append((xy1[i + 1][0] - xy1[i][0], xy1[i][1]))
	edge_list[xy2[i][1]].append((xy2[i + 1][0] - xy2[i][0], xy2[i + 1][1]))
	edge_list[xy2[i + 1][1]].append((xy2[i + 1][0] - xy2[i][0], xy2[i][1]))

judge = [0]*N
G = []
heapq.heapify(G)
for edge in edge_list[0]:
	heapq.heappush(G, edge)

judge[0] = 1
total = 0
num = 0
while num < N - 1:
	edge = heapq.heappop(G)
	if judge[edge[1]] == 0:
		judge[edge[1]] = 1
		total += edge[0]
		num += 1
		for add in edge_list[edge[1]]:
			if judge[add[1]] == 0:
				heapq.heappush(G, add)

print(total)

Measured memory_bytes: 111324
#include<iostream>
#include<cmath>
using namespace std;
int x,y,z;
int e;
int solve(){
	int minnum = 1000000;
	for(int z = 0; pow(z, 3) <= e; z++)
	{
		y = (int)sqrt(e - pow(z, 3));
		minnum = min(minnum,(int)(e - pow(z, 3)-pow(y, 2))+y+z); 
	}
	return minnum;
};
int main(){
	int A[100000];
    int k = 0;
	while( cin>>e && e>0 )
	{
		A[k]=solve();
        k++;
	}
	for(int l = 0;l < k; l++)
    {
        cout<<A[l]<<endl;
    }
	return 0;
}

Measured memory_bytes: 3192
// Problem : D - Banned K
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

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

	for(ll i = 0; i < n; i++){
		map[a[i]]++;
	}

	ll sum = 0;	
	for( auto const& x : map){
		ll val = x.second;
		
		sum += (val * (val - 1) / 2);
	}
	
	for(ll i = 0; i < n; i++){
		ll tmp = sum;
		ll x = a[i];
		tmp -= (map[x] * (map[x]-1) ) / 2;
		tmp += ((map[x] - 1) * ((map[x]) - 2)) / 2;
		
		cout << tmp << endl;
	}
	return 0;	
}


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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, n) {
    for(int j = i+1; j < n; j++) {
      int r = lower_bound(v.begin()+j, v.end(), v[i] + v[j]) - v.begin() - 1;
      ans += max(0, r-j);
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256