akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	x := sc.ReadInt()

	books := make([]Book, n)
	for i := 0; i < n; i++ {
		book := Book{0, make([]int, m)}
		book.Price = sc.ReadInt()
		for j := 0; j < m; j++ {
			book.Powers[j] = sc.ReadInt()
		}
		books[i] = book
	}

	variationCount := Pow(2, uint(n))

	perms := make([][]bool, variationCount)
	for i := 0; i < variationCount; i++ {
		perms[i] = make([]bool, n)
		cur := i
		for j := n - 1; j >= 0; j-- {
			if cur%2 == 1 {
				perms[i][j] = true
			} else {
				perms[i][j] = false
			}
			cur /= 2
		}
	}

	minPrice := 0
	success := false
	for _, perm := range perms {
		price := 0
		powers := make([]int, m)
		for i := 0; i < n; i++ {
			if perm[i] {
				price += books[i].Price
				for algoI, power := range books[i].Powers {
					powers[algoI] += power
				}
			}
		}

		broken := false
		for _, power := range powers {
			if power < x {
				broken = true
				break
			}
		}
		if broken {
			continue
		}

		success = true
		if minPrice == 0 || price < minPrice {
			minPrice = price
		}
	}

	if !success {
		fmt.Println(-1)
	} else {
		fmt.Println(minPrice)
	}
}

