akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n);
	int b = -1, s = -1;
	rep(i, n){
		cin >> a[i];
		if(b < a[i]){
			if(s < b) s = b;
			b = a[i];
		}
		else if(s < a[i]){
			s = a[i];
		}
	}
	rep(i, n){
		cout << (a[i] == b ? s : b) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2432
n, k = gets.chop.split.map(&:to_i)
x = gets.chop.split.map(&:to_i)


ans = 10**10
(n-k+1).times do |i|
  # 右端からいくパターン 左端からパターンがある
  r = x[i+k-1]
  l = x[i]
  r_dist = (r-l).abs + r.abs
  l_dist = (l-r).abs + l.abs

  ans =[r_dist,l_dist, ans].min
end

p ans

Measured memory_bytes: 12036
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int N;
	std::vector<long> A;
	std::cin >> N;
	A.resize(N);
	for (auto& a : A)
		std::cin >> a;

	long totallen = 0;
	for (auto a : A)
		totallen += a;

	long mindiff = std::numeric_limits<long>::max();
	long sum = 0;
	for (auto a : A) {
		sum += a;
		mindiff = std::min(mindiff, std::abs(sum*2 - totallen));
	}

	std::cout << mindiff << "\n";
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<cstdio>
#include<algorithm>


using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<double> a(n);

	double i,max,min;
	max = -1000000000000;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	min = a[0];
	for (i = 1; i < n; i++)
	{
		if (max < a[i] - min)
		{
			max = a[i] - min;
		}
		if (min > a[i])
		{
			min = a[i];
		}
		
	}
	printf("%.lf\n",max);
	
	return 0;
}


Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans=0;
int main()
{
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==x)ans++;
			}
		}
	}
	cout<<ans;
	return 0;
} 

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

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    PrintWriter out = new PrintWriter(System.out);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int a = Integer.parseInt(sl[0]);
    int b = Integer.parseInt(sl[1]);
    int q = Integer.parseInt(sl[2]);

    TreeSet<Long> ts = new TreeSet<>();
    TreeSet<Long> tt = new TreeSet<>();

    ts.add(-10000000000000L);
    tt.add(-10000000000001L);
    ts.add(-10000000000002L);

    ts.add(10000000000000L);
    tt.add(10000000000001L);
    ts.add(10000000000002L);

    for(int i = 1; i <= a; i++)
    {
      ts.add(Long.parseLong(r.readLine()));
    }
    for(int i = 1; i <= b; i++)
    {
      tt.add(Long.parseLong(r.readLine()));
    }
    for(int i = 1; i <= q; i++)
    {
      long x = Long.parseLong(r.readLine());

      long v1 = ts.floor(x);
      long v2 = tt.floor(v1);
      long z = x - v2;

      v1 = ts.floor(x);
      v2 = tt.ceiling(v1);
      z = Math.min(z, (x - v1) + (v2 - v1));

      v1 = ts.ceiling(x);
      v2 = tt.floor(v1);
      z = Math.min(z, (v1 - x) + (v1 - v2));

      v1 = ts.ceiling(x);
      v2 = tt.ceiling(v1);
      z = Math.min(z, v2 - x);

      v1 = tt.floor(x);
      v2 = ts.floor(v1);
      z = Math.min(z, x - v2);

      v1 = tt.floor(x);
      v2 = ts.ceiling(v1);
      z = Math.min(z, (x - v1) + (v2 - v1));

      v1 = tt.ceiling(x);
      v2 = ts.floor(v1);
      z = Math.min(z, (v1 - x) + (v1 - v2));

      v1 = tt.ceiling(x);
      v2 = ts.ceiling(v1);
      z = Math.min(z, v2 - x);

      out.println(z);
    }
    out.flush();
  }

}

