akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	set<string> st;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		st.insert(S);
	}
	printf("%d", st.size());

	return 0;
}


Measured memory_bytes: 19292
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    int a[2000100],k;
    cin >> k;
    
    a[1] = 7%k;
    for(int i=2;i<=k;i++) a[i] = (a[i-1]*10 + 7)%k;
    
    for(int i=1;i<=k;i++) if(a[i] == 0){
        cout << i << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7464
#include <stdio.h>

int main(void){
    int N, H[100005], x, M, i;
    scanf("%d", &N);
    x=0;
    M=0;
    H[0]=0;
    for (i=1; i<=N; i++) {
        scanf("%d", &H[i]);
        if (H[i]<=H[i-1]) {
            x++;
            if (x>M) M=x;
        }
        else x=0;
    }
    printf("%d", M);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int sumD(int N)
{
	int sum = 0;
	while (N>0) {
		sum += (N % 10);
		N /= 10;
	}
	return sum;
}

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

	cout << (N%sumD(N) ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int n = scan.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int amax = 0;
		int bmin = Integer.MAX_VALUE;
		int bmini = 0;

		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
			if(a[i] > amax) {
				amax = a[i];
			}
			if(b[i] < bmin) {
				bmin = b[i];
				bmini = i;
			}
		}
		scan.close();



		int[] min = new int[h+amax+1];
		for(int i = 1; i < a[bmini]+1; i++) {
			min[i] = bmin;
		}


		for(int i = a[bmini]+1; i < h+amax+1; i++) {
			int tm = Integer.MAX_VALUE;
			for(int j = 0; j < n; j++) {
				int t = Integer.MAX_VALUE;
				if(a[j] >= i) {
					t = b[j];
				}
				if( (i-a[j]) > 0 ) {
					t = min[i-a[j]] + b[j];
				}
				if(t < tm) {
					tm = t;
				}
			}
			min[i] = tm;
		}

		int ans = Integer.MAX_VALUE;
		for(int i = h; i < h+amax+1; i++) {
			if(min[i] < ans) {
				ans = min[i];
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 27728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	int S, W;
	cin >> S >> W;
	if (S > W) {
		cout << "safe";
	}
	else {
		cout << "unsafe";
	}


	return 0;
}


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

typedef long long int ll;
#define f(a, b) for(auto i = a;i < b;i++)

bool sortbysec(const pair<ll, ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 
void solve()
{
	return ;
}

int main()
{
	ll n, m, sum = 0;
	cin >> n >> m;

	f(0, m)
	{
		ll a;
		cin >> a;
		sum += a;
	}

	if(sum > n)
		cout << "-1\n";
	else
		cout << n - sum << "\n";
}

Measured memory_bytes: 3632
n,K = map(int,input().split())
a = list(map(int,input().split()))
cnt = {}
for x in a:
    if x not in cnt:cnt[x] = 1
    else:cnt[x] +=1
res = []
for k in cnt:
    v = cnt[k]
    res.append(v)
res.sort()
ans = 0
for i in range(len(res)):
    if len(res) - i <=K:
        
        print(ans)
        break
    ans +=res[i]
    


    

Measured memory_bytes: 33312
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

const int m = 2019;

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

    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int n = s.size();
    int x = 1, total = 0;
    vector<int> cnt(m);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cnt[total]++;

        total += (s[i] - '0') * x;
        total %= m;

        ans += cnt[total];

        x = x * 10 % m;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3780
import numpy as np

n = int(input())
h = np.array(list(map(int, input().split())))

dh = h[1:] - h[:n-1]
move_index = np.where(dh <= 0)[0]

temp, count = 1, 0
for i in range(len(move_index) - 1):
    if move_index[i+1] - move_index[i] == 1:
        temp += 1
    else:
        temp = 1
    if temp > count:
        count = temp

print(count)


Measured memory_bytes: 23364
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    int p = ri();
    int k[n];
    INPUT(k);
    int res = n;
    FOR(i,n)p-=k[i];
    int m = INF;
    FOR(i,n) m = min(m, k[i]);
    res += p/m;
    cout << res << endl;
 return 0;
}


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

int main() {
    int N, ans=0;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
	if(s[i]=='?')
	    s[i]='D';
    }


    cout << s << endl;
} 




Measured memory_bytes: 3724
N, M = map(int, input().split())
cities = [(x,)+tuple(map(int, input().split())) for x in range(M)]

n = 1
p = 0
ans = []
for city in sorted(cities, key = lambda x:(x[1],x[2])):
  if p != city[1]:
    n = 1
    p = city[1] 
  ans.append((city[0], city[1], n))
  n += 1

ans = sorted(ans)

for x in ans:
  print('{:06}{:06}'.format(x[1],x[2]))

Measured memory_bytes: 37820
#include <cstdio>
#define scanf __builtin_scanf
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    if (n==2) {
        long x, y; scanf("%ld %ld", &x, &y);
        if (x<y) swap(x, y);
        printf("%ld\n%ld %ld\n", x-y, x, y);
        return 0;
    }
    multiset<long> neg, pos;
    for(int i=0; i<n; ++i) {
        long a; scanf("%ld", &a);
        if (a<0)
            neg.insert(a);
        else
            pos.insert(a);
    }

    vector<pair<long, long>> res;
    while (pos.size()==0 and neg.size()>1) {
        auto y=begin(neg);
        auto x=end(neg); --x;
        res.emplace_back(*x, *y);
        pos.insert(*x-*y);
        neg.erase(x);
        neg.erase(y);
    }
    while (neg.size()==0 and pos.size()>1) {
        auto x=begin(pos);
        auto y=end(pos); --y;
        res.emplace_back(*x, *y);
        neg.insert(*x-*y);
        pos.erase(x);
        pos.erase(y);
    }
    while (pos.size()>1) {
        auto x=begin(neg);
        auto y=begin(pos);
        res.emplace_back(*x, *y);
        neg.insert(*x-*y);
        neg.erase(x);
        pos.erase(y);
    }
    while (neg.size()>0) {
        auto x=begin(pos);
        auto y=begin(neg);
        res.emplace_back(*x, *y);
        pos.insert(*x-*y);
        pos.erase(x);
        neg.erase(y);
    }
    printf("%ld\n", *begin(pos));
    for(auto& e: res) printf("%ld %ld\n", e.first, e.second);
}


Measured memory_bytes: 8184
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=500150;
///
int mod=1000000007;

ll arr[mx];
int main()
{
//    SPEED;

    int t,tc=1;
//    sf(t);
    t=1;
    while(t--)
    {
        int n,k;
        sf2(n,k);
        for(int i=1;i<=n;i++)
        {
            sl(arr[i]);
        }
        int l=1;
        for(int i=k+1;i<=n;i++)
        {
            if(arr[i]>arr[l])
            {
                cout<<"Yes"<<endl;
            }
            else
                cout<<"No"<<endl;
            l++;
        }
    }

    return 0;
}



Measured memory_bytes: 5320
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

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

  // vector<int> h;
  // for (int i = 0; i < N; ++i) {
  //   int hin;
  //   cin >> hin;
  //   h.push_back(hin);
  // }


  cout << N * (N - 1) / 2;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%2 == 0) {
			System.out.println(n/2-1);
		}else {
			System.out.println((n-1)/2);
		}
		sc.close();
	}

}

