akhauriyash/Code-Regression huggingface dataset:
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  val n, k = in.next().toInt

  val mc = new ModComb(n, MOD)
  var ans = 0L

  for (i <- 1 to (k min (n-1))) {

    val ball = i
    val stick = (n-i)-1
    ans += mc.comb(n, i) * mc.comb(ball+stick, stick)
    ans %= MOD
  }

  if (k % 2 == 0 || k >= 3) {
    ans += 1
  }

  println(ans)
}


class ModComb(maxNum: Int, mod: Long) {

  private def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2)
    else
      (x * repeatSquares(x*x % mod, n/2)) % mod
  }

  private val fact = new Array[Long](maxNum + 1)

  fact(0) = 1
  for (i <- 1 to maxNum)
    fact(i) = (i * fact(i-1)) % mod

  val factInv = new Array[Long](maxNum + 1)

  factInv(maxNum) = repeatSquares(fact(maxNum), mod-2)
  for (i <- (1 to maxNum).reverse)
    factInv(i-1) = (i * factInv(i)) % mod


  // nCk
  def comb(n: Int, k: Int): Long = {
    val numer = fact(n)
    val denom = (factInv(n-k) * factInv(k)) % mod

    (numer * denom) % mod
  }

}


object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 29608
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    // priority_queue<double, vector<double>, greater<double> > queue;
    priority_queue<double> queue;
    rep(i,n){
        double tmp;
        cin >> tmp;
        queue.push(tmp);
    }
    rep(i,m){
        double tmp = queue.top(); queue.pop();
        // cout << tmp << endl;
        tmp/=2;
        queue.push(tmp);

    }
    ll sum=0;
    rep(i,n){
        sum+=(int)queue.top();queue.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<cstring>
#include<algorithm>
const int maxn=110;
int n,a[maxn];
long long ans=0x7fffffffffffffff,tmp;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=-100;i<=100;i++)
    {
        tmp=0;
        for(int j=1;j<=n;j++)
        {
            tmp+=1ll*(a[j]-i)*(a[j]-i);
        }
        ans=std::min(ans,tmp);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 128
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string a,b;
	cin>>a>>b;
	cout<<"A"<<b[0]<<"C";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  long long a, b;
  cin >> a >> b;
  long long g = __gcd(a, b);
  int ans = 1;
  for (long long i = 2; i * i <= g; i++) {
    if (g % i) continue;
    ans++;
    while (g % i == 0) g /= i;
  }
  if (g > 1) ans++;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int INF = 1000000000;

int main() {
    int N, M;
    cin >> N >> M;

    vii to(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].psb(b);
        to[b].psb(a);
    }

    queue<int> q;
    vector<int> dist(N, INF);
    vector<int> pre(N, -1);

    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : to[v]) {
            if (dist[u] != INF) continue;

            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep (i, N) {
        if (i == 0)
            continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
}


Measured memory_bytes: 10608
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S, W = get_ints

if S > W
  puts 'safe'
else
  puts 'unsafe'
end


Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k;
char s[N];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    int ans=1;
    for(int i=1;i<n;i++)
        if(s[i]!=s[i+1]) ans++;
    while(k--)
    {
        if(ans-2>=1) ans-=2;
        else {ans=1;break;}
    }
    printf("%d\n",n-ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;

int main()
{
    // 第15回日本情報オリンピック予選-E ゾンビ島, 解説してからRE-RE-WA-AC : BFSのcontinueを忘れずに.long longを使うべきか確認する習慣をつけよう.
    /*cin >> n >> m >> k >> s;
    cin >> pcost >> qcost;

    edge.resize(n);
    zombie.assign(n, false);
    danger.assign(n, false);

    queue<int> que;

    rep(i, k) {
        ll a; cin >> a; a--;
        zombie[a] = true;
        que.push(a);
    }
    rep(i, m) {
        ll a, b; cin >> a >> b; a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    for (ll i = 0; i <= s; ++i) {
        // ゾンビがいるエッジから距離s以下のエッジをすべて探索
        // 0はゾンビがいる地点なので0から始める
        if (que.empty()) break;
        for (ll j = que.size() - 1; j >= 0; --j) {
            ll from = que.front(); que.pop();
            if (danger[from]) continue; // すでにdangerだとされている場所は計算済みなのでスキップ(計算量削減)
            danger[from] = true;
            for (ll e : edge[from]) que.push(e); // 更新したエッジから繋がっているエッジ情報をキューに入れておく
        }
    }
    dijkstra(0);
    cout << dist[n - 1] << endl;
    */

    // ABC074-D, 
    int n; cin >> n;
    vector<vector<ll>> dist(n, vector<ll>(n, 0));
    rep(i, n) rep(j, n) {
        ll a; cin >> a;
        dist[i][j] = a;
        dist[j][i] = a;
    }
    vector<vector<ll>> ans = dist;
    vector<vector<bool>> changed(n, vector<bool>(n, false));
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == k || j == k) continue;
                if (ans[i][j] >= ans[i][k] + ans[k][j]) {
                    ans[i][j] = ans[i][k] + ans[k][j];
                    changed[i][j] = true;
                }
            }
        }
    }
    if (ans != dist) {
        cout << -1 << endl;
    }
    else {
        ll num = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (!changed[i][j]) {
                    num += ans[i][j];
                }
            }
        }
        cout << num << endl;
    }

    return 0;
}

