akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
int msearch(vector<vector<bool>> &g)
{
    int ans = 0;
    int p[N - 1];
    rep(i, 0, N - 1)
    {
        p[i] = i + 2;
    }
    do
    {
        bool check = true;
        if (!g[1][p[0]])
            continue;
        rep(i, 0, N - 2)
        {
            if (!g[p[i]][p[i + 1]])
            {
                check = false;
                break;
            }
        }
        // rep(i, 0, N - 1) cout << p[i] << ' ';
        // cout << endl;
        if (check)
            ++ans;
    } while (next_permutation(&p[0], &p[N - 1]));
    return ans;
}
void func()
{
    cin >> N >> M;
    vector<vector<bool>> g(N + 1, vector<bool>(N + 1, false));
    int ai, bi;
    rep(i, 0, M)
    {
        cin >> ai >> bi;
        g[ai][bi] = true;
        g[bi][ai] = true;
    }
    cout << msearch(g) << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3600
#include <cstdio>
 
int main(){
	int a;
	int b;
	int c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&b<=c){
	printf("%d %d %d\n",a,b,c);
	}else if(a<=c&&c<=b){
	printf("%d %d %d\n",a,c,b);
	}else if(b<=a&&a<=c){
	printf("%d %d %d\n",b,a,c);
	}else if(b<=c&&c<=a){
	printf("%d %d %d\n",b,c,a);
	}else if(c<=a&&a<=b){
	printf("%d %d %d\n",c,a,b);
	}else if(c<=b&&b<=a){
	printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

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

#define PI acos(-1)
using namespace std;

int main() {
  double ans,rad,deg,A,B;
  double H,M;
  cin >> A >> B >> H >> M;
  H = 30*H + 0.5*M;
  M *= 6;
  if(H > M){
    deg = H - M;
  }
  else{
    deg = M - H;
  }
  rad = cos((deg*PI)/180.0);
  ans = A*A + B*B - rad*2*A*B;
  cout << setprecision(20) << sqrt(ans) << endl;
  return 0;
}

Measured memory_bytes: 4212
#include<stdio.h>

int main()
{
    int A,B,i,j=0,k,l,o,r;
    scanf("%d %d",&A,&B);
    for(i=A;i<=B;i++)
    {
        o=i;
        r=0;
        while(o!=0)
        {
            l=o%10;
            r=r*10+l;
            o=o/10;
        }
        if(r==i)
            j++;
    }
    printf("%d\n",j);

    return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int x,a;
  cin >> x >> a;
  if(x<a) cout << 0 << "\n";
  else cout << 10 << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		for(int i=n-1;i>0;i--){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
	}
}

Measured memory_bytes: 26404
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ll n, m;
	cin >> n >> m;
	if (n*2 >= m) {
		cout << m / 2<< endl;
		return 0;
	}
	else {
		ll count = n;
		m -= 2* n;
		count += m / 4;
		cout << count << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001

/*
int main() {
  ll k;
  cin >> k;

  ll cnt = 0;
  ll i = 1;
  while(1) {
    string s = to_string(i);
    bool flag = true;
    ll len_s = s.size();
    char a = s[0];
    for (ll i = 1; i < len_s; i++) {
      char b = s[i];
      if (!((a-b <= 1) && (-1 <= a-b))) {
        flag = false;
        break;
      }
    }

    if (flag) cnt++;

    if (cnt == k) {
      cout << s << endl;
      return 0;
    }

    i++;
  } 
}
*/

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

  int si = max(9, k);
  vector<ll> lunlun(si+1, -1);
  vector<pii> info(si+1); //桁数/頭
  for(ll i = 0; i <= 9; i++) {
    lunlun[i] = i;
    info[i] = pii(1, i);
  }
  int cnt = 9;
  //cnt = k+1で終了
  if (k <= 9) {
    cout << k << endl;
    return 0;
  }

  ll tens = 1;
  int keta = 2;
  while (1) {
    for (ll h = 1; h <= 9; h++) {
      int i = 0, imax = 0;
      while(lunlun[imax] != -1) imax++;
      //cout << "h " << h << endl;
      while(i < imax) {
        ll a = lunlun[i];
        //cout << "i " << i << " a " << a << endl;
        int ak = info[i].first;
        int ah = info[i].second;

        if (ak != keta-1) {
          if ((h == 1) && ((ah == 1) || (ah == 0))) {
            cnt++;
            lunlun[cnt] = (ll) (tens * 10 * h) + a;
            info[cnt] = pii(keta, h);
            //cout << lunlun[cnt] << endl;
          }
        }

        else {
          if ((-1 <= ah - h) && (ah - h <= 1)) {
            cnt++;
            lunlun[cnt] = (ll) (tens * 10 * h) + a;
            info[cnt] = pii(keta, h);
            //cout << lunlun[cnt] << endl;
          }
        }

        if (cnt == k) {
          cout << (ll) lunlun[k] << endl;
          //cout << info[k].first << " " << info[k].second << endl;
          return 0;
        }        
        //
        i++;
      }
      i = 0;
    }

    keta++;
    tens *= 10;
  }
  
}

Measured memory_bytes: 1792
H = int(input())
B = [int(i) for i in input().split()]

def left(i):
    return i*2

def right(i):
    return i*2 + 1

def maxHeapify(A, i):
    H = len(A)
    l = left(i)
    r = right(i)
    if l <= H and A[l-1] > A[i-1]:
        largest = l
    else:
        largest = i
    if r <= H and A[r-1] > A[largest-1]:
        largest = r
    if largest != i:
        A[i-1], A[largest-1] = A[largest-1], A[i-1]
        A = maxHeapify(A, largest)
    return A

def buildMaxHeap(A):
    H = len(A)
    for i in range(H//2, 0, -1):
        A = maxHeapify(A,i)
    return A

A = buildMaxHeap(B)
print("", *A)


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

using namespace std;
int _w;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if( c > a + b ) {
		cout << a + b + 1 + b << endl;
	} else {
		cout << c + b << endl;
	}
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int D;
vll C, T;
vvll S;

ll calcScore(vll &T) {
	vll last(26, -1);	
	ll score = 0;
	for (int i = 0; i < D; i++) {
		score += S[i][T[i]];
		last[T[i]] = i;
		for (int j = 0; j < 26; j++) {
			score -= (i-last[j])*C[j];
		}
	}
	return (score);
}

void Main() {
	cin >> D;
	C = makeVector(26, 0ll); cin >> C;
	S = makeVector(D, 26, 0ll); cin >> S;
	T = makeVector(D, 0ll); cin >> T;
	for (int i = 0; i < D; i++) --T[i];

	int M; cin >> M;
	for (int i = 0; i < M; i++) {
		int d, q; cin >> d >> q; --d, --q;
		T[d] = q;
		cout << calcScore(T) << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3672
#B_Exchange
a, b, k = list(map(int, input().split()))
ab = [a, b]
for i in range(k):
    if ab[i%2] % 2 == 1:
        ab[i%2] -= 1
        
    if i%2 == 0:
        ab[i%2+1] += ab[i%2]/2
        ab[i%2] /= 2
    else:
        ab[i%2-1] += ab[i%2]/2
        ab[i%2] /= 2

print(int(ab[0]), int(ab[1]))

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  ll X,Y,Z; cin >> X >> Y >> Z;
  int K; cin >> K;
  ll A[1010],B[1010],C[1010];
  for ( int i = 0; i < X; i++ ) cin >> A[i];
  for ( int i = 0; i < Y; i++ ) cin >> B[i];
  for ( int i = 0; i < Z; i++ ) cin >> C[i];
  if ( X*Y*Z < 3000 ) {
    vector<ll> ABC;
    for ( int i = 0; i < X; i++ ) {
      for ( int j = 0; j < Y; j++ ) {
	for ( int k = 0; k < Z; k++ ) {
	  ABC.push_back(A[i]+B[j]+C[k]);
	}
      }
    }

    sort(ABC.begin(),ABC.end(),greater<ll>());
    for ( int i = 0; i < K; i++ ) {
      cout << ABC[i] << endl;
    }
  } else {
    vector<ll>AB;
    for ( int i = 0; i < X; i++ ) {
      for ( int j = 0; j < Y; j++ ) {
	AB.push_back(A[i]+B[j]);
      }
    }
    sort(AB.begin(),AB.end(),greater<ll>());
    vector<ll>ABC;
    sort(C,C+Z,greater<ll>());
    for ( int i = 0; i < min(10000,(int)AB.size() ); i++ ) {
      for ( int j = 0; j < Z; j++ ) {
	ABC.push_back(AB[i]+C[j]);
      }
    }
    sort(ABC.begin(),ABC.end(),greater<ll>());
    for ( int i = 0; i < K; i++ ) {
      cout << ABC[i] << endl;
    }
    
  }

  
  return 0;
}


Measured memory_bytes: 141660
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int h, w; cin >> h >> w;

	vector<vector<int> > c(10, vector<int>(10));
	REP(i, 10) REP(j, 10) cin >> c[i][j];
	// k が経由するポイント
	REP(k, 10) REP(i, 10) REP(j, 10)
		if (c[i][j] > c[i][k] + c[k][j])
			c[i][j] = c[i][k] + c[k][j];

	int res = 0;
	REP(i, h) REP(j, w) {
		int a; cin >> a;
		if (a >= 0) res += c[a][1];
	}

	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    vector<int>A(N,0);
    REP(i,N)cin>>A[i];
    bool okz=true;
    REP(i,N){
        if(A[i]!=0)okz=false;
    }
    bool oko=false;
    sort(A.begin(),A.end());
    if(N%3==0){
        if(A[0]==A[N/3-1]&&A[N/3]==0&&A[N-1]==0)oko=true;
    }
    bool okt=false;
    if(N%3==0){
        if((A[0]^A[N/3]^A[N*2/3])==0&&A[0]==A[N/3-1]&&A[N/3]==A[N*2/3-1]&&A[N*2/3]==A[N-1]){
            okt=true;
        }
    }
    if(oko||okt||okz)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdbool.h>

int main() {
  int i,j,N,v;
  int k=0,l=0;
  bool flg=true;
  int Min;
  int A[100];

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    /* code */
    scanf("%d", &A[i]);
  }
  if (flg==true) {


  for ( i = 0; i < N-1; i++) {
    /* code */
    Min=i;
    flg=false;
    for (j = i; j < N; j++) {
      /* code */
      if (A[j] < A[Min]){
        Min=j;
      }


    }
  if(A[i]!=A[Min]){
    v=A[i];
    A[i]=A[Min];
    A[Min]=v;
    k++;
    }

  }
}
  printf("%d", A[0]);

  for ( i = 1; i < N; i++) {
    printf(" %d", A[i]);
  }
  printf("\n");
  printf("%d\n", k);
  return 0;
}



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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using piii = pair<int, pii>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	REP(i, h) cin >> s[i];
	int b = 0;
	REP(i, h) REP(j, w) if(s[i][j] == '#') b++;
	priority_queue<piii, vector<piii>, greater<piii> >que;
	vector<vi> cost(h, vi(w, INF));
	cost[0][0] = 1;
	que.push({1, {0, 0}});
	while(!que.empty()){
		auto e = que.top(); que.pop();
		if(cost[e.Y.X][e.Y.Y] < e.X) continue;
		for(int i = 0; i < 4; ++i){
			int x = e.Y.X + dx[i], y = e.Y.Y + dy[i];
			if(x < 0 || x >= h || y < 0 || y >= w || s[x][y] == '#' || cost[x][y] <= cost[e.Y.X][e.Y.Y] + 1) continue;
			cost[x][y] = cost[e.Y.X][e.Y.Y] + 1;
			que.push({cost[e.Y.X][e.Y.Y] + 1, {x, y}});
		}
	}
	if(cost[h - 1][w - 1] == INF) cout << "-1\n";
	else cout << h * w - b - cost[h - 1][w - 1] << "\n";
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  vector<int>b=a;
  sort(a.begin(),a.end(),greater());
  for(int i=0;i<n;i++){
    if(b.at(i)==a.at(0))
      cout << a.at(1) << endl;
    else
      cout << a.at(0) << endl;
  }
  return 0;
}

Measured memory_bytes: 4828
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back

using namespace std;

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

int a[500];

int main(){
     
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
        
	int n , ans = 0;
	cin >> n;

	for(int i = 0 ; i < 2*n ; i++)
	   cin >> a[i];

	sort(a , a+2*n);

	for(int i = 0 ; i < 2*n ; i+=2)
	   ans += a[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1 or M == 1:
    ans = max(N, M) -2
elif N == 2 or M == 2:
    ans = 0
else:
    ans = (N-2) * (M -2)
print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(void)
{
	int a, b;

	cin >> a >> b;
	
	if( a > b )
	{
		cout << "a > b" << endl;
	}
	else if( a < b )
	{
		cout << "a < b" << endl;
	}
	else
	{
		cout << "a == b" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
table[9999][9999],j;
main(p,W,a,b,c){
	for(;scanf("%d",&W),W;){
		for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)table[c-1][j]=(j<a)?table[c][j]:(table[c][j]>table[c][j-a]+b)?table[c][j]:(table[c][j-a]+b);
		for(j=0;table[0][j]!=table[0][W];j++);
		printf("Case %d:\n%d\n%d\n",p++,table[0][W],j);
	}
}

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

int main(void){
    int a,b;
    string m;
    cin >> a >> b;
    if(a < b) m = "<";
    if(a == b) m = "==";
    if(a > b) m = ">";
    cout << "a " << m << " b" << endl;
    return 0;
}

Measured memory_bytes: 3100
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}


int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	long long total = 0;
	vector<int> a(n), b(n);
	int max_b = 1e9+1;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		total += a[i];
		if (b[i] < a[i])
			max_b = min(max_b, b[i]);
	}

	if (a == b)
	{
		cout << 0;
	}
	else
	{
		cout << total - max_b;
	}



	return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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 getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	s, t := getString(), getString()
	r := ""
	for i := 0; i < N; i++ {
		r = r + string(s[i]) + string(t[i])
	}
	out(r)
}


Measured memory_bytes: 1788
S = input()
count = len(S)-1
for i in range(2**count):
  sign=['-']*count
  for j in range(count):
    if ((i>>j)&1):
      sign[j]='+'
  formula=''
  for k in range(count):
    formula += S[k] + sign[k]
  formula += S[count]
  if eval(formula)==7:
    print(formula+'=7')
    break

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    LL ans = 1000 * 1000 * 1000;
    for(LL i = 0; i < 1000 * 1000; ++i){
        LL cost = c * i * 2;
        cost += max<LL>(0, x-i) * a;
        cost += max<LL>(0, y-i) * b;
        ans = min<LL>(ans, cost);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q;
#define Maxn 200010
int mins[Maxn];

inline void rd(int &x){
    x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
}

int main(){
    memset(mins,127,sizeof(mins));
    rd(n);rd(m);rd(q);
    int x,y;
    for(register int i=1;i<=q;++i){
        rd(x);rd(y);
        x--;y--;
        mins[x]=min(mins[x],y);
    }
    int right=0;
    for(register int i=1;i<n;++i)
        if(right>=mins[i]){
            printf("%d\n",i);
            return 0;
        }else if(right+1<mins[i])right++;
    printf("%d\n",n);
    return 0;
}

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

using namespace std;

int main()
{
	long N;
	cin >> N;
	
	vector<long> a(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i + 1];
	}
	
	vector<long> b(N + 1);
	
	// 大きい倍数から処理する
	for (long i = N; i >= 1; i--)
	{
		long sum = 0;
		
		// i以外の倍数をの総和
		for (int j = i + i; j <= N; j += i)
		{
			sum += b[j];
		}
		
		sum %= 2;
		// ボールの総数を2で割った余りの数がa[i]でない場合に
		if (sum != a[i])
		{
			// 現在のiの箱にボールをいれます。
			b[i] = 1;
		}
	}
	
	vector<long> answer;
	
	// 1の倍数からNの倍数の箱
	for (long i = 1; i <= N; i++)
	{
		// ボールがある場合
		if (b[i])
		{
			// ボールを入れる箱に書かれた整数を格納する
			answer.push_back(i);
		}
	}
	
	// 出力
	cout << answer.size() << endl;
	for (int i = 0; i < answer.size(); i++)
	{
		cout << answer[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4980
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){for(var e=t.in(),n=0,r=1;n<e;)n+=r,r++;for(var i=[],s=0,o=--r;o>=1;o--)s+o<=e&&(s+=o,i.push(o));console.log(i.join("\n"))}}]);

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

int main() {
  int n; cin>>n;
  vector<int> h(n);
  rep(i,n){
    cin>>h.at(i);
  }
  int ans=0, c=0, i=0;
 
  while(i<n-1){   
    if(i==n-2&&h.at(i)>=h.at(i+1)){
      c++;ans=max(ans,c);}
    if(h.at(i)>=h.at(i+1)){c++;}
    else{ans=max(ans,c);c=0;}
    i++;
  }
  cout<<ans;
 
 
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

class UnionFind
{
public:
    vs32 p;

    UnionFind() {}
    UnionFind(int size)
    : p(vs32(size, -1))
    {}

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        x = findSet(x); y = findSet(y);
        if (x == y) return;

        if (p[x] > p[y]) swap(x, y);
        p[x] += p[y];
        p[y] = x;
    }

    int findSet(int x)
    {
        if (p[x] < 0) return x;
        else return p[x] = findSet(p[x]);
    }
};

int kruskal(int n, vector< pair<int, P> >& edge, int ng)
{
    int ret = 0;
 
    UnionFind uf(n);
    rep (i, edge.size())
    {
        int u, v, c;
        c = edge[i].first;
        u = edge[i].second.first;
        v = edge[i].second.second;
        if (i == ng || uf.same(u, v)) continue;

        uf.unite(u, v);
        ret += c;
    }

    return ret;
}

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

    int n, m;
    cin >> n >> m;

    vector< pair<int, P> > edge(m);
    rep (i, m)
    {
        int s, d, c;
        cin >> s >> d >> c;
        --s, --d;
        edge[i] = make_pair(c, P{s, d});
    }

    sort(edge.begin(), edge.end());

    int cost = 0;
    UnionFind uf(n);
    vs32 ng;
    rep (i, m)
    {
        int u, v, c;
        c = edge[i].first;
        u = edge[i].second.first;
        v = edge[i].second.second;
        if (!uf.same(u, v))
        {
            uf.unite(u, v);
            ng.push_back(i);
            cost += c;
        }
    }

    int num = 0;
    int ans = 0;
    rep (i, ng.size())
    {
        if (cost != kruskal(n, edge, ng[i]))
        {
            ++num;
            ans += edge[ng[i]].first;
        }
    }

    cout << num << " " << ans << "\n";
    return 0;
}