Measured memory_bytes: 21844
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_buy_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    cost: int
    skill_points: List[int]


@dataclass
class SingleResult:
    border_line: int
    dim: InitVar[int]
    cost: int = 0
    skill_points: List[int] = field(init=False)

    def __post_init__(self, dim: int):
        self.skill_points = [0 for _ in range(dim)]

    def register(self, book: Book):
        self.cost += book.cost

        self.skill_points = [p1 + p2 for p1, p2 in zip(self.skill_points, book.skill_points)]

    def has_item(self) -> bool:
        return self.cost > 0

    def is_ok(self) -> bool:
        return all([p >= self.border_line for p in self.skill_points])


@dataclass(frozen=True)
class Results:
    values: List[SingleResult] = field(default_factory=list)

    def add(self, single_result: SingleResult) -> None:
        self.values.append(single_result)  # メモリ優先

    def __len__(self) -> int:
        return len(self.values)

    def __getitem__(self, index: int) -> SingleResult:
        return self.values[index]

    def min_cost_ok(self) -> int:
        border_line_pass_books = [book for book in self.values if book.is_ok()]

        if not border_line_pass_books:
            return -1

        return min([book.cost for book in border_line_pass_books])

    @staticmethod
    def create(dim: int, border_line: int, book_lineup: List[Book], buy_patterns) -> Results:
        results = Results()

        for buy_pattern in buy_patterns:
            single_result = SingleResult(border_line, dim)

            for idx, is_buy in enumerate(buy_pattern):
                if is_buy == 1:
                    single_result.register(book_lineup[idx])

            if single_result.has_item():
                results.add(single_result)

        return results


