akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
int n;
vector<int> pathes[100050];
int parent[100050];
vector<int> children[100050];
ll white[100050];
ll black[100050];
void bfs1(int from, int now){
    parent[now] = from;
    children[from].push_back(now);
    for(int i = 0; i < pathes[now].size(); i++){
        int to = pathes[now][i];
        if(from == to) continue;
        bfs1(now, to);
    }
}

void bfs2(int now){
    if(children[now].empty()){
        black[now] = 1;
        white[now] = 1;
        return;
    }
    ll number = 1;
    ll sub = 1;
    for(int i = 0; i < children[now].size(); i++){
        int to = children[now][i];
        bfs2(to);
        number = (number * (black[to] + white[to])) % mod;
        sub = (sub * white[to]) % mod;
    }
    black[now] = sub;
    white[now] = number;
}

int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        pathes[x].push_back(y);
        pathes[y].push_back(x);
    }
    bfs1(0, 1);
    bfs2(1);
    cout << (black[1] + white[1]) % mod << endl;
    return 0;
}


Measured memory_bytes: 20096
def primeFactorize(n):
        a = []
        while n % 2 == 0:
                a.append(2)
                n //= 2
        f = 3 
        while f * f <= n:
                if n % f == 0:
                        a.append(f)
                        n //= f
                else:
                        f += 2
        if n != 1:
                a.append(n)
        return a

X = int(input())
for i in range(X, 10000000000):
        a = primeFactorize(i)
        if len(a) == 1:
                print(i)
                break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
  int n,a,b,c;
  string s;
  
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;

}


Measured memory_bytes: 256
from fractions import gcd
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
tmp=x[1]-x[0]
for i in range(1,n):
    a=x[i+1]-x[i]
    tt=gcd(tmp,a)
    tmp=tt
