akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import static java.lang.System.out;

class Rectangle {
    private int area;
    private int perimeter;

    Rectangle(int height, int width) {
        this.area = height * width;
        this.perimeter = (height * 2) + (width * 2);
    }

    @Override
    public String toString() {
        return String.format("%d %d", this.area, this.perimeter);
    }
}

public class Main {
    public static void main( String... args) {
        Scanner scan = new Scanner( System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        out.println(new Rectangle(a, b));
    }
}

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

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


Measured memory_bytes: 3620
#include<stdio.h>
int kansu(int);
struct Card{
  char suit;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;
  int a=0;
  a=kansu(a);
  if(a == 0){
  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].suit, &C1[i].value);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}
}

int kansu(int a){
   return a;
}


Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N,M;
vector<edge> G[100010];
int d[100010];
int d2[100010];

void Dijkstra(int s){
	std::priority_queue<P,vector<P>,std::greater<P>> que;
	std::fill(d,d+N,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p =que.top();que.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(int i=0;i<(signed)G[v].size();i++){
			edge e =G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

signed main(){
	cin>>N;
	M=N-1;
	REP(i,M){
		int a,b;
		cin>>a>>b;
		edge e;
		e.to=b-1,e.cost=1;
		G[a-1].push_back(e);
		e.to=a-1;
		G[b-1].push_back(e);
	}
	Dijkstra(N-1);
	REP(i,N){
		d2[i]=d[i];
	}
	int ans1=0,ans2=0;
	Dijkstra(0);
	REP(i,N){
		if(d[i]<=d2[i]){
			ans1++;
		}
		else{
			ans2++;
		}
	}
	if(ans1>ans2){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}


Measured memory_bytes: 9876
import bisect
N=int(input())
A=sorted(map(int,input().split()))
B=map(int,input().split())
C=sorted(map(int,input().split()))
ans=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
print(ans)

Measured memory_bytes: 26656
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> data(N);
    for (auto &i: data) cin >> i.first >> i.second;
    sort(data.begin(), data.end());
    for (auto i: data) cerr << i.first << " " << i.second << endl;
    int nokori = M;
    long long ans = 0;
    for (auto i: data)
    {
        if (nokori <= i.second)
        {
            ans += (long long)i.first * nokori;
            break;
        }
        ans += (long long)i.first * i.second;
        nokori -= i.second;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if(z >= 0 && z <= k) ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
import sys
N = int(sys.stdin.readline().rstrip())
D = list(map(int, sys.stdin.readline().rstrip().split()))
D_sum = 0 
D_sum_gusu = 0

for i, d in enumerate(D, 1):
    D_sum += d
    if i % 2 == 0:
        D_sum_gusu += d

ans = []

r = D_sum - 2 * D_sum_gusu
ans.append(r)
for d in D[:-1]:
    r = 2 * d - r
    ans.append(r)

print(" ".join(map(str, ans)))

Measured memory_bytes: 81048
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
p = 0
D = {N-1-2*i: 0 for i in range((N+1)//2)}
for i in A:
  if i in D:
    D[i] += 1
s = 0
if sum(D[i] for i in D) == N and max(D[i] for i in D) == 2:
  if 0 in D:
    if D[0] == 1:
      s = 1
  else:
    s = 1
elif N == 1 and 0 in D:
  s = 1
if s == 1:
  p = 1
  for i in range(N//2):
    p *= 2
    p %= mod
print(p)

Measured memory_bytes: 14692
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000009
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,a[20],b[20],c[20],fa[50],dep[50],cnt[50];
ll ans=0,p[3000005],P[3000005],X[1000005],Y[1000005];
vector<int> A,B;
int find(int x){
	if (fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
void unite(int x,int y){
	x=find(x),y=find(y);
	if (x==y) return ;
	if (dep[x]<dep[y]){
		fa[x]=y;
		return ;
	}
	fa[y]=x;
	if (dep[x]==dep[y])
		dep[x]++;
}
ll solve(){
	memset(cnt,0,sizeof(cnt));
	for (int i=1;i<=45;i++)
		fa[i]=i;
	for (int i=1;i<=m;i++)
		if (!c[i]) unite(a[i],b[i]);
	for (int i=1;i<=45;i++)
		cnt[find(i)]++;
	int c3=0,c2=0;
	for (int i=1;i<=45;i++){
		if (cnt[i]>3) return 0;
		if (cnt[i]==3) c3++;
		if (cnt[i]==2) c2++;
	}
	int c1=3*n-3*c3-2*c2;
	if (c1<c2) return 0;
	ll res=(p[c1]*P[c1-c2])%mod;
	res=(res*p[c1-c2])%mod;
	res=(res*X[(c1-c2)/3])%mod;
	res=(res*Y[(c1-c2)/3])%mod;
	return res;
}
void dfs(int now,int cnt){
	if (now>m){
		if (cnt&1)
			ans=(ans-solve()+mod)%mod;
		else
			ans=(solve()+ans)%mod;
		return ;
	}
	dfs(now+1,cnt);
	if (c[now]){
		c[now]=0;
		dfs(now+1,cnt+1);
		c[now]=1;
	}
}
ll pow(ll x,int y){
	ll res=1;
	while (y){
		if (y&1) res=(res*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return res%mod;
}
int main(){
	p[0]=1;
	n=read(),m=read();
	for (int i=1;i<=3*n;i++)
		p[i]=(p[i-1]*(ll) i)%mod;
	for (int i=max(0,3*n-100);i<=3*n;i++)
		P[i]=pow(p[i],mod-2);
	for (int i=max(0,n-100);i<=n;i++)
		X[i]=pow(p[i],mod-2);
	for (int i=max(0,n-100);i<=n;i++)
		Y[i]=pow(pow((ll) 6,i),mod-2);
	for (int i=1;i<=m;i++)
		a[i]=read(),b[i]=read(),c[i]=read();
	for (int i=1;i<=m;i++)
		A.push_back(a[i]),A.push_back(b[i]);
	sort(A.begin(),A.end());
	A.erase(unique(A.begin(),A.end()),A.end());
	for (int i=1;i<=m;i++){
		a[i]=lower_bound(A.begin(),A.end(),a[i])-A.begin()+1;
		b[i]=lower_bound(A.begin(),A.end(),b[i])-A.begin()+1;
	}
	dfs(1,0);
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 26648
n=gets.to_i
a,b=gets.split.map &:to_i
p=gets.split.map(&:to_i).sort
cnt1,cnt2=0,0
p.map{|i|cnt1+=1 if i<=a}
p.map{|i|cnt2+=1 if (i>=a+1 and i<=b) }
puts [cnt1,cnt2,n-(cnt1+cnt2)].min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
string s;
int flag;
int main()
{
	cin>>s;
	if(s[0]!='A'){
		puts("WA");return 0;
	}
	for(int i=2;i<=s.length()-2;i++){
		if(s[i]=='C') flag++;
	}
	if(flag!=1){
		puts("WA");return 0;
	}
	for(int i=0;i<s.length();i++)
	 if(s[i]>='A'&&s[i]<='Z'&&s[i]!='A'&&s[i]!='C'){
	 	puts("WA");return 0;
	 }
	puts("AC");
	return 0;
} 

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    S = input()
    cnt = 0
    for i in range(1,N):
        if S[i] == S[i-1]:
            cnt += 1
    ans = min(N-1,cnt+2*K)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 68564
from fractions import gcd
import math

mod = 998244353

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def S(x1, y1, x2, y2, x3, y3):
    return heron(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), math.sqrt((x1 - x3)**2 + (y1 - y3)**2), math.sqrt((x3 - x2)**2 + (y3 - y2)**2))

def heron(a, b, c):
    try:
        d = (a + b + c) / 2
        return round(math.sqrt(d * (d - a) * (d - b) * (d - c)) * 2)
    except Exception as e:
        return 0

def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        if len(str(i)) % 2 == 1:
            ans += 1
    print(ans)
main()


Measured memory_bytes: 5680
T = 1000
def f(x):
    return max(0, T + 1 - abs(T - x))
while True:
    try:
        n = input() 
    except EOFError:
        break
    cnt = 0
    for i in range(n+1):
        cnt += f(i) * f(n-i)
    print cnt

#O(n), 

Measured memory_bytes: 4336
n, m = map(int, input().split())

A = []
B = []
for i in range(m):
    a, b= map(int, input().split())
    A.append(a)
    B.append(b)
t = 0
ans = 0
for i in range(10000):
    t = 0
    if len(str(i)) == n:
        for j in range(m):
            if int(str(i)[A[j] - 1]) == B[j]:
                t += 1
        if t == m:
            print(i)
            ans = 1
            break
if ans == 0:
    print(-1)

Measured memory_bytes: 40688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;
 
int main(){
  ll x;
  cin >> x;
  for(ll i=-1000;i<=1000;++i){
    for(ll j=-1000;j<=1000;++j){
      if( pow(i,5) - pow(j,5) == x ){
        cout << i << " " << j << "\n";
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<map>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const ll MOD = 1000000007;// 10^9+7
const int INF = (1ll << 30);


//変数
int N, Ma, Mb;
vector<vector<int>> l, r;
int suma = 0;




//サブ関数
//入力
void input()
{
	cin >> N >> Ma >> Mb;
	int rcnt = min(N / 2, 19);
	l.resize(N-rcnt, vector<int>(3));
	r.resize(rcnt, vector<int>(3));
	REP(i, N - rcnt) REP(j, 3)cin >> l[i][j];
	REP(i, rcnt) REP(j, 3)cin >> r[i][j];

	if (Ma < Mb) {
		swap(Ma, Mb);
		for (auto& row : l)swap(row[0], row[1]);
		for (auto& row : r)swap(row[0], row[1]);
	}

	for (const auto& row : l)suma += row[0];
	for (const auto& row : r)suma += row[0];
}

vector<int> bit2value(const vector<vector<int>>& obj, const int i)
{
	const int N = obj.size();
	int a = 0;
	int b = 0;
	int c = 0;

	REP(j, N) if (i&(1 << j)) {
		a += obj[j][0];
		b += obj[j][1];
		c += obj[j][2];
	}
	return { a,b,c };
}

map<int, map<int, int>> make_half(const vector<vector<int>>& obj)
{
	const int N = obj.size();
	map<int, map<int, int>> res;

	REP(i, 1 << N) {
		auto sum = bit2value(obj, i);
		int a = sum[0];
		int b = sum[1];
		int c = sum[2];

		if (res[a].find(b) == res[a].end()) {
			res[a][b] = c;
		}
		else {
			res[a][b] = min(res[a][b], c);
		}
	}
	return res;
}


int find_pair(map<int, map<int, int>>& other, const vector<int>& sum)
{
	int cost = INF;
	int a = sum[0];
	int b = sum[1];
	int c = sum[2];
	FOR(times, 1, suma / Ma + 1)
	{
		ll obja = Ma * times;
		ll objb = Mb * times;
		ll resta = obja - a;
		ll restb = objb - b;
		if (resta < 0)continue;
		if (restb < 0)continue;

		//if (other.find(resta) == other.end())continue;
		if (other[resta].find(restb) == other[resta].end())continue;
		cost = min(cost, other[resta][restb]);
	}
	return cost + c;
}


//計算
void calc()
{
	int cost = INF;
	int rsiz = r.size();
	auto lhalf = make_half(l);
	
	REP(i, 1 << rsiz)
	{
		auto sum = bit2value(r, i);
		if (sum[2] > cost)continue;
		auto bestCost = find_pair(lhalf, sum);
		cost = min(cost, bestCost);
	}

	cout << (cost == INF ? -1 : cost) << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int N;
vector<int> flag(101);

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        flag.at(d) = 1;
    }

    int ans = 0;
    for (int i = 0; i < 101; i++) {
        ans += flag.at(i);
        // cout << i << " " << flag.at(i) << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    for(int i=0;i<N;i++) cin >> c[i] >> t[i];
    int ans=1000;
    bool flag=false;
    for(int i=0;i<N;i++){
        if(t[i]<=T){
            ans=min(ans, c[i]);
            flag=true;
        }
    }
    if(flag) cout << ans << endl;
    else cout << "TLE" << endl;
    return 0;

}

Measured memory_bytes: 256
// AOJ 1080: Everything Starts With Your Vote
// 2018.2.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ		150011
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int id)
{
	unsigned i = 0;
	int inc = *s;
	char *p = s;
	HASH *tp;

	while (*p) i = (i<<5) + *p++; i %= HASHSIZ;
	tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	tp->s = s, tp->id = id;
}

int lookup(char *s)
{
	unsigned i = 0;
	int inc = *s;
	char *p = s;
	HASH *tp;

	while (*p) i = (i<<5) + *p++; i %= HASHSIZ;
	tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	return -1;
}

typedef struct { char *nm; int x; char fav; } T;
T tbl[100002], *fav;
char name[100002][22];
int N, M, K, L;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(T *a, T *b)
{
	if (a->fav - b->fav) return a->fav - b->fav;
	if (b->x - a->x) return b->x - a->x;
	return strcmp(a->nm, b->nm);
}

int check(int m)
{
	int i, f, x, base, sum;
	char *nm;

	base = K-m;
	if (base < 0) return 0;
	if (base >= N) return 1;
	sum = 0, nm = tbl[base].nm, base = tbl[base].x;
	for (i = 0; i < m; i++) {
		x = base - fav[i].x;
		if (x < 0) continue;
		f = (strcmp(fav[i].nm, nm) <= 0);
		if (!x && f) continue;
		sum += x; if (!f) sum++;
		if (sum > L) return 0;
	}
	return sum <= L;
}

int main()
{
	int i, lo, hi, mi;
	char buf[12], *p;

	while (N = in()) {
		M = in(), K = in(), L = in();
		memset(hash, 0, sizeof(hash));

		for (i = 0; i < N; i++) {
			fgets(name[i], 22, stdin);
			tbl[i].nm = p = name[i];
			while (*p > ' ') p++; *p = 0;
			insert(name[i], i);
			tbl[i].x = atoi(p+1), tbl[i].fav = 0;
		}
		for (i = 0; i < M; i++) {
			fgets(p=buf, 12, stdin);
			while (*p > ' ') p++; *p = 0;
			tbl[lookup(buf)].fav = 1;
		}
		qsort(tbl, N, sizeof(T), cmp);
		N -= M, fav = tbl + N;

		lo = 0;
		hi = M; if (hi > K) hi = K; hi++;
		while (hi-lo > 1) {
			mi = (lo + hi) >> 1;
			if (check(mi)) lo = mi; else hi = mi;
		}
		printf("%d\n", lo);
	}
	return 0;
}


Measured memory_bytes: 9588
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  char c;
  cin >> c;

  cout << (char)(c + 1) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if((a*b)%2==0){
      System.out.println("Even");
    }
    else{
      System.out.println("Odd");
    }
  }
}

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

signed main(){
    int N; cin>>N;
    string s; cin>>s;

    vector<vector<int>> dp(N+1,vector<int>(N+1));
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<N;j++){
            if(s[i]!=s[j]){
                dp[i][j]=0;
            }else{
                dp[i][j]=dp[i+1][j+1]+1;
            }
        }
    }
    int ans=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int len=min(j-i,dp[i][j]);
            ans=max(ans,len);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){

    string s;
    cin >> s;
    set<char> a;

    rep(i,s.size()){
        a.insert(s[i]);
    }

    if(s.size()==a.size()){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, A, B; cin >> N >> A >> B;
    cout << ((B - A) % 2 == 0 ? "Alice" : "Borys") << endl;
}

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

int main(){
  int N;
  cin >> N;
  int val[N];
  int cst[N];
  int i;
  for(i=0;i<N;i+=1){
    cin >> val[i];
  }
  for(i=0;i<N;i+=1){
    cin >> cst[i];
  }
  int incm=0;
  for(i=0;i<N;i+=1){
    if( (val[i]-cst[i]) >= 0){
      incm += val[i]-cst[i];
    }
  }
  cout << incm << endl;
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> map = new TreeMap<>();
        int max = 0;
        for(int i = 0; i < n; i++){
            String s = sc.next();
            int a = map.getOrDefault(s, 0) +1;
            if(a > max) max = a;
            map.put(s, a);
        }
        
        StringBuilder sb = new StringBuilder();
        for (String s : map.keySet()) {
            if(map.get(s) == max){
                sb.append(s).append(System.lineSeparator());
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 78584
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P2; //dis,city,ticket

int main(){
  int n,m;
  int a,b,c;
  vector<P> g[110];
  int d[110][2];

  while(cin >> n >> m, n||m){
    for(int i=1;i<=n;i++)g[i].clear();
    for(int i=0;i<m;i++){
      cin >> a >> b >> c;
      g[a].push_back(P(c,b));
      g[b].push_back(P(c,a));
    }

    priority_queue<P2,vector<P2>,greater<P2> > q;
    q.push(P2(0,P(1,0)));
    for(int i=1;i<=n;i++)d[i][0] = d[i][1] = 100000000;
    d[1][0] = 0;

    while(q.size()){
      P2 p = q.top(); q.pop();
      int dis = p.first, city = p.second.first, tick = p.second.second;

      for(int i=0;i<(int)g[city].size();i++){
	int cost = dis + g[city][i].first;
	int next = g[city][i].second;

	if(cost < d[next][tick]){
	  d[next][tick] = cost;
	  q.push(P2(cost,P(next,tick)));
	}
	if(!tick){
	  for(int j=0;j<(int)g[next].size();j++){
	    int next2 = g[next][j].second;

	    if(dis < d[next2][1]){
	      d[next2][1] = dis;
	      q.push(P2(dis,P(next2,1)));
	    }
	  }
	}
      }
    }

    cout << min(d[n][0],d[n][1]) << endl;
  }
}

Measured memory_bytes: 0
M, D = map(int, input().split())
ans = 0
for m in range(M+1):
    for d in range(10, D+1):
        d1 = int(str(d)[0])
        d2 = int(str(d)[1])
        if d1 > 1 and d2 > 1 and m == d1 * d2:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll n,b,a;
  cin >> n >> a >> b;

  b=b-a+1;
  a=1;

  ll ans,minsum,maxsum;

  minsum=a*(n-1)+b;
  maxsum=a+b*(n-1);

  ans=maxsum-minsum;

  if(a>b){
    cout << 0 << endl;
    return 0;
  }
  if(n==1 && a!=b){
    cout << 0 << endl;
    return 0;
  }
  cout << ans+1 << endl ;


  }


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

int main(){
  string s; cin>>s;
  int n; cin>>n;
  vector<string> v;
  for(int i=0;i<s.size();i++){
    v.push_back(s.substr(i,1));
  }
  if(s.size()>1){
    for(int i=0;i<s.size()-1;i++){
      v.push_back(s.substr(i,2));
    }
  }if(s.size()>2){
    for(int i=0;i<s.size()-2;i++){
      v.push_back(s.substr(i,3));
    }
  }if(s.size()>3){
    for(int i=0;i<s.size()-3;i++){
      v.push_back(s.substr(i,4));
    }
  }if(s.size()>4){
    for(int i=0;i<s.size()-4;i++){
      v.push_back(s.substr(i,5));
    }
  }sort(v.begin(),v.end());
  string x; int i=0;
  while(true){
    if(n==1){
      cout<<v[i]<<endl;
      return 0;
    }x=v[i];
    i++;
    while(x==v[i]) i++;
    n--;
  }
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

// 0-indexed bottom up Segment Tree
// UNIT is the identity element of operation func
template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n      = 1;
        int nv = v_.size();
        while (n < nv)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < nv; ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, T a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    // get result of func() in [l, r)
    T query(int l, int r) {
        l += n - 1;
        r += n - 1;
        T retl = UNIT, retr = UNIT;
        while (l < r) {
            if ((l & 1) == 0)
                retl = func(retl, dat[l]);
            if ((r & 1) == 0)
                retr = func(dat[r - 1], retr);
            l = l / 2;
            r = (r - 1) / 2;
        }
        return func(retl, retr);
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    auto f          = [](lint l, lint r) { return max(l, r); };
    const lint unit = 0; // -inf;
    SegmentTree<lint> seg(300010, f, unit);
    for (int i = 0; i < n; ++i) {
        lint maxi = min(300009LL, a[i] + k);
        lint mini = max(0LL, a[i] - k);
        lint curr = seg.query(mini, maxi + 1);
        seg.update(a[i], curr + 1);
    }
    cout << seg.query(0, 300010) << "\n";
    return 0;
}

Measured memory_bytes: 13756
import 'dart:io';
 
void main(List<String> args){
  int A = int.parse(stdin.readLineSync());
  int B = int.parse(stdin.readLineSync());
  int C = int.parse(stdin.readLineSync());
  int X = int.parse(stdin.readLineSync());
  int count = 0;
  for(int i=0; i<=A; ++i) for(int j=0; j<=B; ++j) for(int k=0; k<=C; ++k){
    if(500*i+100*j+50*k==X) ++count;
  }
  print(count);
}

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

int main(){
  int n,i,j,k;
  cin >> n;
  long long t,a[n];
  cin >> t;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  long long m=a[0],g=0,cnt=0;
  for(i=1;i<n;i++){
    long long bg=g;
    g = max(g,a[i]-m);
    if(g!=bg){
      cnt=1;
    }else if(g==a[i]-m){
      cnt++;
    }
    m = min(m,a[i]);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
using namespace std;

int inf = INT_MAX;
//int inf = LLONG_MAX;

int a, b, k, ct = 0, num = 1;

int main()
{
    cin >> a >> b >> k;

    num = min(a, b);

    while (true)
    {
        if ((a % num == 0) && (b % num == 0))
        {
            ct++;
            if (ct == k)
            {
                cout << num;
                break;
            }
        }
        num--;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io;
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn str_join<T: std::string::ToString>(s: &Vec<T>) -> String {
    s.iter()
        .map(|i| i.to_string())
        .collect::<Vec<_>>()
        .join(" ")
}
fn main() {
    let n: usize = read();
    let mut card: Vec<String> = Vec::new();
    for i in 1..14 {
        card.push(format!("S {}", i));
    }
    for i in 1..14 {
        card.push(format!("H {}", i));
    }
    for i in 1..14 {
        card.push(format!("C {}", i));
    }
    for i in 1..14 {
        card.push(format!("D {}", i));
    }
    for _i in 0..n {
        let mut c = String::new();
        io::stdin().read_line(&mut c).unwrap();
        let c = c.trim();
        for j in 0..card.len() {
            if card[j] == c {
                card.remove(j);
                break;
            }
        }
    }
    for x in card {
        println!("{}", x);
    }
}



Measured memory_bytes: 5060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    cin>>a>>b;
    if((b-1)%(a-1) == 0)
        cout<< (b-1)/(a-1);
    else
        cout<<(b-1)/(a-1) + 1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 1000000007;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())


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

    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int s = -1;
    int big = -1;
    for(int i = 0; i < n; i++){
        if(a[i] > big){
            s = big;
            big = a[i];
        }
        else if(a[i] > s) s = a[i];
    }
    for(int i = 0; i < n; i++){
        if(a[i] != big) cout << big << "\n";
        else cout << s << "\n";
    }
}

Measured memory_bytes: 2432
S = input()
if S[0] == "A" and S[2:-1].count("C") == 1 and "C" in S[2:-1]:
    s = S.replace("A", "a").replace("C", "c")
    t = s.lower();
    if s == t:
        print("AC")
        exit()
print("WA")

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

int main(){
  int n,a[200010];
  cin>>n;
  long long sad=0;
  for(int i=0;i<n;++i){
    cin>>a[i];
    a[i]-=i+1;
  }

  sort(a,a+n);

  int b=(n%2?a[n/2]:(a[n/2]+a[n/2-1])/2);

  for(int i=0;i<n;++i){
    sad+=abs(a[i]-b);
  }

  cout << sad << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main()
{
	int t,i,n,k,d,j;
	cin>>n>>k;
	int a[n]={0};
	int c=0;
	for(i=0;i<k;i++)
	{
		cin>>d;
		for(j=0;j<d;j++)
		{
			cin>>t;
			a[t-1]++;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[i]==0)
		c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
S = input()
mae = False
ushiro = False
if int(S[2:4]) <= 12 and int(S[2:4]) != 0:
    ushiro = True
if int(S[0:2]) <= 12 and int(S[0:2]) != 0:
    mae = True

if mae and ushiro:
    print("AMBIGUOUS")
elif mae:
    print("MMYY")
elif ushiro:
    print("YYMM")
else:
    print("NA")

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin >> n) {
    vector<int> A(n), B(n - 1);
    for(int i = 0; i < n - 1; ++i) {
      cin >> B[i];
      if(i == 0) A[i] = A[i + 1] = B[i];
      else {
        if(A[i] > B[i]) A[i] = A[i + 1] = B[i];
        else A[i + 1] = B[i];
      }
    }
    long long sum = 0;
    for(int i = 0; i < n; ++i) sum += A[i];
    cout << sum << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define NMAX 52
using namespace std;
int N, x, y;
vector <int> G[100003];
const long long MOD = 1e9 + 7;
int viz[100003], last, father[100003];
long long dp[100003][2];
void dfs(int node) {
    viz[node] = 1;
    if (G[node].size() == 1 && viz[G[node][0]]) {
        dp[node][0] = dp[node][1] = 1; // 0 ALB , 1 NEGRU
        return;
    }
    for (auto x: G[node]) {
        if (!viz[x]) {
            dfs(x);
        }
        else father[node] = x;
    }
    dp[node][0] = dp[node][1] = 1;
    for (auto x : G[node]) {
        if (x == father[node]) continue;
            dp[node][0] = dp[node][0] * (dp[x][0] + dp[x][1]) % MOD;
            dp[node][1] = dp[node][1] * dp[x][0] % MOD;
    }

}
int main() {
    cin >> N;
    for (int i = 0; i < N - 1; ++i) {
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % MOD;
    return 0;
}


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

int main() {
    int a,b,c,d;cin>>a>>b>>c>>d;
    int l = a+b;
    int r = c+d;
    if(l > r)cout<<"Left"<<endl;
    else if (l < r)cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int main()
{
    //freopen("in.txt","r",stdin);
    int n, t, val;
    cin >> n >> t;
    long long sm = 0;
    mint cen = 0;
    Rep(i,n)
    {
        scanf("%d",&val);
        if(cen <= val)
        {
            sm += t;
            cen = val + t;
        }
        else
        {
            sm += val + t - cen;
            
            cen = val + t;
        }
    }
    cout << sm << endl;
    return 0;
}



Measured memory_bytes: 256
// Author: pankaj_m05 
// Problem: A 
//Created: 17.05.2020 17:34:03

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;

int main(void) { 
	fast
	int n; cin >> n;
	int ones = n % 10;
	if(ones == 0 || ones == 1 || ones == 6 || ones == 8)
		cout << "pon" << '\n';

	else if(ones == 2 || ones == 4 || ones == 5 || ones == 7 || ones == 9)
		cout << "hon" << '\n';
	else 
		cout << "bon" << '\n';
	return 0;
}                                          

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>

#define PI 3.1415926535897932384626433832795028841
#define EPS (1e-10)

int main(void) {
	double R;
	while(scanf("%lf",&R)==1 && R>0.0) {
		int bunbo,bunsi1,bunsi2;
		double g1,g2;
		for(bunbo=1;bunbo<=100000000;bunbo++) {
			bunsi1=(int)(PI*bunbo);
			bunsi2=bunsi1+1;
			g1=fabs((double)bunsi1/bunbo-PI);
			g2=fabs((double)bunsi2/bunbo-PI);
			if(g1<R+EPS ||g2<R+EPS)break;
		}
		printf("%d/%d\n",g1<=g2?bunsi1:bunsi2,bunbo);
	}
	return 0;
}

Measured memory_bytes: 620
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n; string ans;

    while(true)
    {
        p = n/26; q = n%26;
        //cout<<p<<" "<<q<<endl;
        if(q==0){
            p--; q = 26;
        }
        ans+=(char)('a'+q-1);
        if(p<=0) break; n = p;
    }

    reverse(ans.begin(), ans.end());

    cout<<ans<<endl;
  //  main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    	int h,a;
    	cin>>h>>a;
    	double temp=h/(float)a;
    	int ans=ceil(temp);
    	cout<<ans<<endl;

    

}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int a1[20][20];
int a2[20][20];
void mainmain(){
	int a,b;
	while(cin>>a>>b,a||b){
		rep(i,20) rep(j,20) a2[i][j]=1;
		int n;
		cin>>n;
		// vvint v(n);
		rep(i,n){
			int c,d;
			cin>>c>>d;
			a2[c-1][d-1]=0;
		}
		int r=max(a,b);
		a1[0][0]=a2[0][0];
		reep(i,1,r){
			a1[i][0]=a1[i-1][0]*a2[i][0];
			a1[0][i]=a1[0][i-1]*a2[0][i];
		}
		reep(i,1,r){
			reep(j,i,r){
				if(i==0) a1[i][j]=1;
				else a1[i][j]=a1[i-1][j]+a1[i][j-1];
				a1[i][j]*=a2[i][j];
			}
			reep(j,i+1,r){
				if(i==0) a1[j][i]=1;
				else a1[j][i]=a1[j-1][i]+a1[j][i-1];
				a1[j][i]*=a2[j][i];
			}
		}
		// rep(i,a){
			// rep(j,b){
				// cout<<a1[i][j]<<" ";
			// }
			// cout<<endl;
		// }
		// cout<<endl;
		cout<<a1[a-1][b-1]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1164
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto b = new int[](n); b[0] = a[0];
  foreach (i; 1..n) b[i] = gcd(b[i-1], a[i]);
  auto c = new int[](n); c[$-1] = a[$-1];
  foreach_reverse (i; 0..n-1) c[i] = gcd(c[i+1], a[i]);

  auto r = max(b[$-2], c[1]);
  foreach (i; 1..n-1)
    r = max(r, gcd(b[i-1], c[i+1]));

  writeln(r);
}


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

int main()
{
    char n;
    cin >> n;
    char ans;
    if(n == 'A') 
        ans = 'T';
    else if(n == 'T')
        ans = 'A';
    else if(n == 'C')
        ans = 'G';
    else
        ans = 'C';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct Meet{
	int beg;
	int end;
	int num;
}meet[100000];

class setMeet{
	public:
		void init();
		void solve();
		private:
			int n,ans;
};
void setMeet::init(){
	int s,e;
	cin>>n;
	int i;
	for(i=0;i<n;++i)
	{
		cin>>s>>e;
		int min,max;
		max=s+e;
		min=s-e;
		meet[i].beg=min;
		meet[i].end=max;
		meet[i].num=i+1;
	}
}

bool cmp(Meet x,Meet y)
{
	if(x.end==y.end)
	return x.beg>y.beg;
	return x.end<y.end;
}

void setMeet::solve(){
	sort(meet,meet+n,cmp);
	int i;
	ans=1;
	int last=meet[0].end;
	for(i=1;i<n;++i)
	{
		if(meet[i].beg>=last)
		{
			ans++;
			last=meet[i].end;
		 } 
	}
	cout<<ans<<endl;
}
int main(){
	setMeet sm;
	sm.init();
	sm.solve();
	return 0;
}

Measured memory_bytes: 1408
/**
 *   created: 01 June 2019  22:10:21
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n,m;
		cin>>n>>m;
		vi v(m+1);
		rep(i,0,n){
			int k;
			cin>>k;
			while(k--){
				int x;
				cin>>x;
				v[x]++;
			}
		}
		int cnt=0;
		rep(i,1,m+1)
			if(v[i]==n)
				cnt++;
		cout<<cnt;
	
	}
	return 0;
}


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

class A
{
    static void Main(string[] args)
    {
        var ts = TimeSpan.FromSeconds(int.Parse(Console.ReadLine()));
        Console.WriteLine(string.Format("{0}:{1}:{2}", ts.Hours, ts.Minutes, ts.Seconds));
    }
}

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

int main() {
  int n, a;
  cin >> n >> a;

  int x = n % 500;
  if (x <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import heapq
def prim_heap(v):
    used = [True] * v #True:不使用
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist,e)
    used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,e)
        res += minedge[0]
    return res

v,e=map(int,input().split())
edge=[[] for _ in range(v)]
for i in range(e):
    s,t,w=map(int,input().split())
    edge[s].append((w,t))
    edge[t].append((w,s))
print(prim_heap(v))


Measured memory_bytes: 31816
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false); 
    ll n,k;
    cin >> n >> k;
    ll ans=0;
    repr(i,k,n+2) {
        ll a=(n*(n+1)*0.5)-((n-i)*(n-i+1)*0.5)-(i*(i-1)*0.5)+1+MOD;
        ans+=a%MOD;
        ans=ans%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n = 5;
	veci a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	int k;
	cin >> k;
	sort(all(a));
	if (a.back() - a.front() > k)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 3600