akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
  int i ,j;
  int n, u, k, v[100][100]={}, a;

  scanf("%d", &n);  // G??????????????°n

  for(i = 0; i < n; i++)
    {
      scanf("%d %d", &u, &k);
      for(j = 0; j < k; j++)
	{
	  scanf("%d", &a);
	  v[u-1][a-1] = 1;
	}
    }
  
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  if(j == n-1) printf("%d", v[i][j]);
	  else printf("%d ", v[i][j]);
	  if(j == n-1) printf("\n");
	}
    }
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <cstring>
using namespace std;
long long a,b;
int main()
{
	cin >> a >> b;
	if(a <= b)
	{
		a = min(a,b-a);
	}else{
		a = a % b;
		a = min(a, b-a);
	}
	cout << a << endl;
}

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

int main(void)
{
  int N, K;
  cin >> N >> K;
  
  int ans = K;
  
  for (int i=0;i<N-1;i++){
    ans *= (K-1);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    string s;
    cin >> s;
    
    i64 r = whole(count, s, 'R');
    i64 g = whole(count, s, 'G');
    i64 b = whole(count, s, 'B');

    i64 ans = r * g * b;

    range(i, 2, N) range(j, 0, i) {
        if ((i & 1) != (j & 1)) continue;
        set< char > st;
        st.insert(s[i]);
        st.insert(s[(i + j) / 2]);
        st.insert(s[j]);
        
        if (st.size() == 3) ans -= 1;
    }
    
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3632
x,y,u;p(a,b){for(;b--;)putchar(a+68);}main(v){scanf("%d%d%d%d",&u,&v,&x,&y);x-=u;y-=v;p(17,y++);p(14,++x);p(0,y);p(8,x);p(17,1);p(8,1);p(17,y);p(14,x);p(0,y);p(8,--x);}

Measured memory_bytes: 1660
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    int n;

    std::cin >> n;

    vector<int> v = fetch_vec<int>(n);
    int min = v[0];
    int counter = 0;

    for (int i = 0; i < n; ++i) {
        min = std::min(min, v[i]);
        if (v[i] <= min)
            ++counter;
    }

    cout << counter << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> V(N+1);
    ll a, b;
    REP(i, M){
        cin >> a >> b;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    vector<ll> hint(N+1, -1);
    queue<P> q;
    q.push(P(0, 1));
    while(!q.empty()){
        P tmp = q.front();
        if(hint[tmp.second] < 0) {
            hint[tmp.second] = tmp.first;
        for(auto iter: V[tmp.second]) if(hint[iter] < 0) q.push(P(tmp.second, iter));
        }
        q.pop();
    }
    bool connect = true;
    rep(i, 1, N+1) if (hint[i] < 0) connect = false;
    if (!connect){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    rep(i, 2, N+1) cout << hint[i] << endl;

    return 0;
}


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

using namespace std;

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

    int N, A, B, C, D; cin>>N>>A>>B>>C>>D;
    A--,B--,C--,D--;
    string S; cin>>S;

    auto solve = [&]() {
        int cw = 0, cp = 0, maxcp = 0;
        bool corner = C<D;
        for (int i = A; i <= max(C,D); i++) {
            if (S[i] == '#') {
                if (cw > 0)
                    return false;
                cw++;
                cp=0;
            } else {
                if (C>D and cp == 2) {
                    if (i-1 >= B and i-1 <= D)
                        corner = true;
                }
                cp++;
                cw = 0;
            }
        }
        return corner;
    };
    cout << (solve() ? "Yes" : "No");

    return 0;
}



Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	int l;
	int a,b,c,d;

    cin>>l;
    cin>>a>>b>>c>>d;
    int o,p;
    if(a%c==0)o=a/c;
    else o=a/c+1;
    if(b%d==0)p=b/d;
    else p=b/d+1;
    int m=max(o,p);

    cout<<l-m<<endl;

	return 0;
}

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

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

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

const ll MAX = 1e5 + 10;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int N, A[MAX], B[MAX];

int main(){
    cin >> N;
    rep(i, N + 1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll ans = 0;
    for(int i = N - 1; i >= 0; --i){
        if(A[i + 1] > 0){
            ans += min(A[i + 1], B[i]);
            B[i] -= A[i + 1];
        }
        if(B[i] > 0){
            ans += min(A[i], B[i]);
            A[i] -= B[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M, X, Y = map(int, input().split())
    x = sorted(list(map(int, input().split())))
    y = sorted(list(map(int, input().split())))

    arr = x + y
    arr = [i for i in arr if X < i < Y]
    arr = [i for i in arr if x[-1] < i]
    arr = [i for i in arr if y[0] >= i]

    if arr:
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
def main():
    k = int(input())
    a, b = map(int, input().split())
    flg = 0
    for i in range(a, b + 1):
        if i % k == 0:
            flg += 1

    if flg > 0:
        print('OK')
    else:
        print('NG')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
if k<=n:
    for i in range(k):
        p=A[p-1]
    print(p)
else:
    D=[0]+[-1]*(n-1)
    for i in range(n):
        p=A[p-1]
        if D[p-1]==-1:
            D[p-1]=i+1
        else:
            l=D[p-1]
            r=i+1-D[p-1]
            m=(k-l)%r+l
            break
    p=1
    for i in range(m):
        p=A[p-1]
    print(p)

Measured memory_bytes: 32216
#include <stdio.h>
#include <algorithm>

using ll = long long;
using namespace std;
int main() {
	ll n, k, total = 0;
	scanf("%lld %lld", &n, &k);
	
	if (k) {
		for (ll i = k + 1; i <= n; i++)
			total += (n / i) * (i - k) + max(0ll, n % i - k + 1);
	} else {
		total = n * n;
	}

	printf("%lld\n", total);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//replay.
int main(){
	int prace[]={100,101,102,103,104,105};
	
	int x;
	cin>>x;
	
	vi dp(x+1,0);//0 or 1.
	dp[0]=1;
	for(int i=0;i<=x;++i){
		if(dp[i]){
			REP(j,6){
				int tmp=i+prace[j];
				if(tmp<=x) dp[tmp]=1;
			}
		}
	}
	
	cout<<dp[x]<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=1000005;
int son[maxn][2],v[maxn][2],fa[maxn];
int n,l[maxn],r[maxn],cnt,len[maxn],sz[maxn];
i64 a[maxn],b[maxn],p[maxn],q[maxn],np[maxn],nq[maxn];
inline bool dfs(int x,i64 lim){
	int y=son[x][0],z=son[x][1];
	if(!y){
//		if(len[x]>lim)return 0;
		sz[x]=1;
		l[x]=r[x]=++cnt;
		a[cnt]=b[cnt]=len[x];
		return 1;
	}
	if(dfs(y,lim)&&dfs(z,lim)){
		if(sz[y]>sz[z])swap(y,z);
		int tot=0,j=l[z]-1;
		rep(i,l[y],r[y]){
			while(j<r[z]&&(a[j+1]+b[i]<=lim))j++;
			if(j>=l[z]){
				p[++tot]=a[i];
				q[tot]=b[j];
			}
		}
		if(tot==0)return 0;
		rep(i,tot+1,tot+tot){
			p[i]=q[tot-(i-tot)+1];
			q[i]=p[tot-(i-tot)+1];
		}int i=1;j=tot+1;
		rep(k,1,tot+tot){
			if(j>tot+tot||(i<=tot&&p[i]<=p[j])){
				np[k]=p[i];nq[k]=q[i++];
			}else{
				np[k]=p[j];nq[k]=q[j++];
			}
		}l[x]=cnt+1;
		rep(i,1,tot+tot){
			if(i==1||(np[i]>a[cnt]&&nq[i]<b[cnt])){
				a[++cnt]=np[i];b[cnt]=nq[i];
			}else if (np[i]==a[cnt])b[cnt]=min(b[cnt],nq[i]);
		}r[x]=cnt;sz[x]=r[x]-l[x]+1;
		rep(i,l[x],r[x])a[i]+=len[x],b[i]+=len[x];
		assert(2*tot<=400000);
	}else return 0;
	return 1;
}
inline bool check(i64 md){
	cnt=0;return dfs(1,md);
	assert(cnt<=400000);
}
int main(){
    read(n);
    rep(i,2,n){
    	int x,y;read(x);read(y);
    	len[i]=y;fa[i]=x;
    	if(son[x][0])son[x][1]=i,v[x][1]=y;else son[x][0]=i,v[x][0]=y;
    }
    i64 lq=0,rq=1ll<<40,ans=0;
    while(lq<=rq){
    	i64 md=(lq+rq)>>1;
    	if(check(md)){
    		ans=md;
    		rq=md-1;
    	}else{
    		lq=md+1;
    	}
    }
    printf("%lld\n",ans);
    return 0;
}


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

vector<int> g[100100];
int dp[100100];

int dfs ( int pos ) {
    if ( ~dp[pos] ) return dp[pos];
    int rec = 0;
    for ( int i = 0; i < (int)g[pos].size(); i++ ) {
        rec = max ( rec, dfs ( g[pos][i] ) );
    }
    return dp[pos] = rec + 1;
}

signed main ( ) {

    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    for ( int i = 0; i < m; i++ ) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }

    memset(dp, -1, sizeof(dp));

    int ans = 0;
    for ( int i = 1; i <= n; i++ ) {
        ans = max ( ans, dfs ( i ) );
    }

    cout << (ans-1) << endl;

    return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	ll H;
	cin >> H;
	ll sum = 0;
	int i = 0;
	while (H != 0)
	{
		sum += pow(2, i);
		H /= 2;
		i++;
	}
	cout << sum << endl;
}



Measured memory_bytes: 384
import collections
import heapq
 
x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)]
res = []
used = collections.defaultdict(lambda: False)
while len(res) < k:
    s, i, j, l = heapq.heappop(q)
    res.append(-s)
    if i + 1 < x and not used[(i + 1, j, l)]:
        heapq.heappush(q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l))
        used[(i + 1, j, l)] = True
    if j + 1 < y and not used[(i, j + 1, l)]:
        heapq.heappush(q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l))
        used[(i, j + 1, l)] = True
    if l + 1 < z and not used[(i, j, l + 1)]:
        heapq.heappush(q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1))
        used[(i, j, l + 1)] = True
print(*res, sep='\n')

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

#define int long long

signed main(){
    int n;
    cin >> n;
    double v[1000];

    for(int i = 0;i < n;i++) cin >> v[i];
    sort(v, v+n);

    double ans = v[0];
    for(int i = 1;i < n;i++){
        ans = (ans + v[i]) / 2;
    }

    printf("%.12lf\n", ans);

    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    S = list(input()[:-1])
    ans = 0; rtmp = 0
    cnt = K + (S[0] == '1')
    for l in range(N):
        if cnt > 0:
            for r in range(rtmp, N):
                if r == N-1:
                    break
                if S[r] > S[r+1]:
                    cnt -= 1
                if cnt <= 0:
                    break
        rtmp = r+1
        ans = max(rtmp - l, ans)
        if l == N-1:
            break
        if S[l] < S[l+1]:
            cnt += 1

    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4084
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int s, w;
    cin >> s >> w;

    if(w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String input1 = sc.nextLine();
		int n = Integer.parseInt(input1);
		String input2 = sc.nextLine();
		String[] data = input2.split(" ");
		String output = "";
		int value = 0;
		boolean judge = true;

		out: for (int i = data.length - 1; i >= 0; i--) {
			value = Integer.parseInt(data[i]);
			if (value < 0 || value > 1000) {
				judge = false;
				break out;
			}
			if (i == data.length - 1) {
				output += "" + value;
			} else {
				output += " " + value;
			}
		}

		if ((n > 0 && n <= 1000) && (data.length == n) && (judge == true)) {

			System.out.println(output);

		}

	}

}



Measured memory_bytes: 26264
#include<bits/stdc++.h>
using namespace std;int N,a,b,i,V[1<<20],f[1<<20];pair<int,int>R[1<<20];main(){for(cin>>N;i<N;cin>>a>>b,R[i]={a,a+b},i++);for(sort(R,R+N),V[N]=1;i--;){for(a=i+1;a<N&&R[a].first<R[i].second;a=f[a]);V[i]=(V[i+1]+V[f[i]=a])%998244353;}cout<<*V;}

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans=0;
  int n=s.size();
  
  for(int i=0;i<n;i++){
    if(s[i]!=t[i]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	
	ll n,m;
	ll sum=0;
	cin>>n>>m;
	sum+=n*(n-1)/2;
	sum+=m*(m-1)/2;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

/* originally written by SugarDragon5 */
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main() {
    int n = ri();
    int m = ri();
    int p[n];
    INPUT(p);
    UnionFind uni(n);
    FOR(i,m) uni.unite(ri()-1,ri()-1);
    vector<int> v[n];
    FOR(i,n) v[uni.root(i)].push_back(i);
    vector<set<int> > vv;
    FOR(i,n) {
        if (v[i].size()) {
            set<int> tmp;
            for(auto j : v[i])tmp.insert(j);
            vv.push_back(tmp);
        }
    }
    vector<set<int> > vvv;
    for(auto i : vv) {
        set<int> tmp;
        for (auto ii : i) {
            tmp.insert(p[ii]);
        }
        vvv.push_back(tmp);
    }/*
    cout << "vv" << endl;
    for (auto i : vv) {
        for (auto j : i) {
            cout << j << " ";
        }
        cout << endl;
    }
    cout << endl << "vvv" << endl;
    for (auto i : vvv) {
        for (auto j : i) {
            cout << j << " ";
        }
        cout << endl;
    }*/
    // cout << vv.size() << " " << vvv.size() << endl;
    assert(vv.size() == vvv.size());
    int res = 0;
    FOR(i,vv.size()) {
        assert(vv[i].size() == vvv[i].size());
        for(auto j:vvv[i]) {
            if (!vv[i].insert(j-1).se) res++;
        }
    }
    cout << res << endl;
 return 0;
}


Measured memory_bytes: 31788
using System;

namespace RangeProduct {
    class Program {
        static void Main(string[] args) {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            if (a > 0 && b >= a) {
                Console.WriteLine("Positive");
            }else if (a <= 0 && b >= 0) {
                Console.WriteLine("Zero");
            }
            else if ((b - a + 1) % 2 == 0) {
                Console.WriteLine("Positive");
            }else if ((b - a + 1) % 2 == 1) {
                Console.WriteLine("Negative");
            }
        }
    }
}
 

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

int main() {
  
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<int> vec(M);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
  }
  
  int sumL, sumH;
  
  for (int i = 0; i < M; i++) {
    if (X > vec.at(i)) {
      sumL++;
    } else {
      sumH++;
    }
  }
  
  if (sumL > sumH) {
    cout << sumH << endl;
  } else {
    cout << sumL << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

total = 0
for i in range(N):
	#print(A,B)
	num1 = min(B[i],A[i])
	B[i] -= num1
	A[i] -= num1
	#print(A,B)
	num2 = min(B[i],A[i+1])
	B[i] -= num2
	A[i+1] -= num2
	total += num1+num2
print(total)


Measured memory_bytes: 19116
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

string s;

int main() {
	cin >> s;
	char c = s[0];
	int ans = s.size();
	for (int i = 1; i < s.size(); i++) {
		if (c != s[i]) {
			ans = min(max(i, (int)(s.size()) - i), ans);
			c = s[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

struct City {
    int cityNum;
    int prefNum;
    int year;
    string ID = "";
};

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

    int D, G;
    cin >> D >> G;
    vector<pair<int, int>> pc(D);
    cin >> pc;

    int ans = INF;
    //全問題を全完するかどうかのbit全探索
    REP(i, (int)pow(2, D)) {
        int point = 0;
        int cnt = 0;
        vector<bool> isSolved(D, false);
        //全問題を全完するか解かないかを考えた後のスコアを計算
        REP(j, D) {
            int b = i & (1 << j);
            if (b) {
                point += pc[j].second;
                point += pc[j].first * (j + 1) * 100;
                cnt += pc[j].first;
                isSolved[j] = true;
            }
        }

        //ポイントが足りなければ解いていない問題の中から得点が高いものを解く
        if (point < G) {
            FORR(j, D, 0) {
                if (!isSolved[j]) {
                    int remain = G - point;
                    int c = round_up(remain, ((j + 1) * 100));
                    if (c >= pc[j].first)break;
                    cnt += c;
                    point += c * (j + 1) * 100;
                    break;
                }
            }
        }
        if (point < G)continue;
        ans = min(ans, cnt);
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
/*
 * 2×N のマス目があります。上から i 行目、左から j 列目 (1≤i≤2, 1≤j≤N) のマスをマス (i,j) と表すことにします。
 * 
 * あなたははじめ、左上のマス (1,1) にいます。 あなたは、右方向または下方向への移動を繰り返し、右下のマス (2,N) に移動しようとしています。
 * 
 * マス (i,j) には Ai,j 個のアメが置かれています。 あなたは移動中に通ったマスに置いてあるアメをすべて回収します。 
 * 左上および右下のマスにもアメが置かれており、あなたはこれらのマスに置かれているアメも回収します。
 * 
 * 移動方法をうまく選んだとき、最大で何個のアメを回収できるでしょうか。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int[][] candies = new int[2][n];
            int[][] dp = new int[2][n];
            
            for(int i=0; i<2*n; i++){
            	candies[i/n][i%n] = Integer.parseInt(sc.next());
            }
            dp[0][0] = candies[0][0];
            dp[1][0] = dp[0][0] + candies[1][0];
            for(int i=1; i<n; i++){
            	dp[0][i] = dp[0][i-1] + candies[0][i];
            	dp[1][i] = candies[1][i] + Math.max(dp[0][i], dp[1][i-1]);
            }
            
            //出力
            System.out.println(dp[1][n-1]);
            sc.close();
        }
    }
	

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long maxLen = 1l;
        while (y >= x * (long) Math.pow(2, maxLen)) {
            maxLen++;
        }
        System.out.println(maxLen);
    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    set<string>ss;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        ss.insert(s);
    }
    cout<<ss.size()<<endl;

    return 0;
}



Measured memory_bytes: 19256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
}

int main() {
  std::cin.tie(nullptr);                 // 標準入出力高速化
  std::ios_base::sync_with_stdio(false); // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15); // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int q = sc.nextInt();
		
		for(int i = 0; i < q; i++) {
			String command = sc.next();
			
			if(command.equals("print")) {
				int i1 = sc.nextInt();
				int i2 = sc.nextInt();
				
				if(i2 == str.length()-1) {
					System.out.println(str.substring(i1));
				}else {
					System.out.println(str.substring(i1,i2+1));
				}
			}
			
			if(command.equals("reverse")) {
				int i1 = sc.nextInt();
				int i2 = sc.nextInt();
				StringBuilder s = new StringBuilder("");
				
				for(int i3 = i2; i3 >=i1; i3--) {
					s.append(str.charAt(i3));
				}
				str = str.substring(0, i1) + s + str.substring(i2+1);
			}
			
			if(command.equals("replace")) {
				int i1 = sc.nextInt();
				int i2 = sc.nextInt();
				String strr = sc.next();
				
				str = str.substring(0,i1) + strr + str.substring(i2+1);
			}
		}
	}
}


Measured memory_bytes: 29972
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const int MOD = 1e9 + 7;



signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    double a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    double ans = (a[0] + a[1])/2;
    for (int i = 2; i < n; i++) {
        ans = (ans + a[i])/2;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 500000;
int n;
int a[N];
int f[N];
int ans[N];
int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int m = 1;
    for (int i = 2; i <= n; i++) {
        if (a[i] != a[m]) {
            m++;
            a[m] = a[i];
        }
    }
    n = m;
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = f[i - 1] + ans[a[i]];
        if (f[i] >= mod) {
            f[i] -= mod;
        }
        ans[a[i]] += f[i - 1];
        if (ans[a[i]] >= mod) {
            ans[a[i]] -= mod;
        }
    }
    cout << f[n] << "\n";
    return 0;
}


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

int main() {
  size_t N;
  string S;
  cin >> N;
  cin >> S;
  int ans{};
  size_t start{};
  while (start < N) {
    size_t cur = S.find("ABC", start);
    if (cur != string::npos) {
      ++ans;
      start = cur + 3;
    } else {
      start = N;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;

    string ans;

    for(int i = 0; i < S.size(); i++) {
        if (S[i] == '0') ans = ans + "0";
        if (S[i] == '1') ans = ans + "1";
        if (S[i] == 'B') 
            if (!ans.empty()){
                ans.pop_back();
            }
    }

    cout << ans << endl;
    


    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    lint ans=n/2 -(n%2==0);

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 764
main :: IO ()
main = do
  s <- getLine
  putStrLn $ pickOdds' s

pickOdds, pickOdds'
  :: [a] -> [a]
pickOdds []       = []
pickOdds [a]      = [a]
pickOdds (a:b:bs) = a : pickOdds bs 

pickOdds' = map snd . filter (odd . fst) . zip [1..]

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	ll a, b, c; cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
	} else {
		cout << min(a * b, min(a * c, b * c)) << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

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

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int x;
  FOR(i, 1, 6) {
    cin >> x;
    if(x == 0) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>

int digits(int n, int k);

int main(){
    int n, k;
    scanf("%d %d", &n, &k);

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

int digits(int n, int k){
    int ret = 0;
    for(int i = n; i > 0; i /= k){
        ret++;
    }
    return ret;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
//#include <boost/multiprecision/cpp_int.hpp>

#define BIT(a) (1 << (a))

using namespace std;
//using namespace boost::multiprecision;

long long MOD = 1000000007;


long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

int main(void){
    int H, W;
    cin >> H >> W;
    int cnt = 0;
    char c;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            scanf(" %c", &c);
            if (c == '#') cnt++;
        }
    }
    if ((cnt - 1) == (H - 1) + (W - 1)){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
    
}



Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int house;
  scanf("%d\n", &house);
  int crd[house];
  int max = 0;
  int min = 1001;

  for (int i = 0; i < house; i++) {
    scanf("%d", &crd[i]);
  }

  for (int i = 0; i < house; i++) {
    if (crd[i] > max) max = crd[i];
    if (crd[i] < min) min = crd[i];
  }

  printf("%d\n", max - min);
  return 0;
}


Measured memory_bytes: 128
// abc104_a
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
  int r;
  cin >> r;
  if(r < 1200){
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<functional>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

typedef pair<int, int>P;


int main() {
  long long N, A, B, C, D;
  int flag = 0;
  cin >> N >> A >> B >> C >> D;
  for (int i = 0; i < N; i++) {
	if (i*C - (N - 1 - i)*D <= (B-A)&&(B-A) <= i*D - (N - 1 - i)*C)flag = 1;
  }
  if (flag) {
	cout << "YES" << endl;
  }
  else
	cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import Data.List

f::Int->Int->Int
f hp d
   |hp<=0 = 0
   |hp `mod` d==0 = hp `div` d
   |otherwise=(hp `div` d) +1

f2::Int->[(Int,Int)]->Int->[Int]
f2 _ [] _=[]
f2 a ((c,b):xs) hp=(c + f (hp-b) a) : f2 a xs hp 

main = do
          e<-getLine
          es<-getContents
          let (n:h:[])=map read (words e)::[Int]
              xs=lines es
              a=maximum $ map (\x -> let (a1:_:[])=map read (words x)::[Int] in a1) xs
              bs1=scanl (+) 0 $ reverse $ sort $ map (\x -> let (_:b1:[])=map read (words x)::[Int] in b1) xs
              bs2=zip [0..] bs1
          putStrLn $ show $ minimum $ f2 a bs2 h

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

using namespace std;

constexpr int INF = 1e8;

int main(){
    int h,w,s;
    while(cin>>h>>w>>s,h){
        int u[32][32];
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                cin>>u[i][j];
                s-=u[i][j];
            }
        }
        s=-s;
        pair<int,int> dp[32][32][32][32]={};
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(u[i][j]>=s){
                    dp[i][j][0][0]=make_pair(1,u[i][j]);
                }else{
                    dp[i][j][0][0]=make_pair(0,u[i][j]);
                }
            }
        }
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                for(int y=h-i-1;y>=0;--y){
                    for(int x=w-j-1;x>=0;--x){
                        for(int hk=0;hk<i;++hk){
                            auto p1=dp[y][x][hk][j], p2=dp[y+hk+1][x][i-hk-1][j];
                            if(p1.first==0 || p2.first==0){
                                auto p=make_pair(0, p1.second+p2.second);
                                if(p.second>=s)p=make_pair(1, p1.second+p2.second);
                                dp[y][x][i][j]=max(dp[y][x][i][j],p);
                                continue;
                            }
                            dp[y][x][i][j]=max(dp[y][x][i][j],make_pair(p1.first+p2.first, min(p1.second,p2.second)));
                        }
                        for(int wk=0;wk<j;++wk){
                            auto p1=dp[y][x][i][wk], p2=dp[y][x+wk+1][i][j-wk-1];
                            if(p1.first==0 || p2.first==0){
                                auto p=make_pair(0, p1.second+p2.second);
                                if(p.second>=s)p=make_pair(1, p1.second+p2.second);
                                dp[y][x][i][j]=max(dp[y][x][i][j],p);
                                continue;
                            }
                            dp[y][x][i][j]=max(dp[y][x][i][j],make_pair(p1.first+p2.first, min(p1.second,p2.second)));
                        }
                    }
                }
            }
        }
        cout<<dp[0][0][h-1][w-1].first<<" "<<dp[0][0][h-1][w-1].second-s<<endl;
    }
}


Measured memory_bytes: 11272
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



int main(int argc, char *argv[])
{
	int a, b, k;
	vector<int> ans;

	//input
	cin >> a >> b >> k;
	


	//calc
	for (int i = 100; i >= 1; i--){
		if (a % i == 0 && b % i == 0){
			ans.push_back(i);
		}
	}


	//ans
	cout << ans[k - 1] << endl;


	return 0;
}


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

public class Prog
{
    public static void Main()
    {
        long N = long.Parse(Console.ReadLine());
        long m = 0;
        for(long i = 1; i*i<=N; i++)
        {
            long X = N - i;
            if(X%i == 0 && i < X/i)
            {
                m += X / i;
            }
        }
        Console.WriteLine(m);
    }
}



Measured memory_bytes: 13140
N, S = map(int, input().split())
A = list(map(int, input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    ai = A[i]
    for j in range(S + 1):
        here = dp[i][j]
        # aiがTに含まれない
        dp[i + 1][j] += here
        # aiがTに含まれるが, Uに含まれない
        dp[i + 1][j] += here

        dp[i + 1][j] %= MOD

        # aiがUに含まれる
        if j + ai <= S:
            dp[i + 1][j + ai] += dp[i][j]
            dp[i + 1][j + ai] %= MOD

print(dp[N][S])


Measured memory_bytes: 135312
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using TP = tuple<int, int, int>;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

void Main(){
    int n, q;
    cin >> n >> q;

    vi c(n);
    BIT<int> bit(n);
    vector<bool> seen(n, false);
    vvi color(n);
    
    rep(i, n){
        cin >> c[i];
        c[i]--;
        color[c[i]].pb(i);
    }

    /*
    cout << "color[i]_confirm: " << endl;;
    rep(i, 3) {
        cout << i << ": ";
        for(auto x : color[i]) cout << x << " ";
        cout << endl;
    }
    //*/

    rep3rev(i, n-1, 0){
        if(!seen[c[i]]) bit.add(i, 1);        
        seen[c[i]] = true;
    }
    
    vector<TP> Q(q);
    rep(i, q){
        int l, r; cin >> l >> r;
        l--; r--;
        get<0>(Q[i]) = l; 
        get<1>(Q[i]) = r;
        get<2>(Q[i]) = i;
    }
    
    // r の降順でソート
    sort(all(Q), [&](TP x, TP y){ return get<1>(x) > get<1>(y); });
    
    // for(auto [l, r, i] : Q) cout << l << " " << r << " " << i << endl;
    
    vi ans(q);
    int rnow = n-1;
    int rnext;
    
    rep(i, q){
        /*
        cout << "BIT_confirm: ";
        rep(j, 4) cout << bit.sum(j, j+1) << " ";
        cout << endl;
        //*/
        auto [l, r, id] = Q[i];
        while(rnow != r){
            color[c[rnow]].pop_back();
            /*
            cout << "c[rnow]_confirm: ";
            for(auto x : color[c[rnow]]) cout << x << " ";
            cout << endl;
            //*/
            if(color[c[rnow]].size() > 0) {
                rnext = color[c[rnow]].back();
                // cout << "rnext = " << rnext << endl;
                bit.add(rnext, 1);
            }
            rnow--;
        }
        ans[id] = bit.sum(l, r+1);
    }
    
    rep(i, q) cout << ans[i] << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 42948
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    K = I()
    x = LI()

    ans = sum([2 * min(x[i], K - x[i]) for i in range(N)])
    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<queue>
#include<deque>
#include<stack>
#include<ctime>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<cctype>
#include<bitset>
#include<list>
using namespace std;

int n,m;
string s[105];

int main(){
	cin>>n>>m;
	for(int i=0;i<100;i++){
		for(int j=0;j<50;j++) s[i]+='#';
		for(int j=0;j<50;j++) s[i]+='.';
	}
	cout<<100<<" "<<100<<endl;
	n--,m--;
	int i;
	for(i=0;i<n/25;i++) for(int j=0;j<25;j++) s[i*2][j*2]='.';
	for(int j=0;j<n%25;j++) s[i*2][j*2]='.';
	for(i=0;i<m/25;i++) for(int j=0;j<25;j++) s[i*2][j*2+51]='#';
	for(int j=0;j<m%25;j++) s[i*2][j*2+51]='#';
	for(int i=0;i<100;i++) cout<<s[i]<<endl;
	return 0;
}

Measured memory_bytes: 256