akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;
char s[N], t[N];

int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    rep(i,1,n) t[i]=s[i];
    sort(t+1,t+1+n);
    int cnt=0;
    rep(i,1,n) if(s[i]!=t[i]) ++cnt;
    cnt>>=1;
    printf("%d\n",cnt);
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     ·ð×æ±£ÓÓ      ÓÀÎÞBUG


Measured memory_bytes: 4180
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define BSZ  __builtin_popcount
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
// G : yen, H : snuke
vector<pii> G[N], H[N];
ll n, m, a[N], ans = 1e15, s, t;
ll d1[N], d2[N], mi[N];

void dijkstra1(int src) {
	set<pii> q;
	d1[src] = 0;
	q.insert(MP(0, src));
	while (q.size()) {
		ll v = q.begin()->second;
		q.erase(q.begin());
		for (auto u : G[v])
			if (d1[u.first] > d1[v] + u.second) {
				q.erase(MP(d1[u.first], u.first));
				d1[u.first] = d1[v] + u.second;
				q.insert(MP(d1[u.first], u.first));
			}
	}
}

void dijkstra2(int src) {
	set<pii> q;
	d2[src] = 0;
	q.insert(MP(0, src));
	while (q.size()) {
		ll v = q.begin()->second;
		q.erase(q.begin());
		for (auto u : H[v])
			if (d2[u.first] > d2[v] + u.second) {
				q.erase(MP(d2[u.first], u.first));
				d2[u.first] = d2[v] + u.second;
				q.insert(MP(d2[u.first], u.first));
			}
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	memset(d1, 63, sizeof d1);
	memset(d2, 63, sizeof d2);
	cin >> n >> m >> s >> t;
	for (ll i = 0, v, u, w1, w2; i < m; i++) {
		cin >> v >> u >> w1 >> w2;
		G[v].push_back(MP(u, w1));
		G[u].push_back(MP(v, w1));
		H[v].push_back(MP(u, w2));
		H[u].push_back(MP(v, w2));
	}
	dijkstra1(s);
	dijkstra2(t);
	for (int i = 1; i <= n; i++)
		a[i] = d1[i] + d2[i];
	mi[n] = a[n];
	for (int i = n - 1; i; i--)
		mi[i] = min(a[i], mi[i + 1]);
	for (int i = 0; i < n; i++)
		cout << ans - mi[i + 1] << endl;
}


Measured memory_bytes: 22016
from collections import deque

n=int(input())
a=list(map(int,input().split()))

b=deque()

if n%2==0:
    for i in range(n):
        if i%2==0:
            b.append(a[i])
        else:
            b.appendleft(a[i])

else:
    for i in range(n):
        if i%2==0:
            b.appendleft(a[i])
        else:
            b.append(a[i])

print(*b)

Measured memory_bytes: 25412
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
const ll SIZE=1010;
//未AC

int main(void){
	ll n,k,x,y,W[SIZE][SIZE],B[SIZE][SIZE],Wdp[SIZE][SIZE],Bdp[SIZE][SIZE],ans=0;
	char c;
	rep(i,SIZE)rep(j,SIZE){
		W[i][j]=0;
		B[i][j]=0;
		Wdp[i][j]=0;
		Bdp[i][j]=0;
	}
	cin>>n>>k;
	rep(i,n){
		cin>>x>>y>>c;
		ll d = x/k + y/k;//全てkxk内に収める
		bool black=true;
		if(c=='W')black=false;
		if(d%2==1)black=!black;
		if(black){
			B[x%k][y%k]++;
		}else{
			W[x%k][y%k]++;
		}
	}
	rep(i,k)rep(j,k){//(0,0)から(i,j)までの総和
		if(i>0){
			Wdp[i][j]+=Wdp[i-1][j];
			Bdp[i][j]+=Bdp[i-1][j];
		}
		if(j>0){
			Wdp[i][j]+=Wdp[i][j-1];
			Bdp[i][j]+=Bdp[i][j-1];
		}
		if(i>0 && j>0){
			Wdp[i][j]-=Wdp[i-1][j-1];
			Bdp[i][j]-=Bdp[i-1][j-1];
		}
		Wdp[i][j]+=W[i][j];
		Bdp[i][j]+=B[i][j];
	}
	// rep(i,k){
	// 	rep(j,k)printf("%lld ",W[i][j]);
	// 	printf("\n");
	// }
	// rep(i,k){
	// 	rep(j,k)printf("%lld ",B[i][j]);
	// 	printf("\n");
	// }
	rep(i,k)rep(j,k){//i,jまでが切れ目
		ll w=Wdp[k-1][k-1],b=0;
		//BW
		//WB
		w-=Wdp[i][k-1];
		b+=Bdp[i][k-1];
		w-=Wdp[k-1][j];
		b+=Bdp[k-1][j];
		w+=2*Wdp[i][j];
		b-=2*Bdp[i][j];
		ans=max(ans,b+w);

		w=0,b=Bdp[k-1][k-1];
		//WB
		//BW
		b-=Bdp[i][k-1];
		w+=Wdp[i][k-1];
		b-=Bdp[k-1][j];
		w+=Wdp[k-1][j];
		b+=2*Bdp[i][j];
		w-=2*Wdp[i][j];
		ans=max(ans,b+w);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 32128
#include <stdio.h>
#include <math.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    double a1=(double)a,b1=(double)b,c1=(double)c/180.0*M_PI;
    double S=a1*b1*(sin(c1))/2.0;
    double h=b1*sin(c1);
    double L=a1+b1+pow(pow(h,2.0)+pow(a1-b1*cos(c1),2.0),0.5);
    printf("%lf %lf %lf\n",S,L,h);
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int num = 0;
  int bai = 1;
  vector<int> n(2019);
  for(int i=s.size()-1;i>=0;i--){
    int z = s[i] - '0';
    num = (num+z*bai)%2019;
    bai = bai*10%2019;
    n[num%2019]++;
  }
  n[0]++;
  long long ans = 0;
  for(int i=0;i<2019;i++){
    ans+=(n[i]-1)*n[i]/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3748
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] num = new int[n];
        ArrayList<Integer>[] p = new ArrayList[n];
        for(int i=0; i<n; i++){
            p[i] = new ArrayList<Integer>();
        }
        for(int i=0; i<m; i++){
            int tmp1 = sc.nextInt()-1;
            int tmp2 = sc.nextInt()-1;
            num[tmp1]++;
            num[tmp2]++;
            p[tmp1].add(tmp2);
            p[tmp2].add(tmp1);            
        }
        sc.close();
        //System.out.println("input end");

        int e1 = 0;
        int e2 = p[e1].get(0);
        ArrayDeque<Integer> path = new ArrayDeque<>();
        path.addFirst(e1);
        path.addLast(e2);
        boolean[] use = new boolean[n];
        use[e1] = true;
        use[e2] = true;

        //int count = 0;
        out: while(true){
            int tmp = 0;
            for(int i=0; i<p[e1].size(); i++){
                int mtmp = p[e1].get(i);
                if(use[mtmp]){
                    tmp++;
                }else{
                    e1 = mtmp;
                    path.addFirst(e1);
                    use[e1] = true;
                    continue out;
                }
            }
            for(int i=0; i<p[e2].size(); i++){
                int mtmp = p[e2].get(i);
                if(use[mtmp]){
                    tmp++;
                }else{
                    e2 = mtmp;
                    path.addLast(e2);
                    use[e2] = true;
                    break;
                }
            }
            if(tmp == p[e1].size() + p[e2].size()) break;


            // count++;
            // if(count % 100 == 0){
            //     System.out.println(e1 + " " + e2 + " " + tmp + p[e1].size() + p[e2].size() + " " + tmp);
            // }
        }

        int tmp = path.size();
        System.out.println(tmp);
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<tmp; i++){
            sb.append(path.poll()+1);
            sb.append(" ");
            if(tmp / 1000 == 0){
                System.out.print(sb);
                sb = new StringBuilder();
            }
        }
        System.out.println(sb);
    }
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

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

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

string n;

int main(){
	cin >> n;
	int c = 0;
	bool b = 0;
	c = (n[0] - '1') + (n.size() - 1) * 9;
	for(int i = 1; i < n.size(); i++){
		if(n[i] != '9') b = 1;
	}
	if(!b) c = (n.size()-1) * 9 + (n[0] - '0');
	if(n.size() == 1) c = (n[0]-'0');
	
		
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main()
{
    int a = 0, b = 0;

    std::cin >> a >> b;

    if(b==1)
    {
        std::cout << 0 << std::endl;
        return 0;
    }

    int count = 0;
    b -= a;

    count += 1;


    while(b>0){
        count++;
        b -= a-1;

    }

    std::cout << count << std::endl;
        return 0;

    return 0;
}



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

int main(){
  int n, k;
  cin >> n >> k;
  vector<double> hoge(n);
  for (int i = 1; i <= n; i++){
    if (i < k){
      int tmp = i;
      int count = 0;
      while (tmp < k){
        tmp = tmp * 2;
        count += 1;
      }
      hoge[i - 1] = n*pow(2.0, double(count));
    }else{
      hoge[i - 1] = n;
    }
  }

  double prob = 0;
  for (int i = 0; i < n; i++){
    prob += 1/hoge[i];
  }

  cout << fixed << setprecision(12) << prob << endl;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC138_a solver = new ABC138_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC138_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            String s = in.next();
            if (a >= 3200) {
                out.println(s);
            } else {
                out.println("red");
            }
        }

    }
}



Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int
main()
{
    uint64_t x;
    cin >> x;

    int a = 0;

    while(x){
        if(x >= 500) {
            x -= 500;
            a += 1000;
        } else if(x >= 5) {
            x -= 5;
            a += 5;
        } else if(x >= 100) {
            x -= 100;
        } else if(x >= 50) {
            x -= 50;
        } else if(x >= 10) {
            x -= 10;
        } else {
            x -= 1;
        }
    }
    cout << a << endl;;
    return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        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,
        k: i32,
        h: [i32; n],
    }

    let mut num = 0;
    for i in 0..n {
        if h[i] >= k {
            num = num+1;
        }
    }

    println!("{}", num)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        
        int main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        
        ll n,x,y;
        cin>>n>>x>>y;
        vector<ll> ans(n,0);
        for(ll i=1;i<=n;i++){
            for(ll j=i+1;j<=n;j++){
                ans[min(abs(j-i), min( abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1) )]++;
            }
        }
        for(ll i=1;i<n;i++)
            cout<<ans[i]<<"\n";

        return 0;
        }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main()
{
   int n,l;
   while(cin >> n >> l)
   {
       getchar();
       string a[n];
       for(int i = 0;i < n;i++)
       {
           cin >> a[i];
       }
       sort(a,a+n);
       for(int i = 0;i <n;i++)
        cout << a[i];
       cout << endl;
   }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void)
{
	int i,j;
	double a,s[1001],d,f,g,h;
	while(1){
		f=0;
		d=0;
		scanf("%lf",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			scanf("%lf",&s[i]);
			d+=s[i];
		}
		d=d/a;
		for(i=0;i<a;i++)
			f+=(s[i]-d)*(s[i]-d);
		f=f/a;
		f=sqrt(f);
		printf("%lf\n",f);
	}
	return 0;
}