Measured memory_bytes: 5044
n, m = map(int, input().split())
s = [0]*n
c = [0]*m
for i in range(n):
  s[i] = list(map(int, input().split()))
for i in range(m):
  c[i] = list(map(int, input().split()))

for i in range(n):
  min_c = 0
  min_d = float('inf')
  for j in range(m):
    d = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1])
    if d < min_d:
      min_c = j+1
      min_d = d
  print(min_c)
  

Measured memory_bytes: 3064
N = int(input())

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

flag = True
ans = 1
if 0 in A:
    print(0)
    flag = False

if flag:
    for i in A:
        ans *= i
        if ans > pow(10,18):
            print(-1)
            flag = False
            break

if flag:
    print(ans)

Measured memory_bytes: 87780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> sum;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}

int main(){
    string s;cin>>s;
    ll n=s.size();
    vector<ll> num(n+1);
    if(n==1){
        cout<<0<<endl;
        return 0;
    }

    bool prev=false;
    rep(i,n-1){
        if(s[i]==s[i+1]){
            if(prev==true){
                num[i]=-1;
                prev=false;
            }else{
                num[i]=1;
                prev=true;
            }
        }
    }

    pre_process(num,sum);

    ll one=0,zero=0;
    rep(i,n){
        if(sum[i]==0){
            zero++;
        }else{
            one++;
        }
    }

    cout<<min(one,zero)<<endl;


    return 0;
}

Measured memory_bytes: 5088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll a[100000];
ll sum[100000];
ll cnt[100000];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	for (int i = 0; i + 1 < n; i++) {
		sum[a[i + 1]] += (a[i + 1] + m - a[i]) % m - 1;
		if (a[i] < a[i + 1]) {
			cnt[a[i] + 1]++;
			cnt[a[i + 1]]--;
		}
		else {
			if (a[i] + 1 < m) cnt[a[i] + 1]++;
			cnt[0]++;
			cnt[a[i + 1]]--;
		}
	}
	for (int i = 0; i + 1 < m; i++) cnt[i + 1] += cnt[i];
	ll now = 0;
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] < a[i + 1]) now += a[i + 1] - a[i];
		else now += a[i + 1] + 1;
	}
	ll ans = now;
	for (int i = 0; i + 1 < m; i++) {
		now += sum[i];
		now -= cnt[i];
		ans = min(ans, now);
	}
	cout << ans << endl;
 }

Measured memory_bytes: 2560
import java.util.PriorityQueue;
import java.util.Scanner;

