akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
//ワーシャルフロイゼ法(隣接行列を受け取り、それぞれの最短を受け取る、size:10^2-)
vector<vector<long long>> WarshallFloyd(vector<vector<long long>> &pathmatrix){
    int index=pathmatrix.size();
    vector<vector<long long >>res=pathmatrix;
    for (int a = 0; a < index; a++){
        for (int b = 0; b < index; b++){
            for (int c = 0; c < index; c++){ 
                chmin(res[b][c], res[b][a] + res[a][c]);
            }
        }
    }
    return (res);
}
int main(){
    int n;
    ll ans=0LL;
    ll stack=0LL;
    cin >>n;
    VV ppath(n,V(n));
    VV upath(n, V(n,0LL));

    rep(i,n){
        rep(j,n){
            cin>>ppath[i][j];
            ans+=ppath[i][j];
        }
    }
   // clog<<ans<<endl;
        int index = ppath.size();
        vector<vector<long long>> res = ppath;
        for (int a = 0; a < index; a++)
        {
            for (int b = 0; b < index; b++)
            {
                for (int c = 0; c < index; c++)
                {
                    if(a!=b and a!=c and b!=c){
                        if ((res[b][c] == res[b][a] + res[a][c])){
                         
                        //    clog << "(" << res[b][c] << " " << res[b][a] + res[a][c] << ")  ";
                         //   clog<<b<<" "<<c<<" ->thourg "<<endl;
                        }else if (res[b][c] > res[b][a] + res[a][c]){
                            
                            cout<<-1<<endl;
                            return 0;
                        }else if(upath[b][c]!=-1){
                           
                        //    clog << "(" << res[b][c] << " " << res[b][a] + res[a][c] << ")  ";
                          //  clog << b << " " << c << " ->strate " << endl;
                        }
                        //chmin(res[b][c], res[b][a] + res[a][c]);
                    }
                   
                }
            }
        }
        

    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(k!=i and k!=j){
                    if(res[i][k] + res[k][j] == res[i][j]){
                        ans-=res[i][j];
                        break;
                    }
                }
          
            }
         //   clog << upath[i][j] << " ";
        }
       // clog<<endl;
    }

    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      cout<<"#x "<<x<<"\n";
#define trace(x,y)  cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          cout<<"\n";


bool SBF(const pair <int,int>&a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair<int,int>& a, const pair<int,int>& b){return a.S<b.S;}


const int maxn = 1e9+7;
int n , k;
void solve(){
    ll a, b, c;
    cin >> a >> b>> c>> k;
    
    if(k <= a)cout<<k<<"\n";
    else if(k <= b+a)cout<<a<<"\n";
    else if(k<=c+a+b){
        k = k - a - b;
        cout<<a-k<<"\n";
    }
}
int main(){
    solve();
return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>


using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}




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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> h(n);
    REP(i,n)cin >> h[i];

    vector<int> dp(n,INF);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);

    for(int i=2;i < n;i++){
        dp[i] = min(dp[i-1]+abs(h[i-1]-h[i])
                    ,dp[i-2] + abs(h[i-2]-h[i]));
    }

    cout << dp[n-1] << endl;
    return 0;
}    

Measured memory_bytes: 1024
#![allow(clippy::needless_range_loop)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        s: [String; n]
    }
    let mut judges = [0; 4];
    for judge in s {
        match &judge as &str {
            "AC" => judges[0] += 1,
            "WA" => judges[1] += 1,
            "TLE" => judges[2] += 1,
            "RE" => judges[3] += 1,
            _ => unreachable!()
        }
    }

    println!("AC x {}", judges[0]);
    println!("WA x {}", judges[1]);
    println!("TLE x {}", judges[2]);
    println!("RE x {}", judges[3]);
}