Measured memory_bytes: 3312
#include <stdio.h>
#include <math.h>

int main()
{
    double x[2], y[2], a;
    
    scanf("%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1]);
    a = sqrt(pow((x[1]-x[0]), 2) + pow((y[1]-y[0]), 2));
    printf("%f\n", a);
    
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

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

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int count = 0;
    while (B <= A) {
        ++count;
        B *= 2;
    }
    while (C <= B) {
        ++count;
        C *= 2;
    }

    cout << (count <= K ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3608
import math
n = int(input())
a = 0
for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
        a = i
b = n//a
j = 0
while True:
    m = b / (10**j)
    if m>=1 and m<10:
        ans = j+1
        break
    j+=1

print(ans)


Measured memory_bytes: 9164
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; i++) { cin >> a[i]; }
    for (int i = 0; i < y; i++) { cin >> b[i]; }
    for (int i = 0; i < z; i++) { cin >> c[i]; }

    vector<ll> ab;
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        ab.push_back(a[i] + b[j]);
      }
    }

    sort(ab.begin(), ab.end());
    reverse(ab.begin(), ab.end());

    vector<ll> abc;
    for (int i = 0; i < min(k, (int)ab.size()); i++) {
      for (int j = 0; j < z; j++) {
        abc.push_back(ab[i] + c[j]);
      }
    }
    sort(abc.begin(), abc.end());
    reverse(abc.begin(), abc.end());

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

    return 0;
}