def actual(N, M, X, books_info):
    book_lineup = []
    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, cost=book_info[0], skill_points=book_info[1:])
        book_lineup.append(book)

    results = Results.create(N, X, book_lineup, buy_patterns=create_buy_patterns(N))

    return results.min_cost_ok()


N, M, X = [int(x) for x in input().split()]

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

Measured memory_bytes: 19552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
typedef int64_t ll;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }




int main() {
	string S, T;
	cin >> S >> T;
	
	if (S==T)
	{
		cout << "Yes" << endl;
		return 0;
	}
	for (int i = S.size()-1; i >= 1; i--)
	{
		string U;
		for (int j = i; j < S.size(); j++)
		{
			U.push_back(S.at(j));
		}
		for (int k = 0; k < i; k++)
		{
			U.push_back(S.at(k));
		}
		
		bool ok = true;
		rep(m, T.size()) {
			
			if (T.at(m) != U.at(m)) {
				ok = false;
				break;
			}		
		}
		if (ok) {
			cout << "Yes" << endl;
			return 0;
		}
		
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int n,m,dp[5050],a[1010],b[1010],c[1010]={0};


  int main() {
    
    cin >> n >> m;
    
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
      
        for (int j = 0; j < b[i]; ++j){
            int d; 
          cin >> d; 
          
            c[i] += (1<<d-1);
        }
    }
   
      
      for(int i=0;i<(1<<n);i++){
        dp[i] = 1e9;
      }
      dp[0] = 0;
    
    for(int i=0;i<m;i++){
      for(int j=0;j<(1<<n);j++){
        
        dp[c[i]|j]= min(dp[c[i]|j],dp[j]+a[i]);
    }
    }
      
    cout<<(dp[(1<<n)-1]<1e9? dp[(1<<n)-1]:-1)<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] a = new int[N+1];
        int[] knot = new int[N];
        for(int i=1;i<=N;i++) a[i]=sc.nextInt();
        for(int i=1;i<=N-1;i++){
            knot[i]=a[i]+a[i+1];
        }
        int max=0;
        int pos=-1;
        for(int i=1;i<N;i++){
            if(knot[i]>max){
                max = knot[i];
                pos=i;
            }
        }
        if(max<L){
            System.out.println("Impossible");
        }
        else{
            System.out.println("Possible");
            for(int i=1;i<pos;i++) System.out.println(i);
            for(int i=N-1;i>=pos+1;i--) System.out.println(i);
            System.out.println(pos);
        }
    }
}


Measured memory_bytes: 65956
#include <iostream>

using namespace std;

