akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let s: String = read();
    let sc: Vec<char> = s.chars().collect();

    let mut r: Vec<usize> = vec![];
    let mut g: Vec<usize> = vec![];
    let mut b: Vec<usize> = vec![];
    let mut ans = 0;

    for i in 0..sc.len() {
        let si = sc[i];
        if si == 'R' {
            r.push(i)
        }
        if si == 'G' {
            b.push(i)
        }
        if si == 'B' {
            g.push(i)
        }
    }

    ans += r.len() * b.len() * g.len();

    for i in 0..n {
        for j in i + 1..n {
            let k = j * 2 - i;
            if n <= k {
                continue;
            }

            if sc[i] != sc[j] && sc[i] != sc[k] && sc[j] != sc[k] {
                ans -= 1;
            }
        }
    }

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


Measured memory_bytes: 2120
N = gets.chomp.to_i
M = N-1
restaurants = []
for i in 1..N do
    sp = gets.chomp.chars.sort.join('')
    restaurants << sp
end


count_hash = Hash.new(0)
 
restaurants.each do |a|
  count_hash[a] += 1
end
 
result = 0
count_hash.each_value do |culc|
  result += culc*(culc-1) / 2
end
 
p result

Measured memory_bytes: 31996
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
using namespace std;

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

// マクロ
#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; itr++)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; i--)
#define reprev(itr, end) reprrev(i, 0, end)
#define all(container) container.begin(), container.end()
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX 9223372036854775807i64
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };
struct edge { ll to; ll cost; };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    for (T& x : vec) os << x << endl;
    return os;
}

// ***<ここから>****************************************************************

