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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

vector<string> input(int h,int w){
    vector<string> p(h+2);
    rep(i,0,h+2) p[i].assign(w+2,'.');
    rep(i,1,h+1){
        string s;
        cin >> s;
        rep(j,0,w) p[i][1+j]=s[j];
    }
    return p;
}

pair<vector<set<int>>,int> make_tree(vector<string> p){
    int h=p.size(),w=p[0].size();
    vector<vector<int>> g(h,vector<int>(w,-1));
    vector<set<int>> res;
    vector<int> dy={0,-1,0,1,-1,-1,1,1},dx={1,0,-1,0,1,-1,-1,1};
    function<void(int,int,int)> dfs=[&](int y,int x,int i){
        g[y][x]=i;
        rep(j,0,p[y][x]=='.'?4:8){
            int ny=y+dy[j],nx=x+dx[j];
            if(ny<0 or h<=ny or nx<0 or w<=nx) continue;
            if(p[y][x]==p[ny][nx] and g[ny][nx]==-1) dfs(ny,nx,i);
            if(p[y][x]!=p[ny][nx] and g[ny][nx]!=-1){
                res[i].insert(g[ny][nx]);
                res[g[ny][nx]].insert(i);
            }
        }
    };
    rep(y,0,h) rep(x,0,w) if(g[y][x]==-1){
        res.push_back({});
        dfs(y,x,res.size()-1);
    }
    return make_pair(res,0);
}

template<class graph_type> string normalization(const graph_type& tree,int root,int parent){
    vector<string> vs;
    for(int child:tree[root]){
        if(child==parent) continue;
        vs.push_back(normalization(tree,child,root));
    }
    sort(vs.begin(),vs.end());
    string res("(");
    for(auto& s:vs) res+=s;
    res+=')';
    return res;
}

template<class graph_type> bool tree_isomorpshism(const pair<graph_type,int> &t1,const pair<graph_type,int> &t2){
    return normalization(t1.first,t1.second,-1)==normalization(t2.first,t2.second,-1);
}

void solve(int h1,int w1){
    auto p1=input(h1,w1);
    int h2,w2;
    cin >> h2 >> w2;
    auto p2=input(h2,w2);
    auto t1=make_tree(p1),t2=make_tree(p2);
    if(tree_isomorpshism(t1,t2)) cout << "yes" << endl;
    else cout << "no" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int h1,w1;
        cin >> h1 >> w1;
        if(!h1 and !w1) break;
        solve(h1,w1);
    }
    return 0;
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  cin >> n >> m;
  vector<ll>a(n),b(n),c(m),d(m);
  rep(i,n)cin >> a[i] >> b[i];
  rep(i,m)cin >> c[i] >> d[i];
  vector<int>ans(n);
  rep(i,n){
    int dist=1e9;
    for(int j=m-1;j>=0;j--){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<=dist){
        dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
        ans[i]=j+1;
      }
    }
  }
  
  rep(i,n) cout << ans[i] << endl;

  return 0;     
}


Measured memory_bytes: 256
(defun solve (xs &optional (cnt 0))
  (cond
    ((= cnt 3) t)
    ((null xs) nil)
    ((= (first (first xs)) (rest (first xs))) (solve (rest xs) (1+ cnt)))
    (t (solve (rest xs) 0))))


(defun main ()
  (let* ((n (read))
         (xs (loop repeat n collect (cons (read) (read)))))
    (princ (if (solve xs)
               "Yes"
               "No"))
    (fresh-line)))

#-swank (main)


Measured memory_bytes: 23740
package main

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

var reader = bufio.NewReader(os.Stdin)

func readNum() int {
	var str, _ = reader.ReadString('\n')
	var trimmed = strings.TrimSpace(str)
	var i, _ = strconv.Atoi(trimmed)
	return i
}

func leadSplit() []string {
	var str, _ = reader.ReadString('\n')
	var trimmed = strings.TrimSpace(str)
	var values = strings.Split(trimmed, " ")
	return values
}

func toNum(str string) int {
	var s, _ = strconv.Atoi(str)
	return s
}

func toInts(strs []string) []int {
	var results = make([]int, 0)
	for _, v := range strs {
		results = append(results, toNum(v))
	}
	return results
}

func main() {
	var N = readNum()
	var lengths = make([]int, 0)
	for _, v := range leadSplit() {
		lengths = append(lengths, toNum(v))
	}
	sort.Ints(lengths)
	var total int = 0
	for i := 0; i < 2 * N; i += 2 {
		var min = lengths[i]
		total += min
	}
	fmt.Println(total)
}


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