int main()
{
int i,n,k;
cin>>n;
string s;
for(i=0; i<n; i++){
    cin>>s;
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
        k+=1;
    }

}
cout<<k;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int x=0;
	char buf[5];
	scanf("%s", buf);
	for (int i = 0; buf[i]; ++i){
		if (buf[i] == '+')
			++x;
		else
			--x;
	}
	printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k;
long long fac[400009], ans;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

long long fun(int a, int b)
{
	long long ret = fac[b];
	ret *= quickpow(fac[a], MOD - 2);
	ret %= MOD;
	ret *= quickpow(fac[b - a], MOD - 2);
	ret %= MOD;
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fac[0] = 1;
	for (int i = 1; i <= 400000; i++) {
		fac[i] = i * fac[i - 1];
		fac[i] %= MOD;
	}
	cin >> n >> k;
	if (k >= n - 1) {
		ans = fun(n, n + n - 1);
	}
	else {
		for (int i = 0; i <= k; i++) {
			//if ((k - i) % 2 && i == 1) continue;
			long long tmp = fun(i, n);
			tmp *= fun(i, n - 1);
			tmp %= MOD;
			ans += tmp;
			ans %= MOD;
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 6788
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
import datetime
# import webbrowser

# f = open("input.txt", 'r')
# g = open("output.txt", 'w')
# n, m = map(int, f.readline().split())

n, k = map(int, input().split())
dislike = list(map(int, input().split()))
while True:
    for i in str(n):
        if int(i) not in dislike:
            continue
        else:
            break
    else:
        break
    n += 1
print(n)


Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
int ans, a[1000001], n, maxi;
bool dk, check[1000001];
void sieve(){
    a[0] = a[1] = 1;
    for(int i = 2; i * i <= 1000000; i++){
        if(a[i] != 0) continue;
        for(int j = i * i; j <= 1000000; j += i) if(a[j] == 0) a[j] = i;
    }
}
void fact(int x){
    int t = x, pre = 0;
    while(t != 1){
        if(a[t] == 0) a[t] = t; 
        if(check[a[t]] && a[t] != pre) {dk = true; break;}
        else check[a[t]] = true;
        pre = a[t], t /= a[t];
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); 
    sieve();
    cin >> n;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        ans = i == 0 ? x : __gcd(ans, x);
        if(!dk) fact(x);
    }
    if(dk){
        if(ans == 1) cout << "setwise coprime";
        else cout << "not coprime";
    }
    else cout << "pairwise coprime";
    return 0;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    long a;
    long b;
}sword;

//b→aの降順
int desc(const void* a, const void* b){
    sword p=*(sword*)a;
    sword q=*(sword*)b;
    if(q.b-p.b>0) return 1;
    else if(q.b-p.b<0) return -1;
    else{
        if(q.a-p.a>0) return 1;
        else if(q.a-p.a<0) return -1;
        else return 0;
    }
}

int main(void){
    int N;
    long H;
    scanf("%d%ld",&N,&H);

    //A[0]~A[N-1]に格納する
    sword* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%ld%ld",&A[i].a,&A[i].b);
    }
    qsort(A,N,sizeof(sword),desc);

    //その刀を投げるより、別の刀を振るう方がダメージでかい奴はそもそも使わない→除外
    int M=0; //除外されない刀の数
    long a_max=A[0].a;
    for(int i=0;i<N;i++) a_max=MAX(a_max,A[i].a);
    for(int i=0;i<N;i++){
        if(A[i].b>=a_max) M++;
    }

    //全ての刀を投げつけた時の合計ダメージ
    long b_sum=0;
    for(int i=0;i<M;i++) b_sum+=A[i].b;

    long ans=9999999999;
    long tmp=0;
    long damage=0;
    //刀を振らなくても大丈夫なとき
    if(H<=b_sum){
        for(int j=0;j<M;j++){
            if(damage>=H) break;
            tmp++;
            damage+=A[j].b;
        }
    }
    //最後に残した刀を使うパターン
    else{
        damage=b_sum;
        tmp=M;
        if(H-damage>0){
            tmp+=(H-damage)/a_max;
            if((H-damage)%a_max) tmp++;
        }
    }
    ans=MIN(ans,tmp);
    
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 3324
n = int(input())
h = [int(j) for j in input().split()]
dp = [0 for i in range(n)]
dp[0]=0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

// 約数列挙
vector< ll > divisor(ll n) {
	vector< ll > ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret), greater<ll>());
	return (ret);
}