Measured memory_bytes: 2732
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>

int main() {
  int N;
  std::vector<int> target;
  std::vector<int> list;
  scanf("%d", &N);
  for(int i = 0; i < 3; i++){
    int tmp;
  	scanf("%d", &tmp);
    target.push_back(tmp);
  }
  for(int i = 0; i < N; i++){
    int tmp;
  	scanf(" %d", &tmp);
    list.push_back(tmp);
  }
  int min_cost = 0xfffffff;
  for(uint64_t i = 0; i < (1 << (2 * list.size())); i++){
	int sum[4] = {0, 0, 0, 0};
    int cost = 0;
    for(int k = 0; k < list.size(); k++){
      int idx = (i >> (2 * k)) & 3;
      if(sum[idx] && idx != 3) cost += 10;
      sum[idx] += list[k];
    }
    if(!sum[0] || !sum[1] || !sum[2]) continue;
    for(int k = 0; k < 3; k++){
    	cost += std::abs(target[k] - sum[k]);
    }
    min_cost = std::min(min_cost, cost);
  }
  printf("%d\n", min_cost);
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){;
    int sum =0, m = 10, tmp;
    for(int i =0;i<5;i++){
        cin >> tmp;
        sum += tmp/10;
        if(tmp%10 != 0){ 
            sum++;
            if(tmp%10 < m) m = tmp%10;
        }
    }
    cout << (sum - 1)* 10 + m << "\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())

alp = "abcdefghijklmnopqrstuvwxyzz"
ans = ""

while(N != 0):
    a = (N % 26)
    ans = alp[a-1] + ans

    if a != 0:
        N = int((N-a)/26)
    else:
        if N == 26 : break
        N = int((N-26)/26)

print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int H,N;
int sum=0;
cin>>H>>N;
vector<int>vec(N);
for(int i=0;i<N;i++){
cin>>vec.at(i);
sum+=vec.at(i);
}
if(sum>=H){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}




Measured memory_bytes: 640
import sys
input=sys.stdin.readline
def main():
  R,C,K=map(int, input().split())
  M=[[0 for i in range(C)]for i in range(R)]
  for i in range(K):
    r,c,v=map(int, input().split())
    r-=1
    c-=1
    M[r][c]=v
  dp0=[[0 for j in range(C)] for i in range(R)]
  dp1=[[0 for j in range(C)] for i in range(R)]
  dp2=[[0 for j in range(C)] for i in range(R)]
  dp3=[[0 for j in range(C)] for i in range(R)]
  dp1[0][0]+=M[0][0]
  for r in range(R):
    for c in range(C):
      if 0<r:
        dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
        dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
      if 0<c:
        dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
        dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
        dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
        dp0[r][c]=max(dp0[r][c-1],dp0[r][c])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 464584
#include <stdio.h>
int n;
int A[100000];

binarysearch(int k){
int left=0;
int right=n;
int mid;
while(left<right){
  mid=(left+right)/2;
  if(A[mid]<k){
    left=mid+1;
  }
  if(A[mid]>k){
    right=mid;
  }
  if(A[mid]==k){
    return 1;
  }
 }
return 0;
}
    

int main(){
  int i,q,k,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarysearch(k)==1){
      count++;
    }
  }
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2244
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 500
#define M 30


