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

int main() {
  string S;
  cin >> S;
  if (S == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << endl;
    return 0;
  }
  vector<int> X(26, 0);
  for (char c : S) X[c - 'a'] = 1;
  if (S.size() < 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (X[c - 'a'] == 0) {
        printf("%s%c\n", S.c_str(), c);
        return 0;
      }
    }
  }
  while (true) {
    X[S.back() - 'a'] = 0;
    S = S.substr(0, S.size()-1);
    for (char c = S.back()+1; c <= 'z'; c++) {
      if (X[c - 'a'] == 0) {
        swap(S.back(), c);
        cout << S << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define pii pair<int,int> 
#define X first
#define Y second
#define MAXN 200087
int MOD = 1e9 + 7;
lli frac[MAXN], fracp[MAXN];

lli C (int a, int b) {
	return frac[a] * fracp[b] % MOD * fracp[a-b] % MOD;
}

lli modinv (int b) {
	int a1 = b, a2 = MOD, a3 = 1, a4 = 0;
	while (a2 != 0) {
		tie(a3, a4) = make_pair(a4, a3 - a1 / a2 * a4);
		tie(a1, a2) = make_pair(a2, a1 % a2);
	}
	return a3;
}

int main () {
	int n, r, c, x, y;
	cin >> r >> c >> n;
	pii p[n+1];
	lli dp[n];
	fop (i,0,n) cin >> p[i].first >> p[i].second;
	p[n] = mp(r,c);
	sort(p, p + n+1);
	frac[0] = 1;
	fop (i,1,MAXN) frac[i] = frac[i-1] * i % MOD;
	fop (i,0,MAXN) fracp[i] = modinv(frac[i]);
	fop (i,0,n+1) {
		tie(x, y) = p[i];
		dp[i] = C(x + y - 2, x - 1);
		fop (j,0,i) {
			if (p[j].first <= x and p[j].second <= y) {
				dp[i] -= (dp[j] * C(x + y - p[j].first - p[j].second, x - p[j].first));
				dp[i] %= MOD;
			}
		}
	}
	if (dp[n] < 0) dp[n] += MOD;
	cout << dp[n] << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

const int mod = 1000000007;

int main() {

    int n;
    cin >> n;


    vector<ll> as(n);
    rep(i, n) cin >> as[i];

    int skip = (n % 2) + 1;


    vector<vector<ll>> dp(n + 1, vector<ll>(skip + 1, -INF));

    auto set = [&](int i, int j, ll value) {
        if (i > n) return;
        if (j > skip) return;
        cmax(dp[i][j], value);
    };

    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= skip; j++) {
            // 飛ばす
            set(i + 1, j + 1, dp[i][j]);

            // 飛ばさない
            // 〇なら足す
            // ×なら足さない

            bool b = (i + j) % 2 == 0;
            ll now = b ? as[i] : 0;
            set(i + 1, j, dp[i][j] + now);

        }
    }

    cout << dp.back().back() << endl;
}


Measured memory_bytes: 15648
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	long long x;
	while(cin >> x) {
		long long a = x / 11;
		long long b = x % 11;
		if(b == 0) cout << 2 * a << endl;
		else if(b > 6) cout << 2 * a + 2<< endl;
		else cout << 2 * a + 1 << endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n;
  cin>>n;
  int mx=0;
  int a[n+1],b[n+1];
  int tot=0;
  bool flag=false;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i]>>b[i];
    if(a[i]!=b[i])
      flag=true;
    tot+=a[i];
  }
  if(!flag)
  {
    cout<<0;
    return 0;
  }
  for(int i=1;i<=n;i++)
  {
    if(a[i]>b[i])
    {
      mx=max(mx,tot-a[i]+a[i]-b[i]);
    }
  }
  cout<<mx;

}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
//using ll = long long;
typedef pair<int, int> P;

#define rep(i, s, c) for (int i = s; i < c; i++)
#define INF 10000000000
#define MAX_N 100010