int main() {
	string s, t;
	cin >> s >> t;
	ll sn = s.size(), tn = t.size();

	vvi pos(26, vi(0));

	for (ll i = 0; i < sn; i++) {
		int index = s[i] - 'a';
		pos[index].pb(i);
	}

	ll id = -1;
	ll count = 0;

	for (ll i = 0; i < tn; i++) {
		int index = t[i] - 'a';
		auto itr = upper_bound(pos[index].begin(), pos[index].end(), id);

		if (pos[index].end() - itr == 0) {
			if (pos[index].empty()) {
				cout << -1 << endl;
				return 0;
			}

			id = pos[index][0];
			count++;
		}
		else {
			id = *itr;
		}
	}

	cout << count * sn + id + 1 << endl;
	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int x;
   cin>>x;
   int val=(8LL - (x - 400)/200);
   cout<<val<<endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


int main(){
    ll n,k;
    cin >> n >> k;

    ll a[n] = {};
    rep(i,0,n) cin >> a[i];

    rep(i,k,n){
        if(a[i-k] < a[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int n;
    string s;
    cin >> n;
    cout << "ABC";
    if (n > 99) cout << n << endl;
    else cout << "0" << n << endl;     
    
    return 0;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e5 + 10, OO = 0x3f3f3f3f, mod = 100000007;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
#define sc1(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define vi vector<int>
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
//int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n ;
pair < int , int > arr[N];

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

    cin >> n;
    for(int i = 0 ; i < n ; ++i)
        cin >> arr[i].first >> arr[i].second; // idx , val

    sort(arr , arr + n);
    pair < ll , ll > mn = arr[n-1];
    ll idx = mn.first ;
    ll val = mn.second;
    ll cnt = idx;
    if(val != 0)
        cnt += val;
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=5002;
const ll mod = 1e9+7;
ll p[M],pt[M],sb[M],dp[M][M],fct[M];
ll getpt(ll x)
{
	if(pt[x]==x)
		return x;
	return pt[x]=getpt(pt[x]);
}
ll power(ll a,ll b)
{
	ll val=1;
	while(b)
	{
		if(b%2)
			val=(val*a)%mod;
		b/=2;
		a=(a*a)%mod;
	}
	return val;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k=0;
	cin>>n;
	fct[0]=1;
	for(ll i=1;i<=n;i++)
	{
		fct[i]=(i*fct[i-1])%mod;
		cin>>p[i];
		if(p[i]==-1)
			k++;
	}
	for(ll i=1;i<=n;i++)
	{
		pt[i]=i;
		sb[i]=1;
	}
	ll val=0;
	for(ll i=1;i<=n;i++)
	{
		if(p[i]==-1)
			continue;
		ll a=getpt(i);
		ll b=getpt(p[i]);
		if(a==b)
			continue;
		val++;
		if(sb[a]>sb[b])
		{
			sb[a]+=sb[b];
			pt[b]=a;
		}
		else
		{
			sb[b]+=sb[a];
			pt[a]=b;
		}
	}
	ll ans=(val*power(n-1,k))%mod;
	// cout<<ans<<endl;
	for(ll i=1;i<=n;i++)
	{
		if(p[i]==-1)
		{
			ans=(ans+power(n-1,k-1)*(n-sb[getpt(i)]))%mod;
		}
	}
	dp[0][0]=1;
	for(ll i=1;i<=n;i++)
	{
		if(p[i]!=-1)
		{
			for(ll j=0;j<=k;j++)
				dp[i][j]=dp[i-1][j];
			continue;
		}
		dp[i][0]=dp[i-1][0];
		for(ll j=1;j<=k;j++)
		{
			dp[i][j] = (dp[i-1][j]+(dp[i-1][j-1]*sb[getpt(i)]))%mod;
		}
 	}
	for(ll i=2;i<=k;i++)
	{
		ll z = (dp[n][i]*power(n-1,k-i))%mod;
		z=(z*fct[i-1])%mod;
		ans=(ans-z+mod)%mod;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 199100
#include <stdio.h>
#include <stdlib.h>
#define NMAX 2000001
#define AMAX 10000
int main(){

  unsigned short *A,*B;

  int i,j,n;
  int C[AMAX+1];

  scanf("%d",&n);


  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }




  for(i=0;i<=AMAX;i++){
    C[i]=0;
  }

  for(j=0;j<n;j++){
    C[A[j+1]]++;
  }

  for(i=1;i<=AMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }




  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i!=n) printf(" ");
  }
  printf("\n");
  
  return 0;
  
}

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

#define ll long long
#define ull unsigned long long
#define LL long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define sch(n) scanf(" %c", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plp pair <int, pll >
#define pb push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define Unique(a)  sort(all(a)),a.erase(unique(all(a)),a.end())

#define inf (1LL<<50)
#define eps 1e-9

ll Set(ll n, ll pos)
{
    return n|(1LL<<pos);
}

bool Check(ll n, ll pos)
{
    return (bool) (n&(1LL<<pos));
}

ll h[100010];

vector <ll> M, B; // y = M*X + B formatted lines, must be sorted in advanced by M //clear M, B for test cases, make qptr = 0
bool bad(int l1, int l2, int l3, bool lowerPart = 1) // returns true if l1-l3 line is better than l2
{
    /*
    intersection(l1,l2) has x-coordinate (b1-b2)/(m2-m1)
    intersection(l1,l3) has x-coordinate (b1-b3)/(m3-m1)
    */
    if (lowerPart == 1)
        return (B[l3]-B[l1])*(M[l1]-M[l2]) <= (B[l2]-B[l1])*(M[l1]-M[l3]);
    else return (B[l3]-B[l1])*(M[l1]-M[l2]) >= (B[l2]-B[l1])*(M[l1]-M[l3]);
}
void addLineToCHT(ll m, ll b, bool lowerPart = 1)
{
// lowerPart is called upper hull. For m decreasing, this creates lower part, but if m increasing, it does reverse
// lower part is needed for finding minimum, upper part for maximum
    M.push_back(m);
    B.push_back(b);
    while (M.size() >= 3 && bad(M.size()-3, M.size()-2, M.size()-1, lowerPart))
    {
        M.erase(M.end()-2);
        B.erase(B.end()-2);
    }
}
ll qptr = 0;
ll queryOffline(ll x, bool findMin = 1) // This one works for increasing query and descending slope + minimum or increasing slope+maximum
{
    if (qptr > M.size()) qptr = M.size() - 1; //qptr can become greater when a new line pops many old
    if (findMin)
    {
        while (qptr + 1 < M.size() && M[qptr+1]*x + B[qptr+1] < M[qptr]*x + B[qptr])
            qptr++;
    }
    else
    {
        while (qptr + 1 < M.size() && M[qptr+1]*x + B[qptr+1] > M[qptr]*x + B[qptr])
            qptr++;
    }
    return M[qptr]*x + B[qptr];
}

int main ()
{
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    //  ios_base::sync_with_stdio(0); // no printf/scanf must be present
    ll cs, ts, i, j, k, x, y, z, q, m, n, c;

    while(sl(n) != EOF)
    {
        sl(c);
        ll ans=0;
        for (i = 1; i <= n; i++)
        {
            sl(x);

            if (i != 1)
            ans = queryOffline(x) + x*x + c;

            addLineToCHT(-2*x, ans + x*x);
        }

        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3564
import math
a, b, x = map(int,input().split())

y = x/a

if y <= (a*b)/2:
    print(90-math.degrees(math.atan((2*y)/pow(b,2))))
else:
    y = a*b - y
    print(math.degrees(math.atan((2*y)/pow(a,2))))


Measured memory_bytes: 3060
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

points = [K for _ in range(N)]

for i in range(Q):
    points[A[i] - 1] += 1

for j in range(N):
    points[j] -= Q

for j in range(N):
    if points[j] >= 1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 11888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int a,b,k;
    cin >> a >> b >> k;
    vi l;
    rep1(i,101){
        if(a%i==0 && b%i==0){
            l.pb(i);
        }
    }
    reverse(all(l));
    cout  << l[k-1] << endl;
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
vector<ll> B,A;
int main()
{
    ll N,sum=0;
    cin >> N;
    B.resize(N-1);
    A.resize(N);
    rep(i, 0, N - 1) cin >> B[i];
    A[0] = B[0];
    sum += B[0];
    rep(i, 1, N - 1)
    {   
        if(B[i-1] < B[i])
            A[i] = B[i - 1];
        else
            A[i] = B[i];
        sum += A[i];
    }
    A[N-1] = B[N - 2];
    sum += A[N-1];
    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define N 100005
#define ll long long
#define inf 0x3f3f3f3f
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,-1,sizeof(x))
using namespace std;
ll ans[2000+5],a[2005][2005];
int main()
{
	ll n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			a[i][j]=max(i-j,j-i);
	}
	a[x][y]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i][j]>a[i][x]+1+a[y][j])
				a[i][j]=a[i][x]+1+a[y][j];
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
		//cout<<i<<' '<<j<<' '<<a[i][j]<<' '<<endl;
			ans[a[i][j]]++;
		}
	//cout<<endl;	
	for(int i=1;i<=n-1;i++)
		cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 31616
#include<stdio.h>
int p[101];
int main(){
    int N;
    scanf("%d", &N);
    int AS=0, BS=0;
    int n=0;
    int pt=0;
    for(int i=1; i<=N; i++){
            scanf("%d", &p[i]);
            }
    for(int i=1; i<=N; i++){
            n=0;
            for(int j=1; j<=N; j++){
                    if(p[n]<p[j]){
                     n=j;
                     }
            }
            if(pt==0){
                      AS+=p[n];
                      pt=1;
                      }
            else{
                 BS+=p[n];
                 pt=0;
                 }
            p[n]=0;            
    }
int rez=0;
rez=AS-BS;
printf("%d", rez);
return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		if (n & 1)
			printf("%d\n", 2*(int)pow(3., n/2)-1);
		else
			printf("%d\n", (int)pow(3., n/2)-1);
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 220000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
vector<ll> divs(ll n){
	vector<ll>ret;
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			if(i*i==n){
				ret.push_back(i);
			}
			else{
				ret.push_back(i);
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
void solve(){
	ll n,i,k;
	cin>>n>>k;
	vector<ll>vec(n);
	// map<ll,ll>count;
	nfl(i,n){
		cin>>vec[i];
	}
	sort(vec.begin(), vec.end());
	ll ans=0;
	nfl(i,k){
		ans+=vec[i];
	}
	cout<<ans<<endl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


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

bit = []
while N > 0:
    M = (N-1) % 26
    N = (N-1) // 26
    bit.append(M)

alph = ["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"]
char = []
for i in range(len(bit)):
        char.insert(0, alph[bit[i]])

ans = "".join(char)
print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int n,f[30][55];
string s;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=0;j<s.size();j++)f[s[j]-'a'+1][i]++;
	}
	for(int i=1;i<=30;i++){
		int k=1e9;
		for(int j=1;j<=n;j++)
			k=min(k,f[i][j]);
		if(k==0)continue;
		for(int j=1;j<=k;j++)printf("%c",i+'a'-1);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  Mohamad Milhem
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)


void solve(){
	int n;
	cin >> n;
	vector<long long> v(n);
	long long sum = 0;


	lp(i, 0 , n){
		cin >> v[i];
		sum+= v[i];
	}


	long long bigsum = 0;


	lp(i , 0 , n){
		sum-= v[i];
		long long l = sum%MOD * v[i]%MOD;
		bigsum = (bigsum%MOD + l%MOD)%MOD;
	}

	cout << bigsum << endl;

}



int main()
{
    FAST;
    int t;
    t = 1;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4780
n = int(input())
a= list(map(int,input().split()))
b= list(map(int,input().split()))
c= list(map(int,input().split()))
ans = 0
for i in range(n):
    ans+=b[a[i]-1]
    if i!=n-1 and a[i+1]==a[i]+1:
        ans+=c[a[i]-1]
print(ans)

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

#Nが奇数の時は末尾に０はない（因数に２をもたないから）
if N%2!=0:
    print(0)
    exit()
    

#Nまでの数を書き出して、いつ5の因数を持つか実験して法則性をつかめばいい
#この時i=5にしないこと！（Nから2つとびで減ってるため！）
ans=0
i=10
while(i<=N):
    ans+=N//i
    i*=5
print(ans)


Measured memory_bytes: 38464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

struct restaurant {
    string s; int score, num;
    bool operator<(const restaurant& a) const {
        if(s == a.s) return score > a.score;
        else return s < a.s;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<restaurant> a(n);
    rep(i, n) {
        cin >> a[i].s >> a[i].score;
        a[i].num = i + 1;
    }
    sort(all(a));
    rep(i, n) {
        cout << a[i].num << endl;
    }
}

Measured memory_bytes: 3628
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Char8 (ByteString)
import qualified Data.Map as M
import Data.Map (Map)
import Data.List (sortBy)
 
main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  as <- B.words <$> B.getLine
  print $ solve k $ count as
 
count :: [ByteString] -> Map ByteString Int
count = M.fromListWith (+) . flip zip (repeat 1)
 
solve :: Int -> Map ByteString Int -> Int
solve k = sum . drop k . descSort . M.elems
 
descSort :: [Int] -> [Int]
descSort = sortBy (flip compare)

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

int main(){
    int H,N;
    cin >> H >> N;
    int A[N];
    int sum =0;
    for(int i=0;i<N;i++) {
        cin >> A[i];
        sum += A[i];
    }

    sort(A,A+N);
    if(sum>=H) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 640
from heapq import *
from bisect import bisect_right, bisect_left
from collections import deque
N = int(input())
A = [int(input()) for i in range(N)]
lb, ub = 0, N
while lb + 1 < ub:
    mid = (lb+ub)//2
    cnt, ms, flag = 1, deque(), 1
    ms.append(A[0])
    for a in A[1:]:
        if a <= ms[0]:
            ms.appendleft(a)
            cnt += 1
            if cnt > mid:
                flag = 0
                break
        else:
            i = bisect_left(ms, a)-1
            ms[i] = a
    if flag:
        ub = mid
    else:
        lb = mid
cnt, ms, flag = 1, deque(), 1
ms.append(A[0])
for a in A[1:]:
    if a <= ms[0]:
        ms.appendleft(a)
        cnt += 1
        if cnt > mid:
            flag = 0
            break
    else:
        i = bisect_left(ms, a)-1
        ms[i] = a
if flag:
    print(mid)
else:
    print(mid+1)


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

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

int main(){
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#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 N;
    cin >> N;
    vector<ll> a(3 * N);
    for (int i = 0; i < 3 * N; i++)
    {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end(), greater<int>());
    ll ans = 0;
    for (int i = 0; i < 2 * N; i++)
    {
        if (i % 2 == 1)
        {
            ans += a[i];
        }
        
    }
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll a,b,c;
    cin >> a >> b;
    c=a*b/(__gcd(a,b));
    cout << c;


}

Measured memory_bytes: 256