int main() {
	int S, h, m, s;
	scanf("%d", &S);//////////////////////////
	
	h = (S - (S % 3600)) / 3600;
	S = S - h * 3600;
	m = (S - (S % 60)) / 60;
	s = S - m * 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 2684
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {

//		Scanner sc = new Scanner(new File("/workspace/AOJ/src/section12/sample4.txt"));
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] mat = new int[n+1][n+1];

		// 初回訪問リスト
		int[] d = new int[n+1];
		Arrays.fill(d, -1);

		// 訪問完了リスト
		int[] f = new int[n+1];
		Arrays.fill(f, -1);

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();			// 番号
			int k = sc.nextInt();			// uの出次数
			for (int j = 0; j < k; j++) {
				int v = sc.nextInt();
				mat[u][v] = 1;
			}
		}

		Stack<Integer> stack = new Stack<Integer>();

		int count = 0;
		for (int index = 1; index <= n; index++) {
			if (d[index] == -1) {
				stack.add(index);
				d[index] = ++count;
			} else {
				continue;
			}

			while (!stack.isEmpty()) {
				int from = stack.peek();
				boolean isNext = false;
				for (int to = 1; to <= n; to++) {
					if (mat[from][to] == 1 && d[to] == -1) {
						stack.push(to);
						d[to] = ++count;
						isNext = true;
						break;
					}
				}
				if (!isNext) {
					from = stack.pop();
					f[from] = ++count;
				}
			}
		}



		// 幅優先探索
//		for (int i = 0; i < n; i++) {
//			int u = sc.nextInt();
//			int k = sc.nextInt();
//			for (int j = 0; j < k; j++) {
//				int v = sc.nextInt();
//				mat[u][v] = 1;
//			}
//		}
//
//
//		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
//		q.add(1);
//		v[1] = 0;
//
//		while (!q.isEmpty()) {
//			int f = q.poll();
//			for (int t = 1; t <= n; t++) {
//				if (mat[f][t] == 1) {
//					q.add(t);
//					if (v[t] == -1) {
//						v[t] = v[f] + 1;
//					}
//				}
//			}
//		}

		for (int i = 1; i <= n; i++) {
			System.out.println(i + " " + d[i] + " " + f[i]);
		}



	}

	public static void matPrint(int[][] mat) {
		for (int i = 1; i < mat.length; i++) {
			for (int j = 1; j < mat[i].length; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print("\n");
		}
	}

}



