akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        aa: [u64;n],
        bcs: [(usize,u64);m]
    }
    let mut aa = aa;
    aa.sort();
    let mut bcs = bcs;
    bcs.sort_by_key(|x| x.1);
    let mut p = 0;
    for (b,c) in bcs.into_iter().rev() {
        let mut k = 0;
        for j in p..n {
            if aa[j] < c {
                aa[j] = c;
                k += 1;
            } else {
                break;
            }
            if k == b { break; }
        }
        p += k;
        if n <= p { break; }
    }
    // println!("{:?}", aa);
    println!("{}", aa.iter().sum::<u64>());
}


Measured memory_bytes: 12408
n = int(input())

A = list(map(int, input().split()))

B = []
for i in range(n-1):
    B.append(A[i+1]/A[i])

s = 1000
for i in range(n-1):
    if B[i] > 1.0:
        val = s // A[i]
        s = s - A[i] * val
        s = s + A[i+1] * val
print(s)

Measured memory_bytes: 61908
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i=1;

		for(i=1;i<=5;i++) {
			int n=sc.nextInt();
			if(n==0) {
				break;
			}
		}
		System.out.println(i);
		



	}

}

Measured memory_bytes: 35716
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 N, X;
  cin >> N >> X;
  vector<int64> x(N);
  cin >> x;
  int64 tmp;
  int64 current_gcd = 0;
  for (int64 i = 0; i < N; i++) {
    tmp = abs(x[i] - X);
    if (tmp == 0)
      continue;
    else if (current_gcd == 0) {
      current_gcd = tmp;
      continue;
    }
    current_gcd = __gcd(current_gcd, tmp);
  }
  cout << current_gcd << endl;
  return 0;
}

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

int min(int x,int y){return x<y?x:y;}
const int MAX_N=3*1e5+5;
int sum_w[MAX_N];

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  for(int i=1;i<=n;i++){
    if(s[i-1]=='W')sum_w[i]++;
    sum_w[i]+=sum_w[i-1];
  }
  int ans=MAX_N+100;
  for(int i=1;i<=n;i++){
    ans=min(ans,sum_w[i-1]+n-i-(sum_w[n]-sum_w[i]));
  }
  cout<<ans<<endl;
}


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll a[200100];
int main() {
  ll n;
  cin >> n;
  rep(i, n) cin >> a[i];
  bool result = true;
  sort(a, a + n);
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      result = false;
      break;
    }
  }
  cout << (result ? "YES" : "NO") << endl;
}


Measured memory_bytes: 5200
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int n;
map<int,int>mp;
int solve(){
    int ans=0;
   for(auto& it:mp){
     chmax(ans,it.second);
   }
   return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    rep(i,n){
        int a;
        cin>>a;
        mp[a]++;
        mp[a-1]++;
        mp[a+1]++;
    }
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 4736
N=int(input())
a=list(map(int,input().split()))

res=[0]*(N+1)
for i in range(1,N+1)[::-1]:
    sum_res=sum(res[x] for x in range(i,N+1,i))
    if sum_res % 2!=a[i-1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans=[]
    for i,ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)

Measured memory_bytes: 14140
package main

	import (
		"fmt"
		"math"
	)

	var A, B, ans int

	func main() {
		fmt.Scan(&A, &B)
		if 10 <= A+B {
			fmt.Println("error")
		} else {
			fmt.Println(A + B)
		}
	}

	/*  ----------------------------------------  */

	func gcd(x, y uint64) uint64 {
		if x%y == 0 {
			return y
		} else {
			r := x % y
			return gcd(y, r)
		}
	}

	func combination(x, y int) int {
		return permutation(x, y) / permutation(y, y)
	}

	func permutation(x, y int) int {
		var ans int = 1
		for i := x - y; 0 < i; i-- {
			ans *= i
		}
		return ans
	}

	func max(x ...int) int {
		var res int = x[0]
		for i := 1; i < len(x); i++ {
			res = int(math.Max(float64(x[i]), float64(res)))
		}
		return res
	}

	func min(x ...int) int {
		var res int = x[0]
		for i := 1; i < len(x); i++ {
			res = int(math.Min(float64(x[i]), float64(res)))
		}
		return res
	}

	func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
	func abs(x int) int       { return int(math.Abs(float64(x))) }
	func floor(x int) int     { return int(math.Floor(float64(x))) }

	type XY struct {
		x int
		y int
	}

	type SortBy [][]int

	func (a SortBy) Len() int      { return len(a) }
	func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
	func (a SortBy) Less(i, j int) bool {
		if a[i][0] == a[j][0] {
			return a[i][1] > a[j][1]
		}
		return a[i][0] > a[j][0]
	}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()

int n, m, ans = 0;
vector<vector<int>> g(10);
vector<bool> passed(10, false);

void dfs(int now, int cnt)
{
	if (passed[now])return;
	if (cnt == n)
	{
		++ans;
		return;
	}
	
	passed[now] = true;
	for (int next : g[now])
	{
		dfs(next, cnt + 1);
	}
	passed[now] = false;
	return;
}


int main()
{
	cin >> n >> m;
	rep(i, 0, m - 1)
	{
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, 1);
	cout << ans << endl;
}


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

int main() {
  int k, n;
  cin >> k >> n;
  
  vector<int> a(n);
  
  for (int i=0; i<n;i++) {
    cin >> a[i];
  }
  
  int max, p;
  max=k-a[n-1] + a[0];
  
  for (int i=0; i<n-1; i++) {
    p=a[i+1] - a[i];
    if (p>max) max=p;
    //cout << p << endl;
  }
  cout << k-max << endl;
}

Measured memory_bytes: 1152
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i)) for i in b))

