akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n;
    cin >> n;
    bool one = false;
    ll cnt[105] = {};
    ll mx = -1, mn = INF;
    REP(i, n){
        ll a;
        cin >> a;
        cnt[a]++;
        mx = max(mx, a);
        mn = min(mn, a);
    }
    for(ll i = mx; i >= (mx + 1) / 2; i--){
        if(i == (mx + 1) / 2 && mx % 2 == 0){
            if(cnt[i] < 1){
                cout << "Impossible" << endl;
                return 0;
            }
            cnt[i]--;
            continue;
        }
        if(cnt[i] < 2){
            cout << "Impossible" << endl;
            return 0;
        }
        cnt[i] -= 2;
    }
    for(ll i = 1; i <= (mx + 1) / 2; i++){
        if(cnt[i]){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
}


Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
a = inp.shift().split(' ').map(x => +x)
m = 1000
for (i=0; i<N; i++) {
    min = a[i]
    max = a[i]
    for (j=i; j<N; j++) {
        if (max > a[j]) {
            break;
        }
        max = a[j]
    }
    c = parseInt(m / min)
    m += (max - min) * c
    i = j - 1
}
console.log(m)

Measured memory_bytes: 29864
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T>
void DEBUG(T e)
{
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T>
void DEBUG(const std::vector<T> &v)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v)
  {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T>> &vv)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv)
  {
    DEBUG(v);
  }
}
template <class T, class... Ts>
void DEBUG(T d, Ts... e)
{
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T>
void corner(bool flg, T hoge)
{
  if (flg)
  {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//BELOW

//BELOW
void solve(void)
{
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int res = INF;
  for (int i = 0; i < n; i++)
  {
    vector<int> p, v;
    for (int j = 0; j < n; j++)
    {
      if (a[j] < a[i])
      {
        if (v.size() >= k)
        {
          sort(ALL(v));
          for (int m = 0; m < v.size() - k + 1; m++)
          {
            p.push_back(v[m]);
          }

        }
        
          v.clear();
      }
      else
      {
        v.push_back(a[j]);
      }
    }

    if (v.size() >= k)
    {
      sort(ALL(v));
      for (int m = 0; m < v.size() - k + 1; m++)
      {
        p.push_back(v[m]);
      }

      v.clear();
    }
    if (p.size() < q)
      continue;
    sort(ALL(p));
    chmin(res, p[q - 1] - p[0]);
  }
  cout << res << endl;

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N, K; cin >> N >> K;
    vector<ll> h(N);
    rep(i, N) cin >> h[i];

    sort(all(h));

    deque<ll> deq;

    rep(i, N - K + 1) {
        deq.push_back(h[i + K - 1] - h[i]);
    }

    sort(all(deq));
    cout << deq[0] << endl;
}

Measured memory_bytes: 1920
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[-1] - x[0]) * 2
for i in range(n - k + 1):
    l = x[i]
    r = x[i + k - 1]
    if r < 0:
        ans = min(ans, -l)
    elif l > 0:
        ans = min(ans, r)
    else:
        ans = min(ans, r - l + min(-l, r))
print(ans)


Measured memory_bytes: 14384
#include<cstdio>

typedef long long int lli;
int x[300], y[300];
lli h[300];

lli height(int x, int y, int cx, int cy, lli h) {
    x -= cx;
    if(x < 0) x = -x;
    y -= cy;
    if(y < 0) y = -y;
    h -= x + y;
    return h > 0 ? h : 0;
}

lli inv(int x, int y, int cx, int cy, lli hh) {
    x -= cx;
    if(x < 0) x = -x;
    y -= cy;
    if(y < 0) y = -y;
    return hh + x + y;
}

int main(void) {
    int n;
    scanf("%d",&n);

    for(int i=0; i<n; i++)
        scanf("%d%d%lld",&x[i],&y[i],&h[i]);

    int j=0;
    while(!h[j]) j++;

    for(int cx=0; cx<=100; cx++)
    for(int cy=0; cy<=100; cy++) {
        lli hh = inv(x[j], y[j], cx, cy, h[j]);
        for(int i=0; i<n; i++) {
            if(h[i] != height(x[i], y[i], cx, cy, hh))
                goto next;
        }
        printf("%d %d %lld\n", cx, cy, hh);
        return 0;
next:
        ;
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,M;
  cin>>N>>M;
  ll X=1;
  rep(i,M) X*=2;
  cout<<(1900*M+100*(N-M))*X<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n!=-1){
        ld hoge=(ld)n/2;
        while(true){
            if(abs(hoge*hoge*hoge-(ld)n)<0.00001*n){
                printf("%Lf\n",hoge); break;
            }
            hoge=hoge-(hoge*hoge*hoge-n)/(3*pow(hoge,2));
        }
    }
}

Measured memory_bytes: 3020
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string t;
    cin >> t;

    for (auto &&i : t) {
        if (i == '?') i = 'D';
    }

    cout << t << endl;
}


Measured memory_bytes: 3736
n, x, y = map(int,input().split())
num = [0 for i in range(n)]

for i in range(1,n+1):
    for j in range(i+1,n+1):
        ban = min([j-i,abs(x-i)+1+abs(y-j)])
        num[ban] += 1

for i in range(1,n):
    print(num[i])


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

typedef long long ll;

ll gcd(ll A, ll B){
  ll r=A%B;
  while(r>0){
    A = B;
    B = r;
    r = A%B;
  }
  
  return B;
}

vector<pair<ll,ll>> prime_factor(ll n){
    vector<pair<ll,ll>> p;
    for(ll i=2;i*i<=n;i++){
        if(n % i != 0) {
            //cout << i << endl;
            continue;
        }

        ll ex=0;
        while(n % i == 0){
            ex++;
            n /= i;
        }
        p.push_back(make_pair(i,ex));
    }

    if(n != 1){
        p.push_back(make_pair(n,1));
    }

    return p;
}

int main(){
  ll A,B;
  cin >> A >> B;
  ll x = gcd(A,B);
  //cout << (ll)ceil(sqrt(x)) << endl;
  const auto &prime = prime_factor(x);
  
  /*
  for(int i=1;i<=m.size();i++){
    if(m[i] != 0){
		cout << i << " " << m[i] << endl;
    }
  }
  */
  
  cout << prime.size()+1 << endl;
  
  return(0);
}

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

int maxPointsDP(int **arr, int m, int lastN){
    int **dp=new int*[m+1];
    for(int i=0;i<=m;i++){
      dp[i]=new int[4];
      for(int j=0;j<=3;j++){
          dp[i][j]=0;
      }
    }
    
    for(int j=1;j<=3;j++){
        dp[0][j]=0;
    }
    for(int j=1;j<=3;j++){
        dp[1][j]=arr[0][j-1];
    }
    
    for(int i=1;i<=m;i++){
        for(int j=1;j<=3;j++){
            int first=j==1?INT_MIN:arr[i-1][j-1] + dp[i-1][1];
            int second=j==2?INT_MIN:arr[i-1][j-1]+ dp[i-1][2];
            int third=j==3?INT_MIN:arr[i-1][j-1] + dp[i-1][3];
            dp[i][j]= max(first,max(second,third));
        }
    }
    
    int ans=INT_MIN;
    for(int j=1;j<=3;j++){
        ans=max(ans,dp[m][j]);
    }
    
    return ans;
    
}

int main()
{
  int m,n=3;
  cin>>m;
   
  int **arr=new int*[m];
  for(int i=0;i<m;i++){
      arr[i]=new int[n];
      for(int j=0;j<n;j++){
            cin>>arr[i][j];
      }
  }
   
    cout<<maxPointsDP(arr,m,-1);
   
   
  return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int m=sc.nextInt();
				int n=sc.nextInt();
				if(m+n==0) break;
				int[] w=new int[n+1];
				int max=0;
				int sum=0;
				for(int i=0; i<n; i++) {
					w[i]=sc.nextInt();
					max=Math.max(w[i], max);
					sum+=w[i];
				}
				int mini=0;
				for(int i=max; i<=sum; i++) {
					int h=1;
					int[] book=new int[n+1];
					int end=0;
					for(int j=0; j<n; j++) {
						if(book[h]+w[j]>i) {
							h++;
							if(h>m) {
								end=1;
								break;
							}
						}
						book[h]+=w[j];
					}
					mini=i;
					if(end==0) break;
				}
				System.out.println(mini);

			}
		}
	}
}