//A Way to Invite Friends
public class Main{

	class R implements Comparable<R>{
		int x;
		boolean f;
		public R(int x, boolean f) {
			this.x = x;
			this.f = f;
		}
		public int compareTo(R o) {
			return x-o.x;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<R> q = new PriorityQueue<R>();
		for(int i=0;i<n;i++){
			q.add(new R(sc.nextInt(), true)); q.add(new R(sc.nextInt()+1, false));
		}
		q.add(new R(n+3, true));
		int res = 0, c = 0, f = 1;
		while(!q.isEmpty()){
			R r = q.poll();
			while(f!=r.x){
				if(f-1<=c)res = f-1;
				f++;
			}
			c+=r.f?1:-1;
		}
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    long long n;
    cin >> n;
    long long group_size = 26;
    long long cur_len = 1;
    pair<ll, ll> cur = {1, 26};
    while(n > cur.second)
    {
        group_size *= 26;
        cur.first = cur.second + 1;
        cur.second = cur.first + group_size - 1;
        cur_len++;
    }
    vector<char> ans(cur_len);
    for(int i = 0; i < cur_len; ++i)
    {
        ll val = (n - cur.first);
        ll letter_group = group_size / 26;
        ll id = val / letter_group;
        ans[i] = char('a' + id);
        
        long long new_begin = cur.first + id * letter_group;
        long long new_end   = new_begin + letter_group - 1;
        
        group_size /= 26;
        cur = make_pair(new_begin, new_end);
    }

    for(const char& c : ans) cout << c;
    cout << '\n';
    return 0;
}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> ct(n);
  rep (i, n) cin >> ct[i].first >> ct[i].second;
  int mini = INT_MAX;
  rep (i, n) {
    if (ct[i].second <= t) {
      mini = min(mini, ct[i].first);
    }
  }
  cout << (mini != INT_MAX ? to_string(mini) : "TLE") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

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

    string a, b;
    cin >> a >> b;

    string c = b + a;
    cout << c << "\n";
}


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

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  ll s;
  cin>>s;
  ll x1 = sqrt(s);
  ll y2 = (s+x1-1) / x1;
  if (y2 > 1000000000) {
    ++x1;
    y2 = (s+x1-1) / x1;
  }
  ll d = x1*y2 - s;
  ll x2 = d;
  ll y1 = 1;
  cout<<"0 0 "<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int ans[101000]={0};
	int n,m,flag = 1;
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= m; i ++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		ans[a]++,ans[b]++;
	}
	for(int i = 1; i <= n ; i ++)
		if(ans[i] & 1)
			flag = 0;
	if(flag == 0)
		printf("NO");
	else
		printf("YES");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

ll gcd(ll a, ll b){
  if(a<b)swap(a,b);
  if(b==0)return a;
  return gcd(b,a%b);
}


int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll x,y;cin >> x >> y;
  rep(i,N-1){
    ll x_,y_;cin >> x_ >> y_;
    int n = 1;
    ll s = 0, e = (1e18+10)/max(x_,y_);
    while(e-s>1){
      ll m = (s+e)/2;
      if(x <= m*x_ && y <= m*y_)e = m;
      else s = m;
    }
    x = e*x_;
    y = e*y_;
  }
  cout << x + y << endl;
  return 0;
}


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


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

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
n = int(input())
dat = list(map(int, input().split()))
p = dat[0]
res = 0
for i in range(1, len(dat)):
    if p == dat[i]:
        dat[i] = "x"
        p = "x"
        res += 1
    else:
        p = dat[i]
print(res)


Measured memory_bytes: 38384
N, L = map(int, input().split())

A = []
P = []
for i in range(1, N+1):
    A.append(L+i-1)
    P.append(abs(L+i-1))

for i in range(N):
    if abs(A[i]) == min(P):
        print(sum(A) - A[i])
        break