Measured memory_bytes: 43368
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    vector<int> v;
    for(int i=0; i<3; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    int ans=0;
    for(int i=2; i>=1; --i){
        ans += abs(v[i]-v[i-1]);
    }
    cout << ans << endl;
    return 0;
}
        

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct Cat {
  int s;
  int w, c;
  Cat() {}
  Cat(int s, int w, int c) : s(s),w(w),c(c) {}
  bool operator<(const Cat &rhs) const {
    return c < rhs.c;
  }
};

Cat cats[1000];
int dp[2][10001];
int Na, Nb, W;
bool exist[2];

bool add(int &x) {
  if (x == Na+Nb) return 0;
  int s = cats[x].s;
  exist[s] = 1;
  for (int i=W-cats[x].w; i>=0; --i) {
    int w = i+cats[x].w;
    if (i == 0 || dp[s][i] != -1) {
      if (i == 0) dp[s][w] = x;
      else dp[s][w] = max(dp[s][w], dp[s][i]);
    }
  }
  x++;
  return 1;
}

bool erase(int &x) {
  if (x == Na+Nb) return 0;
  bool f = 0;
  int s = cats[x].s;
  REP(i,W+1) {
    if (dp[s][i] == x) dp[s][i] = -1;
    if (dp[s][i] != -1) f = 1;
  }
  exist[s] = f;
  x++;
  return 1;
}