Measured memory_bytes: 29120
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

bool isPrime(long long x){
	if(x == 2)
		return true;
	else if((x < 2) || (x % 2 == 0))
		return false;

	long long i = 3;
	while(i <= sqrt((double)x)){
		if(x % i == 0)
			return false;
		i += 2;
	}

	return true;
}

int main(){
	long long n;
	
	cin>>n;
	cout<<n<<":";

	while(n%2 == 0){
		n /= 2;
		cout<<" 2";
	}

	for(long long i=3;i*i<=n;i+=2){
		if(isPrime(i)){
			while(n%i==0){
				n /= i;
				cout<<" "<<i;
			}
		}
	}

	if(n!=1) cout<<" "<<n;

	cout<<endl;
	return 0;
}

Measured memory_bytes: 1164
from itertools import permutations

# input
P, Q, R = map(int, input().split())

t = {
    "A": {
        "B": P,
        "C": R
    },
    "B": {
        "A": P,
        "C": Q
    },
    "C": {
        "A": R,
        "B": Q
    }
}
# check
P = list(permutations(["A", "B", "C"], 3))
T = [sum([t[p[i]][p[i + 1]]for i in range(0, 2)]) for p in P]

print(min(T))

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int arr[maxr], prefix[maxr];
const int M = 1e9 + 7;
int32_t main()
{
	GO;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	prefix[0] = arr[0];
	for (int i = 1; i < n; i++) {
		prefix[i] = arr[i] + prefix[i - 1];
		prefix[i] %= M;
	}
	int ans = 0;
	for (int i = n - 2; i >= 0; i--) {
		ans += (prefix[i] * arr[i + 1]);
		ans %= M;
	}
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 6732
//Let's join Kaede Takagaki Fun Club !!
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll b = 1000000000000000000LL%mod;
int n;
vector<ll>make(){
	int m; g(m);
	vector<vector<int>>adj(n);
	rep(i,m){
		int a,b; g(a); g(b); a--; b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	vector<int>num(n);
	for(int i=n-1;i>=0;i--){
		set<int>S;
		for(auto at:adj[i]){
			if(at > i) S.insert(num[at]);
		}
		for(int v=0;;v++) if(S.find(v) == S.end()){
			num[i] = v; 
			break;
		}
	}
	vector<ll>ret(n);
	rep(j,n){
		add(ret[num[j]], modpow(b,j+1));
	}
	while(ret.back() == 0) ret.pop_back();
	return ret;
}
int main(){
	ios::sync_with_stdio(false);
	g(n);
	vector<vector<ll>>gr;
	rep(i,3){
		gr.pb(make());
	}
	ll ans = 0;
	rep(i,gr[0].size()){
		rep(j,gr[1].size()){
			int k = (i^j);
			if(gr[2].size() > k){
				add(ans, gr[0][i]*gr[1][j]%mod*gr[2][k]%mod);
			}
		}
	}
	o(ans);
}

Measured memory_bytes: 8528
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll Q;
    cin >> Q;
    vector<ll> B(Q,0);
    vector<ll> C(Q,0);
    for(ll i=0;i<Q;++i)cin>>B[i]>>C[i];
    ll sum=0;
    for(ll i=0;i<N;++i)sum+=A[i];
    um M;
    for(ll i=0;i<N;++i)M[A[i]]++;
    for(ll i=0;i<Q;++i){
        sum-=B[i]*M[B[i]];
        sum+=C[i]*M[B[i]];
        M[C[i]]+=M[B[i]];
        M[B[i]]=0;
        prt(sum);
    }

    return 0;
}



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

int main(){
    int n, k, i;
    long long c = 0;
    cin >> n >> k;
    if(k == 0){
        c = (long long)n*(long long)n;
    }else{
        for(i=k+1; i<=n; i++){
            c += (long long)max(n%i-k+1, 0);
            c += (long long)(i-k) * (n/i);
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	vector<char> ans;
	rep(i, s.size()) {
		if (s[i] == 'B') {
			if (ans.size() == 0) continue;
			ans.pop_back();
		}
		else {
			ans.push_back(s[i]);
		}
	}
	rep(i, ans.size()) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)

@lru_cache(maxsize=None)
def main():

    def gcd(a, b):
        if b == 0:
            return a
        if a % b == 0:
            return b
        else:
            return gcd(b, a % b)

    N, *A = map(int, sys.stdin.read().split())
    L = [0] * (N + 2)
    R = [0] * (N + 2)
    for i in range(N):
        L[i + 2] = gcd(L[i + 1], A[i])
        R[-i - 2] = gcd(R[-i - 1], A[-i - 1])

    print(max(gcd(L[i], R[i + 1]) for i in range(1, N + 1)))

if __name__=='__main__':
  main()

Measured memory_bytes: 14652
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD (long long)(1e9+7)

using namespace std;
int main() {
    long long N, M;
    cin >> N >> M;
    long long i = 0;
    long long j = 0;
    long long ans = 1;
    if(abs(N-M) > 1) {
        cout << 0 << "\n";
    } else if(abs(N-M) == 1) {
        if(M > N) swap(N, M);
        for(i = 0, j = 0; j != M; i++, j++){
            ans = (ans * (((N-i) * (M-j)) % MOD)) % MOD;
        }
        cout << ans%MOD << "\n";
    }else {
        for(i = 0, j = 0; i != M; i++, j++){
            ans = (ans * (((N-i) * (M-j)) % MOD)) % MOD;
        }
        cout << (ans*2)%MOD << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;
#define ALL(v) (v).begin(), (v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=1ll<<62; const int INF=1ll<<30; const LL MOD=1E9+7;
int h,w,ans,dat[303][303],same[303][303];
char c[303][303]={};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
void dp(int a){
    REP(i,h+1){
        REP(j,1){
            REP(k,min(h-i,h-j)){
                if(c[h-1-i-k][a]==c[h-1-j-k][a+1])++same[i][j];
            }
        }
    }
    REP(i,1){
        FOR(j,1,h+1){
            REP(k,min(h-i,h-j)){
                if(c[h-1-i-k][a]==c[h-1-j-k][a+1])++same[i][j];
            }
        }
    }
    FOR(i,1,h+1){
        FOR(j,1,h+1){
            same[i][j]=same[i-1][j-1]-(c[h-i][a]==c[h-j][a+1]?1:0);
        }
    }

    dat[0][0]=same[0][0];
    FOR(i,1,h+1) dat[i][0]=dat[i-1][0]+same[i][0];
    FOR(i,1,h+1) dat[0][i]=dat[0][i-1]+same[0][i];
    FOR(i,1,h+1){
        FOR(j,1,h+1){
            dat[i][j]=min(dat[i-1][j],dat[i][j-1])+same[i][j];
        }
    }
    return;
}

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

    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> c[i][j];
        }
    }
    REP(i,w-1){
        Fill(dat,0);
        Fill(same,0);
        dp(i);
        /*REP(i,h+1){
            REP(j,h+1) cout << dat[i][j]<< ' ';
            cout << endl;
        }*/
        ans+=dat[h][h];
    }
    cout << ans <<endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }

vector<P>E[100000];
int d[100000],b[100000],cnt[200001],u[200000],v[200000],r[200000];
int main(){
	int n,m,q;reader(n);reader(m);reader(q);
	rep(i,m){
		reader(u[i]);reader(v[i]);u[i]--;v[i]--;r[i]=q;
	}
	rep(i,q){
		int a;reader(a);r[a-1]=i;
	}
	rep(i,m){
		E[u[i]].emplace_back(P(v[i],r[i]));E[v[i]].emplace_back(P(u[i],r[i]));
	}
	d[0]=1;b[0]=q;
	queue<int>que;que.emplace(0);
	while(!que.empty()){
		int p=que.front();que.pop();
		for(P v:E[p]){
			if(d[v.first]==0){
				d[v.first]=d[p]+1;que.emplace(v.first);
			}
			if(d[v.first]==d[p]+1)
				b[v.first]=max(b[v.first],min(b[p],v.second));
		}
	}
	rep(i,n)cnt[b[i]]++;
	int ans=0;
	rep(i,q){
		ans+=cnt[i];
		writer(ans,'\n');
	}
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)

typedef pair<int, int> P;

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

  int n, m; cin >> n >> m;
  vector<P> robot;
  rep(i, m) {
    int x, y; cin >> x >> y;
    robot.emplace_back(x, y);
  }
  sort(all(robot));
  
  vector<int> l(n), h(n);
  rep(i, n) l[i] = h[i] = i;
  for(auto &p : robot) {
    int x, y; tie(x, y) = p;
    l[y] = l[y-1];
    h[y-1] = h[y];
  }

  rep(i, n) cout << h[i]-l[i]+1 << (i==n-1 ? '\n' : ' ');
  
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> pll;

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

	ll n;
	cin >> n;

	ll a[n];
	ll c[n];
	rep(i, n){
		ll t;
		cin >> t;

		a[i] = t - (i + 1);
		c[i] = t - (i + 1); 
	}

	sort(c, c+n);

	ll b1 =  c[n/2];
	ll ans = 0;
	rep(i, n) ans += abs(a[i] - b1);

	cout << ans << endl;
}

Measured memory_bytes: 3328
def main():
    n, r = map(int, input().split())
    if n >= 10:
        print(r)
    else:
        print(r + 100 * (10 - n))


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3064
from itertools import product
import numpy as np

a = []
for _ in range(3):
    a.append([int(i) for i in input().split()])
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

is_open = np.array([[0] * 3 for _ in range(3)])
for i, k in product(range(3), repeat=2):
    if a[i][k] in b:
        is_open[i][k] = 1

bingo = False
for i in range(3):
    if sum(is_open[i, :]) == 3:
        bingo = True
        break
    elif sum(is_open[:, i]) == 3:
        bingo = True
        break
if not bingo:
    if sum(np.diag(is_open)) == 3:
        bingo = True
    elif sum(np.diag(np.fliplr(is_open))) == 3:
        bingo = True

print('Yes') if bingo else print('No')


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a; i<=b; i++){
        if(i%k == 0){
            printf("OK\n");
            return 0;
        }
    }
    printf("NG\n");

    return 0;
}


