akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int dir(char[], char[]);
int main(void){
    int n,a,t=0,h=0;
    char T[108],H[108];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s",T,H);
        a=dir(T,H);
        if(a==0){
            t+=3;
        }else if(a==1){
            h+=3;
        }else{
            t++;
            h++;
        }
    }
    printf("%d %d\n",t,h);
    return 0;
}
int dir(char x[],char y[]){
    int c=0;
    while(x[c]!='\0' || y[c]!='\0'){
        if(x[c]<y[c]){
            return 1;
        }else if(x[c]>y[c]){
            return 0;
        }else{
            c++;
            continue;
        }
        c++;
    }
    return 2;
}


Measured memory_bytes: 2128
a,b,c,x = 4.times.map { gets.to_i}
cnt = 0
  (0..a).each do |i|
    (0..b).each do |j|
      (0..c).each do |k|
        cnt += 1 if i * 500 + j * 100 + k * 50 == x
      end
    end
  end
puts cnt

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

int main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    swap(X,Y);
    swap(X,Z);
    cout << X << " " << Y << " " << Z << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

}

Measured memory_bytes: 21460
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N = int(input())
S = list(map(int ,input().split()))
lcm_1 = lcm(S)-1
max_sum = 0
for i in range(N):
    max_sum += lcm_1%S[i]

print(max_sum)

Measured memory_bytes: 5164
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;


int pgcd(int a,int b)
{
    return a==0?b:pgcd(b%a,a);
}

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        cout<<pgcd(a,b)<<endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, M;
    cin >> N >> M;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());

    ll left = 0, right = 2 * 1e5 + 1;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll cnt = 0;
        int j = N - 1;
        for (int i = 0; i < N; i++) {
            while (j >= 0 && A[i] + A[j] < mid) --j;
            cnt += j + 1;
        }
        if (cnt < M) {
            right = mid;
        }
        else {
            left = mid;
        }
    }

    reverse(A.begin(), A.end());
    Vl csum(N + 1);
    for (int i = 0; i < N; i++) {
        csum[i + 1] = csum[i] + A[i];
    }
    ll cnt = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int a = upper_bound(A.begin(), A.end(), left - A[i]) - A.begin();
        int num = N - a;
        cnt += num;
        ans += csum[N] - csum[a] + A[i] * num;
    }
    ans += left * (M - cnt);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
s = input()

# RLの組で区切っていく
in_r = False
in_l = True
pair = []  # list of (len(R), len(L))
n_r = 0
n_l = 0
for i in range(len(s)):
    if s[i] == 'R' and in_l:
        in_r = True
        in_l = False
        if i != 0:
            pair.append((n_r, n_l))
        n_r = 1
        n_l = 0
    elif s[i] == 'R' and in_r:
        n_r += 1
    elif s[i] == 'L' and in_l:
        n_l += 1
    else:
        in_r = False
        in_l = True
        n_l += 1
pair.append((n_r, n_l))

result = []
# 各組ごとに求める
for i in range(len(pair)):
    n_r, n_l = pair[i]
    x = [0] * (n_r + n_l)
    y = (n_r + n_l) // 2
    z = (n_r+n_l) - y  # z >= y
    n_stable = max(n_r, n_l) - 1
    if n_stable % 2 == 0:
        if n_r > n_l:
            x[n_r-1] = z
            x[n_r] = y
        else:
            x[n_r-1] = y
            x[n_r] = z
    else:
        if n_r > n_l:
            x[n_r-1] = y
            x[n_r] = z
        else:
            x[n_r-1] = z
            x[n_r] = y
    result.extend(x)

print(" ".join([str(x) for x in result]))


