akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int res = 0;
    for(auto e : a){
        while(e % 2 == 0){
            res++;
            e /= 2;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long
//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

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

	int N;
	cin >> N;

	vector<int> ans;
	int i = 1;
	int cnt = 0;
	while (true)
	{
		if (IsPrime(i) && i % 5 == 1) {
			ans.push_back(i);
			cnt++;
		}
		if (cnt == N) {
			break;
		}
		i++;
	}
	for (int i = 0; i < N-1; i++)
	{
		printf("%d ", ans[i]);
	}
	printf("%d\n", ans[N - 1]);

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0;
		
		for (int i = 0; i <= a ; i++) {
			for (int j = 0; j <= b ; j++) {
				for (int k = 0; k <= c ;k++) {
					if (500 * i + 100 * j + k * 50 == x) {
						ans++;
					}
				}
			}
		}
		
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21972
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <sstream>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int N, M;
std::string output[100000];
std::map<int, int> sorted[100000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> M;
	for (size_t i = 0; i < M; i++)
	{
		int p, y;
		in >> p >> y; --p;
		sorted[p].insert(std::pair<int,int>(y,i));
	}

	for (int p = 0;p < N; ++p)
	{
		std::stringstream ss;
		ss << std::setfill('0') << std::right << std::setw(6) << p+1;
		std::string prefix = ss.str();
		int count = 1;
		for (auto& i : sorted[p])
		{
			ss.str("");
			ss << std::setfill('0') << std::right << std::setw(6) << count;
			++count;
			output[i.second] = prefix + ss.str();
		}
	}

	for (size_t i = 0; i < M; i++)
	{
		out << output[i] << '\n';
	}

	return 0;
}
#endif


#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N, T, A;
int32_t H[1000];
constexpr uint64_t MOD = 1000000007;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> T >> A;
	for (size_t i = 0; i < N; i++)
	{
		in >> H[i]; H[i] *= 1000;
	}
	T *= 1000;
	A *= 1000;

	int32_t diff = std::abs((T - 6 * H[0]) - A);
	int32_t index = 0;

	for (size_t i = 0; i < N; i++)
	{
		int32_t tmpdiff = std::abs((T - 6 * H[i]) - A);
		if (tmpdiff < diff) {
			diff = tmpdiff;
			index = i;
		}
	}
	out << index + 1 << endl;

	return 0;
}
#endif


Measured memory_bytes: 11512
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
#define INF (1e18)+1
 
int nChoosek( int n, int k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i; 
    }
    return result;
}

int choose2(int n){
	
	return n*(n-1)/2;
}
 
 int countDigit(int  n) 
{ 
    int k = 0; 
    while (n != 0) { 
        k = n%10; 
        n = n / 10; 
    } 
    return k; 
} 

 int arr[10][10];
int32_t main() {
 
 	int N;
 	
 	
 	cin >> N;
 	 
  
  	for(int i=1;i<=N; i++){
  		
  		int r = i%10;
  		int l = countDigit(i);
  		
  		
	  	arr[l][r]++;
	}
 	
 	int ans =0;
 	for(int i=0; i<=9; i++){
 		
 		for(int j=0; j<=9; j++){
 			
 			ans += arr[i][j] * arr[j][i];
 			
		}
		
	}
	 
	 
 	cout << ans << endl;
 	 
 	 
}

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