int main(void) {

    int N;
    cin >> N;
    int res = N;
    for (int i = 0; i <= N; i++) {
        int cc = 0;
        int t = i ;
        while (t > 0) cc += t % 6 , t /= 6;
        t = N - i ;
        while (t > 0) cc += t % 9 , t /= 9;
        
        if (res > cc) res = cc ;
    }

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

Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e7+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,sum;
void solve()
{
    ll n;cin>>n;ll ar[n];
    ll maxi=INT_MIN,mini=INT_MAX;
    for(int i=0;i<n;i++)
    {
        ll a;cin>>a;
        mini=min(a,mini);
        maxi=max(a,maxi);
    }
    cout<<maxi-mini<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

 int main() {
 int A, B, C, K, cnt = 0;
cin >> A >> B >> C >> K;
 while (A >= B) { cnt += 1; B *= 2; }
 while (B >= C) { cnt += 1; C *= 2; }

 if (cnt <= K) cout << "Yes" << endl;
 else cout << "No" << endl;
return 0;
 }

Measured memory_bytes: 3604
n = int(raw_input())
   
runner = 0
run = 0
out = 0
inning = 0
while inning < n:
    event = raw_input()
    if event == 'HIT':
        if runner == 3:
            run += 1
        else:
            runner += 1
    elif event == 'HOMERUN':
        run += (runner+1)
        runner = 0
    else:
        if out == 2:
            print run
            runner = 0
            run = 0
            out = 0
            inning += 1
        else:
            out += 1

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    cout << (t.substr(0, n) == s ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3628
#abc177_C_6_retry_累積和を使用する
int_n = int(input())
list_tmp = list(map(int, input().split()))
 
int_sum = 0
int_divide = (10**9) + 7
int_sum_tmp = sum(list_tmp)

for i in range(0, len(list_tmp) - 1):
  int_sum_tmp = int_sum_tmp - list_tmp[i]
  int_sum = int_sum + (int_sum_tmp * list_tmp[i])
print(int_sum % int_divide)
#  for j in range(i + 1, len(list_tmp)):
#    if list_tmp[i] >= int_divide:
#      list_tmp_i = list_tmp[i]%int_divide
#    else:
#      list_tmp_i = list_tmp[i]
#      
#    if list_tmp[j] >= int_divide:
#      list_tmp_j = list_tmp[j]%int_divide
#    else:
#      list_tmp_j = list_tmp[j]    
#    
#    int_sum = int_sum + (list_tmp_i*list_tmp_j)
#    
#    if int_sum >= int_divide:
#      int_sum = int_sum%int_divide
#      
#print(int_sum)

Measured memory_bytes: 31656
#include <iostream>
#include <vector>
#include <utility>
#include <string>
using namespace std;

int main(){
	int X,Y;
	cin >> X >> Y;
	int award=0;

	if(X==3){
		award+=100000;
	}else if(X==2){
		award+=200000;
	}else if(X==1){
		award+=300000;
	}
	
		if(Y==3){
		award+=100000;
	}else if(Y==2){
		award+=200000;
	}else if(Y==1){
		award+=300000;
	}

	if(X==1 && Y==1){
		award+=400000;
	}

	cout << award << endl;
	return 0;
}

Measured memory_bytes: 256
import math

x = int(input())
#a = int(input())
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(map(int,input().split(" ")))
#a,b,c = list(input().split())
#string = input()
ans = 0
for i in range(2,x+1):
  tmp = 0
  j = 2
  tmp = i ** j
  while(tmp <= x):
    if ans <= i ** j:
      ans = i ** j
    j += 1
    tmp = i ** j
if ans == 0:
  print("1")
  quit()
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll  sum( ll *weights,ll *prices,ll N,ll W)
{
	ll  dp[N+1][W+1]={0};
	for( ll i=0;i<=N;i++)
	{
		for(ll j=0;j<=W;j++)
		{
			if(i==0 || j==0)
			{
               dp[i][j]=0;
			}
			else
			{
				ll inc=0,exc=0;
				if(j-weights[i-1]>=0)
				inc=prices[i-1]+dp[i-1][j-weights[i-1]];
				exc=dp[i-1][j];
				dp[i][j]=max(inc,exc);
			}
			
		}
	}
	return dp[N][W];
}
int main()
{
   //#ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 ll  n,w;
 cin>>n>>w;
 ll  val[n],wt[n];
 for(ll  i=0;i<n;i++)
 {
 	
 	cin>>wt[i];
 	cin>>val[i];

 }
 cout<<sum(wt,val,n,w); 
  
   
}



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

int main()
{
    // input
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    // solve
    ll cnt=0;
    bool pwinq=false;
    
    if(p>q){
        vector<int> tmp;
        tmp=q;
        q=p;
        p=tmp;
    }
    while(p<q){
        next_permutation(p.begin(),p.end());
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * ID: ITP1_3_B
 * Problem: print test cases
 */

#include <stdio.h>

int main(void)
{
    int n;
    int i = 1;
    while (1) {
        scanf("%d", &n);
        if (n == 0)
            return 0;
        printf("Case %d: %d\n", i++, n);
    }

    return 0;
}



Measured memory_bytes: 2036
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string s; cin >> s;
	int ans = 0;
	stack<char>st;
	rep(i, 0, s.size()) {
		if (st.empty()) {
			st.push(s[i]);
		}
		else if (st.top() != s[i]) {
			ans+=2;
			st.pop();
		}
		else {
			st.push(s[i]);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int Q;
  cin >> Q;
  //if Q == 1
  if (Q==1) {
    std::cout << "Hello World" << "\n";
  }
  else if (Q==2){
    int A, B;
    cin >> A >> B;
    int ans = A+B;
    std::cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 10000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(ll i=a;i<b;i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {
    FASTIO
    int n,rem,h;
    ll sum=0;
    cin>>n;
    int a[n];
    REP(i,0,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    sum+=a[0];
    rem=n-2;
    h=rem/2;
    rem%=2;
    REP(i,1,h+1)
     sum+=2*a[i];
    if(rem) sum+=a[h+1];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define in(n, arr) for (int i = 0; i < n; ++i) cin >> arr[i]
#define out(n, arr) for (int i = 0; i < n; ++i) cout << arr[i] << " "
 
using namespace std;
long long int solve(long long int** dp, long long int* arr, long long int l, long long int r)
{
	if(l > r)
		return  0;
	if(l == r)
		return arr[l];
	if(dp[l][r]!=-1)
		return dp[l][r];
	long long int ans = arr[l] - solve(dp,arr,l+1,r);
	ans = max(ans,arr[r]-solve(dp,arr,l,r-1));
	dp[l][r] = ans;
	return ans;

}
int main()
{
	
	int t;
	cin >> t;
	long long int* arr = new long long int[t]();
	for(int  i =0; i<t; i++)
		cin >> arr[i];
	long long int** dp = new long long int*[t];
	for(int  i = 0; i<t; i++)
		dp[i] = new long long int[t];
	for(int i =0; i<t; i++)
	{
		for(int  j = 0; j<t; j++)
			dp[i][j] = -1;
	}
	cout << solve(dp, arr, 0, t-1) << endl;



return 0;
}

Measured memory_bytes: 70912
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =3e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))

using namespace std;

char mp[2020][2020];
int dis[2020][2020];
int vis[2020][2020];
int h,w,x11,y11,x2,y2;
int sum=inf;
int dx[4]= {0,0,1,-1};
int dy[4]= {1,-1,0,0};
struct A
{
    int x,y,v;
    A(int x=0,int y=0,int v=0):x(x),y(y),v(v) {}
    bool operator<(const A&o)const//优先队列的大小比较
    {
        return v>o.v;
    }
};
int main()
{
    cin>>h>>w;
    cin>>x11>>y11;
    cin>>x2>>y2;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>mp[i][j];
        }
    }
    memset(dis,inf,sizeof(dis));
    priority_queue<A>q;
    q.push(A(x11,y11,dis[x11][y11]));
    dis[x11][y11]=0;
    while(!q.empty())
    {

        int x=q.top().x;
        int y=q.top().y;
        q.pop();
        if(vis[x][y])
        {
            continue;
        }
        vis[x][y]=1;
        for(int i=0; i<4; i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            if(xx>=1&&xx<=h&&yy>=1&&yy<=w&&mp[xx][yy]!='#')//没有越界，不是#
            {
                if(dis[xx][yy]>dis[x][y])
                {
                    dis[xx][yy]=dis[x][y];
                    q.push(A(xx,yy,dis[xx][yy]));
                }
            }
        }
        for(int i=-2; i<=2; i++)
        {
            for(int j=-2; j<=2; j++)
            {
                int xx=x+i;
                int yy=y+j;
                if(xx>=1&&xx<=h&&yy>=1&&yy<=w&&mp[xx][yy]!='#')
                {
                    if(dis[xx][yy]>dis[x][y]+1)
                    {
                        dis[xx][yy]=dis[x][y]+1;
                        q.push(A(xx,yy,dis[xx][yy]));
                    }
                }
            }
        }
    }
    if(dis[x2][y2]==inf)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<dis[x2][y2]<<endl;
    }
    return 0;
}

Measured memory_bytes: 29492
#include <stdio.h>

int main(void)
{
  int h, w;
  scanf("%d%d", &h, &w);
  char board[h][w + 1];
  int manhattan[h][w];

  for (int y = 0; y < h; y++) {
    scanf("%s", board[y]);
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      manhattan[y][x] = board[y][x] == '#' ? 0 : 10000;
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 1; x < w; x++) {
      if (manhattan[y][x] > manhattan[y][x - 1] + 1) {
        manhattan[y][x] = manhattan[y][x - 1] + 1;
      }
    }
    for (int x = w - 2; x >= 0; x--) {
      if (manhattan[y][x] > manhattan[y][x + 1] + 1) {
        manhattan[y][x] = manhattan[y][x + 1] + 1;
      }
    }
  }

  for (int x = 0; x < w; x++) {
    for (int y = 1; y < h; y++) {
      if (manhattan[y][x] > manhattan[y - 1][x] + 1) {
        manhattan[y][x] = manhattan[y - 1][x] + 1;
      }
    }
    for (int y = h - 2; y >= 0; y--) {
      if (manhattan[y][x] > manhattan[y + 1][x] + 1) {
        manhattan[y][x] = manhattan[y + 1][x] + 1;
      }
    }
  }

  int ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (ans < manhattan[y][x]) {
        ans = manhattan[y][x];
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4992
program main
implicit None
	integer(8)::n,x,p,i,q
	integer(8),allocatable::a(:)
	
	read*,n,x
	allocate(a(n))
	
	read*,a
	
	a = abs(a-x)
	p = a(1)
	
	if(n>1)then
	do i = 2,n
		call euc(p,a(i),q)
		p = q
	enddo
	endif
	
	print "(i0)",p
end program main

subroutine euc(a1,b1,c)
implicit None
integer(8)::a1,b1,c,a,b
	
	a =a1
	b =b1
	c =1
	
	do while (a /=0 .and. b /= 0)
		if (a > b)then
			c =b
			a =mod(a,b)
			else
			c =a
			b =mod(b,a)
		endif
	enddo
end subroutine euc

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int n = int(S.length());
    rep(i,n){
        int a = S[i] - 'A';
        if(a+N >= 26){
            int b = N-26;
            S[i] = char(S[i]+b);
            //cout << b << endl;
        }else{
            S[i] = S[i]+N;
        }
        
    }
    cout << S << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> G(H, vector<char>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) cin >> G[i][j];
    }
    vector<vector<char>> Ge(H + 2, vector<char>(W + 2,'.'));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) Ge[i + 1][j + 1] = G[i][j];
    }
    bool good = true;
    for(int i = 1; i < H + 1; i++){
        for(int j = 1; j < W + 1; j++){
            if(Ge[i][j] == '.') continue;
            good = false;
            if(Ge[i - 1][j] == '#' 
            or Ge[i + 1][j] == '#' 
            or Ge[i][j - 1] == '#' 
            or Ge[i][j + 1] == '#') good = true;
            if(!good) goto finish;
        }
    }
    finish:
    if(good) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <unordered_map>

#define mod 1000000007

using namespace std;
using ll = long long;

int addDigit(int x){
    string y = to_string(x);
    int z = 0;
    for(int i = 0; i < y.length(); i++){
        z += y[i]-'0';
    }
    return z;
}

void solve(){
    int n, a, b, res = 0;

    cin >> n >> a >> b;

    for(int i = 1; i <= n; i++){
        int x = addDigit(i);
        if(x >= a && x <= b){
            res += i;
        }
    }

    cout << res << endl;
}

int main(){
    solve();
    return 0;
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
int sum;
bitset<4000001> bs(1);

int main() {
    cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        sum += a;
        bs |= (bs<<a);
    }
    for (int i = (sum+1)/2; i <= sum; i++) {
        if (bs[i]) {
            cout << i << endl;
            return 0;
        }
    }
}
































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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < (k); i++ )

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define debug puts("FANGO")
#define INF (int)MAX_INT
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef long long int32;
typedef unsigned long long uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

template <class T>
T sqr(T val) {
  return val * val;
}

void solve(__attribute__((unused)) int tc = 0) {
  int n;
  cin >> n;
  int maxi = -1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (h >= maxi) {
      maxi = h;
      ans++;
    }
  }
  cout << ans << "\n";
  return;
}

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

  /*int TC;
  cin >> TC;
  REP(tc, TC) {
    solve(tc);
  }*/
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    ll n,a,b,ans = 0;
    cin>>n>>a>>b;
    if(n >= (a + b)){
        ans += ll(n/(a + b)) * a;
        ans += min(a,n % (a + b));
    }
    else{
        ans = min(a,n);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld=long double;
 
int main(){
    int n;
    cin>>n;
    int flag=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(i*j==n){
                flag=1;
                break;
            }
        }
        if(flag==1)
        break;
    }
    if(flag==1)
    cout<<"Yes";
    else
    cout<<"No";
    
    
    
    return 0;
}

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

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/


/*long nCr(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/

int main(){
    int n;
    cin >> n;
    LL ans = 0;
    map<int, int> cnt;
    VI a(n);
    REP(i, n){
        cnt[i]=0;
    }
    REP(i, n-1){
        cin >> a[i];
    }
    for(int i = n-2; i>=0; i--){
        cnt[a[i]-1]+=+1;
    }
    REP(i, n){
        cout << cnt[i] << ' ';
    }
    cout << endl;
   
}


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

int main() {
  int n,d,flg[1002]={};
  cin >> n >> d;
  for(int i=0;i<d;i++) {
    int a,b;
    cin >>a>>b;
    flg[a] = max(flg[a],b);
  }
  
  int sta=0,sum=0,L=0,R=0;
  for(int i=0;i<=n;i++) {
    if(flg[i] != 0 && sta==1) R=max(R,flg[i]);
    else if(flg[i] != 0) L=i,R=flg[i],sta=1;
    else if(i==R) sum += 3*(R-L)+1,sta=0;
    else if(sta==0) sum++;
  }
  cout << sum <<endl;
  return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        int N = scan.nextInt();
        int a = N%Math.max(H, W);
        int ans = N/Math.max(H, W);
        if(a != 0)ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>

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

using namespace std;

int main(){
    int n; cin >> n;
    int first, second, ans = 0; cin >> first >> second;

    REP(i, n - 2){
        int x; cin >> x;
        if(second < max(first, x) && second > min(first, x)) 
            ans++;
        first = second; second = x;
    }cout << ans;

}           

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    ll ans=0;
    ll mi=inf;
    rep(i,n){
        ll a;cin>>a;
        chmin(mi,a);
        if(a<=mi)ans++;
    }
    out(ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<map>
#include<math.h>
#include<set>
#include<string>
#include<vector>
using namespace std;

#define int long long

void fastio()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
  fastio();
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n - 1; i++)
  {
    int a;
    cin >> a;
    a--;
    v[a]++;
  }
  for (int i = 0; i < n; i++)
    cout << v[i] << endl;
  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int C = 26;
int cnt[C];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else                         
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    string s; cin >> s;
    for (char c : s) ++cnt[c - 'a'];
    int ans = 1;
    for (int i = 0; i < C; ++i) for (int j = i + 1; j < C; ++j) ans += cnt[i] * cnt[j];
    cout << ans << '\n';
}   

Measured memory_bytes: 720
max' (x,y) = if x>y then x else y
min' (x,y) = if x>y then y else x

solve :: String->IO ()
solve line = do
    let dat = map (\x->read x::Double) $ words line
    let (xa1, ya1) = (dat!!0, dat!!1)
    let (xa2, ya2) = (dat!!2, dat!!3)
    let (xb1, yb1) = (dat!!4, dat!!5)
    let (xb2, yb2) = (dat!!6, dat!!7)
    if ((min' (xa2, xb2))<(max' (xa1, xb1))) ||
       ((min' (ya2, yb2))<(max' (ya1, yb1))) then putStrLn "NO" else putStrLn "YES"

main :: IO ()
main = do
    str <- getContents 
    mapM_ solve $ lines $ str

Measured memory_bytes: 4180
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		int x, y, z;
		x = scan.nextInt();
		y = scan.nextInt();
		z = scan.nextInt();

		System.out.print(z + " ");
		System.out.print(x + " ");
		System.out.print(y);
	}

	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 21844
I=lambda:map(int,input().split());n,=I();G=[[]for i in[0]*-~n]
for i in G[2:]:a,b,c=I();G[a]+=(b,c),;G[b]+=(a,c),
q,k=I();s=[(k,0,0)]
while s:v,p,u=s.pop();s+=[(t,v,u+c)for t,c in G[v]if p-t];G[v]=u
for p in[0]*q:x,y=I();print(G[x]+G[y])

Measured memory_bytes: 47600
def main(): 
    n = int(input())
    d1 = []
    d2 = []
    for _ in range(n):
        x,y = map(int,input().split())
        d1.append(x+y)
        d2.append(x-y)
    
    print(max(max(d1)-min(d1),max(d2)-min(d2)))
main()

Measured memory_bytes: 96888
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

#define MAX (1<<16)
#define INF (INT_MAX/4)

int dp[MAX+1];
int t[16][17];

int main() {
  int n;
  
  while(cin >> n && n) {
    for(int i=0; i<n; i++)
      for(int j=0; j<n+1; j++)
	cin >> t[i][j];
    
    fill(dp, dp+(1<<n), INF);
    
    dp[0] = 0;
    for(int i=0; i<(1<<n); i++) {
      for(int j=0; j<n; j++) {
	if( !(i>>j & 1) ) {
	  // bare hands
	  dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i]+t[j][0]);
	  for(int k=0; k<n; k++) {
	    if( i>>k & 1 )
	      dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i]+t[j][k+1]);
	  }
	}
      }
    }
    
    cout << dp[(1<<n)-1] << endl;
  }
  
  return 0;
}

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

int main()
{
    int num1;
    int num2;
    cin >> num1 >> num2;
    if(num1 > 0 && num1 < 10 && num2 > 0 && num2 < 10){
        cout << num1 * num2;
    }
    else 
        cout << -1;
}


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

vector<int> w;

int main(void){
    int n;
    cin >> n;
    w = vector<int>(n);

    for(int i=0;i<n;i++){
        cin >> w[i];
    }
    int fs=1000000;
    for(int t=0;t<n;t++){
        int s1,s2;
        s1 = s2 = 0;
        for(int i=0;i<n;i++){
            if(i <= t){
                s1 += w[i];
            }else{
                s2 += w[i];
            }
        }
        fs = min(fs,abs(s1-s2));
    }
    cout << fs << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    int l[n+1] = {};
    int r[n+1] = {};
    int lmax = 0;
    int rmin = 99999999;

    rep(i,m){
        int a,b;
        cin >> a >> b;
        l[a]++;
        r[b]++;
        lmax = max(lmax,a);
        rmin = min(rmin,b);
    }

    int ans = 0;

    if(lmax<=rmin){
        ans = rmin - lmax + 1;
    }

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    vector<vector<pair<int,int>>> a(n);
    for(int i=0;i<n;i++){
        int A;scanf("%d",&A);
        for(int j=0;j<A;j++){
            int x,y;scanf("%d%d",&x,&y);
            x--;
            a[i].push_back({x,y});
        }
    }
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<bool> state(n);
        for(int i=0;i<n;i++){
            if(bit&(1<<i))state[i]=1;
        }
        bool check=0;
        for(int i=0;i<n;i++){
            if(!state[i])continue;
            for(auto p:a[i]){
                if(state[p.first]!=p.second)check=1;
            }
        }
        if(check)continue;
        ans=max(ans,__builtin_popcount(bit));
    }
    printf("%lld\n",ans);
}

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

int main() {
	int n;
	cin>>n;
	int count=0;
	for(int i=0;i<n;i++){
		
		int a,b;
		cin>>a>>b;
		if(a==b){
			count++;
		} else {
			count=0;
		}
		if(count==3){
			break;
		}
	}
	
	if(count>=3){
		cout<<"Yes";
	} else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <list>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
  for (int i = s.size() - 1; i >= 0; i--) {
    for (int j = t.size() - 1; j >= 0; j--) {
      int& ans = dp[i][j];
      ans = max(dp[i + 1][j], dp[i][j + 1]);
      if (s[i] == t[j]) ans = max(ans, dp[i + 1][j + 1] + 1);
    }
  }

  int i = 0, j = 0;
  while (i < s.size() && j < t.size()) {
    int ans = dp[i][j];
    if (ans == dp[i + 1][j]) {
      i++;
      continue;
    }
    if (ans == dp[i][j + 1]) {
      j++;
      continue;
    }
    cout << s[i];
    i++;
    j++;
  }
  cout << endl;

  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int a,b,c;
  cin >> a >>b >> c;
  if(a<b&&b<c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
#include <tuple>

const int MOD=1e9+7;

int H,W,N;

struct Point{
  int x,y;
  void read(){
    scanf("%d %d",&x,&y);
  }
  bool operator<(Point p)const{
    return std::tie(x,y)<std::tie(p.x,p.y);
  }
}ps[3005];

int dp[3005];

int inv[200005]={1,1};
int fact[200005]={1,1};
int invfact[200005]={1,1};

int combo(int r,int c){
  return 1LL*fact[r+c]*invfact[r]%MOD*invfact[c]%MOD;
}

int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=2;i<=H+W;i++){
    inv[i]=1LL*(MOD-MOD/i)*inv[MOD%i]%MOD;
    fact[i]=1LL*fact[i-1]*i%MOD;
    invfact[i]=1LL*invfact[i-1]*inv[i]%MOD;
  }
  for(int i=0;i<N;i++){
    ps[i].read();
  }
  std::sort(ps,ps+N);
  ps[N].x=H,ps[N].y=W;
  for(int i=0;i<=N;i++){
    dp[i]=combo(ps[i].x-1,ps[i].y-1);
    for(int j=0;j<i;j++){
      if(ps[j].x<=ps[i].x&&ps[j].y<=ps[i].y){
	dp[i]=(dp[i]-1LL*dp[j]*combo(ps[i].x-ps[j].x,ps[i].y-ps[j].y))%MOD;
      }
    }
  }
  printf("%d\n",(dp[N]+MOD)%MOD);
  return 0;
}


Measured memory_bytes: 2560
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


n = int(input())
l = [i for i in range(n+1)]
ls = l[1::2]
ans = 0
for i in ls:
    if len(make_divisors(i))==8:
        ans+=1
print(ans)

Measured memory_bytes: 9456
#include<iostream>
using namespace std;
int map[9][9];
int h,w,C;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
main()
{
	while(cin>>h>>w>>C,h)
	{
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>map[i][j];
		int ans=0;
		for(int a=1;a<7;a++)for(int b=1;b<7;b++)for(int c=1;c<7;c++)
			for(int d=1;d<7;d++)
			{
				int now=0;
				bool used[9][9];
				for(int i=0;i<h;i++)for(int j=0;j<w;j++)used[i][j]=0;
				used[0][0]=1;
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==map[0][0])
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==a)
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==b)
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==c)
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==d)
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int cnt=0;cnt<h;cnt++)
				{
					for(int i=0;i<h;i++)for(int j=0;j<w;j++)
					{
						if(!used[i][j]&&map[i][j]==C)
						{
							bool flag=0;
							for(int r=0;r<4;r++)
							{
								int x=i+dx[r],y=j+dy[r];
								if(x>=0&&y>=0&&x<h&&y<w&&used[x][y])flag=1;
							}
							used[i][j]=flag;
						}
					}
				}
				for(int i=0;i<h;i++)for(int j=0;j<w;j++)now+=used[i][j];
				ans=ans<now?now:ans;
			}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3088
#include<stdio.h>

int CalculateBirthday(int, int, int);

int main(){
  int i, n, y, m, d, ans;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d %d %d", &y, &m, &d);
    ans = CalculateBirthday(y, m, d);
    printf("%d\n", ans);
  }
  return 0;
}

int CalculateBirthday(int y, int m, int d){
  int i, ans;

  if(y%3 == 0){
    ans = 21-d + (10-m)*20;
  }else{
    ans = 21-d;
    if(m%2 == 0) ans--;
    for(i=m+1; i<=10; i++){
      ans += 20;
      if(i%2 == 0) ans--;
    }
  }
  for(i=y+1; i<1000; i++){
    if(i%3 == 0) ans += 200;
    else ans += 195;
  }
  return ans;
}

Measured memory_bytes: 0
public class Main {
  private static void solve() {
    double[] p = new double[6];
    double[] q = new double[6];
    for (int i = 0; i < 6; i ++) {
      p[i] = ni() / 100.0;
    }
    for (int i = 0; i < 6; i ++) {
      q[i] = ni() / 100.0;
    }
    
    double l = 0;
    double r = 1.0;
    for (int k = 0; k < 200; k ++) {
      double x = (l * 2 + r) / 3;
      double y = (l + r * 2) / 3;
      if (e(p, q, x) > e(p, q, y)) {
        l = x;
      } else {
        r = y;
      }
    }
    System.out.printf("%.12f\n", e(p, q, l));
  }
  
  private static double e(double[] p, double[] q, double x) {
    double ret = 0;
    for (int i = 0; i < 6; i ++) {
      ret += Math.max(p[i] * x, q[i] * (1 - x));
    }
    return ret;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23508
main = do
  n'<-getLine
  let n = read n' :: Int
  v'<-getLine
  let v = (map (read :: String->Int) . words) v'
  (putStrLn . unwords . map show . calc2) v

calc2 :: [Int] -> [Int]
calc2 v = [foldr1 min  v, foldr1 max  v, foldr1 (+) v]

Measured memory_bytes: 9276
def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return a*power(b, mod-2)%mod

x,y=map(int,input().split())

if y>2*x or x>2*y:
    print(0)
elif (x+y)%3!=0:
    print(0)
else:
    w1=(2*y-x)//3
    h1=(2*x-y)//3

    mod=10**9+7

    ic=1
    ih=1
    for i in range(h1):
        ic=ic*(w1+1+i)%mod
        ih=ih*(i+1)%mod

    ic=div(ic,ih)

    print(ic)
        

Measured memory_bytes: 3064