Measured memory_bytes: 113856
#define M 30100
T[M],t[M];main(i,j,k,L,r){
for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
for(i=2,j=0;i<M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d",&L),L;printf("%d\n",r))for(r=i=0;t[i]<L;i++)for(j=i;(k=L-t[i]-t[j])>=t[j];j++)if(!T[k]&&t[j]-t[i]<k&&k<t[j]+t[i])r++;
exit(0);}

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

int main() {
  int n;
  string s;

  cin >> n >> s;
  
  int ans = 0;

  for (int i=0; i < n-2; i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int o = sc.nextInt();
		int z = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int sum = k <= o ? k : o;
		sum -= (k - o - z) > 0 ? k - o - z : 0;
		System.out.println(sum);
	}

	static class FastScanner {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					return reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}

			return tokenizer.nextToken("\n");
		}

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

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

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

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}
}

Measured memory_bytes: 32612
#include <iostream>

using namespace std;

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

const int N = (int)2e5;

signed main() {
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i], a[i]--;
  
  int r[N];
  rep(i,N) r[i] = 0;
  rep(i,n) r[a[i]]++;
  
  int s = 0;
  rep(i,N) s += r[i] * (r[i] - 1) / 2;
  rep(i,n) cout << s - r[a[i]] + 1 << endl;
  return 0;
}

Measured memory_bytes: 6256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
/*int main()
{
	int n; cin>>n;
	int 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];
	int sum=0;
	for(int i=n-1;i>1;i--)
	{
		for(int j=i-1;j>0;j--)
		{
			if(a[i]==a[j]) continue;
			for(int k=j-1;k>=0;k--)
			{
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] < (a[k] + a[j])) 
				{
					sum++;
				}
				
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] >= (a[k] + a[j])) 
				{
					break;
				}
				
			}
		}
	}
	
	cout<<sum;
}

int main()
{
	int n,d,ans=0;
	cin>>n>>d;
	while(n--)
	{
		int a,b; cin>>a>>b;
		long long int fl=a*a + b*b;
		float sum=sqrt(fl);
		if(sum<=d) ans++;
		
	}
	cout<<ans;
}
int main()
{
	int n,k; cin>>n>>k;
	int a[n],sum=0;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++) sum+=a[i];
	cout<<sum; 
}

int main()
{
	int n,k; cin>>n>>k;
	k%2==0 and k>=2*n and k<=4*n ? cout<<"Yes" : cout<<"No";
}

int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	unsigned long long ans=1,ANS;
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		ans*=a[i];
		ANS=ans;
		while(ANS)
		{
			v.push_back(ANS%10);
			ANS/=10;
		}
		if(v.size()>1000000000000000000)
		{
			cout<<"HRE";
			cout<<"-1";
			return 0;
		}
		v.clear();
	}
	cout<<ans;
}

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	if(s.size()<=n) cout<<s;
	else {
		
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<"...";
}}

int main()
{
	long long int a,b,c,d; cin>>a>>b>>c>>d;
	long long int sum=0,count=0;
	if(a<=d)
	{
		sum+=a;
		d-=a;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(b<=d)
	{
		
		d-=b;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(c<=d)
	{
		sum-=c;
		d-=c;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<sum-d;
		return 0;
	}
	
	
}


int main()
{
	int n,k; cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) a[i]=0;
	while(k--)
	{
		int d; cin>>d;
		for(int i=0;i<d;i++) 
		{
			int x; cin>>x;
			a[x-1]++;
		}
	}
	//cout<<a[2];
	int ans=0;
	for(int i=0;i<n;i++) if(a[i]==0) ans++; cout<<ans;
}
int main()
{
	long long int n,year=0; cin>>n;
	int a=100;
	while(a<n)
	{
		float aa=(1.0/100)*a;
		a+=floor(aa);
		year++;
	}
	cout<<year;
}
int main()
{
	long long int n,m; cin>>n>>m;
	long long int sum=0,a[n];
	for(long long int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];	
	} 
	sort(a,a+n,greater<int>());
	float min=sum*1.0/(4*m);
	a[m-1]<min?cout<<"No": cout<<"Yes\n";	
}*/