int main() {
    int N;
    cin >> N;
    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> bin_num;
    while (N != 1) {
        if (N % 2 == 0) {
            if (N > 0) {
                N /= 2;
                N *= -1;
            }
            else {
                N = abs(N) / 2;
            }
            bin_num.push_back(0);
        }
        else {
            if (N > 0) {
                N /= 2;
                N *= -1;
            }
            else {
                N = (abs(N) + 1) / 2;
            }
            bin_num.push_back(1);
        }
    }
    bin_num.push_back(1);
    for (int i = bin_num.size() - 1; i >= 0; i--) cout << bin_num[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
using namespace std; using ll=long long; using lld=long double;
const lld INF=1e32; using P=pair<lld,int>;

int main() {
  lld x0, y0, x1, y1; cin>>x0>>y0>>x1>>y1;

  int n; cin>>n; n+=2;
  lld x[n], y[n], r[n], t[n]; fill(t,t+n,INF);
  x[0]=x0; y[0]=y0; x[n-1]=x1; y[n-1]=y1; r[0]=r[n-1]=0;
  for(int i=1;i<n-1;i++) {
    cin>>x[i]>>y[i]>>r[i];
  }
  bool u[n]={};

  priority_queue<P, vector<P>, greater<P>> que; que.push({0.0,0}); t[0]=0; // len, id
  while(!que.empty()) {
    P d = que.top(); que.pop(); lld xx,yy,rr;

    if (t[d.second] < d.first) continue;
    xx = x[d.second]; yy = y[d.second]; rr = r[d.second]; u[d.second]=true;

    for(int i=0;i<n;i++) {
      if (u[i]) continue;
      lld pl = sqrt((xx-x[i]) * (xx-x[i]) + (yy-y[i]) * (yy-y[i]));
      pl = max((lld)0, pl - rr - r[i]);
      if (t[i] > d.first + pl) {
        t[i] = d.first + pl; que.push({t[i],i});
      }
      //cout<<d.second<<" "<<i<<" "<<d.first<<" "<<pl<<endl;
    }
  }

  cout<<fixed<<setprecision(10)<<t[n-1]<<endl;
}

Measured memory_bytes: 10220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll h[26][5010];
mt19937_64 mt;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	for(int i = 0; i < 26; i++){
		for(int j = 0; j < 5010; j++){
			h[i][j] = mt();
		}
	}

	string s, t;
	cin >> s >> t;

	int n = s.size(), m = t.size();
	int ans = 0;
	for(int len = min(n, m); len >= 1; len--){
		int cnt[26] = { 0 };
		for(int i = 0; i < len; i++){
			cnt[s[i] - 'a']++;
		}
		ll hash = 0;
		for(int i = 0; i < 26; i++){
			hash ^= h[i][cnt[i]];
		}
		set<ll> hs;
		hs.insert(hash);
		for(int i = len; i < n; i++){
			int add = s[i] - 'a', sub = s[i - len] - 'a';
			hash ^= h[add][cnt[add]];
			hash ^= h[sub][cnt[sub]];
			cnt[add]++;
			cnt[sub]--;
			hash ^= h[add][cnt[add]];
			hash ^= h[sub][cnt[sub]];
			hs.insert(hash);
		}

		memset(cnt, 0, sizeof cnt);
		for(int i = 0; i < len; i++){
			cnt[t[i] - 'a']++;
		}
		hash = 0;
		for(int i = 0; i < 26; i++){
			hash ^= h[i][cnt[i]];
		}
		if(hs.count(hash)){
			//cout << t.substr(0, len) << endl;
			ans = len;
			break;
		}
		for(int i = len; i < m; i++){
			int add = t[i] - 'a', sub = t[i - len] - 'a';
			hash ^= h[add][cnt[add]];
			hash ^= h[sub][cnt[sub]];
			cnt[add]++;
			cnt[sub]--;
			hash ^= h[add][cnt[add]];
			hash ^= h[sub][cnt[sub]];
			if(hs.count(hash)){
				//cout << t.substr(i - len + 1, len) << endl;
				ans = len;
				break;
			}
		}
		if(ans) break;
	}


	cout << ans << endl;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
  int n , m ,x;
  cin >> n >> m >> x ;
  vector < int > cost(n) ;
  vector < vector < int > > in(n,vector<int>(m));
  for( int i = 0 ; i < n ; i++){
    cin >> cost[i] ;
    for(int j = 0 ; j < m ; j++){
        cin >> in[i][j] ;
    }
  }
  ll ans = INT_MAX ;
  for( int i = 1 ; i < (1<<n) ; i++){
    vector < int > a(m);
    ll local = 0 ;
    for( int bit = 0 ; bit < n ; bit++){
        if(i&(1<<bit)){
            local += cost[bit];
            for( int j = 0 ; j < m ; j++){
                a[j]+=in[bit][j];
            }
        }
    }
    bool flag = true ;
    for( int j = 0 ; j < m ; j++)
        if(a[j]<x)
            flag = false ;
    if(flag)
        ans = min(ans,local);
  }
  cout << (ans==INT_MAX?-1:ans) ;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	    //  #ifndef ONLINE_JUDGE
	    //  // for getting input from input.txt
	    //  freopen("input.txt", "r", stdin);
	    //  // for writing output to output.txt
	    //  freopen("output.txt", "w", stdout);
	    // #endif
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n,i=0,ac=0,wa=0,tle=0,re=0;
	    cin>>n;
	    string s[n];
	   for (int i = 0; i < n; ++i)
	   {
	   	/* code */
	   	cin>>s[i];
	   }
	    for (int i = 0; i < n; ++i)
	    {
	    	if(s[i] == "AC" ){
	    		ac++;
	    	}
	    	else if(s[i] == "TLE"){
	    		tle++;
	    	}
	    	else if(s[i] == "RE"){
	    		re++;
	    	}
	    	else{
	    		wa++;
	    	}
	    }

	    cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
	    cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
	    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
	    cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
	    return 0;
	  }


Measured memory_bytes: 6748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        char[] s = sc.next().toCharArray(), t = sc.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < 3; i++)
            if (s[i] == t[i]) ans++;
        out.println(ans);
        out.flush();
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        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());
        }

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

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

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

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

    }


}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <tuple>
#include <iterator>
using namespace std;
using ll = long long;