int N, Q, K;
struct edge {int to; ll cost;};
vector<edge> tree[MAX_N];
ll depth[MAX_N];

void dfs(int now, int from, ll d){
    depth[now] = d;
    rep(i, 0, tree[now].size()){
        if (tree[now][i].to == from) continue;
        dfs(tree[now][i].to, now, tree[now][i].cost + d);
    }
}


int main(){
    cin >> N;
    int a, b, c;
    rep(n, 0, N - 1){
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }


    cin >> Q >> K;
    dfs(K - 1, -1, 0);
    int x, y;
    rep(q, 0, Q){
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }
}

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

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int main() {
  int N, K;
  cin >> N;
  vector<int> A(N);

  for(int i = 0; i < N; i++) cin >> A[i];
  ll sum = 0;

  for(int i = 0; i < N; i++) {
    while(A[i] > 0 && A[i] % 2 == 0) {
      A[i] /= 2;
      sum++;
    }
  }

  cout << sum;
    return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll cnt[10][10] = {};
    int n;
    cin >> n;
    f1(n){
        int L = i % 10;
        int F;
        int cur = i;
        while(cur >= 10){
            cur /= 10;
        }
        F = cur;
        cnt[F][L]++;
    }
    ll ans = 0;
    f(10){
        fr(j,0,10){
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << '\n';
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    vec x = ivec(5);
    rep (i, 5) {
        if (x[i] == 0) print(i + 1);
    }

    return 0;
}


Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	k := nextInt()

	for i := a; i < b+1; i++ {
		if i < a+k {
			fmt.Println(i)
			continue
		}
		if b-k < i {
			fmt.Println(i)
			continue
		}
	}

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
N, M = gets.split.map(&:to_i)
link = Array.new(N).map {Array.new}
ans = 0

M.times do
	a, b = gets.split.map(&:to_i)
	link[a-1] << b-1
	link[b-1] << a-1
end

while link.any? {|a| a.size == 1} do
	link.each_with_index do |a, idx|
		if a.size == 1
			link[a[0]].delete(idx)
			link[idx].clear
			ans += 1
		end
	end
end

puts ans


Measured memory_bytes: 1916
#include <stdio.h>

int	main(void)
{
	char	s[256];
	int		c = 0;

	scanf("%s", &s);
	for( int f=0; f<3; ++f)
    {
		if( s[f]=='\0' ) return -1;
		if( s[f]=='1' ) ++c;
	}
  
	printf("%d\n", c);
	return 0;
}

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

const int maxn = 2010, mod = 1e9 + 7;

int f[maxn][maxn], n, K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> K;
  if( K == 1) {
    return cout << "1\n", 0;
  }
  vector<int> fac(maxn*maxn), ifac(maxn*maxn);
  for ( int i = fac[0] = 1; i < fac.size(); ++ i) {
    fac[i] = 1LL * fac[i-1] * i % mod;
  }
  function<int(int, int)> _pow = [&](int x, int n) {
    int ret = 1;
    for ( ; n; n >>= 1, x = 1LL * x * x % mod) {
      if( n & 1) {
        ret = 1LL * ret * x % mod;
      }
    }
    return ret;
  };
  ifac[fac.size()-1] = _pow(fac[fac.size()-1], mod - 2);
  for ( int i = fac.size()-1; i; -- i) {
    ifac[i-1] = 1LL * ifac[i] * i % mod;
  }
  function<int(int, int)> C = [&](int n, int m) {
    return 1LL * fac[n] * ifac[m] % mod * ifac[n-m] % mod;
  };
  f[0][0] = 1;
  for ( int i = 1; i <= n; ++ i) {
    for ( int k = 0; k <= i; ++ k) {
      f[i][k] = f[i-1][k];
      if( k) {
        f[i][k] = (f[i][k] + 1LL * f[i][k-1] * (n - k + 1) % mod * C(n-i+(K-1)*(n-k+1)-1, K-2) % mod) % mod;
      }
    }
  }
  cout << f[n][n] << "\n";
  return 0;
}

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

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define digits(x)		floor(log10(x))+1
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

class dsu {
private:
	int *id;
	int* sz;

	int root(int i) {
		while (i != id[i]) {
			id[i] = id[id[i]];
			i = id[i];
		}
		return i;
	}
public:
	int n;
	dsu(int v) {
		n = v;
		id = new int[n];
		sz = new int[n];

		for (int i = 0; i < n; i++) {
			id[i] = i;
			sz[i] = 0;
		}
	}

	bool find(int p , int q) {
		return root(p) == root(q);
	}

	void join(int p , int q) {
		int i = root(p);
		int j = root(q);
		if (i == j) {
			return;
		}
		if (sz[i] < sz[j]) {
			id[i] = j ;
			sz[j] += sz[i];
		}
		else {
			id[j] = i;
			sz[i] += sz[j];
		}
	}
};

int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

int modPower(int x, int y , int p) {
	//Used to calculate (x^y)%p
	int res = 1;
	if (y == 0) {
		return 1;
	}

	x = x % p;
	if (x == 0) {
		return 0  ;
	}

	while (y > 0) {
		if (y & 1) {
			res = (res * x) % p;
		}

		y >>= 1;
		x = (x * x) % p;
	}
	return res ;

}

bool allRed(string s) {
	bool ans = true;

	for (int i = 0 ; i  < s.length() ; i++) {
		if (s[i] != 'R') {
			ans = false;
			break;
		}
	}
	return ans;
}

bool allWhite(string s) {
	bool ans = true;

	for (int i = 0 ; i  < s.length() ; i++) {
		if (s[i] != 'W') {
			ans = false;
			break;
		}
	}
	return ans;
}


int bringRed(string s , int n) {

	int ans = 0 ;
	for (int i = 0 ; i < n ; i++) {
		if (s[i] == 'W') {
			int j = n - 1;
			while (s[j] != 'R' and j > i) {
				j--;
			}
			if (j == i) {
				break;
			}
			else {
				swap(s[i], s[j]);
				ans++;
			}
		}
	}
	return ans;

}


int32_t main() {
	FIO;


	int n ;
	cin >> n;

	string s ;
	cin >> s;


	int count = 0 ;
	// cout << count << "\n";
	if (allRed(s)) {
		count = 0;
	}
	if (allWhite(s)) {
		count = 0;
	}
	else {
		count = bringRed(s, n);
	}
	cout << count;








	return 0;
}


Measured memory_bytes: 3868
# [a,b] - [a,b) = {b} なので、端の方は自由。
# 中央が単色であるかを確認すればよい。

import numpy as np
arr = np.array([int(x) for x in input()])
arr_c = arr.cumsum()

N = arr.size

answer = 0

for K in range(N,0,-1):
  left = N-K
  right = K-1
  # [left,right]が単色であればよい
  if left >= right:
    answer = K
    break
  one_cnt = arr_c[right] - arr_c[left] + arr[left]
  zero_cnt = (right - left + 1) - one_cnt
  if one_cnt == 0 or zero_cnt == 0:
    answer = K
    break
    
print(answer)


Measured memory_bytes: 14160
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 998244353LL
using namespace std;
typedef long long ll;

class ModuloCombination {
private:
  vector<ll> fact, inv_fact;

  static ll modulo_power(ll a, ll n) {
    if(n == 0) return 1;
    if(n % 2 == 0) return modulo_power((a * a) % MOD, n / 2);
    return (a * modulo_power(a, n - 1)) % MOD;
  }

public:
  ModuloCombination(ll N): fact(N + 1), inv_fact(N + 1) {
    fact[0] = 1;
    REP(i, 1, N + 1) fact[i] = (i * fact[i - 1]) % MOD;
    REP(i, 0, N + 1) inv_fact[i] = modulo_power(fact[i], MOD - 2);
  }

  ll operator()(ll n, ll r) {
    return fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD;
  }
};

int main(void) {
  ll N, K;
  cin >> N >> K;

  ModuloCombination comb(K * 2 + 1);

  ll ans = 0;
  REP(r, 0, K + 1) if(r >= K - r) {
    ll b = K - r;
    ll t = r - N + 1;
    if(r == b) {
      if(t >= 0) {
        ans = (ans + comb(K - 1, r)) % MOD;
        if(b - 1 - t >= 0) ans = (ans - comb(K - 1, b - 1 - t) + MOD) % MOD;
      }
    }
    if(r > b) {
      if(t > 0) {
        ans = (ans + comb(K, r)) % MOD;
        if(b - t >= 0) ans = (ans - comb(K, b - t) + MOD) % MOD;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

//
int main(void) {
    int a,b,k;
    cin >> a >> b >> k;
    rep(i,k){
        if(i%2==0){
            if(a%2!=0) a--;
            a = a/2;
            b += a;
        }
        else {
            if(b%2!=0) b--;
            b = b/2;
            a += b;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 384
s = int(input())
t = []
t.append(s)
while True:
    if s % 2 == 0:
        s = s // 2
    else:
        s = s * 3 + 1
    t.append(s)
    if t.count(s) == 2:
        print(len(t))
        exit(0)

Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
int a[3];
int main(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]*10+a[1]+a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int r,g,b;
    int a;
    
    
    cin >> r;
    cin >> g;
    cin >> b;
    
    a = r*100 + g*10 + b;
    
    cout << (((a%4) == 0 ) ? "YES" : "NO") << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
  int a, b,  i, j;
  char s[128];
  while(scanf("%s", s) && s[0] != '0'){
    a = b = 0;
    for(i = 1;i < strlen(s); ++i){
      if(s[i] == 'A') a++;
      else if(s[i] == 'B') b++;
    }

    if(a > b) a++;
    else if(b > a) b++;
    printf("%d %d\n", a, b);
  }
  return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

const lli INF=1e8+8;

int main()
{
    lli n;
    cin>>n;
    string s;
    cin>>s;
    lli nr=0;
    for(lli i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            nr++;
        }
    }

    if(nr==n)
    {
        cout<<0<<"\n";
    }else if(nr<n && nr>0)
    {
        lli nnr=nr;
        for(lli i=0;i<nr;i++)
        {
            if(s[i]=='R')
            {
                nnr--;
            }
        }

        cout<<nnr<<"\n";
    }else if(nr==0)
    {
        cout<<0<<"\n";
    }
    
    
    
    
    

    return 0;
    
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int h,n;
	cin>>h>>n;
	int sx = 0;
	for(int i=0;i<n;i++)	
	{
		int z;
		cin>>z;
		sx += z;
	}	
	if(h > sx)
	cout<<"No\n";
	else cout<<"Yes\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fastin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
int n,a,b;
int main(){
	cin>>n>>a>>b;
	printf("%d\n",min(n*a,b));
	return 0;
}


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

int main()
{
	int N, T[100000], X[100000], Y[100000],t,xy,ans = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		scanf("%d %d %d", &T[i], &X[i], &Y[i]);
	}

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			t = T[i];
			xy = X[i] + Y[i];

			if (t < xy)break;
			if (xy % 2 != t % 2)break;
			if (i == N - 1)ans = 1;
			continue;
		}

		t = T[i] - T[i - 1];
	    xy = abs(X[i] + Y[i] - X[i - 1] - Y[i - 1]);

		if (t < xy)break;
		if (xy % 2 != t % 2)break;

		if (i == N - 1)ans = 1;
	}

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

	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>

using namespace std;

int main() {
	int i, j, k;
	int n, m;
	vector<long> a(51, 0), b(51, 0), c(51, 0), d(51, 0);

	cin >> n >> m;

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

	for (i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	
	for (i = 0; i < n; i++) {
		long minn = 99999999999, index = 0;
		for (j = 0; j < m; j++) {
			//minn = min(minn, abs(a[i] - c[j]) + abs(b[i] - d[j]));
			if (minn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				minn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				index = j;
			}
			else if (minn == abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				index = min(index, (long)j);
			}
		}
		cout << index+1 << endl;
	}









	getchar();
	getchar();
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int S = 0;
  int answer;
  int A , B;
  for(int i = 0; i < N; i++){
    cin >> A >> B;
    if(A > S){
      S = A;
      answer = A + B;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    vi v[3];
    int  score[3][32];
    int C[K][K];
    rep(i,K){
        rep(j,K){
            cin >> C[i][j];
        }
    }
    rep(i,N){
        rep(j,N){
            int a; cin >> a; a--;
            if((i+j)%3==0) v[0].pb(a);
            else if((i+j)%3==1) v[1].pb(a);
            else v[2].pb(a);
        }
    }
    rep(i,K){
        rep(j,3){
            int res=0;
            for(auto a:v[j]){
                res+=C[a][i];
            }
            score[j][i]=res;
        }
    }
    int ans = INF;
    rep(i,K){
        rep(j,K){
            rep(k,K){
                if(i == j || j == k || k == i) continue;
                int pos=score[0][i]+score[1][j]+score[2][k];
                ans=min(ans,pos);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2608
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&a!=c||a==c&&a!=b||b==c&&a!=b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


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

    if (c >= a && c <= b) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
        return 0;
    }
}

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

using namespace std;
#define int long long
signed main() {
    int n;
    cin >> n;
    int arr[n];
    int i;
    for(i=0;i<n;i++)
        cin >> arr[i];
    int mx[n];
    mx[n-1] = n-1;
    for(i=n-2;i>=0;i--)
    {
        if(arr[i] < arr[i+1])
            mx[i] = i;
        else
            mx[i] = mx[i+1];
    }
    int money = 1000, stocks = 0;
    int s = mx[0];
    //cout << s << '\n';
    while(s < n - 1)
    {
        stocks+=(money/arr[s]);
        money = money%arr[s];
        int j = s+1;
        while(j < n && arr[j] >= arr[j-1])
            j++;
        j--;
        money = money + stocks*arr[j];
        stocks = 0;
        s = mx[j];
    }
    cout << money << '\n';
}

Measured memory_bytes: 3652
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, x;
	cin >> N >> x;
	vector<int> a(N);
	REP(i, N) cin >> a[i];
	ll res = 0;
	FOR(i, 1, N) {
		if (a[i - 1] + a[i] > x) {
			int tmp = a[i - 1] + a[i] - x;
			res += tmp;
			a[i] = max(0, a[i] - tmp);
		}
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 640
N[]={ 6, 14, 18, 10,  2,  9, 22, 15,  1, 17, 23,  7,  3,  5, 21, 19,  0, 13, 20, 11,  4,  8, 16, 12};
E[]={13, 17,  9,  5,  8, 21, 14,  1, 16, 22,  6,  0,  4, 20, 18,  2, 12, 23, 10,  3, 11, 19, 15,  7};
R_[]={ 3,  0,  1,  2,  7,  4,  5,  6, 11,  8,  9, 10, 15, 12, 13, 14, 19, 16, 17, 18, 23, 20, 21, 22};
a;
d;
T,F,R,t;
char s[9];
main(c)
{
	for(;c-48&&scanf("%s",s);a+=d/4+1)
	{
		c=*s;
		if(c<60)a&&printf("%d\n",a),a=d=0,T=1,F=2,R=3;
		if(c==78)t=T,T=F,F=7-t,d=N[d];
		if(c==83)t=F,F=T,T=7-t,d=N[N[N[d]]];
		if(c==69)t=R,R=T,T=7-t,d=E[d];
		if(c==87)t=T,T=R,R=7-t,d=E[E[E[d]]];
		if(c==82)t=F,F=R,R=7-t,d=R_[d];
		if(c==76)t=R,R=F,F=7-t,d=R_[R_[R_[d]]];
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll T1,T2,A1,A2,B1,B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    if (A1*T1 + A2*T2 == B1*T1 + B2*T2) {
        cout << "infinity" << endl;
        return 0;
    }

    if (A1 < B1) {
        swap(A1,B1);
        swap(A2,B2);
    }
    if (A1*T1 + A2*T2 > B1*T1 + B2*T2) {
        cout << 0 << endl;
        return 0;
    }
    ll D = (A1-B1)*T1;
    ll d = B1*T1 + B2*T2 - A1*T1 - A2*T2;
    ll cnt = D/d*2LL+1LL;
    if (D%d == 0) cnt--;
    
    cout << cnt << endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  vector<int> v;
  for (int i = 0; i < 10; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < 3; i++)
    cout << v.at(i) << endl;
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (N, K) = ReadTuple<int,int>();
        var A = RLongs();
        var (lb, ub) = (0L, 1000000007L);
        while (ub - lb > 1)
        {
            var mid = (lb + ub) / 2;
            if (check(mid,A,K)) lb = mid;
            else ub = mid;
        }
        WriteLine(ub);
    }
    static bool check(long size,long[] A,int K)
    {
        int N = A.Length;
        long count = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[i] > size)
            {
                long c = A[i] / size;
                if (A[i] % size == 0) c--;
                count += c;
            }
        }
        return count > K;
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 44752
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    #ibit目が0である数と1である数
    zero, one = [0]*40, [0]*40

    for i in range(n):
        for bit in range(40):
            if (a[i]>>bit) & 1:
                one[bit] += 1
            else:
                zero[bit] += 1
    #貪欲な方
    res1 = 0
    #貪欲じゃない方
    res2 = 0
    flag = 0
    for i in range(39, -1, -1):
        if flag == 0:
            if (k>>i) & 1:
                res1 += 2**i * one[i]
                res2 += 2**i * zero[i]
                flag = 1
            else:
                res1 += 2**i * one[i]
                res2 += 2**i * one[i]
        else:
            if (k>>i) & 1:
                res1 = max(res1 + 2**i * max(one[i], zero[i]), res2 + 2**i * one[i])
                res2 += 2**i * zero[i]
            else:
                res1 += 2**i * max(one[i], zero[i])
                res2 += 2**i * one[i]
    print(max(res1, res2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 15380
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int B[1000001];
int main(){
  int N;cin>>N;
  vector<int>A(N);
  int d=0;
  bool c=false;
  for(int i=0;i<N;i++){
    cin>>A[i];
    d=gcd(d,A[i]);
    B[A[i]]++;
  }
  for(int i=2;i<1000001;i++){
    int count=0;
    for(int j=1;j*i<1000001;j++){
      count+=B[i*j];
    }
    if(count>1)c=true;
  }
  if(d!=1)puts("not coprime");
  else if(c)puts("setwise coprime");
  else puts("pairwise coprime");
}

Measured memory_bytes: 11180
import numpy as np

A,B,H,M = map(int,input().split())

def rot(deg):
    theta = np.radians(deg)
    c,s = np.cos(theta),np.sin(theta)
    return np.array([[c,-s],[s,c]])

print(np.linalg.norm(A*rot((H*60+M)*360/(60*12)).dot([[0],[1]]) - B*rot(M*360/60).dot([[0],[1]])))


Measured memory_bytes: 27276
#include <stdio.h>


int main(){
	int a,b,i,count=100000,n[101];
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d",&n[i]);
		b=b-n[i];
		if(n[i]<count)count=n[i];
	}
	
	printf("%d\n",a+b/count);
	
	return 0;
}


Measured memory_bytes: 128
import Control.Monad                                                                                                       
                                                                                                                           
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [w,h,n] <- map read . words <$> getLine                                                                                  
  xyas <- replicateM n $ map read . words <$> getLine :: IO [[Int]]                                                        
  let xyat = zip3 (map (!!0) xyas) (map (!!1) xyas) (map (!!2) xyas)                                                       
      x1 = maximum . (0:) . map fst3 . filter ((==) 1 . thd3) $ xyat                                                       
      x2 = minimum . (w:) . map fst3 . filter ((==) 2 . thd3) $ xyat                                                       
      y1 = maximum . (0:) . map snd3 . filter ((==) 3 . thd3) $ xyat                                                       
      y2 = minimum . (h:) . map snd3 . filter ((==) 4 . thd3) $ xyat                                                       
  print $ (max (x2 - x1) 0) * (max (y2 - y1) 0)                                                                            
                                                                                                                           
fst3,snd3,thd3 :: (a,a,a) -> a                                                                                             
fst3 (x,_,_) = x                                                                                                           
snd3 (_,y,_) = y                                                                                                           
thd3 (_,_,z) = z

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    string s; cin >> s;
    
    mat dp(N, vec(N));
    REP(i, N) dp[0][i] = 1;
    int mod = 1000000007;

    FOR(i, 1, N){
        if(s[i - 1] == '<'){
            dp[i][0] = dp[i - 1][0];
            FOR(j, 1, N - i) dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
        }else{
            dp[i][N - 1 - i] = dp[i - 1][N - i];
            IFOR(j, 0, N - 1 - i) dp[i][j] = (dp[i][j + 1] + dp[i - 1][j + 1]) % mod;
        }
    }
    cout << dp[N - 1][0];
    
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
main(){
  #define int long
  int n,W;
  cin>>n>>W;
  vector<vector<int>> dp(n+1,vector<int>(W+1,0));
  vector<int> w(n+1,0),v(n+1,0);
  for(int i=0;i<n;++i)cin>>w[i+1]>>v[i+1];
  for(int i=1;i<=n;++i)for(int j=1;j<=W;++j)dp[i][j]=max(dp[i-1][j],j<w[i]?0:dp[i-1][j-w[i]]+v[i]);
  cout<<dp[n][W];
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

int main() {
    while (true) {    
        int n, m, t, p;
        cin >> n >> m >> t >> p;
        if (n == 0) break;
        int yoko[32], tate[32];
        fill(yoko, yoko + n, 1);
        fill(tate, tate + m, 1);

        for (int i=0; i<t; i++) {
            int d, c;
            cin >> d >> c;
            int buf[32] = {0};
            if (d == 1) {
                for (int j = 0; j < n; j++) {
                    if (c + j < n) buf[j] += yoko[c + j];
                    if (c - 1 - j >= 0) buf[j] += yoko[c - 1 - j];
                }
                copy(buf, buf + n, yoko);
                n = max(c, n - c);
            } else {
                for (int j = 0; j < m; j++) {
                    if (c + j < m) buf[j] += tate[c + j];
                    if (c - 1 - j >= 0) buf[j] += tate[c - 1 - j];
                }
                copy(buf, buf + m, tate);
                m = max(c, m - c);
            }
        }
        int x[p], y[p];
        for (int i = 0; i < p; i++) {
            cin >> x[i] >> y[i];
        }

        for (int i=0; i<p; i++) {
            cout << yoko[x[i]] * tate[y[i]] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using P = pair<int, int>;

vector<int> dx{1, 0, -1, 0};
vector<int> dy{0, 1, 0, -1};
int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  
  int max_dist = 0;
  rep(i, h)rep(j, w){
    if (s[i][j] == '#') continue;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<P> que;
    dist[i][j] = 0;
    que.push(P(i, j));
    while(!que.empty()){
      P now = que.front();
      que.pop();
      rep(k, 4){
        P next = P(now.first+dx[k], now.second+dy[k]);
        if (next.first < 0 || next.first >= h ||
            next.second < 0 || next.second >= w){
          continue;
        }
        if (dist[next.first][next.second] != -1 ||
            s[next.first][next.second] == '#'){
          continue;
        }
        dist[next.first][next.second] = dist[now.first][now.second] + 1;
        max_dist = max(max_dist, dist[next.first][next.second]);
        que.push(next);
      }
    }
  }
  cout << max_dist << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <cstdio>
#include <deque>
#include <vector>

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

using namespace std;

bool check(vector<int> a,int k,int d){
	int n=a.size();
	rep(i,n) a[i]%=d;
	sort(a.begin(),a.end());

	deque<int> D(a.begin(),a.end());
	while(D.size()>=2){
		int x=D.front(),y=d-D.back();
		if     (x<=y && x<=k) D.pop_front(), D.back ()+=x, k-=x;
		else if(x> y && y<=k) D.pop_back (), D.front()-=y, k-=y;
		else return false;
	}
	return true;
}

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

	int ans=0,sum=0;
	rep(i,n) sum+=a[i];
	for(int d=1;d*d<=sum;d++) if(sum%d==0) {
		if(check(a,k,  d  )) ans=max(ans,  d  );
		if(check(a,k,sum/d)) ans=max(ans,sum/d);
	}
	printf("%d\n",ans);

	return 0;
}


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

using namespace std;


int w, a, b;

int main() {
  scanf("%d %d %d", &w, &a, &b);
  if (a < b) {
    printf("%d\n", max(0, b - a - w));
  } else {
    printf("%d\n", max(0, a - b - w));
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        List<Integer> ascList = new ArrayList<>();
        try (Scanner sc = new Scanner(System.in)){
            int cnt = sc.nextInt();
            int[] array = new int[cnt];
            for (int i = 0; i < cnt; i++) {
                array[i] = sc.nextInt();
                ascList.add(array[i]);
            }
            Collections.sort(ascList);
            int diffCnt = 0;
            for(int i =0; i < array.length;i++){
                if (array[i] != ascList.get(i)) diffCnt++;
                if (diffCnt > 2) {
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(a,b,c) for((a)=(b);(a)<(c);(a)++)

using namespace std;

int main(){
    int i, N;
    cin >> N;
    vector<vector<int>> G(N);
    vector<pair<int, int>> vp;
    REP(i,0,N-1){
        int a, b;
        cin >> a >> b;
        G[a-1].emplace_back(b-1);
        G[b-1].emplace_back(a-1);
        vp.emplace_back(a-1,b-1);
    }

    int K=0;
    map<pair<int,int>, int> I;
    vector<int> cs(N,0);
    vector<int> used(N,0);
    queue<int> que;
    used[0]=1;
    que.emplace(0);
    while (!que.empty())
    {
        int v=que.front();que.pop();
        if(K<(int)G[v].size()) K=G[v].size();
        int cur=1;
        for(int u:G[v]){
            if(used[u]) continue;
            if(cur==cs[v]) cur++;
            cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
            used[u]=1;
            que.emplace(u);
        }
    }
    cout<<K<<endl;
    for(auto p:vp) cout<<I[p]<<endl;
    return 0;
}

Measured memory_bytes: 20084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    string S;cin>>S;
    map<char,int> M;
    For(i,0,S.size()) M[S[i]]++;
    cout<<(M.size()==S.size()?"yes":"no")<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<string>s(n); rep(i, n)cin >> s[i];
	VE cnt(5);
	rep(i, n) {
		if (s[i][0] == 'M')cnt[0]++;
		else if (s[i][0] == 'A')cnt[1]++;
		else if (s[i][0] == 'R')cnt[2]++;
		else if (s[i][0] == 'C')cnt[3]++;
		else if (s[i][0] == 'H')cnt[4]++;
	}
	int ans = 0;
	rep(i, 5) {
		FOR(j, i + 1, 5) {
			FOR(k, j + 1, 5) {
				ans += cnt[i] * cnt[j] * cnt[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760