akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a;
	int n;
	cin >> a;
	cin >> n;
	int count = 0;
	for (int i = 0; i < n; i++) {
		string b;
		cin >> b;
		b += b;
		string::size_type index = b.find(a);
		if (index != string::npos) {
			count++;
			continue;
		} 
	}
	cout << count << endl;
	return 0;
}

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

typedef long long ll;

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

    int A, B;

    cin >> A >> B;

    for(double i = 1; i <= 100000; i++) {
        if(static_cast<int> (i * 0.08) == A && static_cast<int> (i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 256
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  string m[] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int cnt = 0, btn = S[0];
    for (int j = 1; j < S.length(); j++) {
      if (S[j] == '0') {
        if (btn != '0') {
          cout << m[btn-'0'-1][cnt%m[btn-'0'-1].length()];
        }
        if (j != S.length()-1) {
          btn = S[j+1];
        }
        cnt = -1;
      } else {
        if (btn != S[j]) {
          btn = S[j];
          cnt = -1;
        }
        cnt++;
      }
    }
    cout<<endl;
  }
}




Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n-1];
        for(int i = 0; i < n-1; i++){
            a[i] = sc.nextInt();
        }

        int[] res = new int[n];
        for(int i = 0; i < n-1; i++){
            res[a[i]-1]++;
        }

        for(int i = 0; i < n; i++){
            System.out.println(res[i]);
        }
    }
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int a,b,c,d; cin >> a>>b>>c>>d;
    Yes(abs(a-c)<=d || (abs(a-b)<=d&&abs(b-c)<=d));
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    else if (b == 'C') cout << 'G' << endl;
    else if (b == 'G') cout << 'C' << endl;
    else cout << 'A' << endl;
    return 0;
}


Measured memory_bytes: 256
X,K,D = map(int,input().split())
if K*D<=abs(X):
    print(abs(X)-K*D)
    exit()

move_num_before = abs(X)//D
move_num_after = move_num_before+1
if (K - move_num_after)%2 == 0:
    print(abs(abs(X)-move_num_after*D))
    exit()
print(abs(X)-move_num_before*D)




Measured memory_bytes: 9172
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def mod_com_once(n, r, MOD):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    r = min(r, n - r)
    numer = denom = 1
    for i in range(n - r + 1, n + 1):
        numer = numer * i % MOD
    for i in range(1, r + 1):
        denom = denom * i % MOD
    return numer * pow(denom, MOD - 2, MOD) % MOD


def main():
    MOD = 1000000007
    X, Y = map(int, readline().split())

    p = (2 * X - Y) // 3
    q = (-X + 2 * Y) // 3

    if (X + Y) % 3 or p < 0 or q < 0:
        print(0)
        return

    print(mod_com_once(p + q, p, MOD))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n;
long long INF = 200000;
long long dp[20][200000];
int bonus[20];
int p[20];
long long f(int curr,int score){
	if(score<=0) return 0;
	long long&ret = dp[curr][score];
	if(~ret) return ret;
	if(curr>n) return ret = INF;
	ret = INF;
	for(int i=0; i<p[curr]; i++){
		ret = min(ret,i+f(curr+1,score-i*curr));
	}
	ret = min(ret,p[curr]+f(curr+1,score-curr*p[curr]-bonus[curr]));
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	int g;
	cin>>n>>g;
	g/=100;
	for(int i=1; i<=n; i++){
		cin>>p[i]>>bonus[i];
		bonus[i]/=100;
	}
	cout<<f(1,g);
}