ll sum(ll n)
{
  ll s = 0;
  while (n > 0)
  {
    s += n % 10;
    n /= 10;
  }
  return s;
}

int main()
{
  ll k;
  cin >> k;
  ll n = 1, d = 1;
  cout << 1 << endl;
  for (ll i = 1; i < k; ++i)
  {
    if (sum(n + d) * (n + d * 10) < sum(n + d * 10) * (n + d))
      d *= 10;
    n += d;
    cout << n << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class SearchNum
{
public:
  int n;
  int q;
  int a[20];
  int solve();
  bool search( int ix, int sum, int g );
};

int SearchNum::solve()
{
  cin >> n;
  for ( int i = 0; i < n; i++ )
    {
      cin >> a[i];
    }
  cin >> q;
  for ( int i = 0; i < q; i++ )
    {
      int m;
      cin >> m;
      if ( search( 0, 0, m ) )
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }

  
  return 0;
}

bool SearchNum::search( int ix, int sum, int g )
{
  if ( ix == n )
    return false;

  if ( sum == g )
    return true;
  
  if ( a[ix] + sum == g )
    return true;

  return search( ix+1, sum, g ) || search( ix+1, sum+a[ix], g );
}

int main()
{
  SearchNum sn;

  sn.solve();
  
  return 0;
}

Measured memory_bytes: 1152
#Energy Drink Collector
N, M = map(int, input().strip().split())

list = [list(map(int, input().strip().split())) for i in range(N)]	
list.sort(key = lambda x : x[0])
sum = 0
cnt = 0
for a, b in list:
	if cnt + b < M:
		sum += a*b
		cnt += b
	else:
		sum += a*(M - cnt)
		break

print(sum)

Measured memory_bytes: 29028
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define ceel(x, y) ((x) / (y) + !((x) % (y) == 0))
#define ss second
#define ff first
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
 
// DEBUG TEMPLATE by livw
void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

bool check(ll a[], ll b[], ll n, ll m, ll k, ll val)
{
    for (int i = 0; i <= n; i++)
    {
        int j = val - i;
        if (j >= 0 and j <= m and a[i] + b[j] <= k) return true;
    }
    for (int i = 0; i <= m; i++)
    {
        int j = val - i;
        if (j >= 0 and j <= n and a[j] + b[i] <= k) return true;
    }
    return false;

}

int main()
{
    fastio;
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    ll a[n + 1], b[m + 1];
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    a[0] = b[0] = 0;
    for (int i = 1; i <= n; i++) a[i] += a[i - 1];
    for (int i = 1; i <= m; i++) b[i] += b[i - 1];
    int l = 1, r = n + m;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (check(a, b, n, m, k, mid))
        {
            l = mid + 1;
            ans = mid;
        }
        else r = mid - 1;
    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 6780
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N;
    cin>>N;
    vector<int> A;

    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;
        A.push_back(-a);
    }

    vector<int> ans;
    ans.push_back(A[0]);

    for(int i = 1;i < N;i++) {
        int a = A[i];
        auto itr = upper_bound(ans.begin(),ans.end(),a);
        if(itr == ans.end())
            ans.push_back(a);
        else
            *itr = a;
    }

    cout<<ans.size()<<endl;

    return 0;
}


Measured memory_bytes: 2032
import sys
sys.setrecursionlimit(10**9)

class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, s):
        if self.parent[s] < 0:
            return s
        self.parent[s] = self.find(self.parent[s])
        return self.parent[s]

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a == b:
            return
        self.parent[a] += self.parent[b]
        self.parent[b] = a

    def size(self, x):
        return -1 * self.parent[self.find(x)]

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.union(a - 1, b - 1)
print(max([uf.size(i) for i in range(n)]))