Measured memory_bytes: 14076
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n; cin >> n; set<string> siritori; bool flag = true;
 
  string s; cin >> s; siritori.insert(s);
  char last = s[s.size()-1];
  
  rep(i,n-1){
    cin >> s; 
    if(s[0] != last or siritori.count(s)) flag = false;

    last = s[s.size()-1];
    siritori.insert(s);
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3620
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

const int max_n = 305;
int dp[max_n][max_n][max_n][2];
// prefix, actions, rented "1"s, kekflag

const int mod = 998244353;
int add(int a, int b) {
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}

void incr(int& a, int b) {
    a = add(a, b);
}

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

    // code here
    string s;
    cin >> s;
    int lim = input<int>();
    int n = SZ(s);
    
    dp[0][0][0][0] = 1;

    for (int i = 0; i < n; ++i) for (int act = 0; act <= n; ++act) for (int rent = 0; rent <= n; ++rent)
        for (int kekflag = 0; kekflag < 2; ++kekflag) {
            if (s[i] == '0') {
                incr(dp[i + 1][act][rent][0], dp[i][act][rent][kekflag]); // write 0
                if (kekflag == 0)
                    incr(dp[i][act + 1][rent + 1][0], dp[i][act][rent][kekflag]); // write 1^+ 0
            } else {
                if (kekflag == 0)
                    incr(dp[i + 1][act][rent][0], dp[i][act][rent][kekflag]); // write 1
                
                if (rent)
                    incr(dp[i + 1][act][rent - 1][1], dp[i][act][rent][kekflag]); // don't write (planing to write "0" next, then)
            }
        }
    
    int ans = 0;
    for (int i = 0; i <= min(max_n - 1, lim); ++i)
        for (int t = 0; t < 2; ++t)
            ans = add(ans, dp[SZ(s)][i][0][t]);

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


Measured memory_bytes: 221336
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

int main()
{
    Phuong_; /// <3
    int n;
    cin >> n;
    int minn,maxx;
    cin >> minn;
    maxx=minn;
    n--;
    while(n--)
    {
        int u;
        cin >> u;
        minn=min(minn,u);
        maxx=max(maxx,u);
    }
    cout << maxx-minn;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        List<int> a = new List<int>();
        a.Add(0);
        a.AddRange(Console.ReadLine().Split().Select(int.Parse).ToArray());
        a.Add(0);
        List<int> b = new List<int>();
        for (int i = 0; i < n+1; i ++) b.Add(Math.Max(a[i],a[i+1]) - Math.Min(a[i],a[i+1]));
        int sum = b.Sum();
        for (int i = 0; i < n; i ++) {
            int result = sum;
            result -= b[i]+b[i+1];
            result += Math.Max(a[i],a[i+2]) - Math.Min(a[i],a[i+2]);
            Console.WriteLine(result);
        }
    }
}

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