Measured memory_bytes: 34868
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int max(int a, int b)
{
	if (a > b)
		return a;
	else 
		return b;
}
int min(int a, int b)
{
	if (a < b)
		return a;
	else
		return b;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	int v[55];
	for (i = 0; i < n; i++)
		scanf("%d", &v[i]);
	int a, b, c;
	int ans = 0, sum;
	int vv[55], m;
	for (a = 0; a <= min(n,k); a++)
	{
		for (b = 0; b <= a; b++)
		{
			m = 0;
			for (i = 0; i < b; i++)
			{
				vv[m] = v[i];
				m++;
			}
			for (i = n - 1; i >= n - a + b; i--)
			{
				vv[m] = v[i];
				m++;
			}
			qsort(vv, m, sizeof(int), asc);
			sum = 0;
			for (i = 0; i < m; i++)
				sum += vv[i];
			c = k - a;
			if (c > 0)
			{
				for (i = 0; i < m; i++)
				{
					if (vv[i] < 0)
					{
						sum -= vv[i];
						c--;
					}
					if (c == 0)
						break;
				}
			}
			ans = max(ans, sum);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int n, h, res;

int main()
{
    cin >> n >> h;
    for (int i = 0, tmp; i < n; ++i) {
        cin >> tmp;
        if (tmp >= h) ++res;
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  int N, M;
  cin >> N;
  map<string, int> dict;
  for(int i=0; i<N; i++){
    string val;
    cin >> val;
    if(dict.count(val)){
      dict.at(val)++;
    }else{
      dict.emplace(val, 1);
    }
  }
  cin >> M;
  for(int i=0; i<M; i++){
    string val2;
    cin >> val2;
    if(dict.count(val2)){
      dict.at(val2)--;
    }
    else{
      dict.emplace(val2, 1);
    }
  }
  int max = 0;
  for(auto a: dict){
    max = a.second > max? a.second: max;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // input N A B
        Scanner sc = new Scanner(System.in);
        int numPerson = sc.nextInt();
        int priceA = sc.nextInt();
        int priceB = sc.nextInt();
        if(numPerson * priceA < priceB){
            System.out.println(numPerson * priceA);
        } else {
            System.out.println(priceB);
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=0;
    
    for(int i=0;i<=100;i++){
        if((a<=i && i<=b) && (c<=i && i<=d)) ans++;
    }
    
    cout<<max(ans-1,0)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	v[0]--;
	for (int i = 1; i < N; i++) {
		if (v[i] - 1 >= v[i - 1])v[i]--;
		if (v[i] < v[i - 1]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int H,W;
	char[][] ch;
	public void solve() {
		H = nextInt();
		W = nextInt();

		ch = new char[H][W];
		for(int i = 0;i < H;i++){
			ch[i] = next().toCharArray();
		}

		char[][] after = new char[H * 2][W];
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				after[2 * i][j] = ch[i][j];
				after[2 * i + 1][j] = ch[i][j];
			}
		}

		for(int i = 0;i < 2 * H;i++){
			for(int j = 0;j < W;j++){
				out.print(after[i][j]);
			}
			out.println();
		}

		out.println();

	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 8916
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, w, k, sx, sy, tx, ty;
    cin >> h >> w >> k >> sx >> sy >> tx >> ty;
    vector<vector<int>> d(h + 2, vector<int>(w + 2, 1e9));
    for (int i = 0; i < w + 2; i++)
        d[0][i] = d[h + 1][i] = 0;
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        d[i][0] = d[i][w + 1] = 0;
        for (int j = 0; j < w; j++)
            if (s[j] == '@')
                d[i][j + 1] = 0;
    }
    d[sx][sy] = 0;
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
    vector<vector<bool>> was(h + 2, vector<bool>(w + 2));
    was[sx][sy] = true;
    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();
        for (int kk = 0; kk < 4; kk++) {
            int i = x, j = y;
            for (int l = 0; l < k; l++) {
                i += dx[kk], j += dy[kk];
                if (d[i][j] <= d[x][y])
                    break;
                if (was[i][j])
                    continue;
                was[i][j] = true;
                d[i][j] = d[x][y] + 1;
                if (i == tx && j == ty) {
                    cout << d[i][j] << endl;
                    return 0;
                }
                que.emplace(i, j);
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 18756
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int A, P;
	cin >> A >> P;

	cout << (P + A * 3) / 2 << endl;

	return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s,t;
	cin >> s >> t;
	int n=(int)s.length(), m=(int)t.length();
	int dp[n+1][m+1];
	for(int i=0; i<=n; i++)for(int j=0; j<=m; j++)dp[i][j]=0;
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(s[i-1]==t[j-1])dp[i][j] = dp[i-1][j-1]+1;
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	 /*
	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}
	// */
	string ans = "";
	
	int i=n,j=m;
	while(dp[i][j]!=0){
		if(dp[i-1][j]==dp[i][j]){
			i--;
		}else if(dp[i][j-1]==dp[i][j]){
			j--;
		}else{
			ans += s[i-1];
			i--; j--;
		}
	}
	reverse(all(ans));
	
	cout << ans << endl;
}	
/* Benq's
	stuff you should look for
	* ll, int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	int n;
	cin>>n;
	vi v(n);
	cin>>v;

	for(int i=1;i<n;i++)
	{
		if(v[i]>v[i-1])
			v[i]--;
		else if(v[i]<v[i-1])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
 
	return 0;	
}

Measured memory_bytes: 640
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[0].split(' ').map(n => Number(n))
  const N = input[0]
  const Y = input[1]

  for (let a = 0; a <= N; a++) {
    for (let b = 0; a + b <= N; b++) {
      let total = a * 10000 + b * 5000 + ((N - a - b) * 1000)
      if (total == Y) {
        console.log(a, b, N - a - b)
        return
      }
    }
  }
  console.log(-1, -1, -1)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N,W;
  cin>>N>>W;
  ll sum=0;
  
  vector<ll> w(N);
  vector<ll> v(N);
  for(ll i=0;i<N;i++) {
cin>>w[i]>>v[i];
    sum+=v[i];
    
  }

  
vector<vector<ll>> dp(N+1,vector<ll>(sum+1,-1));
  dp[N][0]=0;
  
  for(ll i=N-1;i>=0;i--) {
for(ll j=0;j<=sum;j++) {
if(j-v[i]<0) {
if(dp[i+1][j]==-1) {
  dp[i][j]=-1;
}
  else {
dp[i][j]=dp[i+1][j];
  }
}
  else {
 if(dp[i+1][j-v[i]]==-1&&dp[i+1][j]==-1) {
   dp[i][j]=-1;
 }
    else if(dp[i+1][j-v[i]]==-1) {
dp[i][j]=dp[i+1][j];
    }
    else if(dp[i+1][j]==-1) {
dp[i][j]=dp[i+1][j-v[i]]+w[i];
    }
    
    else {
dp[i][j]=min(dp[i+1][j],dp[i+1][j-v[i]]+w[i]);
    }
  }
}
  }
    


  
 
  
  ll ans=-1;
  for(ll i=sum;i>=0;i--) {
    for(ll j=0;j<N;j++) {
if(dp[j][i]!=-1&&dp[j][i]<=W) {
ans=i;
  break;
}
    }
    if(ans>=0) {
break;
    }
  }

  cout<<ans<<endl;
}

    
    
    
 

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

int main(int argc, char const *argv[])
{
	int N;
	int cnt,cnt8 = 0;
	cin >> N;
	for (int i = 1; i <= N; i += 2)
	{
		cnt = 0;
		for (int j = 1; j <= i ; j += 2)
		{
			if(i % j == 0)	++cnt;
		}
		if(cnt == 8)	++cnt8;
	}
	cout << cnt8 << endl;
	return 0;
}


Measured memory_bytes: 256
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define YES            cout<<"YES"<<endl;
#define NO             cout<<"NO"<<endl;
#define sz(x)          x.size()
#define ll             long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)       __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>());
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>());
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    if(n<10)
    {
        cout << n << endl;
    }
    else if(n>=10 && n<100)
    {
         cout << "9" ;
    }
    else if(n>=100 && n<1000)
    {
        cout << (n-100+1)+9 << endl;
    }
    else if(n>=1000 && n<10000)
    {
        cout << "909" << endl;
    }
    else if(n>=10000 && n<100000)
    {
        cout << (n-10000)+1+909 << endl;
    }
    else if(n==100000)
    {
        cout << "90909" << endl;
    }


	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var list = new List<int>();
            for (var i = 0; i < N; i++)
                list.Add(int.Parse(Console.ReadLine()));

            var count = 1;
            list = list.OrderByDescending(z => z).ToList();
            for (var i = 1; i < N; i++)
                if (list[i] < list[i - 1]) count++;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;
const LL mod = 998244353;

int a[20][20];

int sum[20], c[20];

void solve() {

    int n, m, x;

    scanf("%d %d %d", &n, &m, &x);

    rep(i, 1, n) {

        scanf("%d", &c[i]);

        rep(j, 1, m) {

            scanf("%d", &a[i][j]);

            sum[j] += a[i][j];

        }
    }

    rep(i, 1, m) if(sum[i] < x) {

        puts("-1"); return ;

    }

    int ans = INF;

    for(int i = 1; i < (1 << n); i++) {

        int s = 0;

        rep(j, 1, m) sum[j] = 0;

        rep(j, 0, n - 1) {

            if((i >> j) & 1) {

                s += c[j + 1];

                rep(k, 1, m) {

                    sum[k] += a[j + 1][k];

                }

            }

        }

        bool flag = 0;

        rep(j, 1, m) if(sum[j] < x) flag = 1;

        if(!flag) ans = min(ans, s);

    }

    printf("%d\n", ans);

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


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

int main()
{
    int a, b, s;

    cin >> a >> b;

    s = a + b;

    if(s % 2 == 0){
        cout << s / 2 << endl;
    }

    else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


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

using namespace std;
int static dp[100001];
int solve(vector<int> &h,int n,int i,int k)
{
    if(i==n-1)
    {
        return 0;
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    int ans=INT_MAX;
    for(int j=i+1;j<min(n,i+k+1);j++)
    {
        ans=min(ans,solve(h,n,j,k)+abs(h[i]-h[j]));
    }
    return dp[i]=ans;
}
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(h,n,0,k)<<endl;
    return 0;
}


Measured memory_bytes: 11908
import math
A, B, C, D = map(int, input().split())
cdiv = B // C - (A - 1) // C
ddiv = B // D - (A - 1) // D
lcm = (C * D) // math.gcd(C, D)
cddiv = B // lcm - (A - 1) // lcm
ans = (B - A + 1) - (cdiv + ddiv - cddiv)
print(ans)

Measured memory_bytes: 9192
#include<bits//stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const ll INF = (1LL << 63);
#define rep(i,n) for(int i = 0; i < n;i++)
int t; ll n, a[10],d;
map<ll, ll> mp;
ll dfs(ll now) {
    if (now == 0) return 0;
    if (now == 1)return d;
    if (mp.count(now)>0) return mp[now]; // すでにあったらリターン
    ll ret = d * now;
    for (int i : {2, 3, 5}) {
        ll next = now / i; // -をするとき
        ret = min(ret, a[i] + (now - next * i) * d + dfs(next));
        next = (now + i - 1) / i; // ＋をするとき
        ret = min(ret, a[i] + (next * i - now) * d + dfs(next));
    }
    return mp[now] = ret; // メモか
}
int main() {
    cin >> t;
    rep(q, t) {
        cin >> n >> a[2] >> a[3] >> a[5] >> d;
        mp.clear();
        cout << dfs(n) << endl;
    }
}

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

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int min = a;
        int mid = b;
        int max = c;
        if (a > c) {
            if (a > b) {
                max = a;
                if (b > c) {
                    mid = b;
                    min = c;
                } else {
                    mid = c;
                    min = b;
                }
            } else {
                max = b;
                mid = a;
                min = c;
            }
            // a <= c
        } else {
            if (c > b) {
                max = c;
                if (a > b) {
                    mid = a;
                    min = b;
                } else {
                    mid = b;
                    min = a;
                }
            } else {
                max = b;
                mid = c;
                min = a;
            }
        }

        int ans = 0;
        while (mid < max) {
            mid += 2;
            ans++;
        }
        if (mid > max) {
            mid -= 2;
            ans--;
        }
        while (min < max) {
            min += 2;
            ans++;
        }
        if (min > max) {
            min -= 2;
            ans--;
        }

        if (min < max && mid < max) ans++;
        else if (min < max || mid < max) ans += 2;
        System.out.println(ans);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
typedef long long int lli;
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define endl "\n"
#define sortin sort(arr.begin(),arr.end())
#define inputArray for(int i{};i<n;i++){cin>>arr[i];}
#define inputArray1 for(int i{};i<m;i++){cin>>arr1[i];}
#define intloop for(int i{};i<n;i++)
#define intloopminus for(int i{};i<n-1;i++)
#define strloop for(int i{};i<str.length();i++)
#define N int n;cin>>n
#define strlen str.length()
#define InputStr string str;cin>>str
#define twoinputs int n,k;cin>>n>>k
#define T int t;cin>>t;while(t--)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int arr[n];int sum=0;
    for(int i{};i<n;i++)
    {
        cin>>arr[i];
        sum=sum+arr[i];
    }
    int temp=sum;
    temp=ceil(sum/(float)n);
    int floor_sum=0;
    floor_sum=floor(sum/(float(n)));
    int ansCeil=0;int ansFloor=0;
    for(int i{};i<n;i++)
    {
        ansCeil=ansCeil+pow((arr[i]-temp),2);
    }
    for(int i{};i<n;i++)
    {
        ansFloor=ansFloor+pow((arr[i]-floor_sum),2);
    }
    cout<<min(ansCeil,ansFloor)<<endl;
}

Measured memory_bytes: 3620
/**
 * C - Linear Approximation
 * https://atcoder.jp/contests/abc102/tasks/arc100_a
 **/
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>

#define ll long long

using namespace std;

int main() {

    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) {
        ll ai;
        cin >> ai;
        a[i] = ai - i - 1;
    }
    sort(a.begin(), a.end());
    ll b = a[(n-1)/2];

    ll ans = 0;
    for(int i=0; i<n; i++) {
        ans += abs(a[i]-b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main() {

    vector<vector<int>> c;
    c.resize(3);
    rep(i, 3) c[i].resize(3);
    rep(i, 3) rep(j, 3) {
        int ctmp; cin >> ctmp;
        c[i][j] = ctmp;
    }
    
    bool can = false;
    int a[3];
    rrep(i, -100, 100) {
        a[0] = i;
        rrep(j, -100, 100) {
            a[1] = j;
            rrep(k, -100, 100) {
                a[2] = k;
                int b01 = c[0][0] - a[0];
                int b02 = c[1][0] - a[1];
                int b03 = c[2][0] - a[2];
                int b11 = c[0][1] - a[0];
                int b12 = c[1][1] - a[1];
                int b13 = c[2][1] - a[2];
                int b21 = c[0][2] - a[0];
                int b22 = c[1][2] - a[1];
                int b23 = c[2][2] - a[2];

                if (b01 != b02 || b01 != b03) continue;
                if (b11 != b12 || b11 != b13) continue;
                if (b21 != b22 || b21 != b23) continue;

                can = true;
                break;
            }
            if (can) break; 
        }
        if (can) break; 
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    int N,A,B,C;
    string S[114514];
    
    cin >> N >> A >> B >> C;
    REP(i,N){
        cin >> S[i];
    }
    vector<char> Ans;
    
    REP(i,N){
        if(S[i]=="AB"){
            if(A<B || (A==B && i!=N-1 && S[i+1]=="AC")){
                A++;B--;
                Ans.push_back('A');
            }else{
                B++;A--;
                Ans.push_back('B');
            }
        }else if(S[i]=="AC"){
            if(C<A || (C==A && i!=N-1 && S[i+1]=="BC")){
                C++;A--;
                Ans.push_back('C');
            }else{
                A++;C--;
                Ans.push_back('A');
            }
        }else{
            if(B<C || (B==C && i!=N-1 && S[i+1]=="AB")){
                B++;C--;
                Ans.push_back('B');
            }else{
                C++;B--;
                Ans.push_back('C');
            }
        }
        
        if(A<0 || B<0 || C<0){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    REP(i,Ans.size()){
        cout << Ans[i] << endl;
    }
    
    return 0;
}




Measured memory_bytes: 7332
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
double x[100], y[100];
double maX, miX = INF, maY, miY = INF;

double dist( double cx, double cy )
{
  double ret = 0;

  rep( i, N )
    chmax( ret, sqrt((x[i]-cx)*(x[i]-cx)+(y[i]-cy)*(y[i]-cy)) );

  return ret;
}

double g( double cx )
{
  double lb = miY, ub = maY+1;

  rep( t, 50 )
  {
    double c1 = (lb*2+ub)/3.0;
    double c2 = (lb+ub*2)/3.0;

    if( dist( cx, c1 ) > dist( cx, c2 ) )
      lb = c1;
    else
      ub = c2;
  }

  return lb;
}

double f()
{
  double lb = miX, ub = maX+1;

  rep( t, 50 )
  {
    double c1 = (lb*2+ub)/3.0;
    double c2 = (lb+ub*2)/3.0;
    double y1 = g(c1), y2 = g(c2);

    if( dist( c1, y1 ) > dist( c2, y2 ) )
      lb = c1;
    else
      ub = c2;
  }

  return lb;
}

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    std::cin >> x[i] >> y[i];

    chmax( maX, x[i] );
    chmin( miX, x[i] );
    chmax( maY, y[i] );
    chmin( miY, y[i] );
  }

  double cx = f();
  double cy = g(cx);

  printf( "%.12f\n", dist(cx,cy) );

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static final int INF = 1_000_000_000;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N+1];
        for (int i = 1; i <= N; i++) {
            A[i] = sc.nextInt();
        }

        if (K <= N) {
            int pos = 1;
            for (int i = 0; i < K; i++) {
                pos = A[pos];
            }
            System.out.println(pos);
            return;
        }

        boolean[] visited = new boolean[N+1];
        int x = 1;
        while (!visited[x]) {
            visited[x] = true;
            x = A[x];
        }

        int preLen = 0;
        int pos = 1;
        while (pos != x) {
            pos = A[pos];
            preLen++;
        }

        int len = 1;
        pos = A[x];
        while (pos != x) {
            pos = A[pos];
            len++;
        }

        int modPos = (int)((K-preLen)%len);
        int ans = x;
        for (int i = 0; i < modPos; i++) {
            ans = A[ans];
        }

        /*
        System.out.println(preLen);
        System.out.println(x);
        System.out.println(len);
        */

        System.out.println(ans);
    }
}



Measured memory_bytes: 60132
#include<iostream>
#include<queue>
using namespace std;
int main(){

  int p,c,n,r,fuda[50];
  queue<int> shuffle;

  while(1){

  cin >>n>>r;
  
  if(n == 0 && r == 0)break;

  for(int i=0 ; i < 50  ; i++){
    fuda[i]=i+1;
  }
  
  for(int i=0 ; i < r ; i++){
    
    cin >>p>>c;
    
    for(int j=n-p+1 ; j < n ; j++){ 
      shuffle.push(fuda[j]);
    }
    for(int j=n-p+1-c ; j < n-p+1; j++){
      shuffle.push(fuda[j]);
    }
    for(int j=n-p+1-c ; j < n ; j++){
     fuda[j] = shuffle.front();
      shuffle.pop();
    }
    
  }
  
  cout << fuda[n-1]<<endl;;
  
  }

  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

bool is_prime(int n) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
#ifdef WIN32
	freopen("input.txt", "r", stdin);
#endif
	int x;
	cin >> x;
	while (is_prime(x) == false) x++;
	cout << x << endl;
}

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

int main() {
  int a,b,x; cin>>x>>a>>b;
  if (b<=a) cout<<"delicious"<<endl;
  else if (b<=a+x) cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
}


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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,n)      for(int i=0; i < (n); ++i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define sz(x)         (x).size()
#define M             1e9+7;
#define MM            998244353
#define PI            3.14159265358979

typedef long double ld;
typedef pair <int,int> pii;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,ans; string str;

int solve(){
    cin>>n>>str;
    for (int i = 0; i < n-1; ++i)
    {
        if(str[i]!=str[i+1]) ans++;
    }
    cout<<ans+1;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> monsters(n+1);
    vector<int> heroes(n);
    for(int i=0;i<=n;i++)
    {
        cin>>monsters[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>heroes[i];
    }
    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        if(monsters[i]==heroes[i])
        {
            ans+=monsters[i];
        }
        else if(monsters[i]<heroes[i])
        {
            ans+=monsters[i];
            heroes[i]-=monsters[i];
            if(heroes[i]<monsters[i+1])
            {
                ans+=heroes[i];
                monsters[i+1]-=heroes[i];
            }
            else if(heroes[i]>=monsters[i+1])
            {
                ans+=monsters[i+1];
                monsters[i+1]=0;
            }
        }
        else
        {
            ans+=heroes[i];
        }
    }
    cout<<ans<<endl;
	return 0;  
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        List<String>temp = new ArrayList<>();
        int y = 0;//1行目の数値は受け取り、空白しか残ってないため2行目から読み取るため1行目はスキップ
        while(scanner.hasNextLine()){
            String temp1 = scanner.nextLine();
            if(y>=1){
                temp.add(temp1);
            }
            y++;
        }
        scanner.close();
        char[][] temp2 = new char[h][w];
        //配列に詰める、横の判定、全て.の場合削除
        for(int i=0;i<temp.size();i++){
            boolean isSharp = false;
            for(int x=0;x<w;x++){
                temp2[i][x]=temp.get(i).charAt(x);
                if(temp2[i][x] == '#'){
                    isSharp = true;
                }
            }
            if(!isSharp){
                for(int z=0;z<w;z++){
                temp2[i][z]='a';
                }
            }
        }
        //縦の判定、全て.の場合削除
        for(int ww=0;ww<w;ww++){
            boolean isSharp = false;
            for(int hh=0;hh<h;hh++){
                if(temp2[hh][ww] == '#'){
                    isSharp = true;
                }
            }
            if(!isSharp){
                for(int z=0;z<h;z++){
                temp2[z][ww]='a';
                }
            }
        }
        //出力例と同じになるように整頓し、出力する。
        
        for(int q=0;q<h;q++){
            boolean sakujo = true;
            for(int a=0;a<w;a++){
                if(temp2[q][a]=='.' || temp2[q][a]=='#'){
                    sakujo=false;
                }
                if(temp2[q][a]!='a'){
                    System.out.print(temp2[q][a]);
                }
            }
            
            if(sakujo){
                continue;
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 24532
N,X,Y=list(map(int,input().split()))
A=[[] for i in range(N+1)]
for i in range(1,N):
    for j in range(i,N+1):
        A[int(min(j-i,abs(X-i)+abs(Y-j)+1))].append(1)
        
for i in range(N):
    if i!=0:
        print(sum(A[i]))

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

int main(void){
  int h,w,k;
  int ans = 0;
  cin >> h >> w >> k;
  vector<vector<char> > c(h,vector<char>(w,0));
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c[i][j];
    }
  }
  
  for(int maski=0;maski<pow(2,h);maski++){
    for(int maskj=0;maskj<pow(2,w);maskj++){
      int black = 0;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if((((maski >> i) & 1) == 0) && (((maskj >> j) & 1) == 0) && (c[i][j] == '#')){
            black++;
          }
        }
        if(black > k) break;
      }
      if(black == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4012
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    var A = Array(4, {IntArray(4)})
    for(i in 1..3){
        for(j in 1..3) {
            A[i][j] = scn.nextInt()
        }
    }

    val N = scn.nextInt()
    var b = IntArray(N+1)
    for(i in 1..N){
        b[i] = scn.nextInt()
    }

    for(i in 1..3){
        for(j in 1..3) {
            for(k in 1..N){
                if(A[i][j] == b[k]) A[i][j] = 0
            }
        }
    }

    var result = false
    // 横
    for(i in 1..3){
        if(isBingo(A[i][1], A[i][2], A[i][3])) result = true
    }

    // 縦
    for(j in 1..3){
        if(isBingo(A[1][j], A[2][j], A[3][j])) result = true
    }

    // 斜め
    if(isBingo(A[1][1], A[2][2], A[3][3])) result = true
    if(isBingo(A[1][3], A[2][2], A[3][1])) result = true

    if(result) {
        println("Yes")
    }else{
        println("No")
    }
}

fun isBingo(i:Int,j:Int,k:Int): Boolean {
    if(i==0 && j ==0 && k ==0) return true
    return false
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, W;
	vector<P> v;

	cin >> N >> W;
	v.resize(N);
	llong w0, sum = 0;
	for(int i = 0; i < N; i++){
		cin >> v[i].first >> v[i].second;
		if(i == 0)
			w0 = v[i].first-1;
		v[i].first -= w0;
		sum += v[i].first;
	}

	vector<vector<llong> > dp(N+1, vector<llong>(sum+1, -1));
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = N; j >= 1; j--){
			for(int k = sum; k >= v[i].first; k--){
				if(dp[j-1][k-v[i].first] != -1)
					dp[j][k] = max(dp[j][k], dp[j-1][k-v[i].first] + v[i].second);
			}
		}
	}

	llong ans = 0;
	for(int i = 1; i <= N; i++)
		for(int j = 0; j <= sum; j++){
			// cerr << i << w0 << " " << " " << j << " " << i*w0+sum << endl;
			if(i*(w0) + j > W)
				break;
			else
				ans = max(ans, dp[i][j]);
		}

	cout << ans << endl;

	return 0;
}

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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        long a=fsc.nextLong(), b=fsc.nextLong();
        a-=b;
        long[] h=new long[n];
        for(int i=0;i<n;i++) h[i]=fsc.nextLong();
        fsc.close();
        long pass=1_000_000_000l;
        long fail=0;
        While:while(pass-fail>1){
            long mid=fail+(pass-fail)/2;
            long count=0;
            for(int i=0;i<n;i++){
                if(h[i]>b*mid) count+=(long) Math.ceil((double)(h[i]-b*mid)/a);
                if(count>mid){
                    fail=mid;
                    continue While;
                }
            }
            pass=mid;
        }
        System.out.println(pass);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1, 0);
    vector<bool> v(n+1, false);
    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;
        if(!v[p]) {
            if (s == "WA") {
                a[p]++;
            }
            else {
                v[p] = true;
            }
        }
    }
    int sum = 0;
    int pen = 0;
    for (int i = 1; i <= n; i++) {
        if (v[i]) {
            pen += a[i];
            sum++;
        }
    }
    cout << sum << " " << pen << endl;
}

Measured memory_bytes: 640