akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

fn main() {
    let n: usize = input();
    let mut s = input::<String>().chars().collect::<Vec<_>>();
    let mut t = input::<String>().chars().collect::<VecDeque<_>>();

    let mut ans = n;
    s.append(&mut vec!['?'; n]);
    for slide in 0..n+2 {
        if (0..t.len()).all(|i| match (s[i], t[i]) {
            ('?', _) | (_, '?') => true,
            (a, b) => a == b
        }) {
            ans += slide;
            break;
        }
        t.push_front('?');
    }

    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}



Measured memory_bytes: 4352
// ievazquez
// // https://atcoder.jp/contests/abc147/tasks/abc147_b
// // implementation
//
import scala.io.StdIn._


object Main extends App {

  var ans = 0;
  val s = readLine
  val len = s.length
  for (i <- 0 until len / 2 ) {
    if(s(i) != s(len-i-1)) {
        ans += 1
    }
  }
  println(ans)
}

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

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

    string s;
    cin >> s;
    int n = s.length();
    if(n == 2){
        if(s[0] == s[1]){
            cout << 1 << " " << 2 << endl;
        }
        else{
            cout << -1 << " " << -1 << endl;
        }
        return 0;
    }
    int left = -1, right = -1;
    for(int i = 0; i < n - 2; ++i){
        if(s[i] == s[i + 1] || s[i] == s[i + 2]){
            left = i + 1;
            right = i + 3;
            break;
        }
    }

    cout << left << " " << right << endl;
}

Measured memory_bytes: 512
if __name__=='__main__':
    V_MAX = 100000
    E_MAX = 500000
    INF = float('inf')

    v,e,r=(int(x) for x in  input().split())
        
    e_from = []
    e_to = []
    e_cost= []
    dist=[]

    for i in range(e):
        f, t, c=(int(x) for x in  input().split())
        e_from.append(f)
        e_to.append(t)
        e_cost.append(c)

    for i in range(v):
        dist.append(INF)
   
    dist[r] = 0
   
    while True:
        flag = 1
        for i in range(e):
            if (dist[e_from[i]] != INF) and (dist[e_to[i]] > dist[e_from[i]]+e_cost[i]):
                dist[e_to[i]] = dist[e_from[i]] + e_cost[i]
                flag=0

        if flag:
            break
    

    for i in range(v):
        if dist[i] ==  INF:
            print("INF")
        else:
            print(dist[i])



Measured memory_bytes: 67424
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    ll k, n, a0, ai, aj;
    ll dist = -1;

    cin >> k >> n;

    cin >> a0;

    ai = a0;

    for (size_t i = 1; i < n; i++) {
        cin >> aj;
        dist = max(dist, aj-ai);
        ai = aj;
    }

    dist = max(dist, k - (aj-a0));

    cout << k - dist << endl;
    
    return 0;
}


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

int main(){
   int n; cin>>n;
   vector<int> p(n);
   rep(i,n) cin>>p[i];
   int mi=p[0];
   int cnt=0;
   rep(i,n){
      mi=min(mi,p[i]);
      if(mi==p[i]) cnt++;
   }
   cout<<cnt<<endl;
   return 0;
}

   


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    int N, X, T;
    cin >> N >> X >> T;
    cout << ((N -1) / X + 1)*T << endl;
}

Measured memory_bytes: 3628
from math import factorial

x,y = map(int,input().split())
MOD = 10**9 + 7

if (2*y - x)%3 != 0 or (2*x - y)%3 != 0 or (2*y - x) < 0 or (2*x - y) < 0:
  print(0)
  exit()