Measured memory_bytes: 36020
#include<cstdio>
const int N=2e5+6;
int n,A[N];
int a[N],b[N],top;
bool check(int c){
	top=0;
	for(int i=2;i<=n;++i)
	if(A[i]<=A[i-1]){
		int pos=A[i];
		while(top&&a[top]>pos)--top;
		if(!top||a[top]!=pos)a[++top]=pos,b[top]=1;else{
			while(top&&a[top]==pos&&b[top]==c-1)--top,--pos;
			if(!pos)return 0;
			if(top&&a[top]==pos)++b[top];else a[++top]=pos,b[top]=1;
		}
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",A+i);
	bool ok=1;
	for(int i=1;i<=n;++i)if(A[i]<=A[i-1])ok=0;
	if(ok){puts("1");return 0;}
	int l=2,r=1e9,ans=1e9;
	while(l<=r){
		const int mid=l+r>>1;
		if(check(mid))r=(ans=mid)-1;else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
A.sort()
def main():
    if A[0] == N % 2:
        print(0)
        return 0
    if len(A) == 1 and A[0] == 0:
        print(1)
        return 0
    elif len(A) == 1:
        print(0)
        return 0
    if A[0] == 0:
        del A[0]
    if A[0] == 0:
        print(0)
        return 0
    i = 1
    while True:
        if i >= len(A):
            break
        if len(A) % 2 != 0:
            print(0)
            return 0
        if A[i] != A[i - 1]:
            print(0)
            return 0
        i += 2
    i = 2
    while True:
        if i >= len(A):
            break
        if A[i] == A[i - 1]:
            print(0)
            return 0
        i += 2
    print(pow(2, len(A) // 2) % 1000000007)
main()


Measured memory_bytes: 14008
N = int(input())
P = list(map(int, input().split()))

rui = [None] * (N)
rui[0] = P[0]
# print(rui)

for i in range(1, N):
    a = rui[i-1]
    b = P[i]
    rui[i] = min(a, b)


c = 0
for i in range(N):
    if P[i] <= rui[i]:
        c += 1
print(c)

Measured memory_bytes: 24744
#include<stdio.h>

void swap(int* x, int* y){
    int buf = *(x);
    *(x) = *(y);
    *(y) = buf;
}

void sort(int* ap, int* bp, int n){
    if(n <= 1){
        return;
    }
    int l = 0, r = n-1;
    int p = *(bp + (n/2));
    while(1){
        while(*(bp+l) < p){
            l++;
        }
        while(p < *(bp+r)){
            r--;
        }
        if(r <= l){
            break;
        }
        swap(bp+l, bp+r);
        swap(ap+l, ap+r);
        l++;
        r--;
    }
    sort(ap, bp, l);
    sort(ap+r+1, bp+r+1, n-r-1);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int a[m], b[m], f[m];
    for(int i=0; i<m; i++){
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
        f[i] = 1;
    }
    sort(a, b, m);
    int count = 0;
    for(int i=0; i<m; i++){
        if(f[i] == 1){
            f[i] = 0;
            for(int j=i; j<m; j++){
                if((f[j] == 1) && (a[j] < b[i])){
                    f[j] = 0;
                }
            }
            count++;
        }
    }
    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1280
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;
    vs S(N); REP(i, N) cin >> S[i];

    string ptn = "MARCH";
    map<char, ll> mp;
    for(string s : S) {
        REP(i,5) {
            if (s[0] == ptn[i]) mp[s[0]]++;
        }
    }
    
    ll ans = 0;
    if (mp.size() >= 3) {
        REP(i, 5)
            FOR(j, i + 1, 5)
                FOR(k, j + 1, 5)
                    ans += mp[ptn[i]] * mp[ptn[j]] * mp[ptn[k]];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll memo[2005];
ll dp(ll n)
{
    if(n<3) return 0;
    if(n>=3 && n<=5) return 1;
    if(memo[n]!=-1) return memo[n];
    ll ans = 1;
    for(ll i=3;n-i>=3;i++)
    {
        ans=MOD(ans+MOD(dp(n-i),mod),mod);
    }
    return memo[n]=ans;
}

int main()
{
    //fastio
    ll n ;
    sfl(n);
    memset(memo,-1,sizeof(memo));
    //if(n>=6) cout<<MOD(dp(n)+1,mod)<<endl;
    //else
    cout<<dp(n);

    return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll binpow(ll a, ll b, ll m) {
	a %= m;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int MOD = 1e9 + 7;
	ll n; cin >> n;
	ll tot = binpow(10, n, MOD);
	ll single = binpow(9, n, MOD);
	single *= 2;
	single %= MOD;
	ll dup = binpow(8,n,MOD);
	ll temp = (single - dup + MOD) % MOD;
	tot = (tot - temp + MOD ) % MOD;
	cout << tot << endl;
	return 0;
}




Measured memory_bytes: 3620
package main

import (
	"fmt"
)
func main() {
	var (
		a, b, c, x int
		count = 0
	)
	fmt.Scan(&a, &b, &c, &x)

	for i := 0; i < a+1 ; i++{
		for j := 0; j < b+1; j++ {
			for k := 0; k < c+1; k++ {
				if i * 500 + j * 100 + k * 50 == x {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
raw = [0 for _ in range(3*10**5)]
for x in a:
  raw[x] += 1
ans = 0
for y in raw:
  ans += y * (y-1) // 2
for x in a:
  tmp = int(ans)
  tmp -= raw[x] - 1
  print(tmp)

Measured memory_bytes: 26268
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [ set(map(int, input().split())) for _ in range(m) ]
d = [ 0 ] * n
for i,j in p:
    d[i-1] = max(d[i-1], h[j-1])
    d[j-1] = max(d[j-1], h[i-1])
c = [ 0 for i in range(n) if d[i] < h[i] ]
print(len(c))

Measured memory_bytes: 43592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll h, w;
    int n;
    cin >> h >> w >> n;
    ll a, b;
    map<pair<ll, ll>, int> mp;
    rep(i, n) {
        cin >> a >> b;
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                int ny = a + i, nx = b + j;
                if (ny <= 1 || h <= ny || nx <= 1 || w <= nx) continue;
                mp[{ny, nx}]++;
            }
        }
    }
    ll ans[10] = {};
    ans[0] = (h - 2) * (w - 2) - mp.size();
    for (auto a : mp) {
        ans[a.second]++;
    }
    for (int i = 0; i <= 9; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  int x = N % 500;
  
  if (x > A) {
    cout << "No" << endl;
  }
  if (x <= A) {
    cout << "Yes" <<endl;
  }
}

Measured memory_bytes: 256
a,b,c,d,e=map(int,input().split())
x=[a,b,c,d,e]

if x[0]==0:
    print(1)
elif x[1]==0:
    print(2)
elif x[2]==0:
    print(3)
elif x[3]==0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9052
n = int(input())
a = list(map(int, input().split()))
ans = 0
ans2 = 0
a_sum = 0
b_sum = 0

if a[0] < 0:
	a = [-a[i] for i in range(n)]

b = list.copy(a)

if a[0] == 0:
	a[0] = 1
	ans += 1

a_sum += a[0]

for i in range(1, n, 2):
	if a_sum + a[i] >= 0:
		ans += a_sum + a[i] + 1
		a[i] = -1 - a_sum
	a_sum += a[i]
	if i == n - 1:
		break
	if a_sum + a[i + 1] <= 0:
		ans += 1 - a_sum - a[i + 1]
		a[i + 1] = 1 - a_sum
	a_sum += a[i + 1]

if b[0] == 0:
	b[0] = -1
	ans2 += 1
else:
	ans2 += b[0] + 1
	b[0] = -1

b_sum += b[0]

for i in range(1, n, 2):
	if b_sum + b[i] <= 0:
		ans2 += 1 - b_sum - b[i]
		b[i] = 1 - b_sum
	b_sum += b[i]
	if i == n - 1:
		break
	if b_sum + b[i + 1] >= 0:
		ans2 += b_sum + b[i + 1] + 1
		b[i + 1] = -1 - b_sum
	b_sum += b[i + 1]

print(min(ans, ans2))

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

int main(void)
{
	int ac = 0, bc = 0, oc = 0, abc = 0, num, n;
	string str;
	char ch;

	while (cin >> str)
	{
		n = str.size();
		if (n == 1)break;
		if (str[n - 2] == ',') {
			if (str[n - 1] == 'A')ac++;
			else if (str[n - 1] == 'B')bc++;
			else oc++;
		}
		else {
			abc++;
		}
	}
	cout << ac << endl;
	cout << bc << endl;
	cout << abc << endl;
	cout << oc << endl;
	return 0;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long N, long long M, std::vector<long long> A){
    ll res = N - accumulate(A.begin(), A.end(), 0);;
    cout << (res >= 0 ? res : -1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>
int main()
{
	int n,m,a,b,i,j,k,l,end;
	int b1,b2;
	while(~scanf("%d%d",&n,&m))
	{
		k=0;l=0;int G[200005]={0};
		int END=0;
		for (i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			if (a==1)
			{
				if (G[b]>0)
				{
					END=1;
				}
				G[b]++;
			}
			else if (b==n)
			{
				if (G[a]>0)
				{
					END=1;
				}
			    G[a]++;
			}
		}
		if (END==1)
		{
			puts("POSSIBLE");
		}
		else 
		{
			puts("IMPOSSIBLE");
		}
	}
	return 0;
}

Measured memory_bytes: 896
//MD. HASNAIN ALI (UNSOLVED)
#include<bits/stdc++.h>
using namespace std;
 
#pragma GCC             optimize ("Ofast")
#pragma GCC             optimize("O3")
#define ll              long long
#define lo(i,a,b,c)     for(i=a;i<=b;i=i+c)
#define sca(n)          scanf("%lld", &n)
#define pri(n)          printf("%lld", n)
#define SORT(x)         sort(x.begin(), x.end())
#define REV(x)          reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define distance(a,b)   (sq(a.x-b.x) + sq(a.y-b.y))
#define end0             "\n"
#define end1            cout<<"\n";
#define pi              acos(-1)
#define mod             1000000007
#define inf             999999999999999999
#define eps             10e-9      
 
 
 
 
 
int main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0), cout.tie(0);
  //freopen("test.txt","r",stdin);
  
  ll a,b;
  cin>>a;
  b=a+a*a+a*a*a;
  cout<<b<<end0;

    return 0;
}













Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}


int main() {
    ll n, k;
    cin>>n>>k;
    ll ans = n/k;
    if(k%2==1){
        pr(ans*ans*ans);
    }else{
        ll y =  (n + k / 2) / k;

        pr(ans*ans*ans+y*y*y);
    }
}

Measured memory_bytes: 256
n,k = map(int,input().split())
mod = 10**9 + 7
def factorial(N,MOD,r=True):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1,N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N],MOD-2,MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    if r:
        return fact,rfact
    else:
        return fact
fact,rfact = factorial(2*n,mod)

def perm(n,k): #上のfactorialと併用
    return fact[n]*rfact[n-k]%mod
def comb(n,k): #上のfactorialと併用
    return fact[n]*rfact[k]*rfact[n-k]%mod
ans = 0

if k+1>=n:
    ans = comb(2*n-1,n)
    print(ans)
else:
    ans = 0
    for i in range(k+1):
        ans += comb(n,i)*comb(n-1,i)
        ans %= mod
    print(ans)

Measured memory_bytes: 47340
import java.io.*;
import java.util.*;


public class Main {

  void solve() throws IOException {
    int h = nextInt();
    int n = nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextInt();
      b[i] = nextInt();
    }
    long[] dp = new long[h + 1];
    for (int i = 0; i <= h; i++) {
        dp[i] = -1;
    }
    dp[h] = 0;
    for (int i = h; i > 0; i--) {
      if (dp[i] != -1) {
        for (int j = 0; j < n; j++) {
          int next = Math.max(i - a[j], 0);
          if (dp[next] == -1 || dp[next] > dp[i] + b[j]) {
            dp[next] = dp[i] + b[j];
          }
        }
      }
    }
    out.println(dp[0]);
  }

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

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

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

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

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

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


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main() {
	int a, b, c;
	while (cin >> a >> b >> c, a | b | c) {
		map<int, int>d;
		int s = 0;
		for (int e = 0; e < a; e++) {
			int f;
			cin >> f;
			s += f;
			d[e + 1] = f;
		}
		int g = (100-c)*s;
		if(d[b])cout << g / d[b] << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 3056
/* Code by Saborit */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast") 
#define MX 100005
#define INF (1<<30)
#define EPS 1e-9
#define MOD 1000000007
#define mid (x+xend)/2
#define izq nod*2
#define der nod*2+1
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define unique(X) (X).resize(unique(all(X)) - (X).begin())
#ifdef LOCAL 
	#include "debug.h"
#endif
using namespace std;
using namespace __gnu_pbds;
typedef long long int64;
typedef unsigned long long unt64;

string S;

int main(void){
    //~ freopen("a.in", "r", stdin);
    //~ freopen("a.out", "w", stdout);
    
    cin >> S;
    
    if( S == "SUN" ) printf("7\n");
    if( S == "MON" ) printf("6\n");
    if( S == "TUE" ) printf("5\n");
    if( S == "WED" ) printf("4\n");
    if( S == "THU" ) printf("3\n");
    if( S == "FRI" ) printf("2\n");
    if( S == "SAT" ) printf("1\n");
    
    
   return 0;
}


Measured memory_bytes: 3620
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def discount(M, A):
    from heapq import heappush, heappop
    hq = []
    for x in A:
        heappush(hq, (-x, x))
    for _ in range(M):
        _, price = heappop(hq)
        dprice = int(price/2)
        heappush(hq, (-dprice, dprice))
    return sum([x for _, x in hq])

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    print(discount(M, A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 21268
a, b, c, d, e, f = map(int, input().split())
w = []
for i in range(f//100+1):
	for j in range(f//100+1):
		x = a*i*100+b*j*100
		if x > 0 and x <= f:
			w.append(x)
w.sort()
s = []
for i in range(f//c+1):
	for j in range(f//d+1):
		if  c*i+(c*i)*e/100 + d*j+(d*j)*e/100 <= f:
			s.append(c*i + d*j)
s.sort(reverse=True)
c = -1.0
for i in w:
	for j in s:
		if i+j <= f and j <= i*e/100:
			if c < 100*j/(i+j):
				c = 100*j/(i+j)
				g, h = i+j,j
print(g,h)

Measured memory_bytes: 5232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String nk = in.readLine();
        String[] nkSplit = nk.split(" ");
        int n = Integer.parseInt(nkSplit[0]);
        int k = Integer.parseInt(nkSplit[1]);
        int[] packages = new int[n];
        int max = 0;
        int total = 0;
        for (int i = 0; i < n; i++) {
            int w = Integer.parseInt(in.readLine());
            packages[i] = w;
            if (w > max) {
                max = w;
            }
            total += w;
        }
        int minMax = binarySearch(max, total, k, packages);
        System.out.println(minMax);
    }

    private static boolean loadSuccessful(int maxLoad, int k, int[] packages) {
        int currentWeight = 0;
        for (int w : packages) {
            if (currentWeight + w <= maxLoad) {
                currentWeight += w;
            } else {
                k--;
                currentWeight = w;
            }

            if (k == 0) {
                return false;
            }
        }
        return true;
    }

    private static int binarySearch(int left, int right, int k, int[] packages) {
        int mid = (left + right) / 2;
        while (left <= right) {
            if (loadSuccessful(mid, k, packages)) {
                right = mid - 1;
                mid = (right + left) / 2;
            } else {
                left = mid + 1;
                mid = (right + left) / 2;
            }
        }
        return mid + 1;
    }
}



Measured memory_bytes: 35164
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}

int N, M;
vvi es;
vb vis;
int cnt;
int ans;
void dfs(int x, int px = - 1) {
    if (vis[x])
        return;
    vis[x] = True;
    cnt += 1;

    if (cnt == N) ans += 1;

    for (var nx in es[x]) {
        if (nx == px) continue;
        dfs(nx, x);
    }

    vis[x] = False;
    cnt -= 1;
}


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
    vs args(argv, argv+argc);
    string sample = make_sample(args, "sample-1");
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    cin >> N>>M;
    vi A(M), B(M);
    REP(i,M) {
        cin >> A[i] >> B[i];
        A[i] -= 1; B[i] -= 1;
    }

    es = vvi(N);
    REP(i,M) {
        es[A[i]].push_back(B[i]);
        es[B[i]].push_back(A[i]);
    }
    vis = vb(N, False);
    cnt = 0;
    ans = 0;
    dfs(0);

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int[] as = new int[3];
        as[0] = sc.nextInt();
        as[1] = sc.nextInt();
        as[2] = sc.nextInt();

        Arrays.sort(as);

        System.out.println(as[1] - as[0] + as[2] - as[1]);
    }

}

Measured memory_bytes: 21844
//tree sample template
#include<stdio.h>
#include<stdlib.h>

typedef struct{
    long long st;
    long long fi;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

typedef struct{
long long node;
long long dist;
}qdt;

qdt q[16777216];
long long qp=0,qqp=0;

void qpush(qdt x){
    qp++;q[qp]=x;
}

qdt qpop(){
    qqp++;
    return q[qqp];
}

int main(void){
    long long n,a[131072],b[131072],i,wd[131072],bd[131072];
    long long f=0,s=0;
    rs g[262144];
    mkj x[131072];
    qdt sd,nsd;
    for(i=0;i<131072;i++){
        wd[i]=-1;bd[i]=-1;
    }
    scanf("%lld",&n);
    for(i=0;i<n-1;i++){
        scanf("%lld%lld",&a[i],&b[i]);
        g[2*i].st=a[i];g[2*i].fi=b[i];
        g[2*i+1].st=b[i];g[2*i+1].fi=a[i];
    }
    qsort(g,2*n,sizeof(rs),sortfnc);
    makemkj(g,x,2*n);
    sd.node=1;sd.dist=0;
    wd[1]=0;
    qpush(sd);
    while(qp-qqp){
        sd=qpop();
        wd[sd.node]=sd.dist;
        for(i=x[sd.node].st;i<x[sd.node].st+x[sd.node].kz;i++){
            if(wd[g[i].fi]!=-1){continue;}
            nsd.node=g[i].fi;
            nsd.dist=sd.dist+1;
            qpush(nsd);
        }
    }
    sd.node=n;sd.dist=0;
    bd[n]=0;
    qpush(sd);
    while(qp-qqp){
        sd=qpop();
        bd[sd.node]=sd.dist;
        for(i=x[sd.node].st;i<x[sd.node].st+x[sd.node].kz;i++){
            if(bd[g[i].fi]!=-1){continue;}
            nsd.node=g[i].fi;
            nsd.dist=sd.dist+1;
            qpush(nsd);
        }
    }
    for(i=1;i<=n;i++){
        if(wd[i]<=bd[i]){f++;}else{s++;}
    }
    if(f>s){printf("Fennec\n");}else{printf("Snuke\n");}
    return 0;
}


Measured memory_bytes: 13936
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100005;
char s[N];
int ans;
int main(){
	scanf("%s",s);
	int len = strlen(s);
	if(len == 1){
		printf("0\n");
		return 0;
	}
	int head = 0,tail = len-1;
    while(head<tail){
    	if(s[head]!='x'&&s[tail]!='x'&&s[head]!=s[tail]){
    		printf("-1\n");
    		break;
    	}
    	if(s[head]==s[tail]){
    		head++;
    		tail--;
    	}
    	else if(s[head]=='x'){
    		ans++;
    		head++;
    	}
    	else if(s[tail]=='x'){
    		ans++;
    		tail--;
    	}
    }
	if(head >= tail) printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using namespace std;
int a[27]={0};
int main()
{
    char b[30];
    scanf("%s",b);
    for(int i=0;i<strlen(b);i++)
        a[b[i]-'a'+1]++;
    int i;
    for(i=1;i<=26;i++)
        if(a[i]>1)
        {
            printf("no\n");
            break;
        }
    if(i>26)
        printf("yes\n");
    return 0;
}


Measured memory_bytes: 128