int main()
{
    string s;
    cin >> s;
    int a(0), b(0) ;
    rep(i,3)
    {
        if(s.at(i)=='A')
        {
            a++;
        }
        else
        {
            b++ ;
        }
        
    }
    if(a&&b)
    {
        cout << "Yes" << endl ;
    }
    else
    {
        cout << "No" << endl ;
    }
    
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n;
  int k;
  cin >> n >> k;
  bool snuke[101] = {};
  LOOP(i,k){
    int d;
    cin >> d;
    LOOP(j,d){
      int a;
      cin >> a;
      snuke[a] = true;
    }
  }
  int ans = 0;
  LOOP1(i,n){
    if(!snuke[i])ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
int t[501][501];
int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n,m,q;
    std::cin >> n >> m >> q;

    for(int i=0;i<m;i++)
    {
        int l, r;
        std::cin >> l >> r;
        t[l][r]++;
    }
    for(int i=1;i<=500;i++)
    {
        for(int j=1;j<=500;j++)
            t[i][j] = t[i][j-1] + t[i][j];
    }
    for(int i=0;i<q;i++)
    {
        int l,r;
        std::cin >> l >> r;
        int ans = 0;
        for(int j=l;j<=r;j++)
        {
            ans += t[j][r] - t[j][j-1];
        }
        std::cout << ans << '\n';
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int mul(int a, int b){
  a %= MOD;
  b %= MOD;
  if (b==0) return 0;
  int res = mul((a+a)%MOD, b>>1);
  if (b&1) res = (res + a) % MOD;
  return res;
};

signed main() {
  INIT;
	VAR(int, n, k);
  VEC(int,a,n);

  int ans = 0;
  REP(i,n){
    int cnt = 0;
    FOR(j,i+1,n){
      if (a[i] > a[j]) ++cnt;
    }
    (ans += (cnt * k) % MOD) %= MOD;
  }

  int kk = (k * (k-1) / 2) % MOD;
  REP(i,n){
    int cnt = 0;
    REP(j,n) {
      if (a[i] > a[j]) ++cnt;
    }
    (ans += (cnt * kk) % MOD) %= MOD;
  }

  OUT(ans)BR;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;


int main(){
    int n,m;
    cin >> n >> m;


    cout << (n-1)*(m-1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,x;
	scanf("%d %d %d",&a,&b,&c);
	
	while(1)
	{
		int n1,n2,x=0;
		if(a>b)
		{
			n1=a;
			a=b;
			b=n1;
			x=1;
		}
		else if(b>c)
		{
			n2=b;
			b=c;
			c=n2;
			x=1;
		}
		if(x==0) break;
	}
	printf("%d %d %d\n",a,b,c);
	
	
	return 0;
}


Measured memory_bytes: 2724
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a + b + 2 - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <iterator>
#include <algorithm>

typedef long long lint;

using namespace std;

void showIntArray(lint a[], lint n);

int main() {
  int A, B;

  cin >> A >> B;

  int ans;
  if (A >= 13) {
    ans = B;
  } else if (6 <= A && A <= 12) {
    ans = B / 2;
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}

void showIntArray(lint a[], lint n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  string str;
  cin>>str;
  ll ans = 0;
  for(int i=0;i<str.size();i++){
    ans += (int)str[i] - (int)'0';
  }
  if(ans%9 == 0)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


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

using namespace std;

int main(void) {
  
 int N, M;
 cin >> N >> M;
 vector<int> A(N);
 int count = 0;
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
    count += A.at(i);
  }

  double lim = (double)count / (4*M) ;

  sort(A.begin(), A.end(),greater<int>());
  
  if (A.at(M-1) >= lim) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

Int n, m, q;
Int x[20][20][20][20];

Int ans[20], max;

int main(){
	cin >> n >> m >> q;
	RC(i, q){
		Int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a;
		--b;
		for(Int j = 1; j + c <= m; ++j){
			x[a][j][b][j + c] = d;
		}
	}
	RC(i, n){
		ans[i] = 1;
	}
	ans[n - 1] = 0;
	for(;;){
		for(Int i = n - 1;; --i){
			if(ans[i] <= m - 1){
				++ans[i];
				for(Int j = i + 1; j < n; ++j){
					ans[j] = ans[j - 1];
				}
				break;
			}else if(i == 0){
				cout << max << endl;
				return 0;
			}
		}
		Int count = 0;
		RC(i, n) RC(j, i){
			count += x[j][ans[j]][i][ans[i]];
		}
		/*
		RC(i, n) cout << ans[i] << " ";
		cout << ": ";
		cout << count << endl;
		*/
		anth(max, count);
	}
}


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

map<long long ,long long > M;
long long st[3]={2,3,5};
long long fy[4];

long long dfs(long long n){
    if(M.count(n))return M[n];
    if(n==0)return M[0]=0;
    M[n]=1LL<<60;
    if(M[n]/fy[3]/n)M[n]=min(M[n],n*fy[3]);
    for(int i=0;i<3;i++){
        if(n%st[i]==0)M[n]=min(M[n],dfs(n/st[i])+fy[i]);
        else{
            M[n]=min(M[n],dfs(n/st[i])+fy[i]+n%st[i]*fy[3]);
            M[n]=min(M[n],dfs(n/st[i]+1)+fy[i]+(st[i]-n%st[i])*fy[3]);
        }
    }
    return M[n];
}

int main(){
    int T;
    cin>>T;
    while(T--){
        M.clear();
        long long N;
        scanf("%lld%lld%lld%lld%lld",&N,&fy[0],&fy[1],&fy[2],&fy[3]);
        printf("%lld\n",dfs(N));
    }
}

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

int main() {
  int N, M, C;
  int ans =0;
  cin >> N >> M >> C;
  vector<int>B(M);
  vector<vector<int>>A(N, vector<int>(M));
 
  
  for(int i=0; i<M; i++){
    cin >> B.at(i);
  }
  
  for(int i = 0; i<N; i++){
    for(int j=0;j<M; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(int i =0; i<N; i++){
    int left = 0;
    for(int j=0; j<M; j++){
      left += B.at(j)*A.at(i).at(j);
    }
    if(left + C >0){ans++;}
  }
  
  cout << ans << endl;
    
}


Measured memory_bytes: 3588
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n = 0, k = 0;   cin >> n >> k;
    string s;   cin >> s;
    if (s[k - 1] >= 'A' && s[k - 1] <= 'Z')
    {
        s[k - 1] = s[k - 1] - 'A' + 'a';
    }
    cout << s;
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

from bisect import bisect_left

N, H = map(int, input().split())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

a_max = max(A)
B.sort()
# 一番強い振る刀より弱い投げる刀はいらない
B2 = list(reversed(B[bisect_left(B, a_max):]))

cnt = 0
# 投げるだけで倒せるか
if H <= sum(B2):
    # 強い方から順番に投げる
    for i in range(len(B2)):
        cnt += 1
        H -= B2[i]
        if H <= 0:
            print(cnt)
            exit()
else:
    # 全部投げた結果
    H -= sum(B2)
    cnt += len(B2)
    # 倒すまでに振る回数
    cnt += -(-H // a_max)
    print(cnt)


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

using namespace std;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   long long ans = 0;
   for(int i = 1; i <= 1e6 + 4; i++) {
       ans += (n - 1) / i;
   }
   cout << ans << endl;
}

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

using namespace std;
const int N = 1e5 + 3;
int n, k;
int main() {
//	freopen("input.in", "r", stdin);
	
	scanf("%d %d", &n, &k);
	long double res = 0;
	for (int i = 1; i <= n; ++i) {
		long double score = i, cur = 1;
		while (score < k) {
			score *= 2;
			cur *= 0.5;
		}
		res += cur;
	}
	res *= (long double) 1 / n;
	printf("%.11Lf\n", res);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

k, n = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]

d = deque(data)
d.appendleft(0)
d.pop()

bet = [i-j for i, j in zip(data, d)]

bet[0] += k - data[-1]

print(k - max(bet))

Measured memory_bytes: 25292
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	string s;
	cin>>s;
	ll flag = 0;
	rep(i,0,s.sz-1){
		if(s[i]=='A'&&s[i+1]=='C'){
			flag = 1;
		}
	}
	if(flag==1){
	    cout << "Yes" << endl;
	}
	else{
	    cout << "No" << endl;
	}
	return 0;
}

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


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

vll graph[200000] = {};
lli score[200000] = {};
lli answer[200000] = {};

void dfs(int i,int s) {

	s += score[i];
	answer[i] = s;

	for(int j = 0;j < graph[i].size(); j++)
		if(answer[graph[i][j]] == -1)
			dfs(graph[i][j],s);

	return;
}

lli ans[2000] = {};

int main(void) {

	lli n, x, y;
	cin >> n >> x >> y;
	x--; y--;

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

			lli min_dis = j - i;

			//通らない

			//x-yを通る

			min_dis = min(min_dis,
				abs(i - x) + abs(j - y) + 1
				);

			ans[min_dis]++;

		}
	}

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



	return 0;
}

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

int dp[100001][3];

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j;
  cin >> n;
  int a[n][3];
  for (i = 0; i < n; i++)
  {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
  for (i = 1; i < n; i++)
  {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
    dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2];
  }
  cout << max(dp[n - 1][2], max(dp[i - 1][0], dp[i - 1][1])) << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
	int main(){
	char a;
	
	scanf("%c",&a);
	
	if(a >= 'a' && a<= 'z'){
		printf("a");
	}
	else if (a >= 'A'&& a<='Z'){
		printf ("A");
	}
	
	
		return 0;
	}

Measured memory_bytes: 1596
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;cin>>A>>B;
  
  int sumA=2*A-1;
  int sumAB=A+B;
  int sumB=2*B-1;
  
  cout<<max(max(sumA,sumB),sumAB)<<endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<iomanip>
int n; int ans=0; int s;
using namespace std;
int main()
{
	cin>>n;
	while(n!=0)
	{
		s=n%10;
		if(s==2) ans++;
		n/=10;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 100002
typedef long long ll;
ll N,M;

ll H[MAX];
ll main(){
    scanf("%d %d",&N,&M);
    for(ll i=1;i<=N;i++)
        scanf("%d",H+i);
    bool keep[MAX];
    memset(keep,true,sizeof(keep));
    for(ll i=1;i<=M;i++){
        ll a,b;
        scanf("%d %d",&a,&b);
        if(H[a] > H[b]) keep[b] = false;
        else if(H[a] < H[b]) keep[a] = false;
        else keep[a] = keep[b] = false;
    }
    ll ans=0;
    for(ll i=1;i<=N;i++){
        if(keep[i]) ans++;
    }
    printf("%d",ans);
}


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

struct union_find_tree1{
    vector<int> par;//0-indexed
    union_find_tree1(int sz){
        par.resize(sz); //サイズをszに変更
        for(int i=0;i<sz;++i) par[i] = i; //最初は自分が根
    }
    int find(int a){
        if(a==par[a]) return a;     //親が自分自身の時、自分が根である
        else return find(par[a]);   //そうでないなら自分に親を代入して辿る
    }
    void unite(int a,int b){
        int root_a = find(a),root_b = find(b);  //aの根,bの根を調べて代入。
        par[root_a] = root_b;       //根aの親をbにする
    }
    bool same(int a,int b){
        return find(a)==find(b);
    }
};

int main() {
    int n, q; cin >> n >> q;
    union_find_tree1 s(n);
    

    for (int i = 0; i < q; i++)
    {
        int com, x, y; cin >> com >> x >> y;
        if(com==0){
            s.unite(x, y);
        }else{
            if (s.same(x, y))
            {
                cout << 1 << endl;
            }else{
                cout << 0 << endl;
            }
            
        }
    }
    
}
//g++ -o d.exe d.cpp


Measured memory_bytes: 3140
import java.util.*;

class Main{           
  
   public static void main(String[] args){
         Scanner sc = new Scanner(System.in);  
         
         while(true){
             
             int n = sc.nextInt();
             int count = 0;
             if(n == 0){
                 break;
             }
             
             String S = "";
             for(int i = 0;i < n;i++){
                 S += sc.next();
             }
             S = S.replace("luru","h");
             S = S.replace("ldrd","h");
             S = S.replace("rulu","h");
             S = S.replace("rdld","h");
                  
             char s[]= S.toCharArray();
             
             for(int i = 0;i < s.length;i++){
                 if(s[i] == 'h'){
                     count++;
                 }
             }
             System.out.println(count);
         }
         
         
   }         
         
 }

Measured memory_bytes: 47476
read n
a=(`dd`)
a+=(AC WA TLE RE)
a=(`echo ${a[@]} | tr ' ' '\n' | sort | uniq -c`)
echo "${a[1]} x $((a[0]-1))"
echo "${a[7]} x $((a[6]-1))"
echo "${a[5]} x $((a[4]-1))"
echo "${a[3]} x $((a[2]-1))"


Measured memory_bytes: 36724
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;

typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define rep(i,n) for(int i = 0;i < n;i++)
   
#define MAX_N 200010

int num[100010];
int main(void){
   string s;cin >> s;
   int k;scanf("%d",&k);
   for(int i = 0;i < s.size();i++){
      num[i] = s[i] - 'a';
   }
   for(int i = 0;i < s.size() - 1;i++){
      if(num[i] == 0)continue;
      if(26 - num[i] <= k){
         k -= (26 - num[i]);
         num[i] = 0;
      }
   }
   num[s.size() - 1] += k;
   num[s.size() - 1] %= 26;
   
   for(int i = 0;i < s.size();i++){
      cout << (char)('a' + num[i]);
   }
   printf("\n");
}


Measured memory_bytes: 896
l, r = map(int, input().split())

mod = 2020
for i in range(l, r, 1):
  for j in range(i + 1, r + 1, 1):
    a = (i * j) % 2019
    if a == 0:
      mod = a
      break
    elif a < mod:
      mod = a
  else:
    continue
  break

print(mod)

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

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

  int n;
  cin>>n;
  vector<int> A(n),B(n);
  for(int i=0;i<n;i++) cin>>A[i];
  int C[k];
  for(int i=0;i < k;i++) C[i]=0;
  for(int j=0;j < n;j++) C[A[j]]++;
  for(int i=1;i < k;i++) C[i]=C[i]+C[i-1];
  for(int j=n-1;j >= 0;j--){
    B[C[A[j]]-1]=A[j];
    C[A[j]]--;
  }
  for(int i=0;i<n;i++){
    if(i)cout << " ";
    cout<<B[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 34168
/*
 * main.c
 *
 *  Created on: 2019/03/09
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

char S[200001] = {0};
char T[200001] = {0};

void change(char a, char b)
{
	int len = 0;
	int i = 0;
	len = strlen(S);
	for(i = 0; i < len; i++) {
		if(S[i] == a) {
			S[i] = b;
		} else if (S[i] == b) {
			S[i] = a;
		}
	}
}

int alp[256] = {0};
int alp2[256] = {0};

int main()
{
	int len = 0;
	int diff = 0;
	scanf("%s", S);
	scanf("%s", T);
	len = strlen(S);
	len -= 1;
	do {
		if (alp[(int)S[len]] == 0) {
			if (alp2[(int)T[len]] == 1) {
				diff++;
//				printf("len=%d, %c %c\n", len, T[len], S[len]);
			}
			alp[(int)S[len]] = T[len];
			alp2[(int)T[len]] = 1;
		} else {
			if (alp[(int)S[len]] == T[len]) {
				//
			} else {
				diff++;
//				printf("len=%d, %c %c\n", len, T[len], S[len]);
			}
		}
		//if (S[len] != T[len]) {
		//	change(S[len],T[len]);
		//}
		len--;
	} while (len >= 0);

	//diff = strncmp(S,T,len);
	if(diff == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	char c;
  	int ans = 700;
  	for(int i=0; i<3; i++){
		cin >> c;
      	if(c=='o'){
			ans+=100;
        }
    }
  	cout << ans << endl;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int ISPRIME_SIZE=11111111;
bool isprime[ISPRIME_SIZE];
struct isprime_exec{
    isprime_exec(){
        for(int i=0;i<ISPRIME_SIZE;i++)isprime[i]=true;
        isprime[0]=isprime[1]=false;
        for(int i=2;i<ISPRIME_SIZE;i++){
            if(!isprime[i])continue;
            for(int j=i+i;j<ISPRIME_SIZE;j+=i)isprime[j]=false;
        }
    }
}isprimeexec;

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

    vint lis;
    for(int i=2;i<=55555;i++){
        if(isprime[i]&&i%5==1)lis.pb(i);
    }
    rep(i,N){
        if(i)cout<<" ";
        cout<<lis[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 11136
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

const int MAXN = 2e5 + 10;
int pc;
int pr[MAXN] , f[MAXN];
LL A[MAXN] , B[MAXN];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void G(int n) {
		for (int i = 2; i <= n; ++i) {
				if (!f[i]) f[i] = pr[++pc] = i;
				for (int j = 1; j <= pc && i * pr[j] <= n; ++j) {
						f[i * pr[j]] = pr[j];
						if (i % pr[j] == 0) break;
				}
		}
}
int main() {
		
		int n;
		scanf("%d" , &n); G(10000);
		for (int i = 1; i <= n; ++i) A[i] = pr[i & 1 ? i / 2 + 1 : n + n - i / 2 + 1];
		for (int i = 1; i <= n; ++i) B[i] = pr[(i & 1 ? n - i / 2 : n + i / 2) + (n & 1)];
		A[0] = A[n + 1] = B[0] = B[n + 1] = 1;
		for (int i = 1; i <= n; ++i , printf("\n")) 
		for (int j = 1; j <= n; ++j)
				if ((i + j) & 1) printf("%lld " , (LL) A[(i + j) / 2] * A[(i + j) / 2 + 1] * B[(n + i - j + (n & 1)) / 2] * B[(n + i - j + (n & 1)) / 2 + 1] + 1);
				else printf("%lld " , A[(i + j) / 2] * B[(n + i - j + (n & 1)) / 2]); 
	  return 0;
}

Measured memory_bytes: 3884
def f(x)
  x * x
end

if __FILE__ == $0
  loop do
    d = gets
    break if d.nil?
    d = d.to_i
    # p (d..(600-d)).step(d).to_a.map{|x| f(x)*d}.inject(:+)
    s = 0
    (d..(600-d)).step(d).each do |x|
      s += f(x) * d
    end
    p s
  end
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vint vec(102);
int n;

int relu(int x){
    return (x>0? x : 0);
}

int num(int x){
    int counter=0;
    reps(i,2,n+1){
        if(vec[i]>=x-1)counter++;
    }
    return counter;
}

int main(){

    cin>>n;
    reps(i,2,n+1){
        int full=i;
        bool check=true;
        reps(j,2,i){
            if(i%j==0){
                check=false;
                break;
            }
        }
        if(check==false){
            vec[i]==0;
            continue;
        }
        reps(j,i,n+1){
            int full=j;
            while(true){
                if(full%i==0){
                    full/=i;
                    vec[i]++;
                }
                else{
                    break;
                }
            }
        }
    }
    int ans=num(75)+num(25)*relu(num(3)-1)+num(15)*relu(num(5)-1)+((num(5)*relu(num(5)-1)*relu(num(3)-2)))/2;
    cout<<ans<<endl;

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<16,INF=1<<30;

vector<int> G[MAX];
int M,dis[MAX];

void BFS(){
    dis[(1<<M)-1]=0;
    queue<int> Q;
    Q.push((1<<M)-1);
    
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(int to:G[u]){
            if(dis[to]==INF){
                dis[to]=dis[u]+1;
                Q.push(to);
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>M>>K;
    vector<int> D(100,-1),revD(M);
    for(int i=0;i<(1<<M);i++) dis[i]=INF;
    vector<vector<int>> to(N,vector<int>(K));
    for(int i=0;i<M;i++){
        int a;cin>>a;
        a--;
        D[a]=i;
        revD[i]=a;
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            cin>>to[i][j];
            to[i][j]--;
        }
    }
    
    for(int bit=(1<<M)-1;bit>0;bit--){
        for(int a=0;a<K;a++){
            int ne=0;
            for(int i=0;i<M;i++){
                if(!(bit&(1<<i))) continue;
                int t=to[revD[i]][a];
                if(D[t]==-1) continue;
                ne|=(1<<D[t]);
            }
            G[bit].push_back(ne);
        }
    }
    
    BFS();
    
    cout<<dis[0]<<endl;
    
    
    
}




Measured memory_bytes: 38800
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n, x;
	vi a(100);
	cin >> n >> x;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int count = 0;
	sort(a.begin(),a.end());
	for (int i = 0; i < n; i++) {
		//cout << "a[i]" << a[i] << endl;
		if (i == n - 1 && x != a[i]) {
			//cout << "+" << endl;
			goto A;
		}
		x = x - a[i];
		//cout << x << endl;
		if (x < 0) {
			goto A;
		}
		count++;
	}
	A:
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400005
using namespace std;
 
int n,m,cnt,tot,num[N],fst[N],pnt[N],nxt[N],dgr[N],a[N],b[N]; bool vis[N];
map<int,int> mp;
void add(int x,int y){
	dgr[x]++;
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x){
	int i,y; vis[x]=1;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (!vis[y]) dfs(y);
	}
}
int main(){
	scanf("%d",&n);
	int i; n++;
	for (i=1; i<n; i++){
		scanf("%d",&a[i]); a[n]^=a[i];
	}
	for (i=1; i<n; i++) {
		scanf("%d",&b[i]); b[n]^=b[i];
	}
	for (i=1; i<=n; i++){
		if (!mp[a[i]]) mp[a[i]]=++cnt; a[i]=mp[a[i]];
		if (!mp[b[i]]) mp[b[i]]=++cnt; b[i]=mp[b[i]];
	}
	for (i=1; i<=n; i++) num[a[i]]++;
	for (i=1; i<=n; i++) num[b[i]]--;
	for (i=1; i<=cnt; i++) if (num[i]) break;
	if (i<=cnt){ puts("-1"); return 0; }
	int ans=0;
	for (i=1; i<=n; i++) num[a[i]]++;
	for (i=1; i<=n; i++) if (a[i]!=b[i]){
		add(a[i],b[i]); add(b[i],a[i]);
		if (i<n) ans++; else ans--;
	} else if (i==n && num[a[i]]>1) ans--;
	for (i=1; i<=cnt; i++) if (!vis[i] && dgr[i]){
		ans++; dfs(i);
	}
	printf("%d\n",max(ans,0));
	return 0;
}


Measured memory_bytes: 15232
import scala.io.StdIn._

object Helpers {
  def readIntLine = readLine.split(" ").map(_.toInt)
  def readInts(n: Int) = Array.fill(n)(readInt)

  def splitDigits(i: Int): Seq[Int] = i.toString.map(_.asDigit)

  def log[A](x: A): A = {println(x); x}

  implicit class IntImplicits(val i: Int) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Int): Int = scala.math.pow(i, exp).intValue
  }

  implicit class LongImplicits(val i: Long) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Long): Long = scala.math.pow(i, exp).longValue
  }
}

object Main extends App {
  import Helpers._

  val x = readInt.toLong

  println((for {
    a <- (-150L to 150L).to(LazyList)
    b <- (-150L to 150L).to(LazyList)
    if (a ** 5) - (b ** 5) == x
  } yield s"${a} ${b}").head)
}



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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> k(M), p(M);
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        int x;
        for (int j = 0; j < k[i]; j++) {
            cin >> x;
            s[i].push_back(x);
        }
    }
    for (int i = 0; i < M; i++) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        bool check = true;
        for (int i = 0; i < M; i++) {
            int cnt = 0;
            for (int j = 0; j < k[i]; j++) {
                if (bit & (1<<(s[i][j] - 1))) cnt++;
            }
            if (cnt % 2 != p[i]) {
                check = false;
                break;
            }
        }
        if (check) ans++;
    }

    cout << ans << endl;
}

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

int main() {

  char A;
    cin >> A;
    
    if (A == 'a' ){
      cout << "vowel";
    }
    else if (A == 'i' ){
      cout << "vowel";
    }
    else if (A == 'u' ){
      cout << "vowel";
    }
    else if (A == 'e' ){
      cout << "vowel";
    }
    else if (A == 'o' ){
      cout << "vowel";
    }
    else cout << "consonant";
}


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

int main(void){

  int N, K;
  cin >> N >> K;
  
  vector<int> p(N);
  for(int i=0; i<N; i++) cin >> p[i];
   
  int sum = 0;
  sort( (p).begin(), (p).end() );
  for(int i=0; i<K; i++) sum += p[i];
  
  cout << sum << "\n";


}//main


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1LL << 60;

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

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


int main(){
    int n,W;
    cin >> n >> W;
    int w[n];
    long long v[n];
    for (int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    long long dp[n+1][W+1];
    for (int i = 0; i < n+1; i++){
        for (int j = 0; j < W+1; j++){
            dp[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < W+1; j++){
            if(j-w[i] >= 0) chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][W];
    

    return 0;
}

Measured memory_bytes: 79104
h, w = map(int,input().split())

grid = []
for _ in range(h):
    grid.append(list(input()))

dx=[-1,0,0,1]
dy=[0,-1,1,0]


for i in range(h):
    for j in range(w):
        flag=False
        if grid[i][j]==".":
            continue

        for x,y in zip(dx,dy):
            if i+x<0 or i+x>h-1 or j+y<0 or j+y>w-1:
                continue
            if grid[i+x][j+y]=="#":
                flag=True
                break

        if not flag:
            print("No")
            exit()

print("Yes")


Measured memory_bytes: 9140
#include<stdio.h>

int main(){
  int A,B,K,max;
  int i,count=0;

  scanf("%d %d %d", &A,&B,&K);

  if(A>=B){
    max=A;
  }else{
    max=B;
  }

  for(i=max;i>=1;i--){
    if(A%i==0){
      if(B%i==0){
        count++;
        if(count==K){
          break;
        }
      }
    }
  }

  printf("%d\n", i);

  return 0;
}


Measured memory_bytes: 128
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
X = int(input())
prices = [100,101,102,103,104,105]


dp = [0 for i in range(2002)]
for price in prices:
    dp[price] = 1
for i in range(len(dp)):
    for price in prices:
        if i > price and dp[i-price] == 1:
            dp[i] = 1

if X > 2000:
    print("1")
else:
    print(dp[X])


Measured memory_bytes: 6856
/**
       ¦¦¦¦¦¦¦¦¦¦¦¦    ¦¦¦¦¦¦¦¦¦¦¦¦
		Author : Avi J Patel
		University : DA-IICT
       ¦¦¦¦¦¦¦¦¦¦¦¦    ¦¦¦¦¦¦¦¦¦¦¦¦
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define N 100000
#define ff first
#define ss second
#define si size()
#define mod 1000000007
#define large 10000000000000001
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main()
{
	FAST;
	ll n;
	cin>>n;
	cout<<(n-2)*180;
    return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>

using namespace std;
using ll = long long;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    cout << (b - a) * (b - a - 1) / 2 - a << endl;
    return 0;
}

Measured memory_bytes: 888
n,m=map(int,input().split())
a=[1 for i in range(n+2)]
for i in range(m):
    a[int(input())]=0
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(n):
    if ((i+1)<(n+1)) and a[i+1]:
        dp[i+1]+=dp[i]
    if ((i+2)<(n+1)) and a[i+2]:
        dp[i+2]+=dp[i]
print(dp[n]%1000000007)


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

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

const int INF = 1e9 + 9;

int main() {
	int n,m,x;

	int cost[15];
	int und[15][15];
	
	cin >> n >> m >> x;
	for(int i=0;i<n;i++) {
		cin >> cost[i];
		for(int j=0;j<m;j++) {
			cin >> und[i][j];
		}
	}

	int ans = INF;

	int val;
	int tot[15];

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

		val = 0;
		memset(tot, 0, sizeof(tot));

		for(int j=0;j<n;j++) {
			if(i & (1<<j)) {
				//jth book
				val += cost[j];
				for(int k=0;k<m;k++) {
					tot[k] += und[j][k];	
				}	
			}
		}

		trace(i, val);
		for(int k=0;k<m;k++) {
			trace(k, tot[k]);
		}

		int flag = 1;
		for(int k=0;k<m;k++) {
			if(tot[k] < x) {
				flag = 0;
				break;
			}
		}
		if(flag == 1) {
			ans = min(ans, val);
		}
	}

	if(ans == INF) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3656