Measured memory_bytes: 516124
#include <iostream>

int main() {
	int n;
	std::cin >> n;

	int x = 0;
	for (int i = 0; i < n; ++i) {
		char c;
		std::cin >> c;

		if (c == 'R')
			++x;
		else
			--x;
	}

	if (x > 0)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int a,b;
	cin >> a >> b;
	print1(a*b);
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef string S;
typedef pair<int,int> P;

const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    S s,t="keyence";
    cin >> s;
    int n=s.size();
    bool ans=false;
    for(int i=0;i<n;i++){
        int j=s.size()-t.size();
        int k=0;
        while(k<i){
            if(s.at(k)!=t.at(k)){
                goto End;
            }
            k++;
        }
        k+=j;
        while(k<s.size()){
            if(s.at(k)!=t.at(k-j)){
                goto End;
            }
            k++;
        }
        ans=true;
    End:
    ;
    }
    cout << (ans?"YES":"NO") << endl;
    return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int N, M;
	while (cin >> N >> M, N || M) {
		vector<int>h(N), w(M);
		rep(i, 0, N)cin >> h[i];
		rep(i, 0, M)cin >> w[i];
		int MAX = 1500009;
		vector<int>x(MAX, 0), y(MAX, 0);

		rep(i, 0, N) {
			int t(0);
			rep(j, i, N) {
				t += h[j];
				x[t]++;
			}
		}

		rep(i, 0, M) {
			int t(0);
			rep(j, i, M) {
				t += w[j];
				y[t]++;
			}
		}

		int ans(0);
		rep(i, 0, MAX)ans += x[i] * y[i];
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 14492
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    REP(i, 0, N) {
        cin >> a[i];
    }
    vector<lli> sum(N + 1, 0);
    REP(i, 0, N) {
        sum[i + 1] += sum[i] + a[i];
    }
    vector<lli> partial;
    partial.reserve(N * (N + 1) / 2);

    REP(i, 0, N + 1) {
        REP(j, 0, i) {
            partial.push_back(sum[i] - sum[j]);
        }
    }

    //sort(begin(partial), end(partial), greater<lli>());

    lli ans = 0;

    for (int i = 50; i >= 0; i--) {

        sort(begin(partial), end(partial), [&](lli a1, lli a2) {
            return (a1 & ((1LL << (i + 1)) - 1)) > (a2 & ((1LL << (i + 1)) - 1));
        });

        bool ok = true;

        /*
        REP(t, 0, partial.size()) {
            cout << partial[t] << endl;
        }
        cout << endl;
        //*/

        lli mask = (1LL << i);
        REP(t, 0, K) {
            ok &= ((partial[t] >> i) != 0);
            mask &= partial[t];
        }
        if (!ok) {
            continue;
        }

        ans += mask;
        vector<lli> tmp;
        for (int j = 0; j < partial.size() && ((ans & partial[j]) == ans) > 0; j++) {
            tmp.push_back(partial[j]);
        }
        partial = tmp;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  ll D, A;
  cin >> N >> D >> A;
  vector<pair<ll, ll> > XH(N);
  rep(i, N) {
    cin >> XH[i].first >> XH[i].second;
  }
  sort(all(XH));
  vector<ll> X(N), H(N);
  rep(i, N) {
    X[i] = XH[i].first;
    H[i] = XH[i].second;
  }
  ll ans = 0;
  queue<pair<ll, ll> > Q;
  ll sumA = 0;
  rep(i, N) {
    while(!Q.empty()) {
      if(Q.front().first < X[i]) {
        sumA -= Q.front().second;
        Q.pop();
      } else {
        break;
      }
    }
    ll cnt = max(0LL, (H[i]-sumA+A-1)/A);
    ans += cnt;
    sumA += A*cnt;
    Q.push(make_pair(X[i]+2*D, A*cnt));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

void file(void){
    freopen("water.in","r",stdin);
    freopen("water.out","w",stdout);
}
const int MAXN=111;

static int n,x,a[MAXN];

int main(void){
	read(n);read(x);
	Rep(i,1,n)read(a[i]);
	sort(a+1,a+n+1);
	Rep(i,1,n)if(x<a[i])return printf("%d\n",i-1),0;
	else x-=a[i];
	printf("%d\n",x?n-1:n);
	return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
        llin(n);
        vllin(a,n);
        SORT(a);
        ll c=0;
        FOR(i,0,n-1){
                if(a[i]>0){
                        c++;
                }
        }
        ll m=0;
        ll k=0;
        if(c!=n){
                FOR(i,0,n-1){
                        m+=abs(a[i]);
                }
                if(c==0) m-=2*abs(a[n-1]);
                sal(m)
        }else{
                m-=a[0];
                FOR(i,1,n-1){
                        m+=a[i];
                }
                sal(m)
        }
        k=a[0];
        FOR(i,n-c+(n==c),n-2){
                says(k)
                sal(a[i])
                k=k-a[i];
        }
        says(a[n-1])
        sal(k)
        k=a[n-1]-k;
        FOR(i,1,n-2-c+(c>0)){
                says(k)
                sal(a[i])
                k=k-a[i];
        }
}


Measured memory_bytes: 2688
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    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 Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,m;
  cin>>n;
  map<ll,ll> v;
  rep(i,n){
    ll a;
    cin>>a;
    v[a]++;
  }
  cin>>m;
  rep(i,m){
    ll a;
    cin>>a;
    v[a]--;
  }
  bool flag=true;
  for(auto tmp:v){
    if(tmp.second<0) flag=false;
  }
  if(flag) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 12800
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string[] n = SpRead(' ');
        long N = long.Parse(n[0]);
        long M = long.Parse(n[1]);
        /*
         000 110 001 010

         0000 1100 0010 0101 0110 N = 1 M > 1 M-2

        0 1 0 0
        0 1 0 1
        0 0 1 0

        000 110 001 010 100 011 000
        000 110 001 010 100 011 000
         */
        if (N == 1 && M == 1) Console.WriteLine(1);
        else if (N == 1) Console.WriteLine(M - 2);
        else if (M == 1) Console.WriteLine(N - 2);
        else Console.WriteLine((N - 2) * (M - 2));
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
void sol()
{
string s;
cin>>s;
ll sum=0;
for(int i=0;i<s.size();i++)
{
    sum+=s[i]-'0';
}
if(sum%9)
cout<<"No";
else
cout<<"Yes";


return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main(void) {

	int x, tmp, maxn=1;

	cin >> x;

	for (int num = 2; num <= x; num++)
	{
		for (int jou = 2;; jou++)
		{
			tmp = pow(num, jou);
			//printf("%d %d %d\n", num, jou, tmp);
			if (tmp <= x) {
				maxn = max(maxn, tmp);
			}
			else {
				break;
			}
		}
	}
	
	cout << maxn << "\n";

	return 0;
}

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

int main() {
 
  string S;
  cin >> S;
 
  int a = S.at(0) - '0';
  int b = S.at(1) - '0';
  int c = S.at(2) - '0';
  int d = S.at(3) - '0';
  
if(10 * a + b >= 1 && 10 * a + b <= 12) {
  if(10 * c + d  >= 1 && 10 * c + d <= 12) {
    cout << "AMBIGUOUS" << endl;
    return 0;
  }
  else {
    cout << "MMYY" << endl;
  }
}
  else {
    if(10 * a + b == 0 && 10 * c + d > 12) {
      cout << "NA" << endl;
      return 0;
    }
    else if(10 * c + d == 0 && 10 * a + b> 12) {
      cout << "NA" << endl;
      return 0;
    }
    else if(10 * c + d == 0 && 10 * a + b == 0) {
      cout << "NA" << endl;
      return 0;
    }
     else if(10 * a + b > 12 && 10 * c + d > 12) {
       cout << "NA" << endl;
       return 0;
     }
    else if(10 * c + d >= 1 && 10 * c + d <= 12) {
      cout << "YYMM" << endl;
      return 0;
    }
  }


 }
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll m1=a*c;
  ll m2=a*d;
  ll m5=max(m1,m2);
  ll m3=b*c;
  ll m4=b*d;
  ll m6=max(m3,m4);
  ll ans=max(m5,m6);
  cout<<ans<<"\n";
}

Measured memory_bytes: 3572
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            _ans = gcd(gcd(a, b), c)
            if a == b and b == c:
                ans += _ans
            elif a == b or b == c:
                ans += 3 * _ans
            else:
                ans += 6 * _ans
print(ans)


Measured memory_bytes: 9196
#include <iostream>
#include <string>
using namespace std;
int main() {
    string a = "Yes";
    string b = "No";
    string N;
    cin >> N;
      for(int i=0;i<N.length();i++) if(N[i]=='9') {
              cout << a <<endl;
              return 0;
          }

    cout << b << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

    int A, B, C;
    cin >> A >> B >> C;
    int pois = min(C, A + B + 1);
    int good = pois + B;
    cout << good << endl;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& a) { cin >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

class UnionFind { private: vector<int> par; vector<int> rnk; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } public: UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } };

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

int f(int a, int b, int i, int m, int u) {
  if (i >= 0) {
    int d = __builtin_ctz(a ^ b);
    int x = a & ~(1 << d);
    int y = b & ~(1 << d);
    u |= 1 << d;
    int k = __builtin_ctz(~u);
    f(x, x ^ (1 << k), i - 1, m | (a & (1 << d)), u);
    f(x ^ (1 << k), y, i - 1, m | (b & (1 << d)), u);
  } else {
    cout << m << " ";
  }
}
signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (__builtin_parity(a ^ b) == 1) {
    cout << "YES" << endl;
    f(a, b, n - 1, 0, 0);
  } else {
    cout << "NO" << endl;
  }
}

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

int main() {
  string s;
  cin >> s ;
  if(s== "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(s=="Cloudy"){
    cout << "Rainy"  << endl;
  }
  else cout << "Sunny" << endl;
}
  

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

using namespace std;

int main()
{
    int k, a, b;

    cin >> k >> a >> b;

    bool ok = false;
    
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
            ok = true;
    }

    if (ok)
        cout << "OK";
    else
        cout << "NG";

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a%3==0 || b%3==0 || (a+b)%3==0) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

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

int main()
{
  //queue<char> q;
  bool flag = true;
  int cnt = 0;
  int m = 0;
  string ch;

  cin >> ch;
  for(int i = 0;i < ch.size();i++){

    if(flag && ch[i] == '(') cnt++;
    if(flag && ch[i] == ')') cnt--;
    
    if(ch[i] == '*') flag = false;
    if(!flag && ch[i] == ')'){
      if(m > cnt) continue;
      m++;
    }
  }
  cout << min(cnt, m) << endl;
  return 0;
}



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

int main(){
  string A,B;
  cin >> A >> B;
  
  string ans;
  
  int a = A.size();
  int b = B.size();
  
  if(a - b > 0){
    ans = "GREATER";
  }else if( a - b < 0){
    ans = "LESS";
  }else{
    ans = "EQUAL";
    for(int i = 0;i < a;i++){
      if(A[i] - B[i] > 0){
    	ans = "GREATER";
        break;
  	  }else if( A[i] - B[i] < 0){
    	ans = "LESS";
        break;
      }
    }
  }

  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#!/usr/bin/env python


def pow(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return (pow(m, int(n / 2)) ** 2) % mod
    elif n % 2 == 1:
        return (pow(m, int((n - 1) * 0.5)) ** 2 * m) % mod


def conb(n, a):
    mod1 = 1
    mod2 = 1
    for i in range(a):
        mod1 *= n - i
        mod1 %= mod
        mod2 *= i + 1
        mod2 %= mod
    mod2 = pow(mod2, mod - 2)
    return (mod1 * mod2) % mod


n, a, b = (int(val) for val in input().split())


ans = 1
noa = 1
nob = 1
mod = 1000000007
ans = pow(2, n) - 1 - conb(n, a) - conb(n, b)
ans %= mod
print(ans)


Measured memory_bytes: 3188
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=1e6+5;
bool isprime[maxn];
int prime[maxn],cnt,a[maxn],n;

bool pairwise()
{
    set<int> t;
    REP(i,1,n)
    {
        int x=a[i];
        for(int j=1;prime[j]*prime[j]<=x;j++)
            if(x%prime[j]==0)
            {
                if(t.count(prime[j])) return 0;
                t.insert(prime[j]);
                while(x%prime[j]==0) x/=prime[j];
            }
        if(x>1)
        {
            if(t.count(x)) return 0;
            t.insert(x);
        }
    }
    return 1;
}

bool setwise()
{
    int x=a[1];
    REP(i,2,n) x=__gcd(x,a[i]);
    return x==1;
}

int main()
{
    REP(i,2,1000000) isprime[i]=1;
    for(int i=2;i<=10000;i++)
        if(isprime[i])
            for(int j=i*i;j<=1000000;j+=i)
                isprime[j]=0;
    for(int i=2;i<=1000000;i++)
        if(isprime[i])
            prime[++cnt]=i;

    n=read();
    REP(i,1,n) a[i]=read();
    if(pairwise()) puts("pairwise coprime");
    else if(setwise()) puts("setwise coprime");
    else puts("not coprime");

    return 0;
}


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

long long int cnt[100100];

int main(){
  long long int N, K;
  cin>>N>>K;
  
  int number, pcs; 
  for(int i = 0; i < N; i++){
    cin>>number>>pcs;
    cnt[number] += pcs;
  }


  for (int i = 1; i <= 100000; i++){
    if(K <= cnt[i]){
      cout<<i<<endl;
      return 0;
    }
    K -= cnt[i] ;
  }

  return 0;
}


Measured memory_bytes: 1024
*c;f;*i;j;m;n;s;u;v;w;A[6003];C[72000];D[2001][2001];M[2001];
main(){
  for(gets(i=A);~scanf("%d",A+n++););
  M[*A]=M[*i]=D[*i][*A]=D[*A][*++i]=m=1e7;
  // for(j=0;j<9;++j) {
  //   printf("%d,%d->%d; ",j/3+1,j%3+1,D[j/3+1][j%3+1]);
  // }
  // puts("");
  for(
    ;
    i<A+n;
  ){
    // printf("%d,%d,%d\n", i[1], i[2], i[3]);
    c=C;
    for(u=*++i,v=*++i,w=*++i,s=0;s++<2e3;)
      u-v|v-w?
        *++c=u,*++c=s,*++c=v-w?:D[s][v]+1,
        *++c=v,*++c=s,*++c=w-u?:D[s][w]+1,
        *++c=w,*++c=s,*++c=u-v?:D[s][u]+1,
        *++c=u,*++c=v,*++c=D[w][w]+1,
        *++c=v,*++c=w,*++c=D[u][u]+1,
        *++c=w,*++c=u,*++c=D[v][v]+1,
        *++c=u,*++c=v,*++c=m,
        *++c=v,*++c=w,*++c=m,
        *++c=w,*++c=u,*++c=m,
        *++c=u,*++c=s,*++c=M[s],
        *++c=v,*++c=s,*++c=M[s],
        *++c=w,*++c=s,*++c=M[s]

        // , s==1&&printf("{%d,%d,%d,%d;%d?:%d+1}\t", u, v, w, s, v-w, D[s][v])
      :++f;
    for(;c>C;)
      w=*c--,v=*c--,u=*c--,
      D[u][v]>w||(D[u][v]=D[v][u]=w),M[u]>w||(M[u]=w),M[v]>w||(M[v]=w),m=m>w?m:w;

    for(j=0;j<9;++j) {
      // printf("%d,%d->%d; ",j/3+1,j%3+1,D[j/3+1][j%3+1]);
    }
    // puts("");
  }
  printf("%d",m+=f/2e3-1e7);
}


Measured memory_bytes: 17720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli k, a, b;
int main() {
  cin >> k >> a >> b;
  if (a>=b-1) { cout << 1+k << endl; return 0; }
  lli y = a; k -= a-1;
  if (k%2==1) { y++; k--; }
  y += (k/2) * (b - a);
  cout << y << endl;
  return 0;
}


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

int main(){
  int A,B;
  cin>>A>>B;
  if(max(A,B)>8){
    cout<<":("<<endl;
  }else{
    cout<<"Yay!"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;


signed _main(){
  int n; cin >> n;
  vv<int> M(n,v<int>(n));
  rep(i,n)rep(j,n) cin >> M[i][j];
  v<int> color(n,0),d(n,INF),p(n,-1);
  d[0]=0;//TとV-Tをつなぐ辺で最も重みが小さいものの大きさ
  int u,minv,sum=0;

  while(1){
    minv=INF;
    u=-1;//確定した頂点
    rep(i,n){
      if(minv > d[i] && color[i] != 2){
        u=i;
        minv = d[i];
      }
    }
    if(u == -1) break;//更新無し
    color[u]=2;
    rep(v,n){
      if(color[v]!=2 && M[u][v]!=-1){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
          color[v]=1;
        }
      }
    }
  }

  rep(i,n){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 3200
# AliceとBobは、2人で1枚ポーカーを行います。
# 1枚ポーカーは、トランプを用いて行う2人ゲームです。
#
# 今回使用するトランプでは、各カードに 1 から 13 までの数が書かれています。
# カードの強さは、カードに書かれている数で決まり，強さの基準は以下の通りです。
# 弱 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 強
#
# 1枚ポーカーは以下の手順で行います。
#
# 各プレイヤーは、トランプからカードを1枚選んで、自分の手札とします。
# 両プレイヤーは、手札を見せ合います。強いカードを持っているプレイヤーが勝ちです。
# なお、両プレイヤーの持っているカードの強さが同じ場合は引き分けです。
# 2人の対戦を眺めていたあなたは、AliceとBobの手札を知ることができます。
# Aliceが持っているカードに書かれている数は A、Bobが持っているカードカードに書かれている数は Bです。
# 2人の代わりに、勝敗を判定するプログラムを作ってください。

input_alice, input_bob = map(int,input().split())

result = 'ret'  # 結果格納用

if input_alice > input_bob: # Aの方がBより大きい
    if input_bob == 1:
        result = 'Bob'  # Bobがエースなので勝ち～
    else:
        result = 'Alice'
elif input_alice < input_bob:   # Bの方がAより大きい
    if input_alice == 1:
        result = 'Alice'    # Aliceがエースなので勝ち～
    else:
        result = 'Bob'
else:
    result = 'Draw'         # どっちも同じ手札なので引き分け～

print(result)   # 結果出力～


Measured memory_bytes: 8948
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sat = sum(B)
for i in range(N-1):
    if A[i+1] == A[i] + 1:
        sat += C[A[i]-1]

print(sat)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	int nGameNum;
	int Stone[1000];
	int People[1000];
	int Output[1000];

	cin >> nGameNum;

	for (int i = 0; i < nGameNum; i++) {
		cin >> Stone[i] >> People[i];
	}

	for (int j = 0; j < nGameNum; j++) {
		Output[j] = (--Stone[j] % People[j]) + 1;
	}

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

	return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 12;
vector<int> v[T+2];
int has[T+2];

int main() {
    ios_base::sync_with_stdio(false);
    int n,m,x; cin >> n >> m >> x;
    int gol = (1<<n);

    for(int i = 0; i < n; i++) {
        int c; cin >> c;
        v[i].pb(c);
        for(int j = 0; j < m; j++) {
            cin >> c;
            v[i].pb(c);
        }
    }

    bool ans = 0, ok = 0;
    int r = INF;

    for(int mask = 0; mask < gol; mask++) {
        memset(has,0,sizeof has);
        ok = 1;
        int cost = 0;
        for(int j = 0; j < n; j++) {
            if(mask&(1<<j)) {
                cost += v[j][0];
                for(int k = 1; k <= m; k++) has[k] += v[j][k];
            }
        }

        for(int j = 1; j <= m; j++) ok &= (has[j] >= x);
        if(ok) {
            ans |= ok;
            r = min(r,cost);
        }
    }

    cout << (ans?r:-1) << endl;
    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;
    
    ll ans = 1;

    for (ll i = 0; i < N; i++) {
        ans *= (i + 1);
        ans %= 1000000000 + 7;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n, s = int(input()), int(input())

f = lambda b,n:n if n < b else n%b + f(b,n//b)
import math
ans = math.inf
if n == s: ans = n+1
for b in range(2,math.ceil(math.sqrt(n))+1): #O(√n)の全探索
    if f(b,n) == s:
        ans = b; break
else:
    for p in range(1,math.ceil(math.sqrt(n))): #n=pb+q (b>√n, p+q=s)に基づいたO(√n)の全探索
        b = (n-s)/p+1
        if b > 1 and b == int(b) and f(b,n) == s:
           ans = min(ans,int(b))
if ans == math.inf: ans = -1
print(ans) 

Measured memory_bytes: 9272