type Book struct {
	Price  int
	Powers []int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 2324
N, X = map(int,input().split())
x = list(map(int,input().split()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
tmp = [abs(X-xx) for xx in x]
ans = tmp[0]
for i in range(1,N):
  ans = gcd(ans, tmp[i])
print(ans)

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

using namespace std;

using ll = long long;

using T = tuple<int, int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<T> v1(2 * n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v1[i] = T(a, b, 0);
    }

    for (int i = n; i < 2 * n; i++) {
        int a, b;
        cin >> a >> b;
        v1[i] = T(a, b, 1);
    }

    sort(v1.begin(), v1.end());

    int ans = 0;
    set<int> s;
    for (int i = 0; i < 2 * n; i++) {
        int a, b, c;
        tie(a, b, c) = v1[i];
        if (c == 0) {
            s.insert(b);
        } else {
            auto it = s.lower_bound(b);
            if (it != s.begin()) {
                --it;
                s.erase(it);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

//The House of Huge Family
public class Main{

	class E{
		int s, t, id;
		long c;
		public E(int s, int t, long c, int id) {
			this.s = s;
			this.t = t;
			this.c = c;
			this.id = id;
		}
	}
	
	int n, m;
	List<E>[] adj;
	
	boolean isCon(int f1, int f2){
		boolean[] u = new boolean[n];
		List<Integer> l = new ArrayList<Integer>();
		l.add(0); u[0] = true;
		int N = 0;
		while(!l.isEmpty()){
			List<Integer> next = new ArrayList<Integer>();
			for(int i:l){
				N++;
				for(E e:adj[i])if(!u[e.t]&&e.id!=f1&&e.id!=f2){
					u[e.t] = true; next.add(e.t);
				}
			}
			l = next;
		}
		return N==n;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt(); m = sc.nextInt();
			if((n|m)==0)break;
			adj = new List[n];
			for(int i=0;i<n;i++)adj[i]=new ArrayList<E>();
			int N = 0;
			long M = 0;
			List<Long> cost = new ArrayList<Long>();
			while(m--!=0){
				int s = sc.nextInt(), t = sc.nextInt();
				long c = sc.nextInt();
				if(c<=0)M+=c;
				else{
					cost.add(c); adj[s].add(new E(s, t, c, N)); adj[t].add(new E(t, s, c, N)); N++;
				}
			}
			long min = 1L << 40;
			if(!isCon(-1, -1))min = 0;
			for(int i=0;i<N;i++)if(!isCon(i, -1))min = Math.min(min, cost.get(i));
			for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)if(!isCon(i, j))min = Math.min(min, cost.get(i)+cost.get(j));
			System.out.println(M+min);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
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 main() {
    ll h,w;
    std::cin >> h>>w;
    ll result = 1e10;
    if(h>=3){
        if(h%3==0){
            result = 0;
        }else{
            result = min(result,w);
        }
    }
    if(w>=3){
        if(w%3==0){
            result = 0;
        }else {
            result = min(result,h);
        }
    }
    
    for (int i = 0; i < h-1; i++) {
        ll maxv = max({ (i+1)*w,(h-i-1)*(w/2),(h-i-1)*(w-w/2) });
        ll minv = min({ (i+1)*w,(h-i-1)*(w/2),(h-i-1)*(w-w/2) });
        result = min(result,maxv-minv);
    }
    for (int i = 0; i < w-1; i++) {
        ll maxv = max({ (i+1)*h,(w-i-1)*(h/2),(w-i-1)*(h-h/2) });
        ll minv = min({ (i+1)*h,(w-i-1)*(h/2),(w-i-1)*(h-h/2) });
        result = min(result,maxv-minv);
    }
    
    std::cout << result << std::endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
vector<vector<Pi>> G;
vector<set<int>> used;
vector<int> ans;


void dfs(int u,int p){
    for(auto v : G[u]){
        if(v.first == p) continue;
        int k = *used[u].lower_bound(0);
        int l = *used[v.first].lower_bound(0);
        int s = max(k,l);
        ans[v.second] = s;
        used[u].erase(s);
        used[v.first].erase(s);
        dfs(v.first,u);
    }
}

int main(){
    cin >> N;
    used.resize(N);
    ans.resize(N-1);
    G.resize(N);
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b,i);
        G[b].emplace_back(a,i);
    }
    rep(i,N){
        int d = G[i].size();
        rep(j,d){
            used[i].insert(j+1);
        }
    }
    dfs(0,-1);
    int ans1 = 0;
    rep(i,N-1){
        ans1 = max(ans1,ans[i]);
    }
    cout << ans1 << endl;
    rep(i,N-1){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
#include<bitset>
#include<iostream>
using namespace std;
#include<math.h>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#define ll long long
#define ld double
#include<stdio.h>
#define f first
#define s second
#include<stack>
#include<queue>
#define its set<int>::iterator
#define itmp map<int,int>::iterator
#include<stack>
#define lp for(int i=0;i<n;i++)
#define dlp for(int i=0;i<n;i++) for(int j=0;j<n;j++)
#define mod 1000000009
//#define N 101
//#include <boost/functional/hash.hpp>
//bitset<1000> b;
//b.set();   all bit have 1
//seive of Erat
//totient theorm for co-prime
/*ll int N=1000;
	int p[1001]={0};
	p[2]=1;
		vector<int>v;
        for(ll int i=3;i<=N;i+=2)
        p[i]=1;
        v.push_back(2);
        for(ll int i=3;i<=N;i+=2)
        {
            if(p[i])
            {
			v.push_back(i);
                for(ll int j=i*i;j<=N;j+=2*i)
                p[j]=0;
            }
        }  */
/*
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} */
/*
stringstream ss;  
ss<<c;  
string s1;
ss>>s1;
*/
/*
int power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}*/
int main()
{
	ios_base::sync_with_stdio(false); 
    	cin.tie(NULL); 
	 
      	ll int t=1;
	//cin>>t;
	while(t--)
	{
           int n;
           cin>>n;
           int c=0;
           int f=0;
           while(n--)
           {
               int x,y;
               cin>>x>>y;
               if(x==y)
               {
                   c++;
               }
               else
               {
                   c=0;
               }
               if(c==3)
                {
                    f=1;
                }
	}
    if(f)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    }
	return 0;
}

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

int main(){
  int K;
  cin >> K;
  int n=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      if((i%2==0)&&(j%2!=0)){
        n++;
      }
    }
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int maxN = 2e3 + 10;
int a[maxN] = {0};
 
int main(){
    int n, x, y, ans = 0;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < i; j++){
            a[min(i-j, abs(x - j) + abs(y - i) + 1)]++;
        }
    }
    for(int i = 1; i < n; i++)
        cout << a[i] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
char a[8][9];
int ans = 0;
while(1){
for(int i = 0; i < 8; i++){
if(scanf("%s",&a[i]) == EOF){
return 0;
}
}

for(int i = 0; i < 8; i++){

for(int j = 0; j < 8; j++){

if(a[i][j] == '1'){

if(i < 7 && j < 7){
if(a[i+1][j] == '1' && a[i][j+1] == '1' && a[i+1][j+1] == '1'){
printf("A\n");
}
}
if(i < 5){
if(a[i+1][j] == '1' && a[i+2][j] == '1' && a[i+3][j] == '1'){
printf("B\n");
}
}
if(j < 5){
if(a[i][j+1] == '1' && a[i][j+2] == '1' && a[i][j+3] == '1'){
printf("C\n");
}
}
if(i < 7 && j < 6){
if(a[i][j+1] == '1' && a[i+1][j+1] == '1' && a[i+1][j+2] == '1'){
printf("E\n");
}
}
if(i < 6 && j < 7){
if(a[i+1][j] == '1' && a[i+1][j+1] == '1' && a[i+2][j+1] == '1'){
printf("F\n");
}
}
if(j > 0 && i < 6){
if(a[i+1][j] == '1' && a[i+1][j-1] == '1' && a[i+2][j-1] == '1'){
printf("D\n");
}
}
if(j > 0 && j < 7 && i < 7){
if(a[i+1][j] == '1' && a[i][j+1] == '1' && a[i+1][j-1] == '1'){
printf("G\n");
}
}

}

}

}
}

	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

Measured memory_bytes: 948
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    //test
    {
        int n;
        cin>>n;
        if(n>=400 and n<=599)cout<<8;
        else if(n>=600 and n<=799)cout<<7;
        else if(n>=800 and n<=999)cout<<6;
        else if(n>=1000 and n<=1199)cout<<5;
        else if(n>=1200 and n<=1399)cout<<4;
        else if(n>=1400 and n<=1599)cout<<3;
        else if(n>=1600 and n<=1799)cout<<2;
        else if(n>=1800 and n<=1999)cout<<1;

    }

End;
}


Measured memory_bytes: 3628
/**
 *  Hi, I'm Arpan.
 *
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
#define inv(v)         \
    for (auto &it : v) \
        cin >> it;
#define MOD 1000000007
#define pb push_back
#define popb pop_back()
#define endl "\n"
#define fi first
#define se second
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
#define sortv(v) sort(v.begin(),v.end())
#define rsortv(v) sort(v.begin(),v.end(), greater<>());

ll modPower(ll num,ll r) {
	if(r==0) return 1;
	if(r==1) return num%MOD;
	ll ans=modPower(num,r/2)%MOD;
	if(r%2==0) {
		return (ans*ans)%MOD;
	} return (((ans*ans)%MOD)*num)%MOD;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    if (r > n - r) {
        r = n - r;
    }
    for(int i=0;i<r;i++) {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

/*******************************************/
//
void solve()
{
    int n;
    cin >> n;
    vl arr(n);
    inv(arr);
    sortv(arr);
    ll ans = 0;
    int c = 2;
    int i=2;
    ans+= arr[n-1];
    while(c <= n){
            if(c+1 <= n){
                ans+= arr[n-i];
            }
            c++;
            if(c+1 <= n){
                ans+=arr[n-i];
            }
            c++;
            i++;
    }

    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;

    while (t--)
        solve();
    return 0;
}




Measured memory_bytes: 4788
dice = {
    '1': {'F':'2', 'R':'4', 'B':'5', 'L':'3'},
    '2': {'F':'6', 'R':'4', 'B':'1', 'L':'3'},
    '3': {'F':'6', 'R':'2', 'B':'1', 'L':'5'},
    '4': {'F':'6', 'R':'5', 'B':'1', 'L':'2'},
    '5': {'F':'6', 'R':'3', 'B':'1', 'L':'4'},
    '6': {'F':'5', 'R':'4', 'B':'2', 'L':'3'}
}

faces = list(map(int, input().split()))
q = int(input())

rightSide = {'F':'L','R':'F','B':'R','L':'B'}

for i in range(q):
    top, front = list(map(int, input().split()))
    topIdx = str(faces.index(top) + 1)
    frontIdx = str(faces.index(front) + 1)
    for k,v in dice[topIdx].items():
        if v[0] == str(frontIdx):
            faceIdx = dice[topIdx][rightSide[k]]
            print(faces[int(faceIdx)-1])
            break

Measured memory_bytes: 7764
n=int(input())
la=list(map(int,input().split()))
s=sum(la)
lk=[2*la[1+2*i] for i in range(n//2)]
k=sum(lk)
ly=[s-k]
for i in range(n-1):
    ly.append(2*la[i]-ly[i])
for k in ly:
    print(k,end=" ")


Measured memory_bytes: 14388
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
lim = N+10  # 必要そうな階乗の限界を入れる
fact = [1] * (lim+1)
fact_inv = [1] * (lim+1)
for n in range(1, lim+1):
    fact[n] = (fact[n-1] * n) % mod
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
    fact_inv[n-1] = (n * fact_inv[n]) % mod

tree = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(N-1):
	a, b = MAP()
	tree[a].append(b)
	tree[b].append(a)

order = []
parent = [0]*(N+1)
stack = [1]
while stack:
    n = stack.pop()
    order.append(n)
    for node in tree[n]:
        if node == parent[n]:
            continue
        stack.append(node)
        parent[node] = n

size = [1]*(N+1)
for v in order[::-1]:
    size[parent[v]] += size[v]

dpLeaf = [1] * (N+1)
for v in order[::-1]:
    pr = parent[v]
    dpLeaf[v] = dpLeaf[v]*fact[size[v]-1]%mod
    dpLeaf[pr] = dpLeaf[pr]*dpLeaf[v]*fact_inv[size[v]]%mod

ans = [0]*(N+1)
ans[1] = dpLeaf[1]
for v in order[1:]:
    pr = parent[v]
    ans[v] = (ans[pr]*pow(N-size[v], mod-2, mod)*size[v])%mod
print(*ans[1:], sep="\n")


Measured memory_bytes: 136720
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	while (1) {
		int a, d, n;
		cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0) break;
		
		/*if (a == 1 && d == 1 && n == 1) {
			cout << 2 << endl;
			continue;
		}*/

		int cnt = 0, t, k = 0;
		while (1) {
			t = a + d*k;
			bool flag = true;
			for (int i = 2; i*i <= t; i++) {
				if (t%i == 0) {
					flag = false;
					break;
				}
			}
			if (flag && t!=1) cnt++;
			if (cnt == n) {
				cout << t << endl;
				break;
			}
			k++;
		}
	}


	return 0;
}

Measured memory_bytes: 2960
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = a[::-1]
    for x in range(n):
        if x != n - 1:
            print(a[x], end = " ")
        else:
            print(a[x])


if __name__ == "__main__":
    main()

Measured memory_bytes: 7768
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
using ll = long long;
std::vector<std::pair<int, int> > ans;
int seq[105];
int main()
{
	// freopen("AGC032-B.in", "r", stdin);
	int n, cur = 0, len = 0;
	scanf("%d", &n);
	if (n & 1)
	{
		n--;
		for (int i = 0; i < n; i++)
			ans.emplace_back(i, n);
	}
	auto add = [&]
	{
		for (int x = 0; x < len; x++)
		{
			if (seq[x] < cur)
				ans.emplace_back(seq[x], cur);
		}
		cur++;
	};
	for (int i = 1; i + 1 < n; i++)
		seq[len++] = i;
	add();
	for (int i = 0, j = len - 1; i < j; i++, j--)
	{
		seq[i]--;
		seq[j]++;
		add();
	}
	add();
	for (int i = (len >> 1) - 1, j = len >> 1; i >= 0; i--, j++)
	{
		seq[i]++;
		seq[j]--;
		add();
	}
	printf("%d\n", (int)ans.size());
	for (auto &it : ans)
		printf("%d %d\n", it.first + 1, it.second + 1);
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.text.*;

public class Main {

	static int[] w, v;
	static long dp[][];

	public static long dp(int i, int remw) {

		if (remw < 0)
			return -(int) 1e9;
		if (i == w.length)
			return 0;
		if (dp[i][remw] != -1)
			return dp[i][remw];
		return dp[i][remw] = Math.max(dp(i + 1, remw), v[i] + dp(i + 1, remw - w[i]));
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int maxw = sc.nextInt();
		w = new int[n];
		v = new int[n];
		for (int i = 0; i < w.length; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		dp = new long[n][maxw + 1];
		for (long[] x : dp) {
			Arrays.fill(x, -1);
		}
		pw.println(dp(0, maxw));
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


Measured memory_bytes: 126420
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main(void) {
	int N, M;
	cin >> N >> M;
	int K;
	cin >> K;
	for (int n = 0; n <= N; n++) {
		for (int m = 0; m <= M; m++) {
			if (n * M + m * N - 2 * n * m == K) {
				cout << "Yes" << endl;
				system("pause");
				return 0;
			}
		}
	}
	cout << "No" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
long long mod = 1e9 + 7;
const int N = 3e5 + 500;

long long n, m, u, v, k, t, q, a, h;


int arr[N];


int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   
   for (int i = 0; i < n; ++i) {
      cin >> arr[i];
   }
   
   long long best = 0;
   
   for (int diff = 1; diff < n; ++diff) {
      long long cur = 0;
      int x = diff, y = n - 1 - diff;
      while (x + diff < n - 1) {
         cur += arr[x];
         cur += arr[y];
         if (x >= y and ((n - 1) % diff) == 0) break;
         best = max(best, cur);
         x += diff;
         y -= diff;
      }
   }
   
   cout << best << endl;
}






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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
int n;
int A[N];

ll power(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

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

  int j;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> j;
    ++A[j];
  }

  bool ok = true;
  if (n & 1) {
    if (A[0] != 1) ok = false;
    for (int i = 2; i <= n - 1; i += 2) {
      if (A[i] != 2) {
        ok = false;
        break;
      }
    }
    if (ok)
      cout << power(2, (n - 1) / 2) << endl;
    else
      cout << 0 << endl;
  } else {
    for (int i = 1; i <= n - 1; i += 2) {
      if (A[i] != 2) {
        ok = false;
        break;
      }
    }
    if (ok)
      cout << power(2, n / 2) << endl;
    else
      cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <numeric>

#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    int N;
    cin>>N;
    vector<vector <int> > XY (N, vector<int>(2, 0));

    for (int i = 0; i < N; ++i) {
        cin >> XY[i][0] >> XY[i][1];
    }
    int distance_num;
    distance_num=0;
    for (int n = 0; n < N-1; ++n) {
        distance_num += n+1;
    }
    vector<vector<double> >distance(N,vector<double>(N));
    double ans;
    ans =0;

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j <N ; ++j) {
            distance[j][i] = sqrt(pow(XY[i][0]-XY[j][0],2)+pow(XY[i][1]-XY[j][1],2));
            distance[i][j] = sqrt(pow(XY[i][0]-XY[j][0],2)+pow(XY[i][1]-XY[j][1],2));
        }
    }
    vector<int>v(N);
    iota(v.begin(),v.end(),0);
    double sum;
    do{
        sum = 0;
        for(int k = 0; k<N-1;++k){
            sum+=distance[v[k]][v[k+1]];
        }
        ans += sum;
    }while(next_permutation(v.begin(),v.end()));

    int Nk;
    Nk=1;
    for (int m = 0; m < N; ++m) {
        Nk *= N-m;
    }
    ans =ans/Nk;
    printf("%.10f\n",ans);

}


Measured memory_bytes: 256
def main():
    n, k, *x = map(int, open(0).read().split())
    x = tuple(x)
    l = x[0 + k - 1] - x[0] + min(abs(x[0 + k - 1]), abs(x[0]))

    for i in range(n - k + 1):
        y = x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i]))
        if y < l:
            l = y

    print(l)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14052
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,K;
    cin >> N >> K;
    vector<pair<ll,ll>> pos(N);
    vector<ll> x(N);
    vector<ll> y(N);
    for(ll i = 0; i < N; i++){
        ll tmpX,tmpY;
        cin >> tmpX >> tmpY;
        pos[i] = pair<ll,ll>(tmpX,tmpY);
        x[i] = tmpX;
        y[i] = tmpY;
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    unsigned long long S = 1ull << 63;
    for(ll xs = 0; xs < N - 1; xs++){
        for(ll xt = xs + 1; xt < N; xt++){
            for(ll ys = 0; ys < N - 1; ys++){
                for(ll yt = ys + 1; yt < N; yt++){
                    ll count = 0;
                    for(ll i = 0; i < N; i++){
                        if((x[xs] <= pos[i].first) && (pos[i].first <= x[xt]) && (y[ys] <= pos[i].second) && (pos[i].second <= y[yt])){
                            count++;
                        }
                    }
                    if(count >= K){
                        S = min(S,(unsigned long long)(x[xt] - x[xs]) * (unsigned long long)(y[yt]- y[ys]));
                    }
                }
            }
        }
    }
    cout << S << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include <queue>
#include<cstdio>
#include<algorithm>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
using namespace std;
int n;
int main(){
    while(scanf("%d",&n) == 1 && n){
        long long sum = 0;
        vector<long long> a(n);
        for(int i = 0;i < n; ++i){
            scanf("%lld", &a[i]);
            sum += a[i];
        }
        int cnt = 0;
        for(int i = 0;i < n; ++i){
            if(a[i] * n <= sum){
                cnt ++;
            }
        }
        printf("%d\n", cnt);
    }
    
    return 0;
}



Measured memory_bytes: 3272
S = input()
N = len(S)

def kaibun(s):
    n = len(s)
    f_kaibun = True
    for i in range(int(n/2)):
        j = n-1-i
        if j <= i:
            break
        if s[i] != s[j]:
            f_kaibun = False
            break
    return f_kaibun

if kaibun(S) and kaibun(S[0:int(round((N-1)/2))]) and kaibun(S[int(round((N+3)/2))-1:N]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61176
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int d;
    cin >> d;
    cout << "Christmas";
    REP(i,25-d){
        cout << " Eve";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [list(input()) for _ in range(n)]

for i in range(n):
    for j in range(n-i-1):
        if w[i] == w[-j-1]:
            print('No')
            exit()

for i in range(n):
    if i < n-1:
        if w[i][-1] != w[i+1][0]:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 9188
s=input()
ans=[0]*len(s)
import itertools
i=0
for key,g in itertools.groupby(s):
  num=len(list(g))
  if key=="R":
    i+=num
    ans[i-1]+=(num//2+(num%2>0))
    ans[i]+=num//2
  elif key=="L":
    ans[i-1]+=num//2
    ans[i]+=(num//2+(num%2>0))
    i+=num
  if i>=len(ans):
    break
print(*ans)


Measured memory_bytes: 6424
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]

import copy
import itertools
c_copy = copy.deepcopy(c)

tate_options = list(itertools.product([0,1],repeat=W))
yoko_options = list(itertools.product([0,1],repeat=H))

answer = 0
for tate_option in tate_options:
    for yoko_option in yoko_options:
        count = 0
        for i in range(W):
            if tate_option[i] == 1:
                continue
            for j in range(H):
                if yoko_option[j]==1:
                    continue

                if c[j][i] == "#":
                    count += 1
        if count == K:
            answer += 1
print(answer)

Measured memory_bytes: 69468
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
      int a=sc.nextInt();int b=sc.nextInt();
      int p=1;
      double pd=-0.006*sc.nextInt()+a;
      for(int i=0;i<n-1;i++){
        double po=-0.006*sc.nextInt()+a;
        if(Math.abs(po-b)<Math.abs(pd-b)){
        	p=i+2;
            pd=po;
        }
      }
      System.out.println(p);
    }
}


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

int main() {
  
  int N,K;
  cin >> N >> K;
  int j=0;
  int S=0;
  while(j<N){
   int x ;
   cin >> x;
   int A=x;
   int B=K-x;
    
    if (A<B){
    S+=2*A;
    }
    else {
    S+=2*B;
    }
    
    j++;
  
  }
  
  cout << S << endl;
  
}
  

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

int solve(string s){
	int ans=0;
	for(int i=0; i<s.length()/2; i++){
		if(s[i] != s[s.length()-1-i]){
			ans++;
		}
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string str;
    cin >> str;
	cout << solve(str);
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n; cin>>n;
    ll h[n];
    ll ans[n+3];
    memset(ans,0,sizeof(ans));
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        ans[i]=1e18;
    }
    ans[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=2;j++)
            ans[i+j]=min(ans[i+j],ans[i]+abs(h[i+j]-h[i]));
    }
    cout<<ans[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n;
    string s;
    cin >> n >> s;

    ll cntR = 0;
    rep(i, n) {
        if(s[i] == 'R') {
            cntR++;
        }
    }

    ll ans = 0;
    rep(i, cntR) {
        if(s[i] == 'W') {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;
  
  int mind = 10000;
  for(int i = 2; i < S.length(); i++){
    int h = S.at(i-2) - '0';
    int t = S.at(i -1) - '0';
    int o = S.at(i) - '0';
    int sum = h * 100 + t * 10 + o;
    mind = min(abs(sum - 753),mind);
  }
  cout << mind;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int ans = 0;
	for (int i = 1; i < N; i++) {
		int K = A[i - 1] - A[i];
		if (K < 0)
			K = 0;
		ans += K;
		A[i] += K;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4788
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
 
import java.util.*;
class Main {
     
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String tar = sc.next().toLowerCase();
        int count = 0;
        while(true) {
            String tmp = sc.next();
            if(tmp.equals("END_OF_TEXT")) break;
            if(tar.equals(tmp.toLowerCase())) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26332
//Love and Freedom.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define pa pair<int,int>
#define mp make_pair
#define fs first
#define se second
#define ll long long
#define inf 20021225
#define N 20
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
	return f*s;
}
map<pa,ll> f[N][N]; int a[N];
ll dfs(int l,int r,int xl,int xr)
{
	if(r==l+1)	return 0;
	if(f[l][r].count(mp(xl,xr)))	return f[l][r][mp(xl,xr)];
	ll ans=1e18;
	for(int k=l+1;k<r;k++)
		ans=min(ans,dfs(l,k,xl,xl+xr)+dfs(k,r,xl+xr,xr)+1ll*(xl+xr)*a[k]);
	return f[l][r][mp(xl,xr)]=ans;
}
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)	a[i]=read();
	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    
    sort(a.begin(), a.end());
    int ans = 0;

    for(int i=0; i<N; i++){
        if(x - a[i] < 0) break;
        if(i == N-1 && x - a[i] != 0) break;
        x -= a[i];
        ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	long long a, b = 0;

	cin >> a >> b;

	long long c = b - a;

	long long l = 0;
	long long Ans = 0;

	for (int i = 1; i < 1001; i++) {
		l = l + i;
		if (i == c) {
			Ans = l - b;
		}
	}

	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define fo(i, a, b) for(int i = a; i <= b; i++)
#define _fo(i, a, b) for(int i = a; i >= b; i--)
#define foa(i, a) for (auto &i : a)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 3e3+5;
const int MAX = 2e5+5;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

pii bcell[N];
ll total[N];
ll fac[MAX], infac[MAX]; 

ll add(ll a, ll b) { return (a+b) % MOD; }
ll sub(ll a, ll b) { return (a-b+MOD) % MOD; }
ll mul(ll a, ll b) { return (a*b) % MOD; }

ll inv(ll val) {
	ll curr = 1, temp = MOD-2;
	
	while(temp > 0) {
		if(temp & 1) curr = mul(curr, val);
		val = mul(val, val);
		temp >>= 1;
	}
	
	return curr;
}

void precompute(ll mx) {
	fac[0] = 1;
	fo(i, 1, mx) fac[i] = mul(i, fac[i-1]);
	infac[mx] = inv(fac[mx]);
	_fo(i, mx-1, 0) infac[i] = mul(i+1, infac[i+1]);
}

ll nCr(int a, int b) {
	return mul(mul(fac[a], infac[a-b]), infac[b]);
}

ll solve(int n) {
	fo(i, 1, n) {
		ll curr = nCr(bcell[i].fi+bcell[i].se-2, bcell[i].fi-1), invalid = 0;
		_fo(j, i-1, 1) {
			if(bcell[i].se >= bcell[j].se) {
				int dx = bcell[i].fi-bcell[j].fi, dy = bcell[i].se-bcell[j].se;
				invalid = add(invalid, mul(total[j], nCr(dx+dy, dx)));	
			} 
		}
		total[i] = sub(curr, invalid);
	}
	return total[n];
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int h, w, n;
	
	cin >> h >> w >> n;
	fo(i, 1, n) cin >> bcell[i].fi >> bcell[i].se;
	
	precompute(h+w);
	sort(bcell+1, bcell+n+1);
	bcell[++n] = {h, w};
	
	cout << solve(n);  
}

Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define base 196471
int a, b;
int main() {
	cin >> a >> b;
	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
	}
	else if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
	}
	else if (a < 0 && b < 0) {
		if (abs(b - a) % 2 != 0) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;if(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int a[101],dp[51][101][101];
int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    //cerr<<setprecision(9)<<fixed;
    int T,i,j,k,ca=0,m,K,n;
    scanf("%d",&n);m=2*n-1;
    map<int,int>g;
    rep(i,0,m){
        scanf("%d",&a[i]);g[a[i]]=1;
    }
    int id=0;
    for(auto &o:g)o.y=++id;
    rep(i,0,m)a[i]=g[a[i]];
    sort(a,a+m);
    dp[0][1][0]=1;
    int ans=0;
    rep(i,0,n){
        rep(j,1,a[n+i-1]-a[n-i-1]+2){
            rep(k,0,j)if(dp[i][j][k]){
                if(i==n-1){
                    add(ans,dp[i][j][k]);continue;
                }
                int nj=j,nk=k;
                if(a[n-i-1]!=a[n-i-2])nj++,nk++;
                if(a[n+i-1]!=a[n+i])nj++;
                rep(l,0,nj)add(dp[i+1][nj-max(abs(l-nk)-1,0)][l-max(l-nk-1,0)],dp[i][j][k]);
            }
        }
    }
    printf("%d\n",ans);
    //cerr<<clock()*1./CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << N*N*N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
const int maxn = 1e6 + 10;
int a[maxn], pos[maxn], dp[maxn];
int32_t main(){
	IOS;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]--;
		pos[a[i]] = i;
	}
	dp[n - 1] = 1;
	int ans = 1;
	for(int i=n-2; i>=0; i--){
		dp[i] = (pos[i+1] > pos[i] ? dp[i+1] + 1 : 1);
		ans = max(ans, dp[i]);
	}
	cout << n - ans << endl;
}


Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int n,a[100042],x,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>n)
			ans++;
		else
			a[x]++;
	}
	for(int i=1;i<=n;i++)
	 if (a[i])
		if(a[i]<i)
			ans+=a[i];
		else if(a[i]>i)
			ans+=a[i]-i;
	cout<<ans;
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/12/13  Problem: a / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

	int N, M; cin >> N >> M;
	if (abs(N - M) > 1) {
		cout << 0 << endl;
	}
	else {
		function<LL(LL)> f = [&](LL x) {
			if (x == 0)return 1LL;
			else return (x*f(x-1)) % MOD;
		};
		LL ans = (f(N)*f(M)) % MOD;
		if (N == M)ans = (ans * 2) % MOD;
		cout << ans<< endl;
	}

	return 0;
}


Measured memory_bytes: 3328