Measured memory_bytes: 2940
def check(s):
	if len(s) % 2 == 1:
		return False
	l = len(s)
	return s[:l // 2] == s[-l // 2:]

s = input()
for i in range(300):
	if check(s[:-i - 1]):
		print(len(s) - i - 1)
		break


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N, H;
    cin >> N >> H;
    vector<LL> a(N);
    vector<LL> b(N);
    REP(i, N) {
        cin >> a[i] >> b[i];
    }
    LL A = *max_element(ALL(a));
    sort(ALL(b), greater<LL>());
    LL t = 0;
    LL res = (H + A - 1)/A;
    REP(i, N) {
        t += b[i];
        LL c = i + 1 + max<LL>((H - t + A - 1)/A, 0);
        res = min(res, c);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = 0;
    if(a>0 && c>0){
        ans = b * d;
    }
    else if(a>0){
        if(d>0) ans = b * d;
        else ans = a * d;
    }else if(c>0){
        if(b>0) ans = b*d;
        else ans = b*c;
    }else{
        ans = max(a*c,b*d);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
from fractions import gcd
mod=10**9+7
def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2%mod, n // 2)%mod
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2%mod, (n - 1) // 2)%mod
h,w,t=map(int,input().split())
H=gcd(h,t);W=gcd(w,t)
groups=H*W
unit=(h//H,w//W)
cnt=(pow_r(2,unit[0])+pow_r(2,unit[1])-3)%mod
unitd=gcd(unit[0],unit[1])
cnt+=pow_r(2,unitd)%mod
print(pow_r(cnt,groups))


Measured memory_bytes: 5176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		if(B < C||D < A)System.out.println("0");
		else if(A <= C&&B >= D)System.out.println(D - C);
		else if(C <= A&&D >= B)System.out.println(B - A);
		else if(A > C&&B > D)System.out.println(D - A);
		else if(A < C&&B < D)System.out.println(B - C);
		
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int fact[2000001], ifact[20000001], pp[2000001];

int powmod(int a, int b, int c = MOD){
    int ans = 1;
    while(b){
        if(b&1){
            ans = (ans*a)%c;
        }
        a = (a*a)%c;
        b >>= 1;
    }
    return ans;
}

void pre(){
    fact[0]=1;
    ifact[0]=1;
    pp[0]=1;
    For(i, 1, 2000001){
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
        ifact[i]=powmod(fact[i], MOD-2);
        pp[i] = pp[i-1] * 25 % MOD;
    }
}

int ncr(int n, int r){
    int v = fact[n]*ifact[n-r]%MOD;
    v = v*ifact[r]%MOD;
    return v;
}

void solve(){
    pre();
    int k; cin>>k;
    string s; cin>>s;
    int n = sz(s);
    int ans = 0;
    For(i, 0, k+1){
        // positions of 'a'
        int v = ncr(n+k, i)*pp[i]%MOD;
        ans += v;
        ans %= MOD;
    }
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 51128
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = ReadInt();
            var num = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

            Console.WriteLine(num[K - 1]);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
using i64 = long long;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

int main() {
    constexpr i64 mod = 998244353;
    int n, s;
    std::cin >> n >> s;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;

    const i64 inv = inverse(2, mod);
    std::vector<i64> dp(s + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        auto next(dp);
        for (int j = 0; j + a[i] <= s; j++) {
            next[j + a[i]] = (next[j + a[i]] + dp[j] * inv % mod) % mod;
        }
        std::swap(dp, next);
    }

    std::cout << dp.back() * pow(2, n, mod) % mod << std::endl;

    return 0;
}


Measured memory_bytes: 3656
function Main(input){
	input = Number(input.trim());
	const L = ~~(input/100),R = input %100;

	if(L >= 1 && L <= 12){
		if(R >= 1 && R <= 12) console.log('AMBIGUOUS');
		else console.log('MMYY');
	}else{
		if(R >= 1 && R <= 12) console.log('YYMM');
		else console.log('NA');
	}
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));
// Main(require('fs').readFileSync('./input.txt','utf8'));


Measured memory_bytes: 7372
#include <stdio.h>

int main(void){
  int x[2], y[2];
  scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);
  int x2, y2;
  y2=y[1]-y[0];
  x2=x[1]-x[0];
  y2<0?-y2:y2;
  x2<0?-x2:x2;
  printf("%d %d %d %d\n", x[1]-y2, y[1]+x2, x[0]-y2, y[0]+x2);
  return 0;
}


Measured memory_bytes: 128
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 998244353

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,X,M; cin>>N>>X>>M;
    vector<ll> v;
    v.push_back(X);
    map<ll,ll> mp;
    
    ll i = 2;
    ll pos = -1;
    ll ans = X;
    mp[X] = 1;
    for(;i<=N;++i)
    {
        ll f = v.back() * v.back();
        f %= M;
        
        if(mp.find(f) != mp.end())
        {
            pos = mp[f];
            break;
        }
        
        v.push_back(f);
        ans += f;
        mp[f] = i;
    }
    vector<ll> patt;
    
    ll sum = 0;
    if(pos != -1)
    {
        for(ll j=(pos - 1);j<(i - 1);++j)
        {
            patt.push_back(v[j]);
            sum += v[j];
        }
        
        ll rem = N - i + 1;
        ll sz = patt.size();
        ans += sum * (rem/sz);

        for(ll j=0;j<rem%sz;++j)
            ans += patt[j];
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 7476
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;


void solve() {
	int a, p; cin >> a >> p;
	cout << (a * 3 + p)/2 << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> dp(n+1,0);
	
	for(int i=0;i<n;++i){
		cin >> v[i];
	}
	int res = 0;
	
	for(int i=1;i<n;++i){
		if(v[i-1] >= v[i]){
			dp[i] = dp[i-1]+1;
		}
		res = max(res,dp[i]);
	}
	
	cout << res <<endl;
	
	
	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int N, Q;
string S[10000]; int x[10000];
int main() {
	while (true) {
		cin >> N >> Q;
		if (N == 0 && Q == 0) { break; }
		for (int i = 0; i < N; i++) {
			cin >> S[i] >> x[i];
		}
		string T; int sum = 0;
		for (int i = 0; i < Q; i++) {
			cin >> T; 
			for (int j = 0; j < N; j++) {
				int OK = 1;
				for (int k = 0; k < 8; k++) {
					if (T[k] != S[j][k] && S[j][k] != '*') {
						OK = 0;
					}
				}
				sum += OK*x[j];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1288
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        var a = r.nextInt();
        var b = r.nextInt();
        if(a <= 0 && b >= 0)
        {
            Console.WriteLine("Zero");
        } else if(a > 0 && b > 0)
        {
            Console.WriteLine("Positive");
        } else if ((Math.Abs(b) - Math.Abs(a)) % 2 != 0)
        {
            Console.WriteLine("Positive");
        } else
        {
            Console.WriteLine("Negative");
        }

    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    r, D, x = list(map(int, input().split()))

    output = x
    for _ in range(10):
        output = r * output - D
        print(output)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A, B, K = map(int, input().split())

    if A > K:
        print(' '.join(map(str, [A-K, B])))
    else:
        print(' '.join(map(str, [0, max(0, B-K+A)])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

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

    return 0;
}

Measured memory_bytes: 256
import itertools
A,B,C = list(map(int, input().split()))
K = int(input())
ans = False
for p in itertools.product(['a','b','c'], repeat=K):
    A0,B0,C0 = A,B,C
    for e in p:
        if e == 'a':
            A0 = 2*A0
        elif e == 'b':
            B0 = 2*B0
        else:
            C0 = 2*C0
    if A0 < B0 < C0 :
        ans = True
        break
print('Yes' if ans else 'No')


Measured memory_bytes: 9196
s = input()
t = input()
ssum = [0 for _ in range(len(s)+1)]
for i in range(len(s)):
    ssum[i+1] = ssum[i] + (s[i] == 'A')
tsum = [0 for _ in range(len(t)+1)]
for i in range(len(t)):
    tsum[i+1] = tsum[i] + (t[i] == 'A')
q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    cnts = (b-a+1)*2 - (ssum[b] - ssum[a-1])
    cntt = (d-c+1)*2 - (tsum[d] - tsum[c-1])
    print("YES" if cnts % 3 == cntt % 3 else "NO")

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

using namespace std;

int main(){
    long long int N,now;
    cin >> N;
    now = N-1;
    long long int ans=0,add=0;
    vector<long long int> A(N),B(N),b(N,N),C(N),c(N);

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

    for(int i=0;i<N;i++){
        cin >> B[i];
    }

    for(int i=0;i<N;i++){
        cin >> C[i];
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    for(int i=N-1;0<=i;i--){
        if(B[now]>=C[i]){
            b[now]=N-1-i;
            now--;
            i++;
            if(now==-1){
                break;
            }
        }
    }

    now=N-1;

    for(int i=N-1;0<=i;i--){
        if(A[now]>=B[i]){
            now--;
            i++;
            if(now==-1){
                break;
            }
        }else{
            ans += (b[i]*(now+1));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

vector <pii> res;

void solve() {
	int N, A[110];
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A+i);
	int a = (int)(min_element(A+1, A+1+N) - A);
	int b = (int)(max_element(A+1, A+1+N) - A);
	if(A[a] + A[b] >= 0) {
		for(int i=1;i<=N;i++) if(A[i] < 0) res.pb(pii(b, i)), A[i] += A[b];
		for(int i=1;i<N;i++) {
			if(A[i] > A[i+1]) res.pb(pii(i, i+1)), A[i+1] += A[i];
		}
	}
	else {
		for(int i=1;i<=N;i++) if(A[i] > 0) res.pb(pii(a, i)), A[i] += A[a];
		for(int i=N;i>1;i--) {
			if(A[i] < A[i-1]) res.pb(pii(i, i-1)), A[i-1] += A[i];
		}
	}
	printf("%d\n", szz(res));
	for(pii e : res) printf("%d %d\n", e.Fi, e.Se);
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int w, h;
	cin >> w >> h;
	int n;
	cin >> n;
	vi x(n), y(n), c(n);
	rep(i, n)cin >> x[i] >> y[i] >> c[i];

	int a = 0, b = 0;
	rep(i, n) {
		if (c[i] == 1) {
			a = max(a, x[i]);
		}
		if (c[i] == 2) {
			w = min(w, x[i]);
		}
		if (c[i] == 3) {
			b = max(b, y[i]);
		}
		if (c[i] == 4) {
			h = min(h, y[i]);
		}
	}

	int ax, ay;
	if (a >= w) {
		ax = 0;
	}
	else {
		ax = w - a;
	}

	if (b >= h) {
		ay = 0;
	}
	else {
		ay = h - b;
	}

	cout << ax*ay << endl;

	return 0;
}


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

int a, b, c;
int a_, b_, c_;

int main() {
  cin >> a >> b >> c;
  if (a == b && b == c && a % 2 == 0) {
    cout << "-1" << "\n";
    return 0;
  }
  int ans = 0;
  while (true) {
    if (a & 1 || b & 1 || c & 1) {
      break;
    } else {
      ans += 1;
      a_ = (b + c) / 2;
      b_ = (a + c) / 2;
      c_ = (a + b) / 2;
      a = a_;
      b = b_;
      c = c_;
    }
  }
  cout << ans << "\n";
}

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

const int MAX = 110;
int mat[MAX][MAX];
int d[MAX], f[MAX];
int n, t;

void dfs(int i)
{
  if (d[i] != -1) return;
  d[i] = ++t;
  for (int j = 0; j < n; j++)
    if (mat[i][j])
      dfs(j);
  f[i] = ++t;
}

int main()
{
  cin >> n;
  memset(mat, 0, sizeof(mat));
  for (int i = 0; i < n; i++) {
    int u; cin >> u; u--;
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int v; cin >> v; v--;
      mat[u][v] = 1;
    }
  }
  memset(d, -1, sizeof(d));
  t = 0;
  for (int i = 0; i < n; i++)
    dfs(i);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i+1, d[i], f[i]);
  return EXIT_SUCCESS;
}



Measured memory_bytes: 3272
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll solve(ll h, ll w){
  ll g=gcd(h, w);
  return (powmod(2, h)+powmod(2, w)+powmod(2, g)-3)%MOD;
}
int main()
{
	ll h, w, t; cin>>h>>w>>t;
  ll gh=gcd(h, t), gw=gcd(w, t);
  cout<<powmod(solve(h/gh, w/gw), gh*gw)<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC077_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            long m=0;
            for (long i = 1; i*i <= N; i++)
                m = i;
            Console.WriteLine(m * m);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

void add_b(vector< vector<int> > &b, int x0, int y0, int K){
    b[x0][y0]++;
    if(x0 < 3 * K) b[x0 + K][y0]--;
    if(y0 < 3 * K) b[x0][y0 + K]--;
    if(x0 < 3 * K && y0 < 3 * K) b[x0 + K][y0 + K]++;
}

signed main(){

    int N, K;
    cin >> N >> K;
    
    vector< vector<int> > b(4 * K, vector<int>(4 * K, 0)), s(4 * K, vector<int>(4 * K, 0));

    int x, y, x0, y0;
    char c;
    REP(i, N){
        cin >> x >> y >> c;
        if(c == 'W') x += K;

        x0 = x % (2 * K);
        y0 = y % (2 * K);
        REP(p, 4){
            REP(q, 4){
                if((p + q) % 2 == 0) add_b(b, (x0 + p * K) % (4 * K), (y0 + q * K) % (4 * K), K);
            }
        }
    }

    s[0][0] = b[0][0];
    int ans = s[0][0];

    FOR(j, 1, 4 * K){
        s[0][j] = s[0][j - 1] + b[0][j];
        ans = max(ans, s[0][j]);
    }
    FOR(i, 1, 4 * K){
        int tmp = 0;
        FOR(j, 0, 4 * K){
            tmp += b[i][j];
            s[i][j] = s[i - 1][j] + tmp;
            ans = max(ans, s[i][j]);
        }
    }

    cout << ans;
    

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 250752
const MOD: usize = 998_244_353;

fn main() {
    let (n, s): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut ans = 0;
    let mut dp = vec![0; s + 1];
    for i in 0..n {
        if a[i] <= s {
            for j in (0..=(s - a[i])).rev() {
                dp[j + a[i]] = (dp[j + a[i]] + dp[j]) % MOD;
            }
            dp[a[i]] = (dp[a[i]] + (i + 1)) % MOD;
        }
        ans = (ans + dp[s]) % MOD;
    }
    println!("{}", ans);
}

Measured memory_bytes: 2124
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int h, w;
  char c;
  bool no = false;
  cin >> h >> w;
  vector<vector<int>> map(h + 2, vector<int>(w + 2, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c;
      if (c == '#')
        map[i][j] = 1;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (map[i][j] == 1 && map[i - 1][j] == 0 && map[i][j - 1] == 0 && map[i][j + 1] == 0 && map[i + 1][j] == 0)
        no = true;
    }
  }
  if (no)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    string s;
    cin>>n>>s;
    string lans="",rans="";
    int l=0,r=0;
    for(int i=0;i<n;i++){
        if(s[i]==')'){
            r++;
            if(l<r){
                lans+="(";
                l++;
            }
        }
        else l++;
    }
    l=r=0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='('){
            l++;
            if(l>r){
                rans+=")";
                r++;
            }
        }
        else r++;
    }
    cout<<lans<<s<<rans<<endl;
}


Measured memory_bytes: 256