int main() {
  cin >> Na >> Nb >> W;
  REP(i,Na) {
    int m, c;
    cin >> m >> c;
    cats[i] = Cat(0,m,c);
  }
  REP(i,Nb) {
    int m, c;
    cin >> m >> c;
    cats[i+Na] = Cat(1,m,c);
  }
  sort(cats,cats+Na+Nb);
  memset(dp,-1,sizeof(dp));
  // REP(i,Na+Nb) {
  //   cout << cats[i].s << " " << cats[i].c << " " << cats[i].w << endl;
  // }

  // dp[0][0] = 100000;
  // dp[0][0] = 100000;
  int head=0, tail=0;
  int ans = INT_MAX;
  while(1) {
    while(!exist[0]||!exist[1]) {
      if (!add(head)) break;
    }
    if (!exist[0]||!exist[1]) break;
    int w = INT_MAX;
    int p[2] = {-2000000000,-2000000000};
    REP(i,W+1) {
      REP(j,2) {
        if (dp[j][i] >= 0) {
          w = min(w, abs(i-p[j^1]));
          p[j] = i;
        }
      }
    }
    int c = cats[head-1].c-cats[tail].c;
    // cout << w << " " << c << endl;
    // cout << head << ", " << tail << endl;
    
    ans = min(ans, max(w, c));
    if (w > c) {
      if (!add(head)) break;
    } else {
      if (!erase(tail)) break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1264
N = int(input())
A = []
Cnt = 0

for i in range(N):
    A.append(int(input()))


def InsertSort(g):
    global A, N, Cnt
    for i in range(g, N):
        j = i - g
        v = A[i]
        while j >= 0 and A[j] > v:
            Cnt += 1
            A[j + g] = A[j]
            j -= g
        A[j + g] = v


G = []
l = 0
while l <= N:
    G.append(l)
    l = 3 * l + 1
G.reverse()
s = ''
for g in G:
    s += str(g) + ' '
    InsertSort(g)
print(len(G))
print(s.rstrip())
print(Cnt)
for a in A:
    print(a)







Measured memory_bytes: 45512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

vector<string> vs;

ll power(ll a,ll b/*,ll mod*/){
    ll ret=1;
    if(b>0){
        ret = power(a,b/2/*,mod*/);
        if(b%2==0)ret = (ret*ret)/*%mod*/;
        else ret = (((ret*ret)/*%mod*/)*a)/*%mod*/;
    }
    return ret;
}

set<char> cant_zero;

map<char,ll> solve(vector<string> vs){
    map<char,ll> mp;
    rep(i,vs.size()-1){
        rep(j,vs[i].size()){
            mp[vs[i][j]]+=power(10,vs[i].size()-j-1);
        }
    }
    
    string right = vs[vs.size()-1];
    rep(i,right.size()){
        mp[right[i]]-=power(10,right.size()-i-1);
    }
    
    return mp;
}


vector<pair<ll,ll>> getValue(vector<char> v,map<char,ll> mp){
    vector<pair<ll,ll>> ret;
    int en = power(10,v.size());
    rep(i,en){
        int num=i;
        vector<int> t;
        rep(i,v.size()){
            t.pb(num%10);
            num/=10;
        }
        reverse(all(t));
        if(set<int>(all(t)).size()!=v.size())continue;
        
        bool f=false;
        rep(i,t.size()){
            if(t[i]==0&&cant_zero.count(v[i]))f=true;
        }
        if(f)continue;
        
        ll tmp=0;
        ll bit=0;
        rep(i,t.size()){
            tmp += mp[v[i]]*t[i];
            bit+=1<<t[i];
        }
        ret.pb(make_pair(tmp,bit));
    }
    return ret;
}


int main(){
    int n;
    while(cin>>n&&n){
        vs.clear();
        vs.resize(n);
        rep(i,n)cin>>vs[i];
        
        cant_zero.clear();
        rep(i,vs.size()){
            if(vs[i].size()==1)continue;
            cant_zero.insert(vs[i][0]);
        }
        
        map<char,ll> mp = solve(vs);
        
        int m = mp.size();
        
        vector<char> vl,vr;
        int c=0;
        for(auto &e:mp){
            if(c<m/2)vl.pb(e.first);
            else vr.pb(e.first);
            c++;
        }
        
        vector<pair<ll,ll>> a = getValue(vl,mp);
        vector<pair<ll,ll>> b = getValue(vr,mp);
        
        int ans=0;
        
        sort(all(a));
        sort(all(b));
        
        rep(i,a.size()){
            ll val = a[i].first;
            ll stat= a[i].second;
            
            int pos = lower_bound(all(b),pair<ll,ll>(-1*val,0))-b.begin();
            
            for(int j=pos;j<b.size();j++){
                if(b[j].first!=-1*val)break;
                
                if((b[j].second & stat)==0 ){
//                    cout<<bitset<10>(stat)<<" "<<bitset<10>(b[j].second)<<endl;
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	long long result = 0;
	for (int i = 1; i <= N; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;

		result += i;
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 3652
n, q = gets.chomp.split.map(&:to_i)
p_list = {}
current_time = 0

n.times do
  p, t = gets.chomp.split
  p_list[p] = t.to_i
end

while !p_list.empty?
  p_list.each_pair do |pr, time|
    p_list[pr] = time - q
    if p_list[pr] <= 0
      current_time += time
      puts pr + " " + current_time.to_s
      p_list.delete(pr)
    else
      current_time += q
    end
  end
end

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

using namespace std;

main()
{
    int a,b,k;

    cin >>a>>b>>k;

    int i,j=0;
    int  l=__gcd(a,b);
    //l=sqrt(l);


    for(i=l;;--i)
    {
        if(a%i==0 && b%i==0)
        {
            j++;
            if(j==k)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    multiset<int> mst;

    REP(i,n) {
        int a; cin >> a;
        mst.insert(a);
    }

    int ans = 0;
    while(!mst.empty()) {
        auto back = mst.end();
        back--;
        int x = *back;
        mst.erase(back);
        double l2 = log2(x);
        if (l2 == floor(l2)) {
            auto it = mst.find(x);
            if (it != mst.end()) {
                ans++;
                mst.erase(it);
            }
        } else {
            int x2 = pow(2,ceil(l2));
            auto it = mst.find(x2-x);
            if (it != mst.end()) {
                ans++;
                mst.erase(it);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int W, H;
vector<vector<int>> field;

void dfs(int h, int w) {
    field[h][w] = 0;
    
    for (int dh = -1; dh <= 1; dh++) {
        for (int dw = -1; dw <= 1; dw++) {
            int nh = h + dh;
            int nw = w + dw;
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (field[nh][nw] == 0) continue;

            dfs(nh, nw);
        }
    }
}

int main() {
    while(cin >> W >> H) {
        if (H == 0 && W == 0) break;
        field.assign(H, vector<int>(W, 0));
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                cin >> field[h][w];
            }
        }

        int cnt = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (field[h][w] == 0) continue;
                dfs(h, w);
                cnt++;
            }
        }

        cout << cnt << endl;
    }
    return 0;
}


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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double s = w*h/2;
  cout << s << endl;
  if (w == 2*x && h == 2*y)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ret = 0;
		int cnt = 0;

		Integer array[] = new Integer[n];

		for (int i = 0; i < n; i++) {
			array[i] = (sc.nextInt());
		}

		Arrays.sort(array, Comparator.reverseOrder());

		while(cnt < k){
			ret = ret + array[cnt].intValue();

			cnt++;
		}

		System.out.println(ret);

		sc.close();
	}
}

Measured memory_bytes: 21716
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int count(int N)
{
        int cnt = 0;
        while (N % 2 == 0)
        {
                cnt++;
                N /= 2;
        }
        return cnt;
}

int main()
{
        int N;
        cin >> N;
        vector<int> A(N + 1);
        rep(i, N) cin >> A[i];
        sort(A.begin(), A.begin() + N);

        cout << A[N - 1] - A[0] << endl;
        return 0;
}


Measured memory_bytes: 256
N = int(input())
tmp_A = list(map(int, input().split(" ")))

# 重複要素の削除
A = []
idx = 0
while idx < N:
    A.append(tmp_A[idx])
    while idx + 1 < N and tmp_A[idx] == tmp_A[idx + 1]:
        idx += 1
    idx += 1


if len(A) == 1:
    print(1)
else:
    diff = []
    for i in range(len(A) - 1):
        if A[i] < A[i + 1]:
            diff.append(1)
        else:
            diff.append(-1)

    ans = 0
    idx = 0
    while idx + 1 < len(diff):
        if diff[idx] != diff[idx + 1]:
            ans += 1
            idx += 1
        idx += 1

    print(ans + 1)

Measured memory_bytes: 64552
#include <stdio.h>

int main(){
   int i, n, k, d, a;
   scanf("%d %d", &n, &k);
   int data[n];
   for(i = 0; i < n; i++){
      data[i] = 0;
   }
   for(i = 0; i < k; i++){
      scanf("%d", &d);
      for(int j = 0; j < d; j++){
         scanf("%d", &a);
         data[a-1]++;
      }
   }
   int count = 0;
   for(i = 0; i < n; i++){
      if(data[i] == 0){
         count++;
      }
   }
   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

using ll = long long;
using ld = long double;
using lli = long long int;
using ull = unsigned long long;

#define PI 3.14159265358979323846264338327950L

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

  if(X >= 30){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  
  return 0;
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    left = [a[0]] * N
    right = [b[-1]] * N

    for i in range(1, N):
        left[i] = left[i-1] + a[i]
    for i in range(N-2, -1, -1):
        right[i] = right[i+1] + b[i]

    ans = 0
    for i in range(N):
        ans = max(ans, left[i]+right[i])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
ma = lambda : map(int,input().split())
n = int(input())
A = list(ma())
B = list(ma())
ans = 0
tmp = 0
for i in range(n):
    for j in range(2):
        tmp = B[i]
        ans += min(B[i],A[i+j])
        B[i] =max(B[i]-A[i+j],0)
        A[i+j] = max(0,A[i+j]-tmp)
print(ans)


Measured memory_bytes: 18468
n=io.read"*n"
a,b,c={},{},{}for i=1,n do
a[i]=io.read"*n"
b[i]=io.read"*n"
c[i]=io.read"*n"end

dp={{a[1],b[1],c[1]}}
for i=2,n do dp[i]={}end

for i=2,n do
dp[i][1]=math.max(dp[i-1][2],dp[i-1][3])+a[i]
dp[i][2]=math.max(dp[i-1][3],dp[i-1][1])+b[i]
dp[i][3]=math.max(dp[i-1][1],dp[i-1][2])+c[i]
end
print(math.max(dp[n][1],dp[n][2],dp[n][3]))

Measured memory_bytes: 12928
# coding: utf-8

import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect


def solve(cs, next_p):
    if len(cs[next_p]) == 0:
        return ["A", "B", "C"][next_p]

    c = cs[next_p][0]
    cs[next_p].pop(0)
    if c == "a":
        return solve(cs, 0)
    if c == "b":
        return solve(cs, 1)
    if c == "c":
        return solve(cs, 2)



a = list(input().strip())
b = list(input().strip())
c = list(input().strip())
cs = [a, b, c]

print(solve(cs, 0))


Measured memory_bytes: 5676
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			
			a = stdIn.next();
			for(int i = 0; i < n; i++) {
				solv();
			}
			System.out.println(a);
		}
	}
	public static void solv() {
		int count = 0;
		char now = a.charAt(0);
		StringBuffer tmp = new StringBuffer();
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) != now) {
				tmp.append(String.valueOf(count) + String.valueOf(now));
				count = 0;
				now = a.charAt(i);
			}
			if(i+1 == a.length()) {
				tmp.append(String.valueOf(count+1) + String.valueOf(now));
			}
			else {
				count++;
			}
		}
		a = tmp.toString();
	}
}

Measured memory_bytes: 50476
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    long X,Y;
    private void solve() {
        X = nextLong();
        Y = nextLong();

        long Z = X;
        int ans = 0;
        while(Z <= Y) {
            ans++;
            Z *= 2;
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21332