SUM = ((2*y - x)//3) + ((2*x - y)//3)
n = ((2*y - x)//3)
m = ((2*x - y)//3)

MOD = 10**9 + 7
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
    
comb = Combination(1000000)
print(comb(SUM, n)%MOD)


Measured memory_bytes: 127844
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

unordered_map<ll, ll> d[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("output.txt", "w", stdout);

	ll n; cin >> n;
	vector<ll>a(n+ 1);
	ll sm = 0;
	for (ll i = 1; i <= n; i++) cin >> a[i], sm += a[i];

	ll k = (n + 1) / 2;

	d[0][0] = 0;
	
	for (ll i = 0; i <= n; i++) {
		ll ost = n - i;
		ll ost1 = max(0LL, i - 1);
		ll left = max({ k - ost, ost1 / 2, 0LL });
		ll right = (k - ost / 2);

		assert(right - left < 7);

		for (ll cnt = left; cnt <= right; cnt++) {
			if (d[i].find(cnt) == d[i].end()) continue;
			if (ost / 2 + cnt > k) continue;
			if (ost + cnt < k) continue;
			for (ll j = i + 1; j <= min(i + 2, n); j++) {
				if (d[j].find(cnt + 1) == d[j].end()) {
					d[j][cnt + 1] = d[i][cnt] + a[j];
				} else {
					d[j][cnt + 1] = min(d[j][cnt + 1], d[i][cnt] + a[j]);
				}
			}
		}
	}

	cout << sm - min(d[n][k], d[n - 1][k]);
	
	return 0;
}

/*

*/


Measured memory_bytes: 39792
#include <cstdio>
#define MAX 100000
using namespace std;

int main() {
    int N;
    int A[MAX];
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    int ans = 1;
    int state = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] > A[i-1]) {
            if (state == 0) state = 1;
            else if (state == -1) {
                ans++;
                state = 0;
            }
        }
        else if (A[i] < A[i-1]) {
            if (state == 0) state = -1;
            else if (state == 1) {
                ans++;
                state = 0;
            }
        }
    }

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


Measured memory_bytes: 512
n = int(input())
a = [None]
for j in range(n):
    a.append(int(input()))

i = 1
c = 0
r = [1]
while True:
    c += 1
    i = a[i]
    if i == 2:
        print(c)
        break
    if c > (10**5):
        print(-1)
        break

Measured memory_bytes: 7080
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args){

        int N;
        long[] Ln;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            Ln = new long[N];
            for (int i = 0; i < Ln.length; i++) {
                Ln[i] = sc.nextLong();
            }

        }
        long result = 0;
        Arrays.sort(Ln);


        for (int i = 0; i < Ln.length; i++) {
            for (int j = i + 1; j < Ln.length; j++) {
                int start = j + 1;
                int end = Ln.length;
                long val = Ln[i] + Ln[j] ;

                start--;
                while (end - start > 1) {
                    int mid = start + (int)Math.floor((end- start) / 2);
                    if (Ln[mid] < val) {
                        start = mid;
                    } else {
                        end = mid;
                    }
                }
                int add = (end-1) -j;
                result += add;
            }
        }
        System.out.println(result);

    }
}

Measured memory_bytes: 28464
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int a,b,mx,mx2,mn;
    cin >> a >> b;
    mx = max(a,b);
    mn = min(a,b);
    mx2 = max(mx-1,mn);
    cout << mx+mx2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        sc.close();

        int tmp = D*2+1;
        if(N%tmp==0) {
        	int ans = N/tmp;
        	System.out.println(ans);
        }else {
        	int ans = (N/tmp)+1;
        	System.out.println(ans);
        }


	}

}