print(tmp)

Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  map<int, int> mp;
  rep(i, 0, N) {
    int a; cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto p : mp) {
    int n = p.second - p. first;
    if(n >= 0) ans += n;
    else ans += p.second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
N = int(input())
ab = sorted([[0, 0]] + [list(map(int, input().split())) for i in range(N)], key=lambda x: x[1])
for i in range(len(ab) - 1):
    ab[i + 1][0] += ab[i][0]
    if ab[i + 1][1] < ab[i + 1][0]:
        print("No")
        break
else:
    print("Yes")


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> pa,pb;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        pa.push_back(make_pair(a,b));
    }
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        pb.push_back(make_pair(a,b));
    }
    
    sort(pb.begin(),pb.end());
    
    int ans=0;
    vector<int> sa(n,0);
    for(int i=0;i<n;i++){
        int maxy=-1,tmpj;
        for(int j=0;j<n;j++){
            if((pb[i].first>pa[j].first)&&(pb[i].second>pa[j].second)){
                if(maxy<pa[j].second && sa[j]==0){
                    maxy=pa[j].second;
                    tmpj=j;
                }
            }
        }
        if(maxy>=0){
            ans++;
            sa[tmpj]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    REP0 (i, N - 2)
    {
        if (S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C')
            cnt++;
    }
    cout << cnt << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#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; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

const int N = 2e6 + 10;
vector<int> fact(N),ifact(N);


int mod_mul(int a,int b)
{
    return (a*b)%MOD;
}

void pre()
{
    //Factorial and Inverse Factorial
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = mod_mul(fact[i-1],i);
        
    ifact[N-1] = mod_pow(fact[N-1],MOD-2);
    for(int i=N-2;i>=0;i--) ifact[i] = mod_mul(ifact[i+1],i+1);
}

int ncr(int n,int k)
{
    if(k>n) return 0;
    return mod_mul(fact[n],mod_mul(ifact[n-k],ifact[k]));
}

void solve()
{
   int k;
    cin >> k;
    
   string s;
   cin >> s;
    
   int res = 0;
    
   int n = s.length(); 
    
   for(int i=0;i<=k;i++)
   {
       int temp = (mod_pow(26,i)*mod_pow(25,k-i))%MOD;
       
       temp = (temp*(ncr(n-1+k-i,n-1)));
       
       res+=temp;
       res%=MOD;
   }
    
  cout <<res;  
}

signed main()
{
    pre();
    
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 35504
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;

const int inf = INT_MAX / 100;

int TSP(vector<vector<int>> &graph, int src){
  int v = graph.size(), n = 1 << v;
  vector<vector<int>> dp(v, vector<int>(n, inf));

  REP(i,v){
    dp[i][1<<i] = graph[src][i];
  }
  
  FOR(s,1,n){
    REP(i,v){
      if(!(s & (1<<i))) continue;
      REP(j,v){
	if(s & (1<<j)) continue;
	dp[j][s | (1<<j)] = min(dp[j][s | (1<<j)], dp[i][s] + graph[i][j]);
      }
    }
  }

  return dp[src][n-1];
}

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

  int v,e;
  cin >> v >> e;
  
  vector<vector<int>> graph(v, vector<int>(v,inf));

  REP(i,e){
    int s,t,d; cin >> s >> t >> d;
    graph[s][t] = d;
  }

  int ans = TSP(graph, 0);
  cout << (ans>=inf ? -1 : ans) << endl;
  
  return 0;
}



Measured memory_bytes: 4932
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <tuple>
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> tup;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
int n, m, l, k, a, h;
bool reitou[110];
vector<pair<int, int> > G[110];
//dist[u][t] :=????????¨????????????u??§???????????????t???????????????????????????
int dist[110][110];
// bool used[110][110];
void dijkstra(int start){
    rep(i, 110)rep(j, 110){
    	dist[i][j] = INF;
    	// used[i][j] = false;
    }
    priority_queue<tup, vector<tup>, greater<tup> >  q;
    q.push(make_tuple(0, start, m));//??????????????¨????????????????????????

    while(!q.empty()){
        int cost, u, t;//????????§???????????£????????? ?????¨?????????????§£???????????§???????????????
        tie(cost, u, t) = q.top(); q.pop();
        // if(used[u][t]) continue;
        if(dist[u][t] < cost) continue;
        for (auto tmp : G[u]){
            int v = tmp.first, time = tmp.second;//??£??\???????????? ?????????????????§????????????
            if(reitou[u]){//????????????
            	for (int i = 0; i <= m; ++i){//i?????????????????????
            		if(t + i > m) break;//????§?????????????????????????
            		if(t + i - time < 0) continue;
            		// if(used[v][t + i - time]) continue;
            		if(cost + i + time < dist[v][t + i - time]){//??????????????´??°
                		dist[v][t + i - time] = cost + i + time;
                		// printf("1 dist[%d][%d] = %d\n", v, cost + i - time, dist[v][cost + i - time]);
                		q.push(make_tuple(dist[v][t + i - time], v, t + i - time));
                		// used[v][t + i - time] = true;
            		}
            	}
            }else{
            	if(t - time < 0) continue;
            	// if(used[v][t - time]) continue;
            	if(cost + time < dist[v][t - time]){//??????????????´??°
                	dist[v][t - time] = cost + time;
                	// printf("2 dist[%d][%d] = %d\n", v, t - time, dist[v][t - time]);
                	q.push(make_tuple(dist[v][t - time], v, t - time));
                	// used[v][t - time] = true;
            	}
            }
        }
    }
}

int main(void){
	while(1){
		cin >> n >> m >> l >> k >> a >> h;
		if(n == 0) return 0;
		rep(i, 110) reitou[i] = false;
		rep(i, 110) G[i].erase(G[i].begin(), G[i].end());
		rep(i, l){
			int tmp; cin >> tmp;
			reitou[tmp] = true;
		}

		rep(i, k){
			int u, v, c; cin >> u >> v >> c;
			G[u].push_back(make_pair(v, c));
			G[v].push_back(make_pair(u, c));
		}

		dijkstra(a);
		int ans = INF;
		for (int i = 0; i <= m; ++i){
			ans = min(ans, dist[h][i]);
		}
		if(ans == INF){
			printf("Help!\n");
		}else{
			printf("%d\n", ans);
		}
	}
	return 0;
}

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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;


int N;
V<LL> a,b,h;

int main(){
    INIT;
    cin >> N;
    a.resize(N); b.resize(N); h.resize(N);
    LL ba,bb,bh;
    REP(i,N) {
        cin >> a[i];
        cin >> b[i];
        cin >> h[i];
        if(h[i] >= 1) {
            ba = a[i]; bb = b[i]; bh= h[i];
        }
    }

    for(LL x = 0; x <= 100; x++) {
        for(LL y = 0; y <= 100; y++) {
            bool ok = true;
            LL baseh = std::max(bh+abs(x-ba)+abs(y-bb), 0LL);
            FOR(i,0,N){
                LL nh = std::max(baseh-abs(x-a[i])-abs(y-b[i]), 0LL);
                if(h[i] != nh) ok = false;
            }
            if(ok) {
                cout << x << " " << y << " " << baseh << "\n";
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(i, c) ((c).find(i) != (c).end())
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define foreach(i, c) for(auto i : c)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watchc(x) TRACE(cerr << #x" = "); for(auto __i : x) cerr << __i << " "; cerr << endl

#define INF 0x3f3f3f3f

int main() {
	
	ifstream infile("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int s = 0;
    s += min(a, k);
    k -= s;
    if(k > 0) k -= b;
    if(k > 0) s -= min(c, k);

    cout << s << endl;
	
	if(infile.good()) infile.close();
	return 0;
	
}



Measured memory_bytes: 3608
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict
import itertools

n, k = LI()
graph = [[] for i in range(n)]
kumis = list(itertools.combinations(list(range(2, n+1)), 2))
m = (n-1) * (n-2) // 2

if m < k:
    print(-1)
else:
    print(m - k + n - 1)
    for i in range(n+1):
        if i in (0, 1):
            continue
        else:
            print(1, i)
    for i in range(m - k):
        print(kumis[i][0], kumis[i][1])


Measured memory_bytes: 4240
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

inputs[0].sort!
aa = inputs[0][0]
bb = inputs[0][1]

puts aa*bb/2

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

int main() {
	int n,k;cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	vector<int> dp(5001,0);
	dp[0]=1;
	int ans=0;
	int minnum=-1;
	for(int i=0;i<n;i++){
		int flag=0;
		for(int j=5000;j>=0;j--){
			if(dp[j]){
				if(j+a[i]<=5000){
					dp[j+a[i]]=1;
				}
				if((j<k)*(j+a[i]>=k)){
					flag=1;
				}
			}
		}
		if(flag==1){
			minnum=i;
		}
	}
	cout<<n-minnum-1<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int a,b,c,i,k;
    
    scanf("%d%d%d",&a,&b,&c);
    
    for(i=a;i<=b;i++){
        if(c%i==0) k++;
    }
    
    printf("%d\n",k);
    
    return 0;
    
}


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

int main() {
    string S, T;
    cin >> S >> T;

    if (equal(S.begin(), S.end(), T.begin())) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
int main(void){
    long n,a,b;
    scanf("%ld %ld %ld",&n,&a,&b);
    long result;
    if((a+b)*pow(10,100)<=n){
        result=a*pow(10,100);
    }else{
        long set=n/(a+b);
        long katamari=set*(a+b);
        long nokori=n-katamari;
        if (nokori>=a) {
            result=a*set+a;
        }else{
            result=a*set+nokori;
        }
    }printf("%ld\n",result);
    return 0;
}


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

int main(){
  ll n;
  cin >>n;
  vector<ll>a(n);
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  ll ans=a.at(n-1);
  ll tmp=n-2;
  for(ll i=0;i<n-2;i++){
    ans+=a.at(tmp);
    if(i%2!=0)tmp--;
  }
  cout <<ans<<endl;
}

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

using ll = long long;
using pii = pair<int, int>;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    map<int, int> cnt;
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    if(cnt.size() > 2) {
        cout << "No" << endl;
    } else {
        if(cnt.size() == 1) {
            auto p = *cnt.begin();
            if(p.first * 2 <= N || p.first + 1 == N) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            vector<pii> v;
            for(auto p : cnt) {
                v.push_back(p);
            }
            int m1 = v[0].first, m2 = v[1].first;
            int n1 = v[0].second, n2 = v[1].second;
            if(m1 + 1 == m2 && n1 < m2 && 2 * (m2 - n1) <= n2) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
}


Measured memory_bytes: 5376
#include <stdio.h> 
 int main(void) {
 int n;
 scanf("%d", &n);

 switch (n % 10) {
 case 2:
 case 4:
 case 5:
 case 7:
 case 9:
 puts("hon");
 break;
 case 0:
 case 1:
 case 6:
 case 8:
 puts("pon");
 break;
 case 3:

puts("bon");
break; }
return 0;
}
 

Measured memory_bytes: 3104
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,money;
int main()
{
	cin>>n>>money;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n-i;j++)
			if(i*10000+j*5000+1000*(n-i-j)==money) {cout<<i<<' '<<j<<' '<<n-i-j<<endl;return 0;}
	cout<<"-1 -1 -1\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se>b.se;
}
ll cmp(ll a,ll b){
    return abs(a)<abs(b);
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    string s;cin>>s;
    ll w;cin>>w;
    string ans="";
    for(ll i=0;i<s.length();i+=w){
        ans+=s[i];
    }
    cout<<ans<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------






















































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

int main() {
  vector<int> PQR(3);
  for (int i = 0; i < 3; i++) cin >> PQR.at(i);
  sort(PQR.begin(), PQR.end());
  
  cout << (PQR[0] + PQR[1]) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int time_s = (H1 * 60) + M1;
    int time_e = (H2 * 60) + M2;
    int ans = (time_e - time_s) - K;
    cout << ans << endl;
}


Measured memory_bytes: 3632
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        v = list(map(int, input().split()))
        c = list(map(int, input().split()))
        arr = [v[i] - c[i] for i in range(n) if v[i] - c[i] > 0]
        print(sum(arr))
        

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int n,s;
    scanf("%d",&n);
    if(n<1000){
        s=n%10;
        if(s==3) printf("bon\n");
        else if(s==0|s==1|s==6|s==8) printf("pon\n");
        else printf("hon\n");
    }
    return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>
#define N 44
int makeFibonacci(int);
int F[N];
int main(){
  int n,x=0;
  scanf("%d",&n);
  x=makeFibonacci(n);
  printf("%d\n",x);  
  return 0;
}
int makeFibonacci(int n){
  int i,x=0;
  F[0]=1;
  F[1]=1;
  if(n==0||n==1){
    return 1;
  }
  if(n>1){
    for(i=2;i<=n;i++){
      F[i]=F[i-2]+F[i-1]; 
      x=F[i];   
    }
    return x;
  }
}

Measured memory_bytes: 596
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) (cin >> as[i]), as[i]--;

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (i == as[as[i]]) cnt++;
  printf("%d\n", cnt / 2);
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Function to find the number of divisors
// of all numbers in the range [1, n]
void findDivisors(int n)
{

    // Array to store the count
    // of divisors
    vector<int> div(n + 1, 0);
    // memset(div, 0, sizeof div);

    // For every number from 1 to n
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j * i <= n; j++)
            div[i * j]++;
    }

    // Print the divisors
    int ans = 0;
    for(int i = 1; i<=n; i++){
        ans = ans + div[i] * i;
    }
    cout << ans <<"\n";
}

// Driver code
int32_t main()
{
    int n ;
    cin >> n;
    findDivisors(n);

    return 0;
}


Measured memory_bytes: 81384
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2005;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
char s[N];int a[N],sz[N],f[N],n,res;
void dfs(int u,int fa){sz[u]=a[u],f[u]=0;go(u)if(v!=fa)dfs(v,u),sz[u]+=sz[v],f[u]+=f[v]+sz[v];}
int get(int u,int fa){
	int to=0;
	go(u)if(v!=fa&&f[v]>f[to])to=v;
	if(!to)return 0;
	int k=get(to,u)+sz[to];
	if(f[u]-f[to]-sz[to]>=k)return f[u]&1;
	return k-(f[u]-f[to]-sz[to]);
}
int main(){
//	freopen("testdata.in","r",stdin); 
	scanf("%d%s",&n,s+1);
	fp(i,1,n)a[i]=s[i]-'0';
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	res=23333333,f[0]=-1;
	fp(i,1,n){
		dfs(i,0);
		if(get(i,0)==0)cmin(res,f[i]>>1);
	}
	printf("%d\n",res==23333333?-1:res);
	return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x:x[0])

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (cnt - m)
        break
    i += 1

print(price)

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

#define INF 1000000000

int A[200000000];
int nmber = 0;
int H = 0;

void maxHeapify(int i){
    int l, r;
    int  largest, temp;
    

    l = i * 2;
    r = i * 2 + 1;

    if(l <= H && A[l] > A[i]) 
        largest = l;
    else 
        largest = i;

    if(r <= H && A[r] > A[largest])
        largest = r;
    
    if(largest != i){
        temp = A[i];
        A[i] = A[largest];
        A[largest] = temp;
        maxHeapify(largest);
    }
}

void increaseKey(int i, int key){
    int temp;
    if(key < A[i])return;

    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        temp = A[i];
        A[i] = A[i/2];
        A[i/2] = temp;
        i = i / 2;
    }
}

int heapExtractMax(){
    int max;
    if(H < 1) return -INF;

    max = A[1];
    A[1] = A[H];
    H--;
    maxHeapify(1);

    return max;
}

void insert(int key){
    H++;
    A[H] = -INF;
    increaseKey(H, key);
}

int main(){
    int nm;
    char op[10];
  
    while(1){
        scanf("%s", op);
        if(strcmp(op, "insert") == 0){
            scanf("%d", &nm);
            insert(nm);
        }
        else if(strcmp(op, "extract") == 0){
            printf("%d\n", heapExtractMax());
        }
        else if(strcmp(op, "end") == 0)break;
    }

    return 0;
}



Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+ 10 ;
const int mod=1e9+ 7 ;
char s[ 1005 ][ 1005 ];
int h,w;
int sx,sy,ex,ey;
int xx[ 5 ]={ 58 , 0 , 0, 1 ,- 1 };
int yy[ 5 ]={ 58 , 1 ,- 1 , 0 , 0 };
int min1= 1e9;

struct ac
{
	int x,y,step;
};


void bfs()
{
	deque<ac> q;
	q.push_front({sx,sy, 0 });
	s[sx][sy]='#';
	while (! q.empty())
	{
		ac u = q.front();
		q.pop_front();
		int x=u.x,y = u.y ;
		if (x==ex&&y== ey)
		{
			min1 = u.step;
			return ;
		}
		s[x][y] ='#';
		for ( int i = 1 ;i<= 4 ;i++ )
		{
			int tx=x+ xx[i];
			int ty=y+ yy[i];
			if (tx< 1 ||ty< 1 ||tx>h||ty>w||s[tx][ty ]=='#')
				continue ;
			q.push_front({tx,ty,u.step});
		}
		for ( int i=x- 2 ; i<=x+ 2 ;i++ )
		{
			for ( int j=y- 2 ;j<=y+ 2 ;j++ )
			{
				if (i< 1 ||j< 1 ||i>h||j>w||s[i][j] =='#')
					continue ;
				q.push_back({i, j,u.step + 1 });
			}
		}
	}
}


int main()
{
	ios::sync_with_stdio( false );
	cin.tie( 0 );
	cin>>h>> w;
	cin>>sx>>sy>>ex>> ey;
	for ( int i = 1 ;i<=h;i++ )
	{
		for ( int j = 1 ;j<=w;j++ )
		{
			cin>> s[i][j];
		}
	}
	bfs();
	if(min1== 1e9)
		cout<<- 1 <<'\n';
	else
		cout<<min1<<'\n';



}


Measured memory_bytes: 11212
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

string lltozeroume(ll a){
  if (a >= 100000){
    return to_string(a);
  }
  else if (a >= 10000){
    return "0" + to_string(a);
  }
  else if (a >= 1000){
    return "00" + to_string(a);
  }
  else if (a >= 100){
    return "000" + to_string(a);
  }
  else if (a >= 10){
    return "0000" + to_string(a);
  }
  else if (a >= 1){
    return "00000" + to_string(a);
  }
}

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<string> ans(m);
  vector<tuple<ll,ll,ll>> input(m);
  for (int i = 0; i < m; i++){
    ll p, y;
    cin >> p >> y;
    
    input[i] = make_tuple(p, y, i);
  }
  sort(input.begin(), input.end());
  
  vector<ll> th(n + 1, 0);
  for (auto i : input){
    int index = get<2>(i);
    ll pref = get<0>(i);
    th[pref]++;
    ans[index] = lltozeroume(pref) + lltozeroume(th[pref]);
  }

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

  return 0;
}


Measured memory_bytes: 9524
#include <bits/stdc++.h>
#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 ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define toInt(x) (x - '0')
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
  return 0;
}


Measured memory_bytes: 764
n, k = map(int, input().split(" "))

a_dic = {}

a = list(map(int, input().split(" ")))
for i in a:
    if i in a_dic:
        a_dic[i] += 1
    else:
        a_dic[i] = 1

cn = 0
diff = len(a_dic) - k
score_sorted = sorted(a_dic.items(), key=lambda x:x[1], reverse=True)
if diff > 0:
    for i in range(diff):
        a = score_sorted.pop()
        cn += a[1]

print(cn)



Measured memory_bytes: 42960
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	//	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

type node struct {
	to []int
}

var g0 []int
var g1 []int
var used []int

func dfs(cnt, i, N int, n []node) {
	used[i] = 1
	if cnt%2 == 0 {
		g0 = append(g0, i)
	} else {
		g1 = append(g1, i)
	}
	for _, v := range n[i].to {
		if used[v] == 1 {
			continue
		}
		dfs(cnt+1, v, N, n)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	n := make([]node, N)
	used = make([]int, N)
	for i := 0; i < N-1; i++ {
		f, t := getInt()-1, getInt()-1
		n[f].to = append(n[f].to, t)
		n[t].to = append(n[t].to, f)
	}

	dfs(0, 0, N, n)

	out(g0, g1)
	p := make([]int, 0, N)
	cnt0 := 0
	for i := 1; i <= N; i++ {
		if i%3 == 1 {
			p = append(p, i)
			cnt0++
		}
	}
	start1 := cnt0
	cnt1 := 0
	for i := 1; i <= N; i++ {
		if i%3 == 2 {
			p = append(p, i)
			cnt1++
		}
	}
	start2 := start1 + cnt1
	cnt3 := 0
	for i := 1; i <= N; i++ {
		if i%3 == 0 {
			p = append(p, i)
			cnt3++
		}
	}
	out("pass", len(p))

	x := make([]int, N)
	if len(g0) <= cnt3 {
		out("pat0")
		for i := 0; i < len(g0); i++ {
			x[g0[i]] = p[len(p)-1-i]
		}
		for i := 0; i < len(g1); i++ {
			x[g1[i]] = p[i]
		}
	} else if len(g1) <= cnt3 {
		out("pat1")
		for i := 0; i < len(g1); i++ {
			x[g1[i]] = p[len(p)-1-i]
		}
		for i := 0; i < len(g0); i++ {
			x[g0[i]] = p[i]
		}
	} else {
		out("pat2")
		idx := 0
		for i := 0; i < cnt0; i++ {
			x[g0[idx]] = p[i]
			idx++
		}
		out("--pass")
		for i, j := idx, 0; i < len(g0); i++ {
			out(start2 + j)
			x[g0[i]] = p[start2+j]
			j++
		}
		idx = 0
		out("--pass")
		for i := 0; i < cnt1; i++ {
			x[g1[idx]] = p[start1+i]
			idx++
		}
		out("--pass")
		for i, j := idx, len(p)-1; i < len(g1); i++ {
			out(start2+j, start1, cnt0, cnt1, cnt3)
			x[g1[i]] = p[j]
			j--
		}
		out("--pass")

	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < N; i++ {
		fmt.Fprintf(w, "%d ", x[i])
	}
	fmt.Fprintf(w, "\n")
}


Measured memory_bytes: 66432
#include <iostream>
#include <math.h>
using namespace std;

long long mod = 1000000007;
long long res = 1;
int N;

int main()
{
	cin >> N;
	for (int i = 2; i <= N; i++)
	{
		bool flag = true;
		//проверка на простоту
		for (int c = 2; c <= (int)sqrt(i + 0.0); c++)		
			if (i % c == 0)
			{
				flag = false;
				break;
			}		
		//поиск чисел
		if (flag)
		{

			int sum = 0;
			for (int j = i; j <= N; j *= i)
				sum += N / j;
			if (sum == 0) continue;
			res = (res * (sum + 1)) % mod;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main(){
    int a, b;
    int amari;
    
    cin >> a >> b;
    
    while(a%b != 0){
        if(a < b){
            swap(a, b);
        }
        amari = a % b;
        
        a = b;
        b = amari;
    }
    
    cout << b << endl;
}


Measured memory_bytes: 3072
N = int(input())
H = list(map(int, input().split()))
def rec(H):
    ans = 0
    if H:
        hmin = min(H)
        ans += hmin
        K = [h - hmin for h in H]
        I = [i for i, k in enumerate(K) if not k]
        ans += rec(K[:I[0]])
        for i, j in zip(I, I[1:]):
            ans += rec(K[i+1:j])
        ans += rec(K[I[-1]+1:])
    return ans
print(rec(H))

Measured memory_bytes: 3188
#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() {
  string s;
  cin >> s;
  deque<char> q;
  for (char c : s) q.push_back(c);
  bool flip = false;
  int Q;
  cin >> Q;
  rep(qi,Q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      flip = !flip;
    } else {
      int f; char c;
      cin >> f >> c;
      if (flip) f = 3-f;
      if (f == 1) {
        q.push_front(c);
      } else {
        q.push_back(c);
      }
    }
  }
  if (flip) reverse(q.begin(), q.end());
  string ans;
  for (char c : q) ans += c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
n = int(input())
#z = [[int(x) for x in input().split()] for i in range(n)]
z = []
t = 0
for i in range(n):
    x, y = [int(x) for x in input().split()]
    t += y
    z.append(x + y)
z.sort(reverse=True)

s = 0
for i in range(n // 2):
    s += z[2 * i]
if n % 2 == 1:
    s += z[len(z) - 1]

print(s - t)

#アルゴリズムが間違っている

Measured memory_bytes: 7404
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
typedef unsigned long long ullong;

static const int MAX = 50;
static const int GMAX = 102;

struct Point{ ullong x, y, z; };
int G[GMAX][GMAX][GMAX];

main(){
  int N, K, nx, ny, nz;
  cin >> N >> K;
  pair<Point, Point> C[MAX];
  set<ullong> X, Y, Z;
  vector<ullong> VX, VY, VZ;
  map<ullong, int> MX, MY, MZ;

  rep(i, N){
    cin >> C[i].first.x >> C[i].first.y >> C[i].first.z;
    cin >> C[i].second.x >> C[i].second.y >> C[i].second.z;
    X.insert(C[i].first.x);
    X.insert(C[i].second.x);
    Y.insert(C[i].first.y);
    Y.insert(C[i].second.y);
    Z.insert(C[i].first.z);
    Z.insert(C[i].second.z);
  }

  nx = ny = nz = 0;
  for ( set<ullong>::iterator it = X.begin(); it != X.end(); it++){
    VX.push_back(*it);
    MX[*it] = nx++;
  }
  for ( set<ullong>::iterator it = Y.begin(); it != Y.end(); it++){
    VY.push_back(*it);
    MY[*it] = ny++;
  }
  for ( set<ullong>::iterator it = Z.begin(); it != Z.end(); it++){
    VZ.push_back(*it);
    MZ[*it] = nz++;
  }

  rep(i, nx) rep(j, ny) rep(k, nz) G[i][j][k] = 0;

  rep(i, N){
    int sx = MX[C[i].first.x];
    int tx = MX[C[i].second.x];
    int sy = MY[C[i].first.y];
    int ty = MY[C[i].second.y];
    int sz = MZ[C[i].first.z];
    int tz = MZ[C[i].second.z];
    REP(x, sx, tx) REP(y, sy, ty) REP(z, sz, tz) G[x][y][z]++;
  }

  ullong sum = 0;
  rep(x, nx){
    rep(y, ny){
      rep(z, nz){
	if ( G[x][y][z] >= K ){
	  sum += (VX[x+1] - VX[x])*(VY[y+1] - VY[y])*(VZ[z+1] - VZ[z]);
	}
      }
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 5344
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

            main.solveA(sc);

        }
    }

    void solveA(Scanner sc) {
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }

        int min = Integer.MAX_VALUE;
        for (int i = -100; i <= 100; i++) {
            int sum = 0;
            for (int num : list) {
                sum += Math.pow(num - i, 2);
            }
            min = Math.min(min, sum);
        }
        System.out.println(min);
    }

}


Measured memory_bytes: 9556
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
const int INF=2147483647;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define SIZE 13
int N,M,X,flag,ans=INF;
int POW[SIZE],a[SIZE];
int b[SIZE][SIZE],c[SIZE];
int main(){
	POW[0] = 1;
	for(int i = 1; i <=SIZE; i++){
		POW[i] = POW[i-1]<<1;
	}
	scanf("%d %d %d",&N,&M,&X);
	for(int i = 0; i < N; i++){
		scanf("%d",&a[i]);
		for(int j = 0; j < M; j++){
			scanf("%d",&b[i][j]);
		}
	}	
	for(int i = 0; i < POW[N]; i++){
		memset(c,0,sizeof(c)); 
		int sum = 0;
		for(int j = 0; j < N; j++){
			if(i & POW[j]){
				sum += a[j];
				for(int k = 0; k < M; k++){
					c[k] += b[j][k];
				}
			}
		} 
		flag = 1;
		for(int j = 0; j < M; j++){
			if(c[j] < X){
				flag = 0;
				break;
			}
		}
		if(flag) ans = min(ans,sum);
	}
	if(ans == INF) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  int K = 0;
  cin >> N >> K;
  vector<int> p(N + 1);
  for(int i = 0;i < N;i++){
    cin >> p.at(i);
  }
  for(int j = 0;j < N * N;j++){
    for(int i = 0;i < N;i++){
      if(p.at(i) > p.at(i + 1)){
        int a = p.at(i);
        p.at(i) = p.at(i + 1);
        p.at(i + 1) = a;
      }
    }
  }
  int sum = 0;
  for(int i = 0;i <= K;i++){
    sum += p.at(i);
  }
  cout << sum << endl;
}

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

typedef long long ll;

int main()
{
   int n,i,ans=0,ma=1000,p,q,f,j;
   string s;
   char c[105][105];
   cin>>s;
   for(i=0;i<s.size();i++)
   {
       c[0][i]=s[i];
   }
   i=97;
   n=s.size();
   while(i<123)
   {
       p=0;
       q=n;
       while(1)
       {
           f=0;
           for(j=0;j<q;j++)
            {
                if(c[p][j]==char(i))
                {
                    if(j+1==q)
                    {
                        f=1;
                       break;
                    }
                }
                else
                {
                    break;
                }
            }
            if(f==1||q==1)
            {
                break;
            }
            q--;
            p++;
            for(j=0;j<q;j++)
            {
                if(c[p-1][j]==char(i)||c[p-1][j+1]==char(i))
                {
                    c[p][j]=char(i);
                }
            }
       }
       i++;
       ma=min(ma,p);
   }
   cout<<ma;
   return 0;
}


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

int gcd(int x, int y){
  int a = max(x, y), b = min(x, y);
  if(b == 0){
    return a;
  }

  return gcd(b, a % b);
}

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

  vector<int> A(N);
  int A_max = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    A_max = max(A_max, A[i]);
  }

  int A_gcd = A[0];
  for(int i = 1; i < N; i++){
    A_gcd = gcd(A_gcd, A[i]);
  }

  bool ans = false;
  if(K <= A_max && (K % A_gcd == 0)){
    ans = true;
  }

  cout << (ans? "": "IM") << "POSSIBLE" << endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始！ */
/* 入力終了！ */
int main(void)
{
   int n;
   int a,b;
   while(cin >> a >> b) {
      int cnt = 0;
      a += b;
      while(1) {
         if(a == 0) break;
         a /= 10;
         cnt++;
      }
      cout << cnt << endl;
   }

   return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for (int i = L; i <= R; ++i)
        ans += !(i % d);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
n, m = map(int, input().split())
spans = [tuple(map(int, input().split())) for _ in range(m)]

spans = sorted(spans, key=lambda x: x[1])

ans = 0
cur_end = -float("inf")

for st, en in spans:
    if cur_end > st:
        continue
    ans += 1
    cur_end = en
print(ans)
    


Measured memory_bytes: 19024
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

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

	ll W,H,x,y;
	cin >> W >> H >> x >> y;

	cout << fixed << setprecision(15);
	cout << (double)W * H / 2 << " ";

	if(W == 2 * x && H == 2 * y){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}

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

int64_t times(int64_t H) {
  if(H==1)
    return 1;
  else
    return times(H/2)*2+1;
}

int main() {
  int64_t H;
  cin >> H;
  cout << times(H) << endl;
}

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

#define clr(arr,val) memset(arr,val ,sizeof arr)
//#define first f
//#define second s

typedef  long long ull;
typedef long long ll;
int const oo=(int)1e9 ;

int const SZ= (int)1e5+1;
//const ll mod=(ll)1e9+7;
int arr[SZ];
int dp[SZ];
int n;
//int mn=oo;
int solve(int i){
    
    if(i==n-1)
        return 0;
    if(i>=n)
        return oo;
    
    int &ret=dp[i];
    
    if(ret!=-1)
        return ret;
        
    int ch1=abs(arr[i]-arr[i+1])+solve(i+1);
    int ch2=abs(arr[i]-arr[i+2])+solve(i+2);
    ret=min(ch1,ch2);
    return ret;
    
}
int main() {
//    int t ;
//    cin>>t;
//    while(t--){
        cin>>n;
        for(int i=0 ;i<n ;i++)
            cin>>arr[i];
        clr(dp,-1);
        cout<<solve(0)<<endl;
//    }
    return 0;
}

Measured memory_bytes: 9060
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;
 
#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

const int nax = 2e5 + 5;
int parent[nax], sz[nax];
int find(int x){
    if(x == parent[x]){
        return x;
    }
    return parent[x] = find(parent[x]);
}

void uni(int a,int b){
    a = find(a);
    b = find(b);
    if(a == b){
        return;
    }
    if(sz[a] >= sz[b]){
        parent[b] = a;
        sz[a] += sz[b];
    }
    else{
        parent[a] = b;
        sz[b] += sz[a];
    }
}

int32_t main(){
    IOS
    int n,m;
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        parent[i] = i;
        sz[i] = 1;
    }
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        uni(a,b);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, sz[find(i)]);
    }
    cout << ans << endl;
} 

Measured memory_bytes: 6772
S=input()
d=[0]*13
d[0]=1
for i in range(len(S)):
  n=[0]*13
  for j in range(13):
    for k in range(10):
      n[(10*j+k)%13]+=(1 if S[i]=='?' or int(S[i])==k else 0)*d[j]
  for j in range(13): d[j]=n[j]%(10**9+7)
print(d[5])

Measured memory_bytes: 43772
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()

s_len = len(s)
t_len = len(t)

# dp[i][j] : sのi文字目、tのj文字目の時のLCSの長さ
# LCS...Longest-common subsequence（最長共通部分列）
dp = [[0] * (t_len+1) for _ in range(s_len+1)] 

for i in range(s_len):
    for j in range(t_len):
        if s[i] == t[j]:
            # dpテーブルの左上の値から+1したものが最長の長さ
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

# for Debug
"""
print('      ', end='')
print(*t, sep=''  '')
ss = ' ' + s
for i in range(len(dp)):
    print(ss[i], end=' ')
    print(dp[i])
"""


# 結果の文字列の算出
# dp配列を逆からたどってLCSを作成する
# LCSの長さが更新されたときの文字を追加していく
res = ""
while s_len and t_len:
    if dp[s_len][t_len] == dp[s_len-1][t_len]:
        s_len -= 1
    elif dp[s_len][t_len] == dp[s_len][t_len-1]:
        t_len -= 1
    else:
        # 先頭からくっつけていく
        res = s[s_len-1] + res
        s_len -= 1
        t_len -= 1

print(res) 


Measured memory_bytes: 136280