Measured memory_bytes: 7684
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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()
{
    int64_t A, B;
    cin >> A >> B;
    if (A > 9 || B > 9 || A < 1 || B < 1) {
        cout << -1 << endl;
    } else {
        cout << A * B << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
# coding: utf-8
#import math
#import numpy
#N = int(input())
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    #K =int(input())
    ANS = []
    
    #ANS.append(a)
    for i in range(K,N):
        if A[i-K] < A[i]:
            print("Yes")
        else:
            print("No")
        
        
        #ANS.append(a)
    #print(ANS)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 31288
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n,m,ans=1;
	cin >> n >> m;
	if(n == m){
		FOR(i,1,n+1){
			ans *= i;
			ans %= 1000000007;
		}
		ans *= ans*2;
	}else if(abs(n-m) == 1){
		FOR(i,1,n+1){
			ans *= i;
			ans %= 1000000007;
		}
		FOR(i,1,m+1){
			ans *= i;
			ans %= 1000000007;
		}
	}
	else{
		ans = 0;
	}
	ans %= 1000000007;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;


signed main(){
    
    string hoge, huga, piyo; cin >> hoge >> huga >> piyo;
    cout << char(hoge[0] - 'a' + 'A') << char(huga[0] - 'a' + 'A') << char(piyo[0] - 'a' + 'A') << endl;   
    return 0;
}


Measured memory_bytes: 256
def resolve():
    A, B, M = map(int, input().split())  
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    x_list = []

    for i in range(M):
        x_list.append(list(map(int, input().split())))

    min_prace = min(a_list) + min(b_list)

    for i_list in x_list:
        tmp_prace = a_list[i_list[0]-1] + b_list[i_list[1]-1] - i_list[2]
        if tmp_prace < min_prace:
            min_prace = tmp_prace

    print(min_prace)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38444
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<queue>
#include<set>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
class UnionFind{
public:
  UnionFind();
  UnionFind(int _n){init(_n);}
  void init(int _n){
    n = _n;
    rank.resize(n, 0);
    parent.resize(n, -1);
  }
  int find(int x){
    if(parent[x] < 0)return x;
    else return parent[x] = find(parent[x]);
  }
  void unite(int x, int y){
    x = find(x), y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      parent[y] += parent[x];
      parent[x] = y;
    }else{
      parent[x] += parent[y];
      parent[y] = x;
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
  int size(int v){
    if(parent[v] < 0)return -parent[v];
    else return size(parent[v]);
  }
private:
  int n;
  vector<int> rank, parent;
};


int main(){
  int n, m;
  std::cin >> n;
  vector<lli> salary(n, 0), c(n);;
  UnionFind uf(n);
  for (int i = 0; i < n; i++){
    std::cin >> c[i];
  }
  std::cin >> m;
  vector<vector<int> > g(n);
  vector<vector<pii> > gg(n);
  for (int i = 0; i < m; i++) {
    int to, from;
    std::cin >> to >> from;
    to--, from--;
    if(c[to] < c[from])swap(to, from);
    if(c[to] == c[from])uf.unite(to, from);
    else g[from].push_back(to);
    gg[from].push_back(pii(c[to], to));
    gg[to].push_back(pii(c[from], from));
  }
  for (int i = 0; i < n; i++) {
    sort(gg[i].begin(), gg[i].end());
    for (int j = 1; j < gg[i].size(); j++) {
      auto &prev = gg[i][j - 1], cur = gg[i][j];
      if(prev.first == cur.first)uf.unite(prev.second, cur.second);
      else g[prev.second].push_back(cur.second);
    }
  }
  vector<int> id;
  for (int i = 0; i < n; i++) {
    if(uf.find(i) == i){
      id.push_back(i);
      salary[i] = 1;
    }else{
      copy(g[i].begin(), g[i].end(), back_inserter(g[uf.find(i)]));
      g[i].clear();
    }
  }
  sort(id.begin(), id.end(), [&](int a, int b){return c[a] < c[b];});
  lli ans = 0;
  for (int i: id) {
    for (int to: g[i]) salary[uf.find(to)] = max(salary[uf.find(to)], salary[i] + 1);
    ans += 1LL * salary[i]*uf.size(i);
    }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 20488
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector <int> a(n);
	for (int i=0;i<n;++i){
		cin>>a[i];
	}
	for (int i=k;i<n;++i){
		if (a[i] > a[i-k]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 4040
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

    ll X;
    cin >> X;
    ll out = 0;
    ll a = 100;
    double b = 1.01;
    while(1){
        a = a*b;
        out++;
        if(a>=X) break;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  i64 a, b, c, d;
  cin >> a >> b >> c >> d;
  i64 tot = b - a + 1;
  tot -= b / c;
  tot += (a - 1) / c;
  tot -= b / d;
  tot += (a - 1) / d;
  i64 lcm = (c * d) / __gcd (c, d);
  tot += b / lcm;
  tot -= (a - 1) / lcm;
  cout << tot << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        sc.close();

        String[] strArray = S.split("");

        int count=0;
        String a,b=null;
        a = strArray[0];

        if (strArray[1].equals(a)){
            if (strArray[2].equals(a)){
                System.out.println("No");
                return;
            }else{
                b = strArray[2];
                if (strArray[3].equals(a) || strArray[3].equals(b)){
                    System.out.println("Yes");
                    return;
                }else{
                    System.out.println("No");
                    return;
                }
            }
        }else{
            b = strArray[1];
            if (strArray[2].equals(a) || strArray[2].equals(b)){
                if (strArray[3].equals(a) || strArray[3].equals(b)){
                    System.out.println("Yes");
                    return;
                }else{
                    System.out.println("No");
                    return;
                }
            }else {
                System.out.println("No");
                return;
            }
        }
    }
}

Measured memory_bytes: 23764
#include<cstdio>
using namespace std;

const int INF=2e9;
int n,k,ans=INF;

inline void dfs(int x,int tot)
{
	if (x>n) {if (tot<ans) ans=tot; return;}
	dfs(x+1,tot*2); dfs(x+1,tot+k);
}
int main()
{
	scanf("%d%d",&n,&k);
	dfs(1,1); printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    //cout << t.substr(0, s.size());
    if (s == (t.substr(0, s.size()))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
/*input
2 2 2 2 2
8 6
9 1
2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    ll ans = 0;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    vector<ll> chosen;
    for(int i = 0; i < a; i++) cin >> p[i];
    for(int i = 0; i < b; i++) cin >> q[i];
    for(int i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());
	for(int i = a - 1; i > a - 1 - x; i--) chosen.emplace_back(p[i]);
	for(int i = b - 1; i > b - 1 - y; i--) chosen.emplace_back(q[i]);
	sort(chosen.begin(), chosen.end());
	int i = 0;
	int j = c - 1;
	while(i < x + y && j > -1 && r[j] > chosen[i])
	{
		chosen[i] = r[j];
		j--;
		i++;
	}
	for(int i = 0; i < x + y; i++) ans += chosen[i];
	cout << ans;
 
    return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<long long int, long long int> P;
typedef pair<P, long long int> PI;

void solve()
{
	int N;
	cin >> N;
	vector<long long int> A(N);
	vector<long long int> B(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i] >> B[i];
	}
	vector<P> dish(N);
	for (int i = 0; i < N; ++i)
	{
		dish[i] = P(A[i] + B[i], i);
	}
	sort(dish.begin(), dish.end());
	reverse(dish.begin(), dish.end());
	long long int takahashi = 0;
	long long int aoki = 0;
	for (int i = 0; i < N; ++i)
	{
		if (i % 2 == 0)
		{
			takahashi += A[dish[i].second];
		}
		else
		{
			aoki += B[dish[i].second];
		}
	}
	cout << takahashi - aoki << endl;
}

int main()
{
	solve();
	return(0);
}

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

int tanri(int init, int year, double rate, int fee ){
  int store=0;
  while( year-- ){
    double rishi = init * rate;
    store += (int)rishi;
    init -= fee;
  }
  return init + store;
}
int hukuri(int init, int year, double rate, int fee ){
  while( year-- ){
    double rishi = init * rate;
    init = init + (int)rishi - fee;
  }
  return init;
}


int main(){
  int m;

  int init, year, n;
  int betu;
  double rate;
  int fee;

  cin >> m;
  while(m--){
    cin >> init >> year >> n;
    int mx=0;
    while( n-- ){
      cin >> betu >> rate >> fee;
      if( betu )
	mx = max( mx, hukuri(init,year,rate,fee) );
      else
	mx = max( mx, tanri(init,year, rate,fee) );
    }
    cout << mx << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do
    s <- getLine
    let [a,b,c,d] = map read (map enlist s)
    let sn = [a+b+c+d,a+b+c-d,a+b-c+d,a-b+c+d,a+b-c-d,a-b-c+d,a-b+c-d,a-b-c-d]
    let n = head (elemIndices 7 sn)
    putStrLn (ans n s)
    
    
enlist :: a -> [a]
enlist a = [a]

ans :: Int -> String -> String
ans n s
  | n == 0 = ([(s !! 0)] ++ "+" ++ [(s !! 1)] ++ "+" ++ [(s !! 2)] ++ "+" ++ [(s !! 3)] ++ "=7")
  | n == 1 = ([(s !! 0)] ++ "+" ++ [(s !! 1)] ++ "+" ++ [(s !! 2)] ++ "-" ++ [(s !! 3)] ++ "=7")
  | n == 2 = ([(s !! 0)] ++ "+" ++ [(s !! 1)] ++ "-" ++ [(s !! 2)] ++ "+" ++ [(s !! 3)] ++ "=7")
  | n == 3 = ([(s !! 0)] ++ "-" ++ [(s !! 1)] ++ "+" ++ [(s !! 2)] ++ "+" ++ [(s !! 3)] ++ "=7")
  | n == 4 = ([(s !! 0)] ++ "+" ++ [(s !! 1)] ++ "-" ++ [(s !! 2)] ++ "-" ++ [(s !! 3)] ++ "=7")
  | n == 5 = ([(s !! 0)] ++ "-" ++ [(s !! 1)] ++ "-" ++ [(s !! 2)] ++ "+" ++ [(s !! 3)] ++ "=7")
  | n == 6 = ([(s !! 0)] ++ "-" ++ [(s !! 1)] ++ "+" ++ [(s !! 2)] ++ "-" ++ [(s !! 3)] ++ "=7")
  | otherwise = ([(s !! 0)] ++ "-" ++ [(s !! 1)] ++ "-" ++ [(s !! 2)] ++ "-" ++ [(s !! 3)] ++ "=7")

Measured memory_bytes: 508
#include <stdio.h>

int n, max;
char s[101], t[101];


int comp(int k) {
    for(int i=0; i<k; i++)
        if(s[i+n-k] != t[i]) return 0;
    return 1;
}

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

    for(int i=1; i<=n; i++)
        if(comp(i)) max=i;
    
    printf("%d", n+n-max);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll arr[10001];
ll dp[10001][101][2];
ll m = 1e9+7;
ll f(ll idx,ll sum,ll flag,ll n,ll d){
    if(idx == n){
        if(sum==0){return 1;}
        else{return 0;}
    }
    if(dp[idx][sum][flag]!=-1){return dp[idx][sum][flag];}
    ll ans=0;
    if(flag==1){
        rep(i,0,arr[idx]){
            if(i<arr[idx]){
              ans = (ans + f(idx+1,(sum%d+i%d)%d,0,n,d)%m)%m;
            }else{
              ans = (ans + f(idx+1,(sum%d+i%d)%d,1,n,d)%m)%m;  
            }
        }
    }
    else{
        rep(i,0,9){
             ans = (ans + f(idx+1,(sum%d+i%d)%d,0,n,d)%m)%m;
        }
    }
    dp[idx][sum][flag] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    string k; cin>>k;
    ll d; cin>>d;
    ll n = k.length();
    rep(i,0,n-1){
     arr[i] = (ll)k[i]-48;
    }
    cout<<(f(0,0,1,n,d)-(1%m)+m)%m ;
}


Measured memory_bytes: 20424
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll k, a, b; cin >> k >> a >> b;
    if(a-b <= 0){
        if(a < k){
            cout << -1 << endl;
        }else{
            cout << 1 << endl;
        }
        return 0;
    }
    ll ans = (k-a+(a-b-1))/(a-b);
    cout << 2*ans+1 << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, r;
    cin >> n >> r;
    if(n >= 10){
    	cout << r << endl;
    }else{
    	cout << r + 100 * (10 - n) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename INT>
INT gcd(INT a, INT b) {
  INT r = a%b;
  while(r){ a=b; b=r; r=a%b; }
  return b;
}

int main() {
  int64_t A, B, C, D; std::cin >> A >> B >> C >> D;
  int64_t L = C/gcd<int64_t>(C, D)*D;

  auto f = [&](int64_t X) { return X - X/D - X/C + X/L; };
  fin(f(B) - f(A-1));
  return 0;
}


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

typedef long long ll;

int k,t;
int a[111];

int main(void){
  cin >> k >> t;
  for(int i = 0; i < t; i++){
    cin >> a[i];
  }
  a[t] = 0;
  sort(a,a+t+1);

  while(1){
    sort(a,a+t+1);
    if(a[t-1]){
      a[t]--;
      a[t-1]--;
    }else{
      cout << max(a[t]-1,0) << endl;
      break;
    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    string mat[n];
    rep(i, n){
        cin >> mat[i];
    }

    vector<int> g[n];
    rep(i, n){
        rep(j, n){
            if(mat[i][j] == '1'){
                g[i].push_back(j);
            }
        }
    }

    // rep(i, n){
    //     cout << i << ": ";
    //     rep(j, g[i].size()){
    //         cout << g[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    ll ans = 0;
    rep(vstart, n){
        queue<int> que;
        que.push(vstart);
        
        int color[n] = {};
        color[vstart] = 1;

        bool isValid = true;

        while(!que.empty()){
            int v = que.front();
            que.pop();

            rep(i, g[v].size()){
                int u = g[v][i];

                if(color[u] != 0 && abs(color[u] - color[v]) == 1){
                    continue;
                }

                if(color[u] != 0 && abs(color[u] - color[v]) != 1){
                    isValid = false;
                    break;
                }

                color[u] = color[v] + 1;
                que.push(u);
            }
        }

        // cout << " " << isValid << endl;

        if(isValid){
            ll tempmax = *max_element(color, color+n);
            ans = max(ans, tempmax);
        }    
    }

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d", &x)
#define sc(x) scanf("%c", &x)
#define sl(x) scanf("%lld", &x)
#define pl(x) printf("%lld\n", x)
#define pi(x) printf("%d\n", x)
#define pii pair <int, int>
#define pll pair <long long, long long>
#define gu getchar_unlocked
#define pu putchar_unlocked
#define setbits __builtin_popcountll
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define speed ios::sync_with_stdio(false)

const int N = 100005;

int main(){
    int n;
    si(n);
    cout<<n * n * n<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int n = arr.length;
        int lastR = 0;
        int[] rArr = new int[n];
        int lastL = n - 1;
        int[] lArr = new int[n];
        for (int i = 0; i < n; i++) {
            if (arr[i] == 'R') {
                lastR = i;
            }
            rArr[i] = lastR;
            if (arr[n - i - 1] == 'L') {
                lastL = n - i - 1;
            }
            lArr[n - i - 1] = lastL;
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            if (arr[i] == 'R') {
                if ((lArr[i] - i) % 2 == 0) {
                    ans[lArr[i]]++;
                } else {
                    ans[lArr[i] - 1]++;
                }
            } else {
                if ((i - rArr[i]) % 2 == 0) {
                    ans[rArr[i]]++;
                } else {
                    ans[rArr[i] + 1]++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (i != 0) {
                sb.append(" ");
            }
            sb.append(ans[i]);
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 30940
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_buck(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second


int main(){
	string s;
	cin>>s;
	s[5]=' ';
	s[13]=' ';
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;

}
//##################################################################
set<ll>s;
void gen(ll num){
    if(num>1ll*3234566667)return;
    s.insert(num);
    ll l=num%10;
    gen(num*10+l);
    if(l+1<=9)gen(num*10+(l+1));
    if(l-1>=0)gen(num*10+(l-1));
}
int main(){
    for(int i=1;i<=9;i++)
        gen(i);
    int k=D();
    int cnt=1;
    for(auto it=s.begin();it!=s.end();it++){
        if(cnt==k){
            cout<<*it;
            return 0;
        }
        cnt++;

    }

}

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

int main() {
	int N, M, X;
	vector<int> V;
	int v;
	int i;
	cin >> N >> M >> X;
	for (i = 0; i < M; i++) {
		cin >> v;
		V.push_back(v);
	}
	int under_x = 0, upper_x = 0;
	for (auto v : V) {
		if (v < X)under_x++;
		else upper_x++;
	}
	cout << min(upper_x, under_x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double angleA = (h / (double)12 * (double)360) + (m / (double)60 * (double)30);
    double angleB = m / (double)60 * (double)360;
    double angleAB = fabsf(angleA - angleB);
    if (angleAB > 180)
    {
        angleAB = 360 - angleAB;
    }
    double temp = (double)pow(a, 2) + (double)pow(b, 2) - (2 * a * b * cos((double)angleAB * M_PI / (double)180));
    double ans = sqrt(temp);
    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4172
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

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

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n; double d, x;

double solve(int n, double d, double x) {
    if (n == 1) return d + x / 2;

    double curr = d + x * (2 * n - 1) / 2;
    return curr + solve(n-1, ((n+1) * d + 2.5 * x) / n, x + 2 * x / n);
}

int main() {
    cin >> n >> d >> x;
    cout << setprecision(12) << solve(n, d, x) << endl;
    
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define GIO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{ GIO;
int a,b;
cin>>a>>b;
if(a+b==15) cout<<"+"<<endl;
else if(a*b==15) cout<<"*"<<endl;
else cout<<"x"<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;

bool ok[1000001];
bool done[1000001];
int n,a,b;

bool check(int k){
	if(k==0) return true;
	if(k<0) return false;
	if(done[k]) return ok[k];

	done[k]=true;
	ok[k]=(check(k-a) || check(k-b));
}

int main()
{
	while(cin>>n>>a>>b && n!=0){
		memset(ok,false,sizeof(ok));
		memset(done,false,sizeof(done));
		int ans=0;
		ok[0]=true;
		for(int i=0;i<=n;i++){
			if(ok[i]){
				if(i+a<=n)
					ok[i+a]=true;
				if(i+b<=n)
					ok[i+b]=true;
			}
			else ans++;
		}
		cout<<ans<<endl;
	}
	return 0; 
}

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

signed main(){
    int n,w;cin>>n>>w;
    int dp[n+1][w+1];
    rep(i,w+1)dp[0][i]=0;
    rep(i,n){
        int ww,vv;cin>>ww>>vv;
        rep(j,w+1){
            if(j>=ww){
                dp[i+1][j]=max(dp[i][j],dp[i][j-ww]+vv);
            }else{
                dp[i+1][j]=dp[i][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 79104
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<complex>
#include<iostream>
#include<assert.h>
#include<algorithm>
using namespace std;
#define pb push_back
#define inf 1001001001
#define infll 1001001001001001001LL
#define FOR0(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR1(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define ld double
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define RI(n) int (n); scanf("%d",&(n));
#define RI2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define RI3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR0(i,sz(t))s<<t[i]<<" ";return s; }
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl
#define all(t) t.begin(),t.end()
#define FEACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS RI(testow)while(testow--)
#define FORZ(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define FORD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define gmax(a,b) (a)=max((a),(b))
#define gmin(a,b) (a)=min((a),(b))
#define ios0 ios_base::sync_with_stdio(0)
using namespace std;
int L[205];
ll ans; 
int main(){
	RI(n);
	FOR1(i,n*2)
		scanf("%d",&L[i]);	
	sort(L+1,L+2*n+1);
	FOR1(i,n){
		ans=ans+min(L[i*2-1],L[i*2]);
	}
	cout<<ans; 
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int A, B;
	int mark =0;
	scanf("%d %d", &A, &B);
	char in[A+B+1];
	scanf("%s", in);
	int ctr = 0;
	for(int i = 0; i < A+B+1 ; i++){
		if(in[i] == '-' && i == A){
			mark = 1;
		}else if(in[i] >= '0' && in[i] <= '9' ){
			++ctr;
		}
	}
	if( mark == 1 && ctr == A+B){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int n;
	cin >> n;
	cout << n * n*n << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

	int number[31] , number2;

	for(int i = 1; i <= 30; i++){
		number[i] = i;
	}
	for(int i = 1; i <= 28; i++){
		cin >> number2;
		for(int j = 1; j <= 30; j++){
			if(number[j] == number2){
				number[j] = 0;
			}
		}
	}

	sort(number+1 , number + 31 , greater<int>());

	cout << number[2] << endl;
	cout << number[1] << endl;
	
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>

using namespace std;

int main(){

    int n;
    cin >> n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    int maxv;
    int minv;

    for(int j=1;j<n;j++){
        if(j==1){
            maxv=arr[1]-arr[0];
            minv=(arr[0]<arr[1])?arr[0]:arr[1];
        }else{
            if((arr[j]-minv)>maxv)maxv=(arr[j]-minv);
            if(arr[j]<minv)minv=arr[j];
        }
    }

    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3872
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
using namespace std;
int main() {
	int a, b, c;
	int CC = 0;
	cin >> a >> b >> c;
	for (int i = a; i < b + 1; i++) {
		if (c % i == 0)CC++;
	}
	cout  << CC << "\n";
	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long N, product = 1, overflag = 0, zeroflag = 0, A;
    long meyasu = 1000000000000000000;
    scanf("%ld",&N);
    
    for(int i = 0; i < N && zeroflag == 0; i++)
    {
        scanf("%ld",&A);
        if(A==0)
        {
            overflag = 0;
            zeroflag = 1;
            product = 0;
        }
        else
        {
            //printf("%lf < %ld\n", (double)meyasu/product, A);
            if((double)meyasu / product < A)
            {
                overflag = 1;
            }
            else
            {
                product *= A;
                if(product > meyasu)
                    overflag = 1;
            }
        }
    }
    printf("%ld\n",(overflag == 1)? -1:product);
}


Measured memory_bytes: 3828
n,x = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
sum = a[0]
count = 1
for i in range(1,n):
  if sum<=x:
    sum += a[i]
    count += 1
if sum == x:
  print(count)
else:
  print(count-1)

Measured memory_bytes: 3060
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,i;cin>>n;
	int uede=-1,ues=0,stde=-1,sts=0;
	for(i=0;i<n;i++){
		int q;cin>>q;
		if(ues<=q){uede=i;ues=q;}
		if(sts>=q){stde=i;sts=q;}
	}
	vector<pair<int,int>>sosa;
	cout<<2*n<<endl;
	if(abs(ues)>abs(sts)){
		cout<<uede+1<<" 1"<<endl;
		cout<<uede+1<<" 1"<<endl;
		for(i=0;i<n-1;i++){
			cout<<i+1<<" "<<i+2<<endl;
			cout<<i+1<<" "<<i+2<<endl;
		}
	}else{
		cout<<stde+1<<" "<<n<<endl;
		cout<<stde+1<<" "<<n<<endl;
		for(i=n-1;i>0;i--){
			cout<<i+1<<" "<<i<<endl;
			cout<<i+1<<" "<<i<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m;
ll z = bit(30)-1;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n){
    int k;
    cin >> k;
    ll b = 0;
    FOR(j, 0, k){
      int a;
      cin >> a;
      a--;
      b ^= bit(a);
    }
    z &= b;
  }
  cout << __builtin_popcountll(z) << endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  reversePorandCalcuration(lines[0].split(" "));
});

function reversePorandCalcuration(tokens) {
  const operands = [];
  function getOperand() {
    const after = operands.pop();
    const before = operands.pop();
    return [before, after];
  }
  tokens.forEach((token) => {
    let o1, o2;
    switch (token) {
      case "+":
        [o1, o2] = getOperand();
        operands.push(o1 + o2);
        break;
      case "-":
        [o1, o2] = getOperand();
        operands.push(o1 - o2);
        break;
      case "*":
        [o1, o2] = getOperand();
        operands.push(o1 * o2);
        break;
      default:
        operands.push(Number(token));
        break;
    }
  });
  console.log(operands[0]);
}



Measured memory_bytes: 16532
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int h, w;
	while(cin >> h >> w) {
		if(h == 0 && w == 0) break;

		vector< vector< int > > v(h, vector<int>(w));
		rep(i, h) {
			rep(j, w) cin >> v[i][j];
		}

		int ans = 0;
		rep(i, 1 << h) {
			vector< vector<int> > t(v.begin(), v.end());
			rep(j, h) {
				if(i & (1 << j)) {
					rep(k, w) t[j][k] = !t[j][k];
				}
			}

			int res = 0;
			rep(j, w) {
				int cnt = 0;
				rep(k, h) cnt += t[k][j];
				res += max(cnt, h - cnt);
			}

			ans = max(ans, res);
		}

		cout << ans << endl;
	}
	return 0;
}

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

#define int long long
#define INF 1e18

int n;
vector<int> v;
vector<int> pref;

int memo[409][409];

int dp(int l, int r){
    if(l >= r) return 0;
    if(l+1 == r) return v[l]+v[r];
    if(memo[l][r] != -1) return memo[l][r];
    memo[l][r] = INF;
    for(int i  = l; i <= r; i++){
        memo[l][r] = min(memo[l][r], dp(l,i)+dp(i+1,r)+pref[r]-pref[l-1]);
    }
    return memo[l][r];
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    v.resize(n+1);
    pref.resize(n+1);
    fill(pref.begin(), pref.end(), 0);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        pref[i] += pref[i-1];
        pref[i] += v[i];
    }
    for(int i = 0 ; i < 409; i++){
        for(int j = 0; j < 409; j++){
            memo[i][j] = -1;
        }
    }
    cout << dp(1,n) << endl;
}


Measured memory_bytes: 1664