Measured memory_bytes: 3636
from random import randint

def solve0(L, R):
    m = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            t = (i*j) % 2019
            if t < m:
                m = t
                I = i
                J = j
    return I, J, m

def solve(L, R):
    M = 2019
    I = L
    mi = []
    mj = []
    for i in range(L, R+1):
        m = i % 2019 
        if m == 0:
            return 0, 0, 0
        mi.append(i)
        I = i

    for i in range(I+1, R+1):
        m = i % 2019 
        if m == 0:
            return 0, 0, 0
        mj.append(i)
    #print(mi)
    m = 2019
    for a in range(0, len(mi)):
        i = mi[a]
        for b in range(a+1, len(mi)):
            j = mi[b]
            t = (i*j)%2019 
            #print(i, j, t)
            if t < m:
                I = i
                J = j
                m = t

    return I, J, m

if 0==1:
    N = 10000
    while True:
        l = randint(0, N)
        r = randint(l+1, N)
        if solve(l,r)[-1] != solve0(l,r)[-1]:
            print("bad", l, r)
            break


def main():
    L, R =[int(x) for x in input().split()]
    answer = solve(L, R)
    #print("solve0", solve0(L, R))
    #print("solve ", answer)
    print(answer[-1])

main()



Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
int main(){
  int h,w,a,c[26]={},q,r;
  bool f=1,t;
  char s;
  cin>>h>>w;
  for(;cin>>s;) c[s-'a']++;
  q=h%2+w%2;
  if(q>1){
    r=h/2+w/2;
    t=0;
    fr(i,26){
      if(c[i]%4==1){
        if(t) f=0;
        else t=1;
      }
      else if(c[i]%4==2){
        if(r) r--;
        else f=0;
      }
      else if(c[i]%4){
        if(t) f=0;
        else t=1;
        if(r) r--;
        else f=0;
      }
    }
  }
  else if(q){
    if(h%2) swap(h,w);
    r=h/2;
    fr(i,26){
      if(c[i]%4==2){
        if(r) r--;
        else f=0;
      }
      else if(c[i]%4) f=0;
    }
  }
  else fr(i,26) if(c[i]%4) f=0;
  cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M = inputMap()
    A = []
    for i in range(N):
        tmp = input()
        A.append(tmp)
        
    B = []
    for i in range(M):
        tmp = input()
        B.append(tmp)
        
    if N < M:
        print("No")
        sys.exit()
        
    if N == M:
        tmp1 = "".join(A)
        tmp2 = "".join(B)
        
        if tmp1 == tmp2:
            print("Yes")
        else:
            print("No")
        sys,exit()
        
    points = []
    AA = copy.deepcopy(A)
    for i,val in enumerate(AA):
        while True:
            tmp = run(val, B[0])
            if tmp != -1 and N-i >= M:
                points.append((i,tmp))
                valval = list(copy.deepcopy(val))
                valval[tmp] = "T"
                val = "".join(valval)
            else:
                break
            
    for i in points:
        lines, point = i
        flg = True
        for j,val in enumerate(B):
            tmp = A[lines+j][point:].find(val)
            if tmp == -1 or tmp != 0:
                flg = False
        
        if flg == True:
            print("Yes")
            sys.exit()
            
    print("No")
    
def run(ss, dd):
    return ss.find(dd)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin>>m>>n; ll a[m][n]; for(ll i=0;i<m;i++) for(ll j=0;j<n;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back
#define N_ cout<<"\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
const ll maxs = 1e6+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }
//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

ll fact[maxs];
ll fib[maxs];
ll ncr[maxs1][maxs1];
bool vis[maxs];
vector<ll>graph[maxs];

//FACTORIAL
void FACT()
{fact[0]=1;for(ll i=1; i<maxs; i++)fact[i] = (i % mod * fact[i-1] % mod) % mod;}
//FIBONACCI
void FIB()
{ fib[0]=0; fib[1]=1; for(ll i=2; i<maxs; i++)fib[i] = (fib[i-1] % mod + fib[i-2] % mod)% mod;}
//NCR
void NCR()
{ll i,j;ncr[1][0] = 1;ncr[1][1] = 1;for(i=2; i<maxs1; i++){for(j=0; j<=i; j++) { if(j==0)ncr[i][j]=1;else ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1] ) % mod;} }}
//PRIME CHECK
bool soe(ll n)
{ bool prime[maxs+1];memset(prime, true, sizeof(prime));for (ll p=2; p*p<=maxs; p++) { if (prime[p] == true){ for (ll i=p*p; i<=maxs; i += p) prime[i] = false; } }
 if(prime[n]) return true;else return false;}    