int main(){
	int a[N][N];
	int b[M][M];
	int c[3][M];
	int n, m, k;
	int x, y, z;
	int min= 1000000000;
	scanf("%d %d", &n,&m);
	k = 0;
	f(i, m){
		f(j, m)scanf("%d", &b[i][j]);
	}
	f(i, n){
		f(j, n){
			scanf("%d", &a[i][j]);
			a[i][j]--;
		}
	}
	f(i, 3){
		f(j, m){
			c[i][j] = 0;
			f(xx, n){
				f(yy, n){
					if((xx+yy)%3==i)c[i][j] += b[a[xx][yy]][j];
				}
			}
		}
	}
	f(xx, m){
		f(yy, m){
			if (yy != xx){
				f(zz, m){
					if (zz != xx&&zz != yy){
						k = c[0][xx] + c[1][yy] + c[2][zz];
						if (k < min)min = k;
					}
				}
			}
		}
	}
	printf("%d\n", min);

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int T[N];
  for (int i=0; i<N; i++) {
    cin >> T[i];
  }
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i=0; i<M; i++) {
    cin >> P[i] >> X[i];
  }
  for (int i=0; i<M; i++) {
    int sum=0;
    for (int j=0; j<N; j++) {
      if (j==(P[i]-1)) {
        sum+=X[i];
      } else {
        sum+=T[j];
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, D: int):
    print(min(A,B)+min(C,D))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()


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

int n;
int H[100005];

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> H[i];
  }
  int ans = 0;
  int tmp = 0;
  for(int i=2;i<=n;i++){
    if(H[i] <= H[i-1]){
      tmp++;
      ans = max(ans,tmp);
    } else {
      tmp = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

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

        String S = sc.next();
        String T = sc.next();
        int ans = 0;

        for(int i=0; i<=2; i++){
            if(S.charAt(i)==T.charAt(i)){
                ans = ans + 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N,M = map(int,input().split())
X = list(map(int,input().split()))

if N >= M:
    print(0)
    exit()

X.sort()
Distance = [0] * (M-1)

for i in range(M-1):
    Distance[i] = (X[i+1] - X[i])

Distance.sort()
print(sum(Distance[0:M-N]))

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

int n;
int flags[101];

int main(){
    for(int i = 0; i < 101; i++) flags[i] = false;
    for(int x = 0; x <=  100 / 4; x++){
        for(int y = 0; y <= 100 / 7; y++){
            flags[4 * x + 7 * y] = true;
        }
    }

    cin >> n;
    if(flags[n]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*input
1
11 26
26 24 26 17 13 10 2 3 8 21 20

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 100001

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(ll a, ll b) {a += b; if (a < 0) a += mod; return a;}
inline int sub(ll a, ll b) {a -= b; if (a < 0) a += mod; return a;}
inline int mul(ll a, ll b) {return (a * 1ll * b) % mod;}
inline int pwr(ll x, ll y) {
    int ans = 1 % mod;
    while (y) {
        if (y & 1) ans = mul(ans, x);
        x = mul(x, x);
        y >>= 1;
    }
    return ans;
}
inline int inv(int a) {return pwr(a, mod - 2);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    a -= c;
    b -= d;
    cout << (a * b) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import bisect
from collections import defaultdict
n,k = map(int,input().split())
a = list(map(int,input().split()))
dc = defaultdict(int)
for i in range(n):
  if dc[a[i]]:
    dc[a[i]].append(i)
  else:
    dc[a[i]] = [i]
p = 0
cnt = 1
dcp = defaultdict(int)
while p != n and cnt<k:
  x = a[p]
  if p == dc[x][-1]:
    p = dc[x][0]+1
    cnt += 1
    dcp[cnt] = p
  else:
    q = bisect.bisect_right(dc[x],p)
    p = dc[x][q]+1
if cnt<k:
  k = k%cnt
ans = []
pos = dcp[k]
flg = [0 for i in range(200000+1)]
for i in range(pos,n):
  if flg[a[i]] == 0:
    ans.append(a[i])
    flg[a[i]] = 1
  else:
    while ans[-1] != a[i]:
      t = ans.pop()
      flg[t] = 0
    ans.pop()
    flg[a[i]] = 0
print(*ans)

Measured memory_bytes: 118860
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define repeat2(n) for (int j = 0; j < n; ++j)
#define all(x) x.begin(), x.end()

#define MAX_SIZE (100001)

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

    int an[MAX_SIZE];
    int sum = 0;

    memset(an, 0, sizeof(int) * MAX_SIZE);

    repeat(n) {
        int a;
        cin >> a;
        ++an[a];
        sum += a;
    }

    int q;
    cin >> q;

    repeat(q) {
        int b, c;
        cin >> b >> c;
        sum += (c - b) * an[b];
        an[c] += an[b];
        an[b] = 0;
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3928
program prob6
    implicit none
    integer(16)::N, i, j, ans, cnt, maxd, maxa, sumd
    integer(16), allocatable::A(:), B(:), c(:), d(:)
    read(*,*) N
    allocate(A(N))
    allocate(B(N))
    allocate(c(N))
    allocate(d(N))
    read(*,*) A
    read(*,*) B

    d = 0
    cnt = 0
    j = 1
    do i = 1, N
        if(B(i) - A(i) > 0) then
            d(i) = B(i) - A(i)
            cnt = cnt + 1
        else if(B(i) - A(i) < 0) then
            c(j) = B(i) - A(i)
            j = j+1
        end if
    end do

    if(sum(d) == 0)then
        write(*,*) 0
        stop
    end if
    if(sum(B) > sum(A))then
        write(*,*) -1
        stop
    end if
    sumd = sum(d)
    call heapsort(j-1,c)

    do i = 1, j-1
        sumd = sumd + c(i)
        cnt = cnt + 1
        if(sumd <= 0) then
            write(*,*) cnt
            stop
        end if
    end do


    write(*,*) cnt

    deallocate(A)
    deallocate(B)
    deallocate(c)
    deallocate(d)
    stop
    contains
    subroutine heapsort(n,array)
        implicit none
        integer(16),intent(in) :: n
        integer(16),intent(inout) :: array(1:n)
       
        integer ::i,k,j,l
        double precision :: t
       
        if(n.le.0)then
           write(6,*)"Error, at heapsort"; stop
        endif
        if(n.eq.1)return
      
        l=n/2+1
        k=n
        do while(k.ne.1)
           if(l.gt.1)then
              l=l-1
              t=array(L)
           else
              t=array(k)
              array(k)=array(1)
              k=k-1
              if(k.eq.1) then
                 array(1)=t
                 exit
              endif
           endif
           i=l
           j=l+l
           do while(j.le.k)
              if(j.lt.k)then
                 if(array(j).lt.array(j+1))j=j+1
              endif
              if (t.lt.array(j))then
                 array(i)=array(j)
                 i=j
                 j=j+j
              else
                 j=k+1
              endif
           enddo
           array(i)=t
        enddo
      
        return
    end subroutine heapsort
end program prob6

Measured memory_bytes: 6272
N=int(input())
CSF=[list(map(int,input().split())) for _ in range(N-1)]
for j in range(N):
    t=0
    for i in range(j,N-1):
        if t<CSF[i][1]:
            t=CSF[i][1]
        else:
            x=(t-1)//CSF[i][2]+1
            t=CSF[i][2]*x
        t+=CSF[i][0]
    print(t)


Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int N, T;
	std::cin >> N >> T;
	
	std::vector<int> vec;
	vec.reserve(N);
	for (int i = 0; i < N; ++i) {
		int c, t;
		std::cin >> c >> t;

		if (t <= T)
			vec.push_back(c);
	}

	if (vec.empty()) {
		std::cout << "TLE" << std::endl;
		return 0;
	}

	std::cout << *std::min_element(vec.begin(), vec.end()) << std::endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

vl x, min_other;
vvl ch;

bool ok = true;

void dfs(ll i) {
	for (ll j: ch[i]) dfs(j);
	
	vl dp(x[i]+1);
	
	for (ll j: ch[i]) {
		vl ndp(x[i]+1,oo);
		ll a = x[j], b = min_other[j];
		FOR(dir,0,2) {
			FOR(s,a,x[i]+1) ndp[s] = min(ndp[s],dp[s-a]+b);
			swap(a,b);
		}
		FOR(s,1,x[i]+1) ndp[s] = min(ndp[s],ndp[s-1]);
		dp = ndp;
	}
	min_other[i] = dp[x[i]];
	if (min_other[i] == oo) ok = false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n; cin >> n;
	x.resize(n);
	min_other.resize(n);
	ch.resize(n);
	
	FOR(i,1,n) {
		ll p; cin >> p;
		p--;
		ch[p].pb(i);
	}
	FOR(i,0,n) cin >> x[i];

	dfs(0);
	cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}



Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int s=0;
    int i;
    for(i=0;i<5;i++){
        int a;
        cin>>a;
        if(a<40)    s=s+40;
        else    s=s+a;
    }
    cout<<s/5;
    cout<<endl;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <algorithm>
#include <vector>

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

using namespace std;

int main() {
    int n, q;
    scanf("%d", &n);
    vector<int> S(n);
    rep(i, n) scanf("%d", &S[i]);
    scanf("%d", &q);
    vector<int> T(q);
    rep(i, q) scanf("%d", &T[i]);

    int ans = 0;
    for (int i = 0; i < T.size(); ++i) {
        for (int j = 0; j < S.size(); ++j) {
            if (S[j] == T[i]) {
                ++ans;
                break;
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){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;}
int get(int n){
	int s = 0;
	while(n){
		s += n%10;
		n/=10;
	}
	return s;
}

void solve(){
	int n;
	cin>>n;
	if(n%get(n)) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,m;
 	cin >> n>>m;
 	cout << m-n+m << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define infpos INT_MAX/8
#define infneg INT_MIN
#define mk_p make_pair

using namespace std;
//ifstream in("C:/testes programas/t.txt");
//ofstream out("C:/testes programas/o.txt");
//ifstream file("C:/testes programas/out.txt");

int main(){
  ios::sync_with_stdio(0);
  map<char, char> dic;
  dic['A'] = 'T';
  dic['T'] = 'A';
  dic['C'] = 'G';
  dic['G'] = 'C';
  char b;
  cin>> b;
  cout<< dic[b];
}


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

const int maxp = 2999+10;

int p, a[maxp];
int MOD(int x) { return (x%p+p)%p; }
void mod(int &x) { x = MOD(x); }

int f[maxp], g[maxp], inv[maxp];
int ans[maxp];

void asserts() {
	int tmp = 1;
	for (int i = 1; i < p; ++i) tmp = MOD(tmp*i);
	assert(tmp == p-1);
}

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

int main() {
	cin >> p;
	asserts();

	inv[1] = 1;
	for (int i = 2; i < p; ++i)
		inv[i] = MOD(-(p/i)*inv[p%i]);

	for (int i = 0; i < p; ++i)
		cin >> a[i];

	f[0] = 1;
	for (int i = 0; i < p; ++i) {
		memset(g, 0, sizeof(g));
		for (int j = 0; j <= p; ++j) {
			mod(g[j] += f[j]*i);
			mod(g[j+1] += f[j]);
		}
		swap(f, g);
	}
//	print(f, p+1);

	for (int i = 0; i < p; ++i) if (a[i]) {
		memset(g, 0, sizeof(g));

		for (int j = p-1; ~j; --j) {
			g[j] = MOD(f[j+1]+i*g[j+1]);
			mod(ans[j]-=g[j]);
		}
//		print(g, p);
	}
	print(ans, p);
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
void swap(int *a, int *b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
void sort(int *c, int *d)
{
    if (*c > *d)
        swap(c, d);
}
 
int main(void) 
{
    int x, y;
    while (std::cin >> x >> y) {
        if (x == 0 && y == 0)
            break;
        if (x > y) {
            sort(&x, &y);
            cout << x << " " << y << endl;
        }
        else {
            cout << x << " " << y << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 3000
from math import ceil

d, g = map(int, input().strip().split())
points = [list(map(int, input().strip().split())) for _ in range(d)]

answer = float("inf")
for combination in range(2 ** d):
    score = 0
    solved = 0
    for difficuty in range(d):
        if (combination >> difficuty) & 1:
            score += points[difficuty][0] * 100 * (difficuty + 1) + points[difficuty][1]
            solved += points[difficuty][0]
    if score < g:
        for difficuty in range(d)[::-1]:
            if not (combination >> difficuty) & 1 and g - score < points[difficuty][0] * 100 * (difficuty + 1):
                solved += ceil((g - score) / (100 * (difficuty + 1)))
                break
        else:
            continue
    if answer > solved:
        answer = solved
print(answer)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){

  int sum=-50;
  int min=99999;
  rep(i,3){
    int tmp;
    cin>>tmp;
    if(min>tmp)min=tmp;
  }
  sum+=min;
  min=99999;
  rep(i,2){
    int tmp;
    cin>>tmp;
    if(min>tmp)min=tmp;
  }
  sum+=min;
  cout<<sum<<endl;

}

Measured memory_bytes: 1160
from math import ceil
menu1 = []
menu2 = []
for _ in range(5):
    m = int(input())
    if m % 10 == 0:
        menu1.append(m)
    else:
        menu2.append(m)
menu2 = sorted(menu2, key=lambda x: str(x)[-1])

ans = sum(menu1)
for i, m in enumerate(menu2):
    if i == 0:
        ans += m
        continue
    ans += ceil(m / 10) * 10
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
vector<long long int> adj[200001];
bool vis[200001];
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    ll binary_lift[n+1][61];
    for(ll i=1;i<=n;i++) {
        cin>>binary_lift[i][0];
        //binary_lift[i][0]--;
    }

    for(ll j=1;j<=60;j++){
        for(ll i=1;i<=n;i++){
            binary_lift[i][j]=binary_lift[binary_lift[i][j-1]][j-1];
           // cout<<binary_lift[i][j]<<"\n";
          //  cout<<i<<" "<<j<<" "<<binary_lift[i][j]<<"\n";
        }
    }


    ll pos=1;
    for(ll jump=60;jump>=0;jump--){

        ll m=(1LL << jump);
        //n=(1 << jump);
        //cout<<m<<" "<<n<<"\n";
        if(m<=k){
            pos=binary_lift[pos][jump];
            k-=m;
        }
    }
    cout<<pos;

    return(0);
}

Measured memory_bytes: 103660
#include <stdio.h>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

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

char a[N][N];
int dist[N][N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  queue<pair<int, int>> q;
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        q.push(make_pair(i, j));
        dist[i][j] = 0;
      }
    }
  }
  int ans = 0;
  while (!q.empty()) {
    int cur_y = q.front().first;
    int cur_x = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int next_y = cur_y + dy[i];
      int next_x = cur_x + dx[i];
      if (next_x >= 0 && next_y >= 0 && next_x < m && next_y < n) {
        if (a[next_y][next_x] == '.') {
          q.push(make_pair(next_y, next_x));
          a[next_y][next_x] = '#';
          dist[next_y][next_x] = dist[cur_y][cur_x] + 1;
          ans = max(ans, dist[next_y][next_x]);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 15632
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()



int main(void){
	int N,M;
    cin >> N >> M;
    int a[M];
    rep(i,M){
        cin >> a[i];
    }
    
    ll p = 1;
    ll fib[N+2];
    fib[0] = 1;
    fib[1] = 1;
    rep(i,N){
        fib[i+2] = (fib[i+1] + fib[i])%MOD;
    }

    int d;
    if(M>1){
        rep(i,M-1){
            d = a[i+1]-a[i];
            if(d == 1){
                p = 0;
            }
        }
    }else if(M == 1){
        p = fib[a[0]-1]*fib[N-a[M-1]-1]%MOD;
    }else{
        p = fib[N];
    }

    if(p==1){
        if(N==1){
        p = 1;
        }else{
            p = fib[a[0]-1]%MOD;
            if(M>1){
                reps(i,M-1){
                    p = (p*fib[a[i]-a[i-1]-2])%MOD;      
                }
            }            
            p = (p*fib[N-a[M-1]-1])%MOD;
        }
    }
    

    cout << p%MOD << endl;
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int x;
    cin >> x;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    int ans = 0;
    while(x > 0 && ans < N){
        if (x - vec[ans] < 0){
            x -= vec[ans];
        }
        else if (ans == N - 1){
            if (x == vec[ans]){
                ans++;
            }
            else{
                x = -1;
            }
        }
        else{
            x -= vec[ans];
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt() , m = sc.nextInt();
        out.println(1l*n*(n-1)/2 + 1l*m*(m-1)/2);        out.flush();
        out.close();
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

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

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

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

    }
}


Measured memory_bytes: 21072
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
if N==1:
    print(1)
    exit()
XY=[list(map(int,input().split())) for i in range(N)]
itelst=combinations(range(N),2)

alst=[]
for a,b in itelst:
    x1,y1=XY[a]
    x2,y2=XY[b]
    Y=y1-y2;X=x1-x2
    if X and Y:
        alst.append([X,Y])
    elif Y or X:
        alst.append([X,Y])



value=50
idlemax=10**18
for Xa,Ya in alst:
    n=set([x+idlemax*y for x,y in XY])

    count=0
    for x,y in XY:
        if x+idlemax*y in n:
            count+=1
            a=0;b=0
            A=x+Xa+a+idlemax*(y+Ya+b)
            while A in n:
                n.remove(A)
                a+=Xa;b+=Ya
                A=x+Xa+a+idlemax*(y+Ya+b)

            a=0;b=0
            A=x-Xa-a+idlemax*(y-Ya-b)
            while A in n:
                n.remove(A)
                a+=Xa;b+=Ya
                A=x-Xa-a+idlemax*(y-Ya-b)
    value=min(value,count)
print(value)


Measured memory_bytes: 80108
#include<iostream>
#include<vector>
#include<limits>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

#define make_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_dir_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1);}
#define make_weighted_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1];w[b-1][a-1]=w[a-1][b-1];G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_weighted_dir_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1]; G[a-1].push_back(b-1);}

int main()
{
	int t=1;
	// cin>>t;
	while (t--)
	{
		// code
		int n,k; cin>>n>>k;
		int h[n+1];
		for (int i = 1; i<n+1; i++)
		{
			cin>>h[i];
		}

		int dp[n+1] = {};
		dp[2] = abs(h[2] - h[1]);
		dp[3] = abs(h[3] - h[2]) + dp[2];

		if (k>1) dp[3] = min(dp[3], abs(h[3] - h[1]));
		for (int i = 4; i<=n; i++)
		{
			dp[i] = abs(h[i] - h[i-1]) + dp[i-1];
			for (int j = 2; j<=k;j++)
			{
				if (i>j)
				{
					dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j]);
				}
			}
		}
		cout<<dp[n];
		cout<<endl;	
	}
}

Measured memory_bytes: 1024
//nexus01
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
 
#define fla(i,c,b) for(int i=c; i<b; i++)
#define flra(i,c,b) for(int i=c; i>b; i--)
#define fl(i,c) for(int i=0; i<(c); ++i)
 
#define endl "\n"
#define prec(x) cout<<fixed<<setprecision(x)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
 
#define data data__
#define SET(c, v) memset(c, v, sizeof c)
#define rank abcdef
#define count uvwxyz
#define union gdarawas
#define digit(x) (int)floor(1+log10((double)x))
const int inf = numeric_limits<int>::max();
const lli linf = numeric_limits<lli>::max();
#define Case cout<<"Case #"<<countt++<<": "<<
const lli MOD= (lli)1e9 + 7;
// const lli MOD=998244353;
lli fast_mod(lli abcd, lli expp)
{
    lli res=1;
    while(expp>0) 
    {
       if(expp%2==1)res=(res*abcd)%MOD;
       abcd=(abcd*abcd)%MOD;
       expp/=2;
    }
    return res%MOD;
}
lli gcd(lli a, lli b) 
{   lli temppp=max(a, b);
    b=min(a, b);
    a=temppp;
    if(b==0)return a; 
    return gcd(b, a%b);
} 
 
//////////////////////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin>>n;
    lli minn=n-1;
    for(lli i=1;i<=sqrt(n)+1;i++)
    {
        if(n%i==0)
        {
            minn=min(minn, i+n/i-2);
        }
    }
    cout<<minn<<endl;
    /*submit karne se pehle idhar dekh
        1)Integer Overflow to nahi kar raha??
        2)Loop to sahi chal raha hai na??
        3)Koi edge case miss to nahi ho raha?? 
        4)Algorithm sahi hai na??
    */   
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


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

    count = 0

    ans = [0]

    for i in range(len(Ps) - 1):
        if Ps[i] >= Ps[i+1]:
            count += 1
        else:
            ans.append(count)
            count = 0

        if i == len(Ps) - 2:
            ans.append(count)

    print(max(ans))


if __name__ == '__main__':
    main()

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

bool solve(vector<vector<int> > a, vector<int> b){
	int n = a.size();
	vector<vector<int> > B(n, vector<int>(n+1) );
	
	for(int i=0 ; i < n ; i++ ){
		for(int j=0 ; j < n ; j++ ){
			B[i][j] = a[i][j];
		}
	}
	for(int i=0 ; i < n ; i++ ){
		B[i][n] = b[i];
	}
	for(int i=0 ; i < n ; i++ ){
		int p = -1, val = -1;
		for(int j=i ; j < n ; j++ ){
			if( val < abs(B[j][i]) ){
				p = j;
				val = abs(B[j][i]);
			}
		}
		
		if( p == -1 || val <= 0 ) continue;
		
		swap(B[p], B[i]);
		for(int j=0 ; j < n ; j++ ){
			if( i == j ) continue;
			
			int m = B[j][i];
			if( m == 1 ){
				for(int k=i ; k <= n ; k++ ){
					B[j][k] = (B[j][k] + B[i][k]) % 2;
				}
			}
		}
	}
	vector<int> res(n);
	for(int i=0 ; i < n ; i++ ){
		res[i] = B[i][n];
		if( B[i][i] == 0 && B[i][n] == 1 ){
			return false;
		}
	}
	return true;
}

int main(){
	int w, h, d, s[25][25];
	while( cin >> w >> h >> d, w || h || d ){
		for(int y = 0 ; y < h ; y++ ){
			for(int x = 0 ; x < w ; x++ ){
				cin >> s[y][x];
			}
		}
		vector<vector<int> > a(w*h, vector<int>(w*h) );
		vector<int> b(w*h, 0);
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( s[y][x] ){
					b[y*w+x] = 1;
				}
				
				for(int y_=0 ; y_ < h ; y_++ ){
					for(int x_=0 ; x_ < w ; x_++ ){
						int dist = abs(x - x_) + abs(y - y_);
						if( dist == d || dist == 0 ){
							a[y*w+x][y_*w+x_] = 1;
						}
					}
				}
			}
		}
		bool ans = solve(a, b);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5824