Measured memory_bytes: 21332
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b)
        printf("%d ", a);
    else
        printf("%d ", b);
    if (a + b - n > 0)
        printf("%d\n",a + b - n);
    else
        printf("0\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=210;

int mp[N][N];
int id[N];
int n;

int vis[N];
int cal(int x) {
    memset(vis,0,sizeof(vis));
    vector<int> from,to;
    from.push_back(x);
    vis[x]=1;

    int cnt=0;
    while(!from.empty()) {
        ++cnt;
        for(int x:from) {
            for(int j=0; j<n; ++j)
                if(mp[x][j]&&!vis[j]) {
                    vis[j]=1;
                    to.push_back(j);
                }
        }
        for(int i=0; i<to.size(); ++i)
            for(int j=i+1; j<to.size(); ++j)
                if(mp[to[i]][to[j]])
                    return -1;
        from=to;
        to.clear();
    }
    return cnt;
}

bool flag=1;
vector<int> vec;
int solve() {
    int res=-1;
    for(int x:vec)
        res=max(res,cal(x));
    if(res==-1)
        flag=0;
    return res;
}


void dfs(int x,int num) {
    vec.push_back(x);
    id[x]=num;
    for(int j=0; j<n; ++j)
        if(mp[x][j]&&!id[j])
            dfs(j,num);
}
int main() {
    cin>>n;
    for(int i=0; i<n; ++i)
        for(int j=0; j<n; ++j)
            scanf("%1d",mp[i]+j);

    int num=0,ans=0;
    for(int i=0; i<n; ++i)
        if(!id[i]) {
            vec.clear();
            dfs(i,++num);
            ans+=solve();
        }
    cout<<(flag?ans:-1);
    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int len = s.size();

  int ans = 0;
  for(int i=0; i<len/2; i++) {
    if(s[i]!=s[len-1-i]) ans++;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : aoj2330.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int n, ans = 0;
	cin >> n;
	while(1){
		while(n % 3 != 0){
			n++;
		}
		ans++;
		n /= 3;
		if(n == 1){
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int H,W,h,w;
  cin >> H >> W;
  cin >> h >> w;
  cout << H * W - h*W - w*H + h*w  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e5+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int n,m;
struct node
{
    LL a,b;
    double x;
}st[maxn];

bool cmp(node a,node b)
{
    return a.a^b.a?a.a<b.a:a.b>b.b;
}


int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n>>m;
    for(Re int i=0;i<n;i++)
    {
        cin>>st[i].a>>st[i].b;
    }
    sort(st,st+n,cmp);
    LL ans=0;
    priority_queue<int> q;
    int cur=0;
    for(Re int i=m-1;i>=0;i--)
    {
        while(cur<n&&i+st[cur].a<=m)
        {
            q.push(st[cur++].b);
        }
        if(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3196
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_091
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var ab = new int[n][];
            var cd = new int[n][];
            for (int i = 0; i < n; i++)
            {
                int[] input = ReadInts();
                ab[i] = new int[2];
                ab[i][0] = input[0];
                ab[i][1] = input[1];
            }
            for (int i = 0; i < n; i++)
            {
                int[] input = ReadInts();
                cd[i] = new int[2];
                cd[i][0] = input[0];
                cd[i][1] = input[1];
            }
            Array.Sort(ab, (a, b) => a[0] - b[0]);
            Array.Sort(cd, (a, b) => a[0] - b[0]);
            int pairCnt = 0;
            for (int i = 0; i < n; i++)
            {
                int aIndex = n - 1;
                for (; aIndex >= 0; aIndex--)
                {
                    if (ab[aIndex][0] > cd[i][0])
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                if (aIndex==-1)
                {
                    continue;
                }
                int redIndex = -1;
                for (int j = aIndex; j >= 0; j--)
                {
                    if (cd[i][1] < ab[j][1])
                    {
                        continue;
                    }
                    else if (redIndex == -1
                            || ab[redIndex][1] < ab[j][1])
                    {
                        redIndex = j;
                    }
                }
                if (redIndex != -1)
                {
                    pairCnt++;
                    ab[redIndex][1] = 3000;
                }
            }
            Console.WriteLine(pairCnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<cmath>
#include<random>
//This code is written by Itst
using namespace std;

inline int read()
{
	int a = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c != EOF)
		c = getchar();
	if(c == EOF)
		exit(0);
	while(isdigit(c))
	{
		a = a * 10 + c - 48;
		c = getchar();
	}
	return f ? -a : a;
}

int d[12][12] , f[107][107];

signed main()
{
	int A = read() , B = read();
	for(int i = 1 ; i <= A ; ++i)
		for(int j = 1 ; j <= B ; ++j)
			d[i][j] = read();
	for(int i = 0 ; i <= 100 ; ++i)
		for(int j = 0 ; j <= 100 ; ++j)
			for(int p = 1 ; p <= A ; ++p)
				for(int q = 1 ; q <= B ; ++q)
					f[i][j] = max(f[i][j] , d[p][q] - i * p - j * q);
	for(int i = 1 ; i <= A ; ++i)
		for(int j = 1 ; j <= B ; ++j)
		{
			int minN = 1e9;
			for(int p = 0 ; p <= 100 ; ++p)
				for(int q = 0 ; q <= 100 ; ++q)
					minN = min(minN , f[p][q] + p * i + q * j);
			if(minN != d[i][j])
			{
				puts("Impossible");
				return 0;
			}
		}
	puts("Possible");
	puts("202 10401");
	for(int i = 1 ; i <= 100 ; ++i)
		printf("%d %d X\n" , i , i + 1);
	for(int i = 102 ; i < 202 ; ++i)
		printf("%d %d Y\n" , i , i + 1);
	for(int i = 0 ; i <= 100 ; ++i)
		for(int j = 0 ; j <= 100 ; ++j)
			printf("%d %d %d\n" , 1 + i , 202 - j , f[i][j]);
	puts("1 202");
	return 0;
}

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

//vector<int> s[2];
//vector<ull> u[2];
//const int N=500;
//int n;
//int d[N][N];

int main(){
  int n;
  cin >>n;
  string ans;
  if(n%10==3){
    ans="bon";
  }else if(n%10==0 ||n%10==1 ||n%10==6 ||n%10==8 ){
    ans="pon";
  }else{
    ans="hon";
  }

  cout <<ans<<endl;
  return 0;

}


Measured memory_bytes: 3624
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    n = int(input())
    mob=np.array(list(map(int,input().split())),dtype=int)
    bra=np.array(list(map(int,input().split())),dtype=int)
    ans=0

    for i in range(n):
        tmp1=min(mob[i],bra[i])
        ans += tmp1
        tmp2=min(mob[i+1],bra[i]-tmp1)
        ans += tmp2
        mob[i+1]-=tmp2
    print(ans)


if __name__=="__main__":
    main()

Measured memory_bytes: 39692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h;
  while(cin>>h,h){
    int a[10][5],ans=0;
    for(int i=0;i<h;i++)
      for(int j=0;j<5;j++)cin>>a[i][j];
    bool f=1;
    while(f){
      f=0;
      for(int i=0;i<h;i++){
	int c=1,p=0;
	for(int j=1;j<5;j++)
	  if(a[i][p]==a[i][j])c++;
	  else if(c<3)c=1,p=j;
	  else break;
	if(c>=3){
	  ans+=c*a[i][p];
	  for(int k=0;k<c;k++)a[i][p+k]=0;
	}
      }
      for(int i=0;i<5;i++)
	for(int j=1;j<h;j++)
	  for(int k=j;k>0;k--)
	    if(!a[k][i]&&a[k-1][i])swap(a[k][i],a[k-1][i]),f=1;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3056
#include<stdio.h>
int main(void)
{
        int d,n;
        scanf("%d%d",&d,&n);
        if(n==100) n++;
        if(d==0)printf("%d\n",n);
        else if(d==1) printf("%d\n",n*100);
        else if(d==2) printf("%d\n",n*10000);
        return 0;
}


Measured memory_bytes: 128
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local T_HP, T_ATK, A_HP, A_ATK = read.nnnn()
local taka = true
while T_HP > 0 and A_HP > 0 do
    if taka then
        A_HP = A_HP - T_ATK
    else
        T_HP = T_HP - A_ATK
    end
    taka = not taka
end
if T_HP <= 0 then
    print("No")
else
    print("Yes")
end


Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define preturn(X) cout<<X<<endl; return 0
//cout.setf(ios::fixed); cout.precision(18)
typedef long long ll;
typedef long double ld;

const ll MOD = 1e9+7;

ll a[100000+10];
ll ans[400000+10];

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin>>n;
    rep(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ind[2];
    ind[0] = 1;
    ind[1] = n-1;
    ll l = 200000,r = 200000;
    ans[l] = a[0];
    while(ind[1]>=ind[0]){
        ll diff[2];
        rep(k,0,2){
            diff[k] = max(abs(ans[r]-a[ind[k]]),abs(ans[l]-a[ind[k]]));
        }
        if(diff[0]>=diff[1]){
            if(diff[0]==abs(ans[r]-a[ind[0]])){
                ans[r+1] = a[ind[0]];
                r++;
                ind[0]++;
            }
            else{
                ans[l-1] = a[ind[0]];
                l--;
                ind[0]++;
            }
        }
        else{
            if(diff[1]==abs(ans[r]-a[ind[1]])){
                ans[r+1] = a[ind[1]];
                r++;
                ind[1]--;
            }
            else{
                ans[l-1] = a[ind[1]];
                l--;
                ind[1]--;
            }
        }
    }
    // cout<<n<<endl;
    ll sum = 0;
    rep(j,l,r){
        // cout<<ans[j]<<" ";
        sum+=abs(ans[j]-ans[j+1]);
    }
    // cout<<endl;
    preturn(sum);
}


Measured memory_bytes: 1792
n, y = gets.to_s.split.map{|t|t.to_i}

y /= 1000

0.upto(y/10) do |m|
  0.upto(y/5) do |g|
    s = y - 10 * m - 5 * g
    if s >= 0 && n == m + g + s
      puts "#{m} #{g} #{s}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;
#define int ll

class MyCombination {
private:
	vector<long long> fac, ifac;
public:
	ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
		ll ans = 1;
		while (n != 0) {
			if (n & 1) ans = ans * x % MOD;
			x = x * x % MOD;
			n = n >> 1;
		}
		return ans;
	}

	ll comb(ll a, ll b) { //aCbをmod計算
		if (a == 0 && b == 0)return 1;
		if (a < b || a < 0)return 0;

		ll tmp = ifac[a - b] * ifac[b] % MOD;

		return tmp * fac[a] % MOD;
	}

	MyCombination(long long SIZE = 200001) {
		fac.resize(SIZE);
		ifac.resize(SIZE);
		fac[0] = 1;
		ifac[0] = 1;
		for (ll i = 0; i < SIZE - 1; i++) {
			fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
			ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
		}
	}
};
signed main() {
	int N; cin >> N;
	MyCombination myc;
	int ans = 0;
	// for each number of solution Xs find Number of subsets
	for (int m = 1; m <=N/3; m++) {
		int temp = myc.comb(N-2*m-1, m - 1);
		ans += temp;
		ans %= MOD;
	}
	cout << ans << endl;
	sysp;
}

Measured memory_bytes: 6420
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

VI p4 = { 1,4,16,64,256,1024,4096,16384,65536,262144,1048576, };

string solve(int n) {
	string ret;

	bool flag = false;
	for (int i = 9; i >= 0; i--) {
		int p = n / p4[i];
		n %= p4[i];
		if (p != 0 || i == 0)flag = true;

		//cout << p4[i] << " : " << p << endl;

		if (flag)ret += '0' + p;
	}

	return ret;
}


int main() {
	while (true) {
		int a; cin >> a;
		if (a == -1)break;
		Cout(solve(a));
	}
}


Measured memory_bytes: 3008
#include <iostream>
#define ll long long
using namespace std;

ll gcd(ll a, ll b){
	ll r = a%b;

	while(r != 0){
		a = b;
		b = r;
		r = a%b;
	}
	return b;
}

ll lcm(ll a, ll b){

	return (a*b)/gcd(a, b);
}

int main(){
	ll A,B,ans;
	cin >> A >> B;
	ans=lcm(A,B);
	cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[])
    {
        Main m = new Main();
        m.p3();
    }

    public void p3()
    {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        int input = Integer.parseInt(str);
        int sum = 0;
        for(int i = 1; i <= input; i++)
        {
            for(int j = 1;j <= input; j++)
            {
                for(int k = 1; k <= input; k++)
                {
                    sum += gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
    }
    private int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }

    public void p2()
    {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        int input = Integer.parseInt(str);
        long sum = 0;
        for(int j = 0; j <= input; j++)
        {
            if(j % 3 != 0 && j % 5 != 0)sum += j;
        }
        System.out.println(sum);
    }

    public void p1()
    {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        if(str.indexOf("7") != -1)System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 35736
var primeNxt = new Array(1000000);

function primeGenerator()
{
    var p, fact, m;
    var maxN = 1002001;
    var primePrv = new Array(1000000);

    // Initial
    for(p=2;p<=maxN;++p){
        primeNxt[p] = p + 1;
        primePrv[p] = p - 1;
    }
    primePrv[2] = 0;
    primeNxt[maxN] = 0;
    
    // Make prime table (primeNxt)
    for(p=2;p*p<=maxN;p=primeNxt[p]){
        for(fact=p;p*fact<=maxN;fact=primeNxt[fact]){
            for(m=p*fact;m<=maxN;m*=p){
                primeNxt[primePrv[m]] = primeNxt[m];
                primePrv[primeNxt[m]] = primePrv[m];
            }
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function(input){
    primeGenerator();
    var lines = input.trim().split('\n');
    var len = lines.length;
    for(var t=0;t<len;++t){
        var N = parseInt(lines[t]);
        var cnt = 1;
        if( N == 1 ){
            console.log(0);
        }
        else if( N == 2 ){
            console.log(1);
        }
        else{
            for(var i=3;i<=N;i=primeNxt[i]){
               ++cnt;
            }
            console.log(cnt);
        }
    }
});

Measured memory_bytes: 72192
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int k;
vector<int>a[26];
set<string > p;
char s[5005];
string cat(int t,int len,char ch)
{
    string a;
    for(int i=t; i<t+len; i++)
    {
        if(s[i]=='\0')
            return "";
        a+=s[i];
    }
  //  cout<<a<<endl;
    return a;
}
void fun()
{
    int len;
    string str;
    for(int i=0; i<26; i++)
    {
        int lena=a[i].size();
        for(int len=1; len<10; len++)
        {

            for(int j=0; j<lena; j++)
            {
                int t=a[i][j];
                str=cat(t,len,s[t]);
                if(str!="")
                    p.insert(str);
			//	cout<< str <<endl;
             //   if(p.size()==k)
               //     return ;
            }
        }
    }

}
int main()
{
    scanf("%s%d",s,&k);
    for(int i=0; s[i]; i++)
    {
        a[s[i]-'a'].push_back(i);
    }
    fun();
	for(int i=0;i<k-1;i++)
		p.erase(p.begin());
	cout<<*p.begin()<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}





signed main(){
	ll n,k,q;
	cin >> n >> k >> q;
	ll	pts[n] = {};


	rep(i,0,q){
		ll a;
		cin >> a;

		pts[a-1]++;
	}

	rep(i,0,n){
		if(k - q + pts[i] <= 0) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    VLL h(n);rep(i,n)cin>>h[i];
    bool ok=true;
    for(int i=n-1;i>=1;i--){
        if(h[i]-h[i-1]==-1)h[i-1]--;
        else if(h[i]-h[i-1]<-1)ok=false;
    }
    cout<<(ok?"Yes":"No")<<endl;
}



Measured memory_bytes: 1024
N, M = input().split()

food_list = []
for i in range(int(M)):
    food_list.append((i+1))
for i in range(int(N)):
    favorite_list = input().split()[1:]
    favorite_list = [int(x) for x in favorite_list]
    if len(food_list) == 0:
        break
    test_list = [int(x) for x in food_list]
    for j in test_list:
        if not (j in favorite_list):
            food_list.remove(j)
print(len(food_list))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 100100100;

//f(0) = 1
//f(1) = 1
//f(2) = 2*f(0) = 2*1
//f(3) = 3*f(1) = 3*1
//f(4) = 4*f(2) = 4*2*1;
//f(5) = 5*f(3) = 5*3*1

//f(2n+1) is odd, there's no 0;
//f(2n) = 1*2*4*....2n;
//  log5(2*10^18) ~ log5(2)+18*log5(10)
// max = 5^26

//example
//1 2 4 8 10 12 14 16 18 20 22 24 26
// mul of 5^2  = 26/25/2=0
// mul of 5^2 = 26/5/2 = 2 >>10,20
 
int main(){
  ll n;
  cin >> n;

  if(n%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i = 26; i >=1; i--){
    ll div = pow(5,i);
    ans += (n/div)/2;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 4124
class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

import sys,bisect

input=sys.stdin.buffer.readline

N,X,Y=map(int,input().split())
cball=[[] for i in range(N)]
ball=[]
color=[-1]*N
for i in range(N):
    c,w=map(int,input().split())
    ball.append((w,c-1,i))
    cball[c-1].append((w,i))
    color[i]=c-1

for i in range(N):
    cball[i].sort()
ball.sort()

if N==1:
    print(1)
    exit()

cmin=[10**20 for i in range(N)]
for i in range(N):
    if cball[i]:
        cmin[i]=min(cball[i][j][0] for j in range(len(cball[i])))

_cmine1=[cmin[i] for i in range(N)]
_cmine2=[cmin[i] for i in range(N)]
for i in range(1,N):
    _cmine1[i]=min(_cmine1[i],_cmine1[i-1])
for i in range(N-2,-1,-1):
    _cmine2[i]=min(_cmine2[i],_cmine2[i+1])
cmine=[0]*N
cmine[0]=_cmine2[1]
cmine[-1]=_cmine1[N-2]
for i in range(1,N-1):
    cmine[i]=min(_cmine1[i-1],_cmine2[i+1])

M=min(ball)
special=-1
for i in range(N):
    if cmine[i]!=M[0]:
        special=i

uf=UnionFindVerSize(N)
for i in range(N):
    if i!=special:
        for j in range(len(cball[i])):
            if M[0]+cball[i][j][0]<=Y:
                uf.unite(cball[i][j][1],M[2])
            if j!=0 and cball[i][j][0]+cball[i][0][0]<=X:
                uf.unite(cball[i][j][1],cball[i][0][1])
    else:
        for j in range(len(cball[special])):
            if cmine[special]+cball[special][j][0]<=Y:
                uf.unite(cball[special][j][1],M[2])
            if M[0]+cball[special][j][0]<=X:
                uf.unite(cball[special][j][1],M[2])

connect={}
for i in range(N):
    root=uf.find_root(i)
    if root not in connect:
        connect[root]=[]
    connect[root].append(i)

ans=1
for root in connect:
    cc={}
    for i in connect[root]:
        if color[i] not in cc:
            cc[color[i]]=0
        cc[color[i]]+=1
    size=len(connect[root])
    for C in cc:
        ans*=g2[cc[C]]
        ans%=mod
    ans*=g1[size]
    ans%=mod

print(ans)

Measured memory_bytes: 138520
import heapq
N,M = map(int,input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

for i in range(M) :
    a = heapq.heappop(A)
    a = int(a/2)
    heapq.heappush(A,a)

print(int(sum(A)*-1))

Measured memory_bytes: 20420
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum = 0;
  for(int i = 0; cin >> ch; i++){
    if(ch == '\\') S1.push(i);
    else if(ch == '/' && S1.size() > 0){
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while(S2.size() > 0 && S2.top().first > j){
	a += S2.top().second;
	S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  while(S2.size() > 0){
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i = 0; i < ans.size(); i++){
    cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3168
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e8;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct DP {
  int g, v;

  DP(int g = 0, int v = 0): g(g), v(v) {}

  DP operator + (DP& dp) {
    return {g + dp.g, min(v, dp.v)};
  }

  bool operator < (const DP& dp) const {
    return g != dp.g ? g < dp.g : v < dp.v;
  }
};

int h, w, s;
int u[40][40];

int sum[40][40];
DP dp[40][40][40][40];

void init() {
  memset(sum, 0, sizeof(sum));
  rep(i, h) {
    rep(j, w) {
      sum[i + 1][j + 1] = u[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
      //cout << sum[i + 1][j + 1] << ' ';
    }
    //cout << '\n';
  }
  s = sum[h][w] - s;
  rep(i, 40) rep(j, 40) rep(k, 40) rep(l, 40) dp[i][j][k][l] = {0, 0};
}

void solve() {
  FOR(dh, 1, h + 1) {
    FOR(dw, 1, w + 1) {
      rep(u, h - dh + 1) {
        int d = u + dh;
        rep(l, w - dw + 1) {
          int r = l + dw;
          if (sum[d][r] - sum[u][r] - sum[d][l] + sum[u][l] < s) continue;
          DP res = {1, sum[d][r] - sum[u][r] - sum[d][l] + sum[u][l] - s};
          FOR(i, u + 1, d) {
            DP nxt = dp[u][i][l][r] + dp[i][d][l][r];
            res = max(res, nxt);
          }
          FOR(j, l + 1, r) {
            DP nxt = dp[u][d][l][j] + dp[u][d][j][r];
            res = max(res, nxt);
          }
          //cout << u << ' ' << d << ' ' << l << ' ' << r << '\n';
          dp[u][d][l][r] = res;
          //cout << res.g << ' ' << res.v << '\n';
        }
      }
    }
  }
  DP ans = dp[0][h][0][w];
  cout << ans.g << ' ' << ans.v << '\n';
}

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

  while (1) {
    cin >> h >> w >> s;
    if (h == 0 && w == 0 && s == 0) return 0;
    rep(i, h) rep(j, w) cin >> u[i][j];

    init();
    solve();
  }




  
  return 0;
}


Measured memory_bytes: 23148
#include <iostream>                                             
#include <vector>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int N;                                                        
  cin >> N;                                                     
  int x;                                                        
  vector<int> A;                                                
  for (int i=0; i<N; i++) {                                     
    cin >> x;                                                   
    A.push_back(x);                                             
  }                                                             
  int t, ans=0;                                                 
  for (int i=0; i<N; i++) {                                     
    int minj = i;                                               
    for (int j=i; j<N; j++) {                                   
      if (A[j]<A[minj]) {                                       
        minj = j;                                               
      }                                                         
    }                                                           
    t = A[i];                                                   
    A[i] = A[minj];                                             
    A[minj] = t;                                                
    if (i!=minj) {                                              
      ans++;                                                    
    }                                                           
  }                                                             
  for (int i=0; i<A.size(); i++) {                              
    cout << (i==0?"":" ") << A[i] << flush;                     
  }                                                             
  cout << endl <<  ans << endl;                                 
  return 0;                                                     
}                                                   

Measured memory_bytes: 3112
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <iostream>
#include <ctype.h>
#include <ctime>
#include <unordered_set>
#include <ctype.h>

#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int n,k,arr[200000];
int main() {
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",arr+i);
	printf("%d\n",((n-1) + (k-1) - 1) / (k-1));
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define ll  long long
  #define ld long double
  #define pb push_back
  #define mp3 make_pair
  #define rep1(i,a,b) for(ll i=a;i<=b;i++)
  #define rep2(i,a,b) for(ll i=a;i<b;i++)
  const ll  mod=1e9+7;
  const ll INF=1e18;
  template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
  template<typename T> T add(T a,T b,ll m){a+=b;while(a>=0)a-=m;while(a<0)a+=m; return a;}
  template<typename T> T mul(T a,T b,ll m){return (a*1ll*b)%m;}
  ll sum;
  ll dp[1000000];
  ll rec(ll x){
    if(x==0)
    return 1;
    if(x<0)
    return 0;
    if(dp[x]!=-1)
    return dp[x];
    ll ans=0;
    for(ll i=3;i<=x;i++){
      ans=add(ans,rec(x-i)%mod,mod);
    }
    return dp[x]=ans;
  }
  int main(){
    IOS;
    cin>>sum;
    memset(dp,-1,sizeof(dp));
    cout<<rec(sum);
  } 

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

int n, k, idx, lst, p = 1;
std::string s;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> s, n = s.size(), s = '0' + s;
	if (s != std::string(s.rbegin(), s.rend()) || s[1] != '1')
		return std::cout << -1 << '\n', 0;
	k = std::count(s.begin(), s.end(), '1'), idx = k + 1;
	for (int i = 1; i <= k; ++i)
		std::cout << i << ' ' << i + 1 << '\n';
	for (int i = 1; i <= n; ++i) if (s[i] == '1') {
		for (int j = 1; j < i - lst; ++j)
			std::cout << p << ' ' << ++idx << '\n';
		++p, lst = i;
	}
	return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;

int main(){
	int n, k, s; scanf("%d%d%d", &n, &k, &s);
	REP(i, k){
		printf("%d ", s);
	}
	int t = 1'000'000'000;
	if(s == t) t = 1;
	REP(i, n-k){
		printf("%d ", t);
	}
	printf("\n");
}


Measured memory_bytes: 1280