int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,r;
    cin >> n >> r;
    if(n >= 10)
        cout << r;
    else
    {
        ll ans = r + (100 * (10 - n));
        cout << ans;
    }
    
}

Measured memory_bytes: 24960
#include <stdio.h>

int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    int h[n];
    int i,cnt=0;
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    for(i=0;i<n;i++){
        if(h[i]>=k){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 512
{-# LANGUAGE RankNTypes #-}
import qualified Data.Ix as I
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Control.Monad
import Control.Monad.ST

solve :: Int -> [(Int,Int)] -> Int -> Int
solve n goods' w = f (0, w) where
  goods = U.fromList goods'
  f = memoize ((0,0), (n,w)) f'
  f' f (i, j)
    | i == n = return 0
    | j < wi = nxt
    | otherwise = liftM2 max nxt nx'
    where
      nxt = f (i+1, j)
      nx' = (+vi) <$> f (i+1, j-wi)
      (wi, vi) = goods U.! i

--{ memoize
memoize :: (I.Ix i, U.Unbox e) => (i, i) ->
  (forall m. Monad m => (i -> m e) -> i -> m e) -> (i -> e)
memoize ran fun i = U.unsafeIndex memo ix
  where
    ix = I.index ran i
    size = I.rangeSize ran
    memo = runST $ do
      memo <- UM.unsafeNew size
      memd <- UM.replicate size False
      forM_ (I.range ran) $ calc memo memd
      U.unsafeFreeze memo
    calc memo memd i = do
      written <- UM.unsafeRead memd ix
      unless written $ do
        UM.unsafeWrite memo ix =<< fun (calc memo memd) i
        UM.unsafeWrite memd ix True
      UM.unsafeRead memo ix
      where ix = I.index ran i
--}

main = do
  [n,w] <- map read.words <$> getLine
  goods <- replicateM n $ (\[a,b]->(a,b)).map read.words <$> getLine
  print $ solve n goods w

Measured memory_bytes: 89852
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
ll dp[41][1<<17];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;
    int m = X+Y+Z;
    int mask1 = (1<<(X-1))-1;
    int mask1_ = (1<<X)-1;
    int mask2 = ((1<<(X+Y-1))-1)^mask1;
    int mask2_ = ((1<<(X+Y))-1)^mask1_;
    int mask3 = ((1<<(X+Y+Z-1))-1)^(mask1|mask2);
    int mask3_ = ((1<<(X+Y+Z))-1)^(mask1_|mask2_);
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= 10; j++){
            for(int k = 0; k < (1<<(m-1)); k++){
                
                int state = 0;
                state += ((k&mask1)<<j)&mask1_;
                state += ((k&mask2)<<j)&mask2_;
                state += ((k&mask3)<<j)&mask3_;
                state |= ((1<<(j-1))&mask1_);
                if((1<<(m-1))&state) {
                    continue;
                }
                dp[i][state] += dp[i-1][k];
                dp[i][state] %= MOD;
            }
        }
    }
    ll ans = 1;
    for(int i = 1; i <= N; i++){
        ans *= 10;
        ans %= MOD;
    }
    for(int i = 0; i < (1<<m); i++){
        ans -= dp[N][i];
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 40192
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, k, m;
	while (cin >> n >> k >> m,n) {
		int used[10001] = {}; used[m] = 1; int now = m;
		for (int i = 1; i < n; i++) {
			int t = k % (n - i);
			if (t == 0)t = n - i;
			for (int j = 0; j < t; j++) {
				now++; if (now == n + 1)now = 1;
				while (used[now]) {
					now++; if (now == n + 1)now = 1;
				}
			}
			used[now] = 1;
		}
		cout << now << endl;
	}
	return 0;
}


Measured memory_bytes: 3128
import numpy as np
import sys
import math

S = input()

mm = [0] * (2019)
mm[0] = 1
a = [0] * (len(S) + 1 ) 
T = 0
ten = 1
ll = len(S)
for i in range(ll):
    if i > 0:
        ten = ( ten * 10 ) % 2019
    a[i+1] =  ( a[i] + (int(S[ll-1-i])*ten ) ) % 2019
    mm[ a[i+1] ] += 1
    #print(s)

ans = 0

for m in mm:
    ans += int( (m * (m-1) ) / 2 )

print(ans)

Measured memory_bytes: 34172
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vi a(N);
	REP(i,N) cin >> a[i];
	int res = 0;
	for (int i = 0; i < N; i += 2) {
		if (a[i] % 2 == 1) ++res;
	}
	cout << res << endl; 
}

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


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

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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i,N) {
    cin >> p[i]; --p[i];
  }

  vector<bool> b(N);
  REP(i,N) b[i] = (p[i] == i);

  vector<int> tmp;
  REP(i,N) {
    if(b[i]) {
      int cnt = 0;
      while(i < N && b[i]) {
        ++i;
        ++cnt;
      }
      tmp.push_back(cnt);
    }
  }
  
  int res = 0;
  for(int e: tmp) {
    res += (e + 1) / 2;
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 1024
import math
def is_ok(mid,K,A):
    p = 0
    for i in A:
        p += (i - 1)// mid
    if p > K:
        return False
    else:
        return True
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.sort()
maxi = A[0]

ng = 0
ok = 10 ** 9
while(abs(ng - ok) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid,K,A):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 31228
import fractions

N=int(input())
A=list(map(int,input().split()))

L=[0]*(N+1)
R=[0]*(N+1)

def gcd(x,y):
    if x==0 or y==0:
        return max(x,y)
    return fractions.gcd(x,y)

for i in range(N):
    j=N-i

    L[i+1]=gcd(L[i],A[i])
    R[j-1]=gcd(R[j],A[j-1])
ans=0

for i in range(N):
    ans=max(ans,gcd(L[i],R[i+1]))

print(ans)

Measured memory_bytes: 89580
n, a, b = map(int, input().split())

PRIME = 10 ** 9 + 7
maximum = min(n + 1, 200001)

fac = [1 for i in range(maximum)]
finv = [1 for i in range(maximum)]
inv = [1 for i in range(maximum)]

fac[1] = n
for i in range(2, maximum):
  fac[i] = fac[i - 1] * (n + 1 - i) % PRIME
  inv[i] = PRIME - inv[PRIME % i] * (PRIME // i) % PRIME
  finv[i] = finv[i - 1] * inv[i] % PRIME

ans = pow(2, n, PRIME) - 1
ans = (ans + PRIME - ((fac[a] * finv[a])  % PRIME) % PRIME) % PRIME
ans = (ans + PRIME - ((fac[b] * finv[b])  % PRIME) % PRIME) % PRIME
print(ans)

Measured memory_bytes: 26776
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x, a[102] = {}, y = 890328;
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i], x -= a[i], y = min(y, a[i]);
    cout << n + x / y;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[4][4];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a[4][4];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cin >> a[i][j];
	ll ct = 0;
	ll n;
	cin >> n;
	for (int k = 0; k < n; k++)
	{
		ll x;
		cin >> x;
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (a[i][j] == x)
					b[i][j] = 1;
	}
	if (b[0][0] * b[1][1] * b[2][2] == 1)
		ct++;
	if (b[0][2] * b[1][1] * b[2][0] == 1)
		ct++;
	for (int i = 0; i < 3; i++)
	{
		if (b[i][0] * b[i][1] * b[i][2] == 1)
			ct++;
		if (b[0][i] * b[1][i] * b[2][i] == 1)
			ct++;
	}
	if (ct > 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;
int n,i;
double v[101];
int main()
{
    cin>>n;
    for(i=1;i<=n;++i)
        cin>>v[i];
    for(i=2;i<=n;++i)
        v[i]=(v[i-1]*v[i])/(v[i-1]+v[i]);
    cout<<v[n];
    return 0;
}

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

int main(){
    int64_t N, X;
    cin >> N >> X;
    vector<int64_t> x(N+1), S(N+1);
    for(int i=1; i<=N; i++){
        cin >> x[i];
        S[i] = S[i-1] + x[i];
    }

    int64_t ans = 1e18;
    for(int d=1; d<=N; d++){
        int64_t res = (N+d)*X;
        int pt = N;
        for(int64_t i=0; pt>0; i++){
            int nxt = max(0, pt-d);
            res += (S[pt]-S[nxt]) * (i==0 ? 5 : 2*i+3);
            if(res >= ans) break;
            pt = nxt;
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int d,w;
int e[13][13];

int main(){
	while(1){
		cin>>d>>w;
		if(d==0&&w==0)break;
		int ans=0;
		for(int i=0;i<d;i++){
			for(int j=0;j<w;j++){
				cin>>e[i][j];
			}
		}
		for(int i=0;i<d-2;i++){
			for(int j=i+2;j<d;j++){
				for(int k=0;k<w-2;k++){
					for(int l=k+2;l<w;l++){
						int out=INF;
						for(int m=0;m<l-k;m++)
							out=min(out,e[i][m+k]);
						for(int m=0;m<l-k;m++)
							out=min(out,e[j][m+k+1]);
						for(int m=0;m<j-i;m++)
							out=min(out,e[m+i+1][k]);
						for(int m=0;m<j-i;m++)
							out=min(out,e[m+i][l]);
						int tans=0;
						for(int m=i+1;m<j;m++){
							for(int n=k+1;n<l;n++){
								if(e[m][n]>=out){
									tans=0;
									goto A;
								}
								tans+=out-e[m][n];
							}
						}
						A:
						ans=max(ans,tans);
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
			
					
					
	



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

	int main(){
		
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	
		// #ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
		// #endif

		int n,W;
		cin >> n >> W;
		long long int w[n+1],v[n+1],dp[n+1][W+1];
		for(int i=0;i<n;i++){
			cin >> w[i+1] >> v[i+1];
		}
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=n;i++){
			for(int j=0;j<=W;j++){
				dp[i][j]=dp[i-1][j];
				if(j>=w[i]){
					dp[i][j]=max(dp[i][j],v[i]+dp[i-1][j-w[i]]);
				}
			}
		}
		cout << dp[n][W];
		


	
	
		
	
	}

Measured memory_bytes: 79232
n = int(input())
c = [[[0 for _ in range(10)] for _ in range(3)]for _ in range(4)]

for i in range(n):
    b, f, r, v = map(int, input().split())
    c[b-1][f-1][r-1] += v

i = 0
for j in c:
    for k in j:
        print('', *k)
    i += 1
    if 0 < i < 4:
        print('####################')


Measured memory_bytes: 5624
// =====================================================================================
//
//       Filename:  cp.cpp
//
//        Version:  1.0
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Priyank Kumar Singh ()
//   Organization:  RVCE Bangalore
//
// =====================================================================================


#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long ,long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin();
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin();
#define ct(i) cout<< i << "\n";
#define mod 1000000007
#define M 100005
vector<int> s[10];
/*
void dfs(int i, int j){
    int c=s[i][j];
    if(i==n-1 && j==m-1 ){
        ans = min(ans, c);
        return;
    }
    
    if(j+1<m) dfs(i,j+1);
    c+=s[i][j];
    if(i+1<n) dfs(i+1,j);
    c+=s[i][j];
}
int c1=0;
*/
vector<int> l[200000];

void prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i)
            l[i].pb(n);
    }
}


void answer(){
    ll x,n,m,ans=0;
    cin>>n>>m;
    vector<ll> v(n+1),r(n+1,0); 
    for(int i=0;i<n;i++){
        cin>>v[i+1];
    }
    while(m--){
        int a,b;
        cin>>a>>b;
        r[a] = max(v[b],r[a]);
        r[b] = max(r[b],v[a]);
    }
    for(int i=1;i<=n;i++){
        ans+=v[i]>r[i];
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int q;
    //cin>>q; while(q--)
        answer();

    return 0;
}


Measured memory_bytes: 9504
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
signed main()
{
    int n;
    cin >> n;
    set<int> se;
    int cc;
    for (int i = 1;; i++)
    {
        if (i == 1)
        {
            cc = n;
            se.insert(cc);
        }
        else
        {
            if (cc % 2 == 0)
            {
                cc /= 2;
                if (se.find(cc) != se.end())
                {
                    cout  << i << endl;
                    return 0;
                }
                else
                {
                    se.insert(cc);
                }
            }
            else
            {
                cc = 3 * cc + 1;
                if (se.find(cc) != se.end())
                {
                    cout << i << endl;
                    return 0;
                }
                else
                {
                    se.insert(cc);
                }
            }
        }
    }
    return 0;
}

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

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

int main() {
  int T; cin >> T >> ws;
  while(T--) {
    string buf;
    getline(cin, buf);
    //     cout << buf << endl;
    // i == buf.size()ÆÈé±Æà éB
    // eof <=> i == buf.size()
    int i = 0;
    int M; cin >> M >> ws;
    REP(m, M) {
      string line;
      string command, op;
      getline(cin, line);
      int j = 0;
      for(j = 0; line[j] != ' '; j++);
      command = line.substr(0, j);
      op = line.substr(j + 1);

      //       cout << command << " " << op << endl;
      if( command == "forward" ) {
        if( op == "word" ) {
          while( i < buf.size() && buf[i] == ' ' ) i++;
          while( i < buf.size() && buf[i] != ' ' ) i++;
        } else if( op == "char" ) {
          if( i != buf.size() ) i++;
        }
      }

      if( command == "backward" ) {
        if( op == "word" ) {
          i--;
          while( i >= 0 && buf[i] == ' ' ) i--;
          while( i >= 0 && buf[i] != ' ' ) i--;
          i++;
        } else if( op == "char" ) {
          if( i > 0 ) i--;
        }
      }

      if( command == "insert" ) {
        string text = op.substr(1, op.size() - 2);

        buf.insert(i, text);
        i += (int)text.size();
      }

      if( command == "delete" ) {
        if( i < buf.size() ) {
          if( op == "char" ) {
            buf.erase(i,1);
          }

          if( op == "word" ) {
            int len = 0;
            while( i + len < buf.size() && buf[i + len] == ' ' ) len++;
            if( i + len == buf.size() ) {
              ;
            } else {
              while( i + len < buf.size() && buf[i + len] != ' ' )len++;
              buf.erase( i, len );
            }
          }
        }
      }
//             cout << buf << " " << i <<  endl;

    }
    buf.insert(i, 1, '^');
    cout << buf << endl;
  }
  return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string s; cin >> s;

    int ans = 0;

    for (char c : s) {
        if (c == '1') {
            ++ans;
        }
    }
    
    cout << ans << endl;
}

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

using i64 = int64_t;

int main(){
    i64 n, W;
    cin >> n >> W;
    vector<pair<i64, i64>> vec;
    i64 mini = LLONG_MAX;
    for(int i=0;i<n;++i){
        i64 w, v;
        cin >> w >> v;
        vec.emplace_back(w, v);
        mini = min(w, mini);
    }
    vector<vector<i64>> items(4, vector<i64>());
    for(int i=0;i<n;++i){
        items[vec[i].first - mini].push_back(vec[i].second);
    }
    for(int i=0;i<4;++i)sort(items[i].rbegin(), items[i].rend());
    i64 ans = 0;
    for(i64 i=0;i<=items[0].size();++i){
        for(i64 j=0;j<=items[1].size();++j){
            for(i64 k=0;k<=items[2].size();++k){
                i64 wl = W - (i*mini + j*(mini+1) + k*(mini+2));
                if(wl < 0)continue;
                i64 l = wl / (mini+3);
                l = min(l, (i64)items[3].size());
                i64 sum = 0;
                for(i64 m=0;m<i;++m)sum += items[0][m];
                for(i64 m=0;m<j;++m)sum += items[1][m];
                for(i64 m=0;m<k;++m)sum += items[2][m];
                for(i64 m=0;m<l;++m)sum += items[3][m];
                ans = max(ans, sum);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<a*b+c*d-a*d-b*c<<endl;
}


Measured memory_bytes: 764
def exc(cookies, turn):
    exccs = 0
    subturn = (turn + 1) % 2
    if (cookies[turn] % 2) == 0:
        exccs = cookies[turn] //2
    else:
        exccs = (cookies[turn] - 1) // 2
    
    cookies[subturn] += exccs
    cookies[turn] = exccs

    return cookies

a, b, k = map(int, input().split())
cookies = [a, b]

for i in range(k):
    turn = i % 2
    cookies = exc(cookies, turn)

print("{} {}".format(cookies[0], cookies[1]))

Measured memory_bytes: 3064