Measured memory_bytes: 28216
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        long count = 0;
        for (int i = 0; i < n; i++) {
            while (array[i] % 2 == 0) {
                array[i] /= 2;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 34120
#include <bits/stdc++.h>
using namespace std;
# define fills(x,y) memset(x,y,sizeof x)
# define ALL(v) (v).begin(), (v).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define INF (int)1e9
# define EPS 1e-9
# define rep(i,n) for(int i=0;i<n;++i)
# define REP(i,k,n) for(int i=k;i<=n;++i)
# define mod 1000000007

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef vector<ll> Vl;
typedef vector<Vl> VVl;
typedef vector<string> VS;
typedef vector<Pll> Vll;
typedef map<ll,ll> Mll;
typedef set<ll> SETl;


int		main()
{
	int k, s; cin >> k >> s;
	int ans = 0;
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			int a = s - i - j;
			if (a > k || a < 0) continue;
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
n = int(input())
for i in range(n):
    y, m, d = map(int, input().split())
    tmp = 0
    tmp += (y-1) * 195
    tmp += ((y-1) // 3) * 5
    tmp += (m-1) * 20
    if y % 3 != 0:
        tmp -= (m-1) // 2
    tmp += d
    print(196471 - tmp)



Measured memory_bytes: 5592
h,w = map(int,raw_input().split(' '))

d = {}

def quat(l):
    a=0
    for b in l:
        a += b % 4
    return a

def odd(l):
    a=0
    for b in l:
        a += b % 2
    return a

for i in range(h):
    s = raw_input()
    for j in range(w):
        if s[j] in d:
            d[s[j]] += 1
        else:
            d[s[j]] = 1
l=[]
for k in d:
    l += [d[k]]

if h*w % 2 == 1:
    if odd(l) != 1 or h+w-1 < quat(l):
        print "No"
    else:
        print "Yes"
elif h % 2 == 1:
    if odd(l) != 0 or w < quat(l):
        print "No"
    else:
        print "Yes"
elif w % 2 == 1:
    if odd(l) != 0 or h < quat(l):
        print "No"
    else:
        print "Yes"
else:
    if 0 == quat(l):
        print "Yes"
    else:
        print "No"


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

int main(void){
    int n,m,ans = 0;
    cin >> n;
    vector<int> t(n);
    for(int i = 0;i < n;i++)cin >> t[i];
    cin >> m;
    vector<int> p(m),x(m);
    for(int i = 0;i < m;i++)cin >> p[i] >> x[i];
    for(int i = 0;i < m;i++,ans = 0){
        ans = accumulate(t.begin(),t.end(),0);
        if(x[i] > t[p[i]-1])ans += x[i] - t[p[i]-1];
        else ans -= t[p[i]-1] - x[i];
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int N_MAX = 200000;
int main()
{
  int n;
  cin >> n;
  int a[N_MAX];
  for(int i=0;i<n;i++)
    cin >> a[i];
  sort(a,a+n);
  int m;
  long long sum = 0;
  if(n%2==1){
    m = (n-1)/2;
    for(int i=1;i<=m;i++)
      sum += 2*i*(long long)(a[i]-a[i-1]+a[n-i]-a[n-i-1]);
    sum -= min(a[m]-a[m-1],a[m+1]-a[m]);
  } else {
    m = n/2-1;
    for(int i=1;i<=m;i++)
      sum += 2*i*(long long)(a[i]-a[i-1]+a[n-i]-a[n-i-1]);
    sum += (2*m+1)*(long long)(a[m+1]-a[m]);
  }
  cout << sum << endl;
  return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll n;

    cin >> n;

    ll a;
    REP(i, n){
        cin >> a;
        if (a%2==0){
            if (a%3!=0 && a%5!=0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  ll A[X], B[Y], C[Z];
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];
  vector<ll> v;
  REP(i, X) REP(j, Y) {
    v.PB(A[i] + B[j]);
  }
  sort(ALL(v));
  reverse(ALL(v));
  v.resize(K);
  vector<ll> ans;
  REP(i, Z) REP(j, K) {
    ans.PB(C[i] + v[j]);
  }
  sort(ALL(ans));
  reverse(ALL(ans));
  REP(i, K) cout << ans[i] << '\n';
}


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

int main() {
  int n, m, x; cin >> n >> m >> x;
  vector<int> tolls(n + 1, 0);
  for (int i = 0; i < m; i++) {
    int num; cin >> num;
    tolls.at(num) = 1;
  }
  
  vector<int> fees(n + 1);
  partial_sum(tolls.begin(), tolls.end(), fees.begin());
  
  int answer = min(fees.at(x), fees.at(n) - fees.at(x));  
  cout << answer << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1), b(n);
    ll count = 0;
    rep(i,n+1) {
        cin >> a[i];
        count += a[i];
    }
    rep(i,n) cin >> b[i];

    rep(i,n) {
        if (a[i] >= b[i]) {
            a[i] -= b[i];
            b[i] = 0;
        }
        else {
            b[i] -= a[i];
            a[i] = 0;
            if (a[i+1] >= b[i]) {
                a[i+1] -= b[i];
                b[i] = 0;
            }
            else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
    }

    ll count2 = 0;
    rep(i,n+1) {
        count2 += a[i];
    }

    cout << count - count2 << endl;


    return 0;
}

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

void Main() {
    // input
    char alpha;
    cin >> alpha;


    // translate
    char ans;
    if (alpha == toupper(alpha)) {
        ans = 'A';
    } else {
        ans = 'a';
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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

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

int main() {
  long long N, K;
  cin >> N >> K;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  long long left = -1, right = 1000000000;
  while (right - left > 1){
    long long mid = (left + right) / 2;
    long long count = 0;
    for (long long i = 0; i < N; i++){
      if (mid == 0) {
        count = 100000000000;
        break;
      }
      count += A[i] / mid;
      if (A[i] % mid == 0) count--;
      if (count > K) break;
    }
    if (count <= K) right = mid;
    else left = mid;
  }
  
  cout << right << endl;
}


Measured memory_bytes: 5180
import qualified Data.Vector.Unboxed as U
import Data.Bits
import Data.List
import Control.Monad

solve :: Int -> Int -> U.Vector (Int, Int) -> Int
solve d g pc = minimum ans where
  ans =
    [ num | b <- [(0 :: Int)..2^d-1]
    , let (num, scr) = f b, scr >= g ] 
  f b = (ncmp + nres, comp + rest) where
    (ncmp, comp) = foldl pairAdd (0, 0) $
      [ (p, p*(i+1)*100 + c)
      | i<-[0..d-1], testBit b i, let (p, c) = pc U.! i ]
    (nres, rest) = case find (not.testBit b) [d-1,d-2..0] of
      Nothing -> (0, 0)
      Just i -> let (p, c) = pc U.! i in
        let nres = max 0 $ min p ((g-comp) `divC` (100*(i+1))) in
        (nres, nres * 100 * (i+1))

pairAdd (a,b) (c,d) = (a+c, b+d)
a `divC` b = (a+b-1) `div` b

main = do
  [d, g] <- readWords
  pc <- replicateM d $ (\[a,b]->(a,b)) <$> readWords
  print $ solve d g (U.fromList pc)

readWords = map read . words <$> getLine

Measured memory_bytes: 1020
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;

    List<Integer>[] lists = new ArrayList[n];

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();

        int m = sc.nextInt();
        for (int i=0; i<m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            lists[s].add(t);
            lists[t].add(s);
        }

        dfs("", n);

        System.out.println(cnt);

    }

    void dfs(String s, int n) {

        if (s.length() == n) {
//            System.out.println(s);
            if (s.charAt(0) == '0') {
                boolean check = true;
                for (int i=0; i<s.length()-1; i++) {
                    if (!lists[s.charAt(i) - 48].contains(s.charAt(i+1) - 48)) {
                        check = false;
                        break;
                    }
                }
                if (check) cnt++;
            }

        } else {
            for (int i=0; i<n; i++) {
                if (s.contains(String.valueOf(i))) continue;
                dfs(s + i, n);
            }
        }
    }


}



Measured memory_bytes: 59016
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    set<pair<int,int>> st;
    int N,Q;
    cin >> N >> Q;
    vector<int> S(N),T(N),X(N);
    vector<tuple<int,int,int>> a(N);
    rep(i,N){
        cin >> S[i] >> T[i] >> X[i];
        a[i] = tie(X[i],S[i],T[i]);
    }
    sort(ALL(a)); // X が小さい順にソートする
    vector<int> D(Q); 
    rep(i,Q)cin >> D[i];
    for(int i = 0; i < Q; i++){
        st.insert({D[i],i}); // 開始時刻が早い人から調べていく
    }
    vector<int> ans(Q,-1);
    for(int i = 0;i<N;i++){
        // x が小さい人から調べていく
        int x,l,r;
        tie(x,l,r) = a[i];
        l-=x;
        r-=x;
        auto it = st.lower_bound(pair<int,int>(l,-1));
        while(it != st.end()){
            if(it->first >=r)break;
            ans[it->second] = x;
            st.erase(it++);
        }
    }
    for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 17536
package main

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

var outCnt int
var out bytes.Buffer

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	H := nextInt()
	W := nextInt()
	var f Filed
	f.mas = make([][]int, H)
	for i := 0; i < H; i++ {
		f.mas[i] = nextInts(W)
	}
	for i := 0; i < H; i++ {
		for j := 0; j < W-1; j++ {
			if f.mas[i][j]%2 == 1 {
				f.Move(i, j, i, j+1)
			}
		}
	}
	for i := 0; i < H-1; i++ {
		j := W - 1
		if f.mas[i][j]%2 == 1 {
			f.Move(i, j, i+1, j)
		}
	}
	fmt.Println(outCnt)
	// fmt.Print(out.String())
	n, err := out.WriteTo(os.Stdout)
	log.Println(n, err)
	// log.Print("\n", f.String())
}

type Filed struct {
	mas [][]int
}

func (f *Filed) Move(a, b, c, d int) {
	out.WriteString(fmt.Sprintf("%d %d %d %d\n", a+1, b+1, c+1, d+1))
	outCnt++
	if f.mas[a][b] <= 0 {
		panic("error")
	}
	f.mas[a][b]--
	f.mas[c][d]++
}

// func (f Filed) String() string {
// 	var out bytes.Buffer
// 	for i := 0; i < len(f.mas); i++ {
// 		out.WriteString(fmt.Sprintln(f.mas[i]))
// 	}
// 	return out.String()
// }
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

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

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  int p[A], q[B], r[C];
  rep(i,A) cin >> p[i];
  rep(i,B) cin >> q[i];
  rep(i,C) cin >> r[i];
  sort(p,p+A,greater<int>());
  sort(q,q+B,greater<int>());
  sort(r,r+C,greater<int>());

  priority_queue<int,vector<int>,greater<int>> l;
  rep(i,X) l.push(p[i]);
  rep(i,Y) l.push(q[i]);

  int idx = 0;
  while (idx<C) {
    int MIN = l.top();
    if (MIN>=r[idx]) break;
    
    l.pop();
    l.push(r[idx]);
    idx++;
  }

  ll ans = 0;
  while (!l.empty()){
    ans += l.top(); l.pop();
  }
  cout << ans << endl;

    

  // cout << fixed << setprecision(10);
  
  return 0;
}


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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;

bool match(string const& a, string const& b, size_t idx){
    for(size_t i=0;i<b.length();++i,++idx)
        if(a[idx] != '?' && a[idx] != b[i])
            return false;
    return true;
}

string replace(string const& a, string const& b, size_t idx){
    string ret = a;
    for(size_t i=0;i<b.length();++i,++idx)
        ret[idx] = b[i];
    for(char& c : ret)
        if(c == '?') c = 'a';
    return ret;
}

void solve(){
    string s,t;
    cin>>s>>t;
    if(t.length() > s.length()){
        cout<<"UNRESTORABLE\n";
        return;
    }
    vector<string> ans;
    for(int i = s.length()-t.length();i>=0;--i)
        if(match(s,t,i))
            ans.pb(replace(s,t,i));
    if(ans.empty())
        cout<<"UNRESTORABLE\n";
    else
        cout<<*min_element(ALL(ans))<<'\n';
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define ld long double
#define F first
#define S second
#define mem(v) memset(v,0,sizeof(v))
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define mp make_pair
#define dbg1(a) cout<<a<<"\n";
#define dbg2(a,b) cout<<a<<" "<<b<<"\n";
#define hell 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using namespace std:: chrono;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; 
if (m == 1) {return 0;} 
while (a > 1) { ll q = a / m; ll t = m;  m = a % m, a = t; t = y; y = x - q * y; x = t; } 
if (x < 0) {x += m0;} return x; } 
inline ll add(ll a, ll b) { return (((a >= hell) ? a % hell : a) + ((b >= hell) ? b % hell : b) + hell) % hell; }
inline ll subt(ll a, ll b) { return (a - b + hell) % hell; }
inline ll mult(ll a, ll b) { return (1ll * ((a >= hell) ? a % hell : a) * ((b >= hell) ? b % hell : b)) % hell; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll mylog(ll n,ll b)
{ll i = 1;ll ans = 0;
while(1)
{if(i>n/b){break;} i = i*b;ans++;}return ans;
}
bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b){
if (a.first == b.first)
{return a.second<b.second;} 
return a.first<b.first;
}
bool comparerev(const pair<ll,ll> &a,const pair<ll,ll> &b){
if(a.first == b.first)
{return a.second>b.second;}
return a.first>b.first;
}
vector<ll>mm[100005];
int main()
{
	fast
	ll t = 1;
	//cin>>t;
	while(t--){
	ll n,m;
	cin>>n>>m;
	ll h[n];
	f(n)
	{
		cin>>h[i];
	}
	ll obs = 0;
	ll no1,no2;
	f(m)
	{
		cin>>no1>>no2;
		mm[no1-1].pb(no2-1);
		mm[no2-1].pb(no1-1);
	}
	f(n)
	{
		if(mm[i].size() == 0)
		{
			obs++;
		}
		else
		{
			bool ok = true;
			for(ll j = 0;j<mm[i].size();j++)
			{
				ll val = mm[i][j];
				if(h[val]>=h[i])
				{
					ok = false;
				}
			}
			if(ok)
			{
				obs++;
			}
		}
		
	}
	cout<<obs<<"\n";
	} 
	return 0;
}

Measured memory_bytes: 10272
count = {}
for i in range(26):
    count[(i)] = 0

while True:
    try:
        x = raw_input()
    except:
        break
    for i in range(len(x)):
        if(ord('a') <= ord(x[i]) and ord(x[i]) <= ord('z')):
            count[(ord(x[i])-ord('a'))] += 1
        elif(ord('A') <= ord(x[i]) and ord(x[i]) <= ord('Z')):
            count[(ord(x[i])-ord('A'))] += 1

for i in range(26):
    print '%s : %d' %(chr(i+ord('a')), count[(i)])
exit(0)

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

int cmp(int a, int b) {
    if (a == b) {
        return 0;
    }
    return a < b ? -1 : 1;
}

void solve() {
    string s;
    read(s);
    int n = s.size();
    int ans = 0;
    char prev = s[0];
    FOR(i, 1, n) {
        if (s[i] != prev) {
            ans++;
            prev = s[i];
        }
    }
    print(ans);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



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

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;


void solve() {
    vector<int> a(5);
    int ans = 0;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
        if (a[i] == 0) ans = i + 1;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
 
int main() {
  int n = 0;
  cin >> n;
  
  double ans = 0.0;
  
  if (n % 2 == 0) {
    ans = 1.0 / 2.0;
  } else {
    ans = (n + 1.0) / (2.0 * n);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  int s[N]={};
  int tmp;
  for(int i=0; i<Q; i++){
    cin >> tmp;
    s[tmp-1]++;
  }
  
  for(int j=0; j<N; j++){
    if(K-Q+s[j]>0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;  
}

Measured memory_bytes: 1024
using System;
class Program
{
  static void Main(string[] args)
  {
    // 入力値を取得
    int n = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
      sum += 1.0 / double.Parse(input[i]);
    }
    Console.WriteLine(1.0 / sum);
  }
}


Measured memory_bytes: 11220
n,m = map(int,input().split())
kls = []
for i in range(m):
    kls.append(list(map(int,input().split())))
pls = list(map(int,input().split()))
#print(kls)
#print(pls)
ans = 0 #答え
for j in range(2**n): #スイッチの点灯状態を表す
    cnt = 0 #点灯している電球の数のカウント
    for h in range(m): #電球の数だけループをまわす
        cnts = 0 #onスイッチの数のカウント
        for y in kls[h][1:]: #電球に接続されているスイッチの数だけループをまわす
            #print(y)
            if (((j >>(y-1))) & 1): #bit全探索スイッチ番号ー１だけずらして判定
                #print(((j >>(y-1))) & 1)
                cnts += 1
        if cnts%2 == pls[h]: #スイッチの個数を2で割った余りが等しい
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
ll const MOD = 1e9 + 7;
int cou(string s,string m)
{
    int ans=0;
    for(int i=0;i<s.size();i++)
        if(s[i]!=m[i])ans++;
    return ans;
}
int main()
{
    string s,t;
    cin>>s>>t;
    int n=t.size();
    int ans=INT_MAX;
    for(int i=0;i<=s.size()-n;i++)
        ans=min(ans,cou(t,s.substr(i,n)));
    cout<<ans<<endl;

}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int n;
    cin >> n;

    int ma1 = 0;
    int ma2 = 0;

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

    sort(b.begin(), b.end(), greater<int>());

    for (int i = 0; i < n; i++) {
        if (a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl; 
    }
    
    return 0;


    
    

}

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

string text;
int result = 0;

int main() {
  
  cin >> text;
  
  if (text[0] == '1') result++;
  if (text[1] == '1') result++;
  if (text[2] == '1') result++;
  
  cout << result << 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);
        List<Integer> amount = new ArrayList<>();
        while (sc.hasNext()) {
            amount.add(sc.nextInt());
        }

        Collections.sort(amount);
        int result = amount.get(0) + amount.get(1);
        System.out.println(result);
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
typedef long long int ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); i++)
#define REPEQ(i, n) FOREQ(i, 0, n)

int main()
{
    int a, b;
    cin >> a >> b;

    if ((a + b) % 2 == 0)
    {
        cout << (a + b) / 2 << endl;
    }
    else
    {
        cout << (a + b) / 2 + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
n, x, y = map(int, sys.stdin.readline().split())

x -= 1
y -= 1
    
final = [0]*(n-1)


for i in range(n-1):
    for j in range(i+2, n):
        if j < x or i > y:
            dist = j-i
        else:
            dist = min([j - i, abs(x-i) + 1 + abs(y-j), abs(y-i) + 1 + abs(x-j)])
        final[dist-1] += 1 
final[0] = n
res = [str(one) for one in final]
print ("\n".join(res))

Measured memory_bytes: 44636
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long a[100010];
int main(){
	cin>>n>>m;
	a[0]=1;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		a[x]=-1;
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1){
			if(a[i-1]!=-1)
				a[i]+=a[i-1]%1000000007;
			if(a[i-2]!=-1)
				a[i]+=a[i-2]%1000000007;
		}
	}
	cout<<a[n]%1000000007;
	return 0;
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fr first
#define sc second
#define MAX ((ll)(1e18+100))
#define MOD ((ll)(1e9+7))
#define HS1 ((ll)(137))
#define HS2 ((ll)(1e9+9))
#define ARRS ((ll)(6e5+900))
#define pb push_back
#define mid ((l+r)>>1)
#define PI 3.14159265358979323846

ll a[ARRS];

string s;
int main(){
	cin>>s;
	ll l=0;
	string k;
	for(int i=0; i<s.size(); i++){
		if(s[i]!='x')k+=s[i],l++;
		else 
			a[l]++;
	}
	string p;
	p=k;
	reverse(p.begin(),p.end());
	if(p!=k){cout<<-1; return 0;}
	ll pas=0;
	for(int i=0; i<=l/2; i++){

		if(i==l-i)continue;
		pas+=abs(a[i]-a[l-i]);
	}
	cout<<pas;
	return 0;
}


Measured memory_bytes: 1024
import numpy as np

def main():

    H,W = map(int,input().split())
    A = [[0 if s == "." else 1 for s in list(input())] for _ in range(H)]

    for i in reversed(range(H)):
        if sum(A[i]) == 0:
            A.pop(i)

    A = np.array(A).T.tolist()
    for i in reversed(range(W)):
        if sum(A[i]) == 0:
            A.pop(i)
    A = np.array(A).T.tolist()

    for i in range(len(A)):
        print("".join(["." if i == 0 else "#" for i in A[i]]))

main()


Measured memory_bytes: 27280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region sieve
struct sieve
{
    ll n;
    vector<ll> f, primes;

    sieve(ll n = 1) : n(n), f(sqrt(n) + 5)
    {
        for (ll i = 2; i * i <= n; i++)
        {
            if (f[i])
                continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= f.size(); j += i)
            {
                if (!f[j])
                    f[j] = i;
            }
        }
    }

    bool isPrime(ll x)
    {
        return f[x] == x;
    }

    vector<ll> factorList(ll x)
    {
        vector<ll> res;
        while (x != 1)
        {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<ll, ll>> factor(ll x)
    {
        auto fl = factorList(x);
        if (fl.size() == 0)
        {
            return {};
        }
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl)
        {
            if (res.back().first == p)
            {
                res.back().second++;
            }
            else
            {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};
#pragma endregion

int main()
{
    ll n;
    cin >> n;
    ll k = n;
    vint t(50);
    rep(i, 50) t[i] = (i * (i + 1)) / 2;
    ll ans = 0;
    map<int, int> pl;
    while (n != 1)
    {
        ll g = n;
        for (int p = 2; p <= sqrt(n) + 5; p++)
        {
            while (n % p == 0)
            {
                n /= p;
                pl[p]++;
            }
        }
        if (n == g)
        {
            pl[n]++;
            break;
        }
    }

    for (P p : pl)
    {
        int c = lower_bound(t.begin(), t.end(), p.second) - t.begin();
        if (p.second < t[c])
        {
            c--;
        }

        ans += c;
    }
    if (pl.size() == 0 && k != 1)
    {
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}

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

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

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

	int a,b,k;
	cin >> a >> b >> k;
	vector<int> factors;
	for(int i=gcd(a,b); i>=1; i--){
		if(a%i==0 and b%i==0){
			factors.push_back(i);
		}
	}
	cout << factors[k-1];
	return 0;
}

Measured memory_bytes: 3612
import collections
dd = collections.defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
    if dd[k] >= 4:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])

Measured memory_bytes: 23720
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

ans = 0

if X > sum(A):
    print(N-1)
else:
    for i in range(len(A)):
        if X >= A[i]:
            X -= A[i]
            ans += 1
        else:
            break
    print(ans)


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

#define ll long long

int main()
{
    ll n, k;
    cin >> n >> k;
        
    ll sum=0;
    
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    sort(a.begin(),a.end());
    
    for(int i=0;i<k;i++)sum+=a[i];

    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3604
N,M = map(int,input().split())
L = []
ans = 0
for i in range(N):
  L.append(list(map(int,input().split())))
K = []
for i in range(M):
  K.append(list(map(int,input().split())))
for j in range(N):
  S = float('inf')
  ans = 0
  for k in range(M):
    if abs(L[j][0]-K[k][0])+abs(L[j][1]-K[k][1]) < S:
      S = abs(L[j][0]-K[k][0])+abs(L[j][1]-K[k][1])
      ans = k+1 
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <tuple>
using namespace std;
using int64 = long long int;
using AnsType = vector< vector<int64> >;
using Graph = vector< vector< pair<int, int> > >;
const int64 INF = 1LL << 60;

int N, T, K, is_base[10010];
AnsType merge(int cost, AnsType& A, AnsType& B) {
  int sz = min<int>(A.size() + B.size(), K + 1);
  AnsType res(sz, vector<int64>(2, INF));
  for(size_t i=0; i<A.size(); i++) {
    for(size_t j=0; i+j<sz and j<B.size(); j++) {
      {
        res[i+j][0] = min(res[i+j][0], A[i][0] + B[j][0]);
        res[i+j][1] = min(res[i+j][1], A[i][1] + B[j][0]);
        res[i+j][1] = min(res[i+j][1], A[i][0] + B[j][1]);
        res[i+j][1] = min(res[i+j][1], A[i][1] + B[j][1]);

        if(i+j+1 < sz) {
          res[i+j+1][0] = min(res[i+j+1][0], A[i][0] + B[j][1] + cost);
          res[i+j+1][1] = min(res[i+j+1][1], A[i][1] + B[j][1] + cost);
        }
      }
    }
  }
  return res;
}

AnsType solve_dp(Graph &G, int cur, int par=-1) {
  // fprintf(stderr, "cur = %d, par = %d\n", cur, par);
  AnsType res(1, vector<int64>(2, INF));
  res[0][is_base[cur]] = 0;
  
  for(auto e : G[cur]) {
    int to, cost; tie(to, cost) = e;
    if(to == par) continue;
    auto tmp = solve_dp(G, to, cur);
    res = merge(cost, res, tmp);
  }

  /*
  for(size_t i=0; i<res.size(); i++) {
    for(size_t j=0; j<res[i].size(); j++) {
      fprintf(stderr, "cur = %d, dp[%zu][%zu] = %lld\n", cur, i, j, res[i][j]);
    }
  }
  */
  return res;
}

int solve(int case_num) {
  scanf("%d%d%d", &N, &T, &K);
  // cin >> N >> T >> K;
  if(N == 0 and T == 0 and K == 0) return 1;
  fill(is_base, is_base + N, false);

  Graph G(N);
  for(int i=0; i<N-1; i++) {
    int u, v, w; // cin >> u >> v >> w;
    scanf("%d%d%d", &u, &v, &w);
    u--; v--;
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
  }

  for(int i=0; i<T; i++) {
    int v; scanf("%d", &v);
    is_base[v-1] = true;
  }

  auto ans = solve_dp(G, 0);
  printf("Case %d: %lld\n", case_num, ans[K][1]);
  // cout << "Case " << case_num << ": ";
  // cout << ans[K][1] << endl;
  return 0;
}

int main() {
  int t = 0;
  while(!solve(++t));
  return 0;
}



Measured memory_bytes: 6472
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
#define cint(...) ll __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__);

int main() {
	cint(m);
	cout << 48 - m << endl;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())

h = [int(input()) for _ in range(N)]

h.sort()

ans = float("inf")

for i in range(len(h)-(K-1)):
    ans = min(ans, h[i+K-1] - h[i])

print(ans)

Measured memory_bytes: 44508
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    }

    let zipper: Vec<_> = s.chars().zip(t.chars()).collect();
    let ans = zipper.iter().fold(
        0,
        |acc, (s_char, t_char)| if *s_char != *t_char { acc + 1 } else { acc },
    );
    println!("{}", ans);
}


Measured memory_bytes: 4284
#include<cstdio>
#include<algorithm>
int a[100000];
int main(){
    int n,sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=std::abs(a[i]);
    }
    std::sort(a,a+n);
    if(a[0]>=0){
        printf("%d\n",sum-2*a[0]);
        int tmp=a[0];
        for(int i=1;i<n-1;i++){
            printf("%d %d\n",tmp,a[i]);
            tmp-=a[i];
        }
        printf("%d %d\n",a[n-1],tmp);
    }else if(a[n-1]<=0){
        printf("%d\n",sum+2*a[n-1]);
        int tmp=a[n-1];
        for(int i=0;i<n-1;i++){
            printf("%d %d\n",tmp,a[i]);
            tmp-=a[i];
        }
    }else{
        printf("%d\n",sum);
        int l=0;
        while(a[l]<=0)l++;
        int tmp=a[0];
        for(int i=l+1;i<n;i++){
            printf("%d %d\n",tmp,a[i]);
            tmp-=a[i];
        }
        printf("%d %d\n",a[l],tmp);
        tmp=a[l]-tmp;
        for(int i=1;i<l;i++){
            printf("%d %d\n",tmp,a[i]);
            tmp-=a[i];
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		ll N,K,X,Y;
		 
		cin >> N >> K >> X >> Y;

		if(N>K){
			cout << X*K+Y*(N-K); 
		}else{
			cout << X*N;
		}
		return 0;
    }

Measured memory_bytes: 256
import sys

np = input().split()
n = int(np[0])
p = int(np[1])
bound_p = int(p ** (1 / min(n, 4)))


if n == 1:
    print(p)
    sys.exit(0)


ilist = list(range(2, bound_p + 1))
ilist.reverse()


for i in ilist:
    pp = p
    for j in range(n):
        if pp % i != 0:
            break
        pp = pp // i
    else:
        print(i)
        sys.exit(0)


print(1)


Measured memory_bytes: 37748