int main()
{
	int n; cin>>n;
	long long sum=(n/500)*1000 + ((n-(n/500)*500)/5)*5;
	cout<<sum;
}


Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var H = ReadLong();
            var W = ReadLong();

            return (N - H + 1) * (N - W + 1);
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (ll i=1; i<=(n); i++)
#define rep0(i,n) for (ll i=0; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

int main() {
    FAST_IOSTREAM();

    ll n;
    cin >> n;
    ll ans = 0;

    // rep1(l,n) {
    //     for(int r=l;r<=n;r++) {
    //         ans += (r-l)+1;
    //     }
    // }

    rep1(l,n) {
        ans += n-l+1;
        ans -= (n-l+1)*l;
        ans += (n*(n+1)/2) - (l*(l-1)/2);
    }

    rep0(i,n-1) {
        int u,v;
        cin >> u >> v;

        // for (int l=1; l<=n; l++) {
        //     if (u >= l && v >= l) {
        //         for (int r=l; r<=n; r++) {
        //             if (u <= r && v <= r) ans--;
        //         }
        //     }
        // }
        ll mx = max(u,v);
        ll mn = min(u,v);
        ans -= mn;
        ans -= n * mn;
        ans += mx * mn;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for y in range(b+1):
        for z in range(c+1):
            if 500 * i + 100 * y + 50 * z == x:
                ans += 1
                
print(ans)

Measured memory_bytes: 3060
if __name__ == '__main__':
    n, k = map(int, input().split())
    heights = list(map(int, input().split()))
    heights.sort()
    # n人、k CM必要
    index = 0
    while len(heights) > index and heights[index] < k:
        index += 1
        if n == 1:
            break
    print(n - index)

Measured memory_bytes: 11912
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n,a,b;
cin>>n>>a>>b;
ll k=n/(a+b);
n%=(a+b);
cout<<k*a+min(n,a)<<endl;
}



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

int main() {
  string inp;
  cin >> inp;
  vector<char> v;
  for(int i = 0; i < inp.size(); i++) {
    if(inp[i] == '0') {
      v.push_back('0');
    }
    else if(inp[i] == '1') {
      v.push_back('1');
    }
    else {
      if(!v.empty()){
        v.pop_back();
      }
    }
  }
  
  for(int i = 0; i < v.size(); i++) {
    cout << v[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int B[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k>>a;

    cin>>S+1;

    cnt = 0;

    for(int i=1;i<=n;i++){
        if(S[i]=='x')continue;
        ++cnt;
        if(k<cnt)break;
        A[cnt] = i;
        i+=a;
    }
    cnt = 0;

    for(int i=n;i>=1;i--){
        if(S[i]=='x')continue;
        ++cnt;
        if(k<cnt)break;
        B[cnt] = i;
        i-=a;
    }


    if(k>cnt)return 0;

    vector<int> ans;

    for(int i=1;i<=k;i++){
        if(A[i]==B[k-i+1]){
            ans.push_back(A[i]);
        }
    }

    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<"\n";

    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e3 + 1;

int N, P;

ll memo[MAX_N][MAX_N];

ll nCr(ll n, ll r)
{
  if (r == 0 || n == r) return 1;
  if (memo[n][r] >= 0) return memo[n][r];
  return memo[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r);
}

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

  int odd, even;
  odd = even = 0;
  memset(memo, -1, sizeof(memo));
  
  cin >> N >> P;
  REP(i, N) {
    CIN(a);
    if (a & 1) odd++;
    else even++;
  }

  ll ans = 0ll;
  
  REP(i, odd + 1) {
    if (i % 2 == P) {
      ans += nCr(odd, i);
    }
  }
  REP(i, even) {
    ans *= 2;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N; cin >> N;
  vvi time(N, vi(10));
  vvi prf(N, vi(11)); 
  rep(i,N){
    rep(j,10){ int a; cin >> a; time[i][j]=a;}
  }
  rep(i,N){
    rep(j,11){ int a; cin >> a; prf[i][j]=a;}
  }

  int ans =-1e10;
  for (int bit=1; bit<(1<<10); bit++){
    int pr = 0;
    vi opn(N,0);
    for (int i=0; i<10; i++){
      if(bit & (1<<i)) {
        rep(j,N){
            if(time[j][i] == 1) opn[j]++;
        } 
      }
    }
    rep(i,N) pr += prf[i][opn[i]];
    if (ans < pr) ans = pr;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<bool> ok;

bool bellmanford(int s, int N, vector<vector<pair<int, int>>>& graph, vector<int>& d){
  d = vector<int>(N, INF);
  d[s] = 0;
  for(int i = 0; i < N; i++){
    for(int v = 0; v < N; v++){
      if(!ok[v]) continue;
      for(int k = 0; k < (int)graph[v].size(); k++){
        pair<int, int> e = graph[v][k];
        if(d[v] != INF && d[e.first] > d[v] + e.second){
          d[e.first] = d[v] + e.second;
          if(i == N-1) return true;
        }
      }
    }
  }
  return false;
}

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

  vector<vector<int>> back(N);
  vector<vector<pair<int, int>>> graph(N);
  REP(i, M){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    back[v].emplace_back(u);
    graph[u].emplace_back(v, -d);
  }

  ok.resize(N, false);
  ok[N-1] = true;

  queue<int> q;
  q.push(N-1);

  while(!q.empty()){
    int v = q.front(); q.pop();
    for(int u : back[v]){
      if(ok[u]) continue;
      ok[u] = true;
      q.push(u);
    }
  }

  vector<int> dist(N);
  if(bellmanford(0, N, graph, dist)){
    cout << "inf" << "\n";
  }else{
    cout << -dist[N-1] << "\n";
  }

  return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!

import math

a, b, C = map(int, input().split())
S = a * b * 0.5 * math.sin(math.radians(C))
L = a + b + (a * a + b * b - 2 * a * b * math.cos(math.radians(C))) ** 0.5
h = b * math.sin(math.radians(C))

print('{:.8f}'.format(S))
print('{:.8f}'.format(L))
print('{:.8f}'.format(h))

# print(S)
# print(L)
# print(h)



Measured memory_bytes: 5728
/**
 * ?????????:O(n^2)
 * ??±?????????????¨?????????´??\?????¢??????????????????????´?,?±????????¨???????????????????
 */
#include <stdio.h>

// ????????????,????????????????????¢????¬???°
int selectionSort(int A[], int N){
	int i, j, minj, sw = 0, tmp;
	for(i = 0; i < N-1; i++){
		minj = i;
		for(j = i+1; j < N; j++){ // ???????????°????°????
			if(A[minj] > A[j]) minj = j;
		}
		if(i != minj) { // ?????¢
			tmp = A[minj]; A[minj] = A[i]; A[i] = tmp; 
			sw++;
		} 
	}
	return sw;
}

int main(){
	//freopen("in.txt", "r", stdin);
	int i,N,A[100],sw;
	while(~scanf("%d", &N)) {
	    for(i = 0; i < N; i++) scanf("%d", &A[i]);
           sw = selectionSort(A, N);
           for(i = 0; i < N; i++){
           	if(i > 0) printf(" ");
           	printf("%d", A[i]);
           }
           printf("\n");
           printf("%d\n", sw);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	int arr[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int uno, dos, tres;
	uno = dos = tres = 0;
	int i;
	for (i = 0; i < n; ++i)
	{
		if (arr[i] > a) break;
		uno++;
	}
	for (; i < n; ++i)
	{
		if (arr[i] > b) break;
		dos++;
	}
	for (; i < n; ++i)
	{
		tres++;
	}
	cout << min(uno, min(dos, tres)) << "\n";
	return 0;
}


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


int main() {

  int n;
  cin>>n;

  map<string,int> w_map;
  bool flg=true;
  string w_old="dummy";
  for(int i=0;i<n;i++){
    string w;
    cin>>w;

    if(w_map.count(w))
      flg=false;
    else
      w_map[w]=1;

    if(i>0){
      if(w.front()!=w_old.back())
        flg=false;
    }
    w_old=w;
  }

  if(flg)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

  return 0;
}




Measured memory_bytes: 3596
import sys
def input(): return sys.stdin.readline().rstrip()

def MIN(a, b):
    if a > b:
        return b
    else:
        return a

def main():
    N = int(input())
    yen6 = [6 ** i for i in range(1, 7) if 6 ** i <= N]
    yen9 = [9 ** i for i in range(1, 6) if 9 ** i <= N]

    if N < 6:
        print(N)
        exit()

    dp = [N] * (N + 1)
    for i in range(6):
        dp[i] = i
    for i in range(1, N + 1):
        for j in yen6:
            if i - j < 0:
                break
            dp[i] = MIN(dp[i], dp[i - j] + 1)
        for j in yen9:
            if i - j < 0:
                break
            dp[i] = MIN(dp[i], dp[i - j] + 1)
    print(dp[N])

if __name__ == '__main__':
    main()


Measured memory_bytes: 41968
from sys import stdin
n = int(input())
s = [stdin.readline()[:-1] for i in range(n-1)]
s.append(input())
ans = [0,0,0,0]
temp = ["AC","WA","TLE","RE"]
for i in s:
    if i=="AC":
        ans[0] += 1
    elif i=="WA":
        ans[1] += 1
    elif i=="TLE":
        ans[2] += 1
    else:
        ans[3] += 1
for i in range(4):
    print("{result} x {num}".format(result=temp[i],num=ans[i]))

Measured memory_bytes: 16116
#include <stdio.h>

int main(void) {
	int a[5], time = 0, min_i = -1;
	
	for (int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
	}
	
	for (int i = 0, min_d = 10; i < 5; i++) {
		if (a[i] % 10 < min_d && a[i] % 10 > 0) {
			min_i = i;
			min_d = a[i] % 10;
		}
	}
	
	for (int i = 0; i < 5; i++) {
		if (min_i == i) {
			time += a[i];
		} else {
			if (a[i] % 10 == 0) {
				time += a[i];
			} else {
				time += a[i] + (10 - a[i] % 10);
			}
		}
	}
	
	printf("%d\n", time);
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3


import sys


class OccCounter(object):

    def __init__(self, n, s):
        self.length = n
        self.base_str = s
        self.occ_nums = [0] * n
        for i in range(1, n):
            self.occ_nums[i] = self.occ_nums[i - 1] + int(s[i - 1] == "A" and s[i] == "C")
        # sentinel
        self.occ_nums.insert(0, 0)
        # debug
        # print(*zip("*" + s, self.occ_nums), file=sys.stderr, sep="\n")
    
    def count_occs(self, le, ri):
        # one-based
        res = self.occ_nums[ri] - self.occ_nums[le - 1]
        if le > 1 and self.base_str[le - 2] == "A" and self.base_str[le - 1] == "C":
            res -= 1
        return res


def main():
    n, q = (int(z) for z in input().split())
    s = input()
    oc = OccCounter(n, s)
    for _ in range(q):
        le, ri = (int(z) for z in input().split())
        print(oc.count_occs(le, ri))


if __name__ == "__main__":
    main()

Measured memory_bytes: 7796
using System;

namespace AizuOnLine
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int num1 = Convert.ToInt32(str[0]);
            int num2 = Convert.ToInt32(str[1]);

            if (num1 < num2)
            {
                Console.WriteLine("a < b");
            }
            else if(num1 > num2)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}

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

const int Mod = 1e9+7;

//逆元
//fermatの定理を利用
// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
  return modpow(a, mod-2, mod);
}

ll cal_comb(ll a, ll b, ll mod) {
  if (b > a-b) return cal_comb(a, a-b, mod);
  ll bunsi = 1;
  ll bunbo = 1;
  for (int i = 0; i < b; ++i) {
    bunsi *= (a - i);
    bunsi %= mod;
    bunbo *= (i + 1);
    bunbo %= mod;
  }
  return bunsi * modinv(bunbo, mod) % mod;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  rep(i, m) {
    ans += i * (m-i) * n * n;
    ans %= Mod;
  }
  rep(i, n) {
    ans += i * (n-i) * m * m;
    ans %= Mod;
  }
  ans *= cal_comb(n*m-2, k-2, Mod);
  ans %= Mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int a,b;
   int x;
   int ans;
   
   cin >> a >> b;
   
   //x = (a+b)/2;
   if((a+b) % 2 == 0){
          cout << (a+b)/2;
   }
        
    else{
          ans = ((a+b)/2) + 1;
          cout << ans;
    }
   
  
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

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

int main(){
	int n;
	cin >> n;
	vi a(n),b(n),c(n);
	rep(i,n) cin >> a[i];
	b[0] = a[0], c[n-1] = a[n-1];
	for(int i = 1; i < n; i++) b[i] = gcd(b[i-1],a[i]);
	for(int i = n-2; i >= 0; i--) c[i] = gcd(a[i],c[i+1]);
	int ma = max(b[n-2],c[1]);
	for(int i = 1; i < n-1; i++){
		ma = max(ma,gcd(b[i-1],c[i+1]));
	}
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long mult_mod(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b; cin >> a >> b;

    cout << max(a + b, max(a - b, a * b));

    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
if a == b:
  if a == 0:
    print("Zero")
  elif a > 0:
    print("Positive")
  else:
    print("Negative")
else:
  if a * b < 0:
    print("Zero")
  elif a * b == 0:
    print("Zero")
  else:
    if a > 0:
      print("Positive")
    else:
      num = b - a + 1
      if num % 2 == 0:
        print("Positive")
      else:
        print("Negative")

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

signed main(){
  int N;cin>>N;
  int a;cin>>a;
  for(int i=0;i<N-1;i++){
    int b;cin>>b;
    a=__gcd(a,b);
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
INF = 500000
mod = 10**9+7

N = int(input())
A = [int(x) for x in input().split()]
M = INF
ans = 0
for a in A:
    if a < M:
        ans += 1
        M = a
print(ans)

# N = int(input())
# dic = defaultdict(lambda : 0)
# for i in range(1, 10):
#     for j in range(1, 10):
#         if i == j:
#             if i <= N:
#                 dic[(i, j)] = 1
#         for k in range(1, 6):
#             x = i*10**k + j
#             if


Measured memory_bytes: 75984
#include<stdio.h>
#include<stdlib.h>
#define INF 100000000
int n;
struct Node
{
  int k;
  int pk;
  int lk;
  int rk;
};

struct Node A[251];

void insertKey(int i)
{
  int j;
  for(j = 1; j <= n; j++)
    {
      if(i != j)
	{
	  if(i / 2 == j)
	    {
	      A[i].pk = A[j].k;
	    }
	  if(2 * i == j)
	    {
	      A[i].lk = A[j].k;
	    }
	  if((2 * i) + 1 == j)
	    {
	      A[i].rk = A[j].k;
	    }
	}
    }
}

void print(struct Node A[])
{
  int i;
  for(i = 1; i <= n; i++)
    {
      printf("node %d: key = %d, ", i, A[i].k);
      if(A[i].pk != INF)
	{
	  printf("parent key = %d, ", A[i].pk);
	}
      if(A[i].lk != INF)
	{
	  printf("left key = %d, ", A[i].lk);
	}
      if(A[i].rk != INF)
	{
	  printf("right key = %d, ", A[i].rk);
	}
      printf("\n");
    }
}


int main()
{
  int i;
  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    {
      scanf("%d", &A[i].k);
      A[i].pk = INF;
      A[i].lk = INF;
      A[i].rk = INF;
    }
  for(i = 1; i <= n; i++)
    {
      insertKey(i);
    }
  print(A);
  return 0;
}



Measured memory_bytes: 2044
H,W = [int(i) for i in input().split()]
table = []
for i in range(H):
  table.append(input())
 
table_ = []
for i in range(H):
  for j in range(W):
      if table[i][j] == '#':
          table_.append(table[i])
          break

ans = []
for i in range((W)):
    for j in range(len(table)):
        if table[j][i] == '#':
            ans.append(i)
            break

for line in table_:
    for i in ans:
        print(line[i],end = '')
    print()


Measured memory_bytes: 4468
from functools import reduce

def gcd_list(n):
    return reduce(gcd, n)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


n, k = map(int, input().split())
a = list(map(int, input().split()))
if k > max(a):
    print("IMPOSSIBLE")
elif k in a:
    print("POSSIBLE")
else:
    if k % gcd_list(a) == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b;
  cin>>a>>b;
  int x = b;
  if(x<10)x+=a*10;
  else if(x<100)x+=a*100;
  else x+=a*1000;
  for(int y=1;y*y<=x;y++)if(y*y==x){
    puts("Yes");return 0;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define PQ priority_queue
#define pb push_back
#define fu(i,a,j) for(int i=a;i<j;i++)
#define fd(i,a,j) for(int i=a;i>=j;i--)
#define SYNC ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define MOD 1000000007 
#define MOD2 1000000021
#define MAXN 2000000
#define INF 1e9
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;

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

ll m_pow(ll a, ll b, ll M = MOD) { ll res = 1; for (; b; b >>= 1, a = (a * a) % M)if (b & 1)res = (res * a) % M; return res; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); for (; b; a %= b, swap(a, b)); return a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
db dis(pii a, pii b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
int dr[] = { 0, 1, 0, -1, 1,1,-1,-1 };
int dc[] = { 1, 0, -1, 0, 1,-1,1,-1 };

int n, m, k, t;

string ansok[2] = { "NO","YES" };

vpii ga[300001];
vpii se[300001];
int cga[300001];
int cse[300001];
pii a[300001];
int main()
{
	SYNC;
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++) {
		cin >> a[i].x >> a[i].y;
		se[a[i].x].pb(a[i]);
		ga[a[i].y].pb(a[i]);
	}
	int ans = 0;
	int r = 0, c = 0;
	int mx = 0, idx = 0;
	for (int i = 1; i <= n; i++) {
		if (mx < se[i].size()) {
			mx = se[i].size();
			idx = i;
		}
	}
	for (auto it : se[idx]) {
		cga[it.y]++;
	}
	ans = mx;
	for (int i = 1; i <= m; i++) {
		ans = max(ans, mx + (int)ga[i].size() - cga[i]);
	}

	r = 0, c = 0;
	mx = 0, idx = 0;
	for (int i = 1; i <= m; i++) {
		if (mx < ga[i].size()) {
			mx = ga[i].size();
			idx = i;
		}
	}
	for (auto it : ga[idx]) {
		cse[it.x]++;
	}
	for (int i = 1; i <= n; i++) {
		ans = max(ans, mx + (int)se[i].size() - cse[i]);
	}


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

Measured memory_bytes: 38820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define MAXN 100
#define MAXV 100001
#define INF 1000000001
ll dp[MAXV][MAXN];

ll weight(ll k, ll i, ll n, ll wi[], ll vi[])
{
    if (k <= 0)
        return 0;
    if (n == i)
        return INF;
    if (dp[k][i] != -1)
        return dp[k][i];
    dp[k][i] = min(weight(k, i + 1, n, wi, vi), wi[i] + weight(k - vi[i], i + 1, n, wi, vi));
    return dp[k][i];
}
void solve()
{
    ll n, w;
    cin >> n >> w;
    ll wi[n], vi[n];
    for (int i = 0; i < n; i++)
    {
        cin >> wi[i] >> vi[i];
    }
    s(dp, -1);
    for (int k = MAXV - 1; k >= 0; k--)
    {
        if (weight(k, 0, n, wi, vi) <= w)
        {
            //cout << dp[k][0] << "::";
            cout << k << "\n";
            break;
        }
    }
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 81788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

ll mul(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = ((res%mod) * (x%mod))%mod;
        n = (n >> 1);
        x = ((x%mod) * (x%mod))%mod;
    }
    return res;
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(ll n, ll r, ll mod = md) {
    if(n < r) return 0;
    return mul(fac[n], mul(ifac[r], ifac[n-r], mod), mod);
}

void sieve(ll n) {
	vector<bool> prime(n+1, true);
    for(int i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(int j = i*i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    p.push_back(2);
    for(int i = 3; i <= n; i += 2) {
        if(prime[i]) {
            p.push_back(i);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll n, x;
   	cin >> n;
   	cin >> x;
   	ll gcd = x;
   	for(int i = 1; i < n; i++) {
   		cin >> x;
   		gcd = __gcd(gcd, x);
   	}
   	cout << gcd << "\n";
    return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include<iostream>


using ll = long long;

using namespace std;


int main() {
	int k,s;
	cin>>k>>s;
	ll ans=0;
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			int z=s-x-y;
			if(z>=0&&z<=k)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let k: usize = sc.read();
    let q: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut ans = std::i64::MAX;
    for &min in &a {
        let mut escape = Vec::new();
        for i in 0..n {
            if a[i] < min {
                escape.push(i);
            }
        }
        escape.push(n);

        let extract = |from: usize, to: usize| -> Vec<i64> {
            if from > to || to - from + 1 < k {
                return Vec::new();
            }

            let mut v = Vec::new();
            for i in from..(to + 1) {
                v.push(a[i]);
            }
            v.sort();
            let removable = to - from + 1 - (k - 1);
            return (0..removable).map(|i| v[i]).collect();
        };

        let mut max = Vec::new();
        if escape[0] > 0 {
            max.append(&mut extract(0, escape[0] - 1));
        }
        for i in 0..(escape.len() - 1) {
            max.append(&mut extract(escape[i] + 1, escape[i + 1] - 1));
        }
        max.sort();
        if max.len() < q {
            continue;
        }
        ans = cmp::min(ans, max[q - 1] - min);
    }
    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

struct Node {
  ll key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(ll k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
  return;
}

void find(Node *u, ll k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) {
      u = u->left;
    } else {
      u = u->right;
    }
  }
  if (u != NIL) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return;
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  cout << ' ' << u->key;
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  cout << ' ' << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main() {
  ll n, m;
  string s;
  cin >> n;
  rep(i, n) {
    cin >> s;
    if (s.at(0) == 'i') {
      cin >> m;
      insert(m);
    } else if (s.at(0) == 'p') {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else {
      cin >> m;
      find(root, m);
    }
  }
}


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


def solve(N: int, A: "List[int]"):
    ans = 0
    limit = 10 ** 18
    if 0 in A:
        print(0)
        return
    for i, v in enumerate(A):
        if i == 0:
            ans = v 
            continue
        ans *= v
        if ans > limit:
            print(-1)
            return
    print(ans)
    return


# Generated by 1.1.7.1 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()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  string s; cin >> s;
  int x = 0, ans = 0;
  for (char c : s) {
    if (c == 'I') ++x;
    else --x;
    ans = max(ans, x);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256