akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define allr(x) (x.rbegin()),(x.rend())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...



ll num;
void test_case(){
    cin>>num;
    string str1 =   "24579";
    if(str1.find(num%10 + '0') != string::npos) cout<<"hon\n";
    else if(num%10 == 3) cout<<"bon";
    else cout<<"pon";
    return;
}




int main(){
	FAST_IO;
	int tt;
//	cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3604
#

import sys
input=sys.stdin.readline

def main():
    H=int(input())
    cnt=0
    ans=0
    while(H>1):
        H=int(H//2)
        ans+=2**cnt
        cnt+=1
    ans+=2**cnt
    print(ans)
    
    
    
if __name__=="__main__":
    main()


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

using ll = int64_t;
const int MAX = 2e5;

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, d; cin >> n >> d;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        ll x, y; cin >> x >> y;
        x = abs(x); y = abs(y);
        if ((x*x + y*y) <= d*d) cnt++;
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3592
h,w = map(int,input().split())

def isvalid(r,c):
    return 0 <= r < h and 0 <= c < w

g = [input() for _ in range(h)]
d = [1,0]
queue = [(0,0)]
dist = [[1000000]* w for _ in range(h)]
dist[0][0] = 0
if g[0][0] == '#':
    dist[0][0] = 1
while len(queue) > 0:
    next_queue = []
    for r,c in queue:
        for i in range(2):
            cos = dist[r][c]
            nr = r + d[i]
            nc = c + d[1^i]
            if not isvalid(nr,nc):
                continue
            if  g[r][c] != g[nr][nc]:
                cos += 1
            if cos < dist[nr][nc]:
                dist[nr][nc] = cos
                next_queue.append((nr,nc))
    queue = next_queue
print((dist[h-1][w-1] + 1)//2)

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

#define INT int
#define REP(i,a,b) for(INT i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    
    if(a > x || a+b < x){
        cout << "NO" <<endl;
    }else{
        cout << "YES" <<endl;
    }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> H >> W >> N;
  while(sum<N){
    sum+=max(H,W);
    num++;
  }
  Out(num);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void run(){
        Scanner sc = new Scanner(System.in);
        while(true){
            int[] card_num = new int[101];
            int m = sc.nextInt();
            if(m==0){
                break;
            }
            int[] value = new int[m];
            int[] num = new int[m];
            for(int i = 0; i < m; i++){
                value[i] = sc.nextInt();
                num[i] = sc.nextInt();
            }
            int[] dp = new int[1001];
            dp[0] = 1;
            for(int i = 0; i < m; i++){
                for(int ii = 1000 - value[i] -1; ii >= 0; ii--){
                    for(int iii = 1; iii <= num[i]; iii++){
                        if(ii + value[i]*iii <= 1000){
                            dp[ii + value[i]*iii] += dp[ii];
                        }
                    }
                }
            }
            /*
              System.out.println(Arrays.toString(dp));
              for(int i = 0; i < 100; i++){
              System.out.println(i + " : " + dp[i]);
              }
            */
            int g = sc.nextInt();
            for(int i = 0; i < g; i++){
                System.out.println(dp[sc.nextInt()]);
            }
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, H, W; cin >> N >> H >> W;
    // vector<ll> A(N), B(N);
    ll cnt = 0;
    rep(i, N){
        ll a, b; cin >> a >> b;
        if (a >= H && b >= W){cnt++;}
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    ll n, m;
    cin >> n >> m;
    if(2*n >= m){
        cout << m / 2 << endl;
    } else {
        cout << n + (m - 2*n)/4 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
S = int(input())

X1 = Y1 = 0
X2 = 10**9; Y2 = 1
if S % (10**9) == 0:
    X3 = 0
else:
    X3 = 10**9 - S%(10**9)

Y3 = (S + X3) // (10**9)

print(X1, Y1, X2, Y2, X3, Y3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main(){
  ll n;
  cin >> n;
  map<ll,ll>ans;
  for(ll i = 2; i * i <= n; i++){
    while(n % i == 0){
      ans[i]++;
      n /= i;
    }
  }
  if(n != 1)ans[n] = 1;
  ll an = 0;
  for(auto i : ans){
    ll ok = 1,cnt = 0;
    while(ok <= i.second){
      i.second -= ok;
      ok++;
      cnt++;
    }
    an += cnt;
  }
  cout << an << endl;
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<9&&b<9){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
        System.out.println();
        sc.close();
    }
}

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

int main(void){
    int n,m,ans = 0;
    cin >> n;
    vector<int> t(n);
    for(int i = 0;i < n;i++)cin >> t[i];
    cin >> m;
    vector<int> p(m),x(m);
    for(int i = 0;i < m;i++)cin >> p[i] >> x[i];
    for(int i = 0;i < m;i++,ans = 0){
        ans = accumulate(t.begin(),t.end(),0);
        if(x[i] > t[p[i]-1])ans += x[i] - t[p[i]-1];
        else ans -= t[p[i]-1] - x[i];
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
class Gcd:

    def __init__(self, K):
        self.table = [[None] * K for i in range(K)]
        return

    def gcd(self, x, y):
        if self.table[x - 1][y - 1] is not None:
            return self.table[x - 1][y - 1]

        if x == y:
            self.table[x - 1][y - 1] = x
            return x
        elif x > y:
            z = x % y
            if z == 0:
                self.table[x - 1][y - 1] = y
                return y
            else:
                z = self.gcd(z, y)
                self.table[x - 1][y - 1] = z
                return z
        else:
            return self.gcd(y, x)

def quest_c():
    K = int(input())

    gcd = Gcd(K)
    sum = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            d = gcd.gcd(a, b)
            if d == 1:
                sum += K
            else:
                for c in range(1, K + 1):
                    sum += gcd.gcd(d, c)
    print(sum)

if __name__ == '__main__':
    quest_c()

Measured memory_bytes: 9256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int i, j, k, N, key;
  int A[100];
  
  scanf("%d",&N);
  if(N < 1 || N > 100){
    fprintf(stderr,"Please enter the number of elements in the range from 1 to 100.(1st line)\n");
    exit(1);
  }
    
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
    
    if(A[i] < 0 || A[i] > 1000){
      fprintf(stderr,"Please enter the element in the range from 0 to 1000. (2nd line :%d)\n",i+1);
      exit(2);
    }
  }

  for(k = 0; k < N-1; k++){
      printf("%d ",A[k]); 
    }
    printf("%d\n",A[k]);
    
  for(i = 1; i < N; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;

    for(k = 0; k < N-1; k++){
      printf("%d ",A[k]); 
    }
    printf("%d\n",A[k]);

  }

  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;

void add_self(int &a, int b)
{
  a += b;
  if(a > mod) a -= mod;
}

void sub_self(int &a, int b)
{
  a -= b;
  if(a < 0) a += mod;
}

int main()
{
  int n, k;
  cin >> n >> k;
  int arr[n];
  for(int i = 0; i < n; i++) cin >> arr[i];
  vector<int>dp(k+1);
  
  dp[0] = 1;
  for(int i = 0; i < n;i++)
  {
    vector<int>fake(k+1);
    for(int j = k; j >= 0; j--)
    {
      int tmp = dp[j];
      int lb = j+1;
      int ub = j + min(k - j, arr[i]);
      if( lb <= ub){
        add_self(fake[lb], tmp);
        if ( ub + 1 <= k) sub_self(fake[ub+1], tmp);
      }
    }
  int sm = 0;
  for(int x = 0; x <= k; x++)
  {
    //cout << fake[x] << endl;
    add_self(sm, fake[x]);
    add_self(dp[x], sm);
  }
  }
  cout << dp[k]%mod << endl;
}
      
      
      
    

Measured memory_bytes: 1024
import itertools
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    names = [input() for _ in range(n)]

    first_char_dict = defaultdict(int)
    for name in names:
        if name[0] not in set("MARCH"):
            continue

        first_char_dict[name[0]] += 1

    chars = set(first_char_dict.keys())
    # 3文字未満なら組み合わせはないので0
    if len(chars) < 3:
        print(0)
        exit(0)

    n_combinations = 0
    for c in itertools.combinations(chars, 3):
        n_combinations += first_char_dict[c[0]] * first_char_dict[c[1]] * \
                          first_char_dict[c[2]]

    print(n_combinations)


Measured memory_bytes: 10156
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007


int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << 0.5;
		return 0;
	}
	else {
		double m = n;
		cout << (m + 1) / 2 / m;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

// べき乗の剰余
lint modpow(lint x, lint y, lint m) {
    if (y == 0) return 1;
    lint res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}

int main(void) {
    int n;
    cin >> n;
    --n;
    
    if (n == 1) {
        cout << "2 2" << endl;
        cout << "1 2 0" << endl;
        cout << "1 2 1" << endl;
        return 0;
    }
    
    const int MOD = 1e9 + 7;
    struct path {int s; int t; int w;};
    vector<path> m;
    bool first_appear = false;
    int k = 0;
    // bit を上から見る
    repeat_reverse_from_to (i, 19, 0) {
        int d = (n >> i) % 2;
        if (d == 0 and !first_appear) continue;
        if (!first_appear) {
            first_appear = true;
            repeat_from_to (j, 1, i) {
                path p, q;
                p.s = j; p.t = j+1; p.w = 0;
                q.s = j; q.t = j+1; q.w = modpow(2, j-1, MOD);
                m.push_back(p);
                m.push_back(q);
                k = j+1;
            }
        }
        else {
            //dump(i); dump(d); el;
            if (d == 0 and i != 0) continue;
            //cout << "here\n";
            path p;
            p.s = i+1; p.t = k;
            p.w = ((n >> (i+1)) << (i+1));
            m.push_back(p);
            if (d == 1 and i == 0) {
                path q;
                q.s = 1; q.t = k; q.w = n;
                m.push_back(q);
            }
        }
    }
    
    cout << k << " " << m.size() << endl;
    repeat (i, m.size()) {
        cout << m[i].s << " " << m[i].t << " " << m[i].w << endl;
    }
               
}

Measured memory_bytes: 256
import Data.IORef
import Control.Monad
 
main :: IO()
main = getLine >> getContents >>= (\(x:y:xs) -> solve (y - x) (min x y) xs).map read.lines >>= print
 
solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef a
                b' <- newIORef b
                forM_ xs $ \z -> do
                    x <- readIORef a'
                    y <- readIORef b'
                    when (z - y > x) $ writeIORef a' (z - y)
                    when (z < y)     $ writeIORef b' z
                readIORef a'

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll a,b,c;

int main(){
  cin >> a >> b >> c;
  if(a+b+2*sqrtl(a*b)<c){cout << "Yes";}
  else{cout << "No";}
  return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[1010][1010];
ll n, cnt, ans, a, b, c, d[1010][1010], tmp, m, h, w, x, y, sum, k, q;
ll sy, sx, gy, gx;

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

  cin >> h >> w >> sy >> sx >> gy >> gx;
  sy--;
  sx--;
  gx--;
  gy--;
  rep(i, h) rep(j, w) cin >> s[i][j];
  priority_queue<pair<P, ll>, vector<pair<P, ll>>, greater<pair<P, ll>>> que;
  rep(i, h + 5) rep(j, w + 5) d[i][j] = LINF;
  d[sy][sx] = 0;
  que.push({{0LL, sy}, sx});
  while (!que.empty()) {
    pair<P, ll> p = que.top();
    que.pop();
    ll nowy = p.fi.se, nowx = p.se;
    if (d[nowy][nowx] < p.fi.fi) continue;
    rep(i, 4) {
      int ny = nowy + dy[i], nx = nowx + dx[i];
      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (s[ny][nx] == '#') continue;
      if (d[ny][nx] > d[nowy][nowx]) {
        d[ny][nx] = d[nowy][nowx];
        que.push({{d[ny][nx], ny}, nx});
      }
    }
    rrep(sax, -2, 3) {
      rrep(say, -2, 3) {
        int ny = nowy + say, nx = nowx + sax;
        if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        if (s[ny][nx] == '#') continue;
        if (d[ny][nx] > d[nowy][nowx] + 1) {
          d[ny][nx] = d[nowy][nowx] + 1;
          que.push({{d[ny][nx], ny}, nx});
        }
      }
    }
  }
  ans = d[gy][gx];
  if (ans == LINF) ans = -1;
  Cout(ans);
  return 0;
}

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

int main () {

    int N;

    scanf("%d", &N);

    int A[N], B[N];

    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        B[i] = A[i] - i;
    }

    sort(B, B + N);

    long long ans = 0LL;

    for (int i = 0; i < N; i++) {
        ans += 0LL + abs(A[i] - (B[N/2] + i));
    }

    printf("%lld\n", ans);

    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  if ((a == 1)&&(b == 2)) {
    cout << 3 << endl;
  }
  if ((a == 2)&&(b == 1)) {
    cout << 3 << endl;
  }
  if ((a == 3)&&(b == 2)) {
    cout << 1 << endl;
  }
  if ((a == 2)&&(b == 3)) {
    cout << 1 << endl;
  }
  if ((a == 1)&&(b == 3)) {
    cout << 2 << endl;
  }
  if ((a == 3)&&(b == 1)) {
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		int K = sc.nextInt();
		int N = sc.nextInt();
		int max=0;int f1=0;int past1=0;
		
		
		
		for(int i =0;i!=N;i++) {
			int dis = sc.nextInt();
			if(i==0) f1=dis;
			if(dis-past1>max) max=dis-past1;
			past1=dis;
			if(i==N-1) {dis=K-dis+f1;if(dis>max)max=dis;}
		}
		p(K-max);
	}

}


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

using namespace std;

void solve()
{
	string S;
	cin >> S;
	regex re("A?KIHA?BA?RA?");
	cout << (regex_match(S, re) ? "YES" : "NO") << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

// mid番目の箇所は採用されるかどうかを判定する
bool isOK(long long mid, vector<long long> &a, long long n, long long m, long long v, long long p){
    
    if (n-p <= mid) return true; // はじめから上位p以内であれば採用される
    
    else if (a[mid] + m < a[n-p]) return false; // mを足されても上位p以内に入れない
    
    
    // otherwise
    long long mv = m * v;
    long long res = 0;
    
    // mid番目の値が, ちょうど上位p位になれるかどうかを判定する
    rep(j, n){
        
        if (a[j] <= a[mid]) res += m; //a[mid]自身以下であれば無視して良いから
        else if (n-p+1 <= j) res += m; // 上位p-1個は無視して良いから
        else res += (a[mid] + m - a[j]);
    }
    
    if (res >= mv) return true;
    else return false;
}

int main(){
    long long n, m, v, p;
    cin >> n >> m >> v >> p;
    
    vector<long long> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    
    //int ans;
    
    // binary_serachによりokの位置の下限を求める
    // ans = n - ok;
    
    //binary_serachによりokの位置の下限を求める
    long long ng = -1; //条件を満たさない
    long long ok = n;  //条件を満たす
    
    while(abs(ok - ng) > 1){
        long long mid = (ng + ok) / 2;
        
        if (isOK(mid, a, n, m, v, p)) ok = mid;
        else ng = mid;
        
       // cout << ng << " " << ok << endl;
    }
    
    long long ans = n - ok;
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
long n,i,a;
int main()
{
	for(cin>>n,i=1,a=99;i<=sqrt(n);i++)if(!(n%i))a=min(a,(long)max(to_string(i).size(),to_string(n/i).size()));cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

signed main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0)cout<<a+b<<endl;
    else cout<<b-a<<endl;
    
    
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;

type Map = HashMap<(usize, usize), i64>;
fn main() {
    input! {
        n: usize,
        mut ai: [i64; n],
    }
    let m = n/2;

    let mut memo = Map::with_capacity(n);
    let ans = dfs(&ai,  0,  m, &mut memo);
    println!("{}", ans);
}

fn dfs(ai: &[i64], idx: usize, count: usize, memo: &mut Map) -> i64 {
    let key = (idx, count);
    if let Some(v) = memo.get(&key) {
        return *v;
    }

    if count == 0 {
        memo.insert(key, 0);
        return 0;
    }

    if count > (ai.len() - idx + 1)/2 {
        memo.insert(key, std::i64::MIN);
        return std::i64::MIN;
    }

    let res = max(
        dfs(ai, idx+1, count, memo),
        dfs(ai, idx+2, count-1, memo) + ai[idx]
    );
    memo.insert(key, res);
    res
}

Measured memory_bytes: 34392
#include <stdio.h>
#include <string.h>
int main(){
  int i,j,n,count,out,hit,homerun,point;
  char s[8];
  char c[4]="HIT",cc[4]="OUT",ccc[8]="HOMERUN";
  scanf("%d",&n);
  for(count=0;count<n;count++){
    out=0;
    hit=0;
    homerun=0;
    point=0;
    while(1){
      if(out == 3){
	break;
      }
      scanf("%s",s);
      if(strcmp(s,c) == 0){
	hit++;
	if(hit == 4){
	  point++;
	  hit--;
	}
      }
      else if(strcmp(s,cc) == 0){
	out++;
      }
      else if(strcmp(s,ccc) == 0){
	point++;
	point+=hit;
	hit=0;
      }
    }
    printf("%d\n",point);
  }
  return (0);
}

Measured memory_bytes: 604
#include <stdio.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *parent;
  struct Node *left;
  struct Node *right;
};

#define NIL NULL
typedef struct Node* NodePointer;
NodePointer root;

void inOrder(NodePointer);
void preOrder(NodePointer);
void print(void);
void insert(int);
NodePointer makeNode(int);
void init(void);

int main(){
  int Q,i,x;
  char order[7];
  scanf("%d",&Q);
  for(i = 0 ; i < Q ; i++){
    scanf("%s",order);
    if(order[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else{
      print();
    }
  }
  return 0;
}

void inOrder(NodePointer x){
  if(x == NIL){ return; }
  inOrder(x->left);
  printf(" %d",x->key);
  inOrder(x->right);
}

void preOrder(NodePointer x){
  if(x == NIL){ return; }
  printf(" %d",x->key);
  preOrder(x->left);
  preOrder(x->right);
}

void print(){
  inOrder(root); printf("\n");
  preOrder(root); printf("\n");
}

void insert(int key){
  NodePointer x = root,y = NIL;
  NodePointer z = makeNode(key);
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

NodePointer makeNode(int key){
  NodePointer newNode = malloc(sizeof(struct Node));
  newNode->key = key;
  newNode->left = newNode->right = NIL;
  return newNode;
}

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


binary_tree = [{"parent": -1} for _ in range(N)]
for _ in range(N):
    node_input = input()
    id, left, right = map(int, node_input.split())

    binary_tree[id]["left"] = left
    binary_tree[id]["right"] = right

    if left != -1:
        binary_tree[left]["parent"] = id
    if right != -1:
        binary_tree[right]["parent"] = id


def set_depth(id, depth):
    if id == -1:
        return

    D[id] = depth
    set_depth(binary_tree[id]["left"], depth+1)
    set_depth(binary_tree[id]["right"], depth+1)

def set_height(id):
    h1, h2 = 0, 0
    if binary_tree[id]["left"] != -1:
        h1 = set_height(binary_tree[id]["left"]) + 1
    if binary_tree[id]["right"] != -1:
        h2 = set_height(binary_tree[id]["right"]) + 1
    H[id] = max(h1, h2)
    return H[id]


D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
    if binary_tree[id]["parent"] == -1:
        set_depth(id, 0)
        set_height(id)
        break



def get_sibling(id):
    parent_id = node["parent"]
    if parent_id == -1:
        return -1
    if binary_tree[parent_id]["left"] != id:
        return binary_tree[parent_id]["left"]
    else:
        return binary_tree[parent_id]["right"]

def get_degree(node):
    degree = 0
    if node["left"] != -1:
        degree += 1
    if node["right"] != -1:
        degree += 1
    return degree

def get_type(node, dgree):
    if node["parent"] == -1:
        return "root"
    if degree == 0:
        return "leaf"
    return "internal node"

for id in range(N):
    node = binary_tree[id]
    parent_id = node["parent"]
    sibling_id = get_sibling(id)
    degree = get_degree(node)
    node_type = get_type(node, degree)
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))


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

#define MAX_N 150
#define INF 9999999999LL

long long p[MAX_N];
long long x[MAX_N][MAX_N];
long long z[MAX_N][2];
long long N, M, D;

long long gcd(long long X, long long Y) {
	return Y ? gcd(Y, X % Y) : X;
}

int main() {
	cin >> N >> M >> D;
	for (int i = 0; i < M; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < M; j++) {
			cin >> x[i][j];
		}
		z[i][1] = 1;
		for (int j = 0; j < M; j++) {
			long long a1 = z[i][0], a2 = z[i][1], cnt1 = 0;
			if (x[i][j] == -1) {

			}
			else {
				while (true) {
					if (cnt1 >= 1000 || a1 >= INF) {
						z[i][0] = INF; z[i][1] = INF; break;
					}
					if (a1%p[j] == x[i][j]) {
						z[i][0] = a1;
						z[i][1] = a2*p[j] / gcd(a2, p[j]);
						break;
					}
					a1 += a2;
					cnt1++;
				}
			}
		}
	}
	int res = N;
	for (int i = 0; i < D; i++) {
		int b1 = z[i][0], b2 = z[i][1];
		if (z[i][0] == INF) {
			res = -1;
		}
		if (res >= 0) {
			int k = (res - b1) / b2;
			k *= b2;
			k += b1;
			res = k;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1284
import sys
input = sys.stdin.readline
from collections import deque

icase=0
if icase==0:
    n,q=map(int,input().split())
    g = [set() for _ in range(n)]
    for i in range(n-1):
        ai,bi=map(int,input().split())
        g[ai-1].add(bi-1)
        g[bi-1].add(ai-1)
    g=tuple(g)
    xx=[0]*n
    for i in range(q):
        pi,xi=map(int,input().split())
        xx[pi-1]=xx[pi-1]+xi
elif icase==2:
    n,q=4,3
    g = [deque([]) for _ in range(n)]
    g[0]=deque([1])
    g[1]=deque([0,2,3])
    g[2]=deque([1])
    g[3]=deque([1])
    p=[0]*q
    x=[0]*q
    p[0]=1
    x[0]=10    
    p[1]=0
    x[1]=100
    p[2]=2
    x[2]=1    
    xx=[0]*n
    for i in range(q):
        xx[p[i]]=xx[p[i]]+x[i]
#ans:100 110 111 110
elif icase==3:
    n,q=6,2
    g = [deque([]) for _ in range(n)]
    g[0]=deque([1,2])
    g[1]=deque([0,3,4])
    g[2]=deque([0,5])
    g[3]=deque([1])
    g[4]=deque([1])
    g[5]=deque([2])
    p=[0]*q
    x=[0]*q
    p[0]=0
    x[0]=10    
    p[1]=0
    x[1]=10    
    xx=[0]*n
    for i in range(q):
#        pi,xi=map(int,input().split())
        xx[p[i]]=xx[p[i]]+x[i]
        
#q = deque([0])
stack=[0]
parent=[-1]*n
while stack:
#    print(q)
    state = stack.pop()
#    print("------------- stack:",stack,"state:",state,"g:",g[state])
    for v in g[state]:
#        print("state:",state,"v:",v,"q:",q)
        if parent[state] == v:
            continue
        else:
            parent[v]=state
            stack.append(v)
            xx[v]+=xx[state]
#            print("parent:",parent,"xx:",xx,"stack",stack)

print(" ".join(map(str,xx[0: ])))


Measured memory_bytes: 93448
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, a) = readIntegerList()
    val xList = readIntegerList()
    //　i枚数　ｊ枚まで　k合計
    val dp = Array(n + 1) { Array(n + 1) { LongArray(50 * 50 + 1) } }
    dp[0][0][0] = 1
    for (i in 0 until n) {
        val x = xList[i]
        for (j in 0 until (n + 1)) {
            for (k in 0..(50 * 50)) {
                dp[i + 1][j][k] = dp[i][j][k] + if (j - 1 >= 0 && k - x >= 0) dp[i][j - 1][k - x] else 0
            }
        }
    }

    var ans = 0L
    for (i in 1..n) {
        ans += dp[n][i][a * i]
    }
    out.println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 109848
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int m1, d1, m2, d2;
	std::cin >> m1 >> d1 >> m2 >> d2;
	std::cout << (m1 != m2) << std::endl;
}

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

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  string s; cin >> s;
  int sum = 0;
  for(auto e:s){
    sum += e-'0';
    sum %= 9;
  }
  cout << (sum == 0 ? "Yes" : "No") << endl;
  return 0;
}


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

#define pi 3.141592654
#define lit 1000000007
#define endl '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define _max(a,b) ((a)>(b)?(a):(b))
#define _min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define lbd lower_bound
#define ubd upper_bound
#define ll  long long
#define ull unsigned long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define out(n) cout << n << " "
#define outl(n) cout << n << endl
#define line cout << endl
#define bug(n) {outl(n);return;}
#define debug(arr) cout << #arr << " = [ "; for(auto x : arr) cout << x << ' '; cout <<']' << endl;
#define print(mp) for(auto x : mp){ cout << #mp << " = [ "; cout << x.first << " , " << x.second << " ]" << endl;};
int main()
{
    io;

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    ll int n;
    cin>>n;

    vector <char> v;
    while(n!=0)
    {
        --n;
        v.pb((char)('a'+(n%26)));
        n=n/26;
    }
    reverse(v.begin(),v.end());
    
    for (auto &i:v)
        cout<<i;

    return 0;
}


Measured memory_bytes: 3620
package main

import "fmt"

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	s := make([]string, h)
	for i := range s {
		fmt.Scan(&s[i])
	}
	ans := "Yes"
	for i := range s {
		for j := range s[i] {
			if s[i][j] != '#' {
				continue
			}
			flg := false
			for x := -1; x <= 1; x++ {
				for y := -1; y <= 1; y++ {
					if abs(x)+abs(y) != 1 {
						continue
					}
					yy := i + y
					xx := j + x
					if xx < 0 || xx >= w || yy < 0 || yy >= h {
						continue
					}
					if s[yy][xx] == '#' {
						flg = true
					}
				}
			}
			if !flg {
				ans = "No"
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

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")
}

fn gcd(mut x: i64, mut y: i64) -> i64 {
    while y != 0 {
        let r = x % y;
        x = y; y = r;
    }
    x
}

fn main() {
    let n: usize = read();
    let mut v = vec![0;n];
    for i in 0..n {
        v[i] = read();
    }
    let mut g = 0;
    for v in v {
        g = gcd(g, v);
    }

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


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

using namespace std;

int main() {
	string s;
	int ans=0;
	cin >>s;
	if (s[0] == '1') ++ans;
	if (s[1] == '1') ++ans;
	if (s[2] == '1') ++ans;
		cout << ans  << endl;

	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;

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

  ll ans = 0;
  for(ll i=1; i<N+1;i++){
    if(!(i%3==0 || i%5==0)){
      ans += i;
    }
  }
  cout<<ans;
}


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

int main(void) {
    int N,R,rate; cin >> N >> R;
    if(N >= 10) rate = R;
    else rate = R + 100 * (10-N);
    cout << rate << endl;
}

Measured memory_bytes: 3604
k = int(input())
a = [
    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
]

print(a[k - 1])

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

struct UnionFindTree {
  vector<int> data;

  UnionFindTree(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  int find(int k) {
    if (data[k] < 0) return k;
    return data[k] = find(data[k]);
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int k) { return -data[find(k)]; }
};

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

  UnionFindTree uf(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
  }

  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));

  cout << ans << endl;
}


Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <queue>

constexpr int MAX_N=5000;

int n,m;

std::vector<int> G[MAX_N];

int in[MAX_N];

void topological_sort(std::vector<int>& order,bool& flag){
    for(auto&& row : G){
        for(auto&& val : row)
            ++in[val];
    }
    std::queue<int> que;

    for(int i=0;i<n;++i){
        if(!in[i])
            que.push(i);
    }

    while(!que.empty()){
        int v=que.front();
        que.pop();
        if(!que.empty())
            flag=true;
        for(auto&& x : G[v]){
            --in[x];
            if(in[x]==0)
                que.push(x);
        }
        order.push_back(v);
    }
}

int main() {
    std::cin>>n>>m;
    int a,b;
    for(int i=0;i<m;++i){
        std::cin>>a>>b;
        --a;
        --b;
        G[a].emplace_back(b);
    }
    std::vector<int> ord;
    bool flag=false;
    topological_sort(ord,flag);
    for(auto&& x : ord)
        std::cout<<x+1<<std::endl;
    std::cout<<flag<<std::endl;

    return 0;
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
package main

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

func nextLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

var fp *os.File

func input() *os.File {
	var err error
	fp, err = os.Open("input.txt")
	if err != nil {
		panic(err)
	}
	return fp
}

// main

func main() {

	//var sc = bufio.NewScanner(input())
	var sc = bufio.NewScanner(os.Stdin)

	var W, H, N int64
	var params = strings.Split(nextLine(sc), " ")
	W, _ = strconv.ParseInt(params[0], 10, 64)
	H, _ = strconv.ParseInt(params[1], 10, 64)
	N, _ = strconv.ParseInt(params[2], 10, 64)

	var maxA1x int64 = 0
	var minA2x int64 = W
	var maxA3y int64 = 0
	var minA4y int64 = H
	var a, x, y int64
	for i := 1; i < int(N+1); i = i + 1 {
		var line = strings.Split(nextLine(sc), " ")

		x, _ = strconv.ParseInt(line[0], 10, 64)
		y, _ = strconv.ParseInt(line[1], 10, 64)
		a, _ = strconv.ParseInt(line[2], 10, 64)

		if a == 1 {
			if x > maxA1x {
				maxA1x = x
			}
		} else if a == 2 {
			if x < minA2x {
				minA2x = x
			}
		} else if a == 3 {
			if y > maxA3y {
				maxA3y = y
			}
		} else if a == 4 {
			if y < minA4y {
				minA4y = y
			}
		}
	}

	var area int64
	if (maxA1x > minA2x) || (maxA3y > minA4y) {
		area = 0
	} else {
		area = (minA2x - maxA1x) * (minA4y - maxA3y)
	}

	fmt.Println(area)

	defer fp.Close()

}


Measured memory_bytes: 640
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;

vector<ll> div_factorize(long long n) {
    vector<ll> res;
    for(ll i=1;i*i<=n;i++){
        if(i*i==n){
            res.push_back(n);
            continue;
        }
        if(n%i==0){
            res.push_back(i);
            res.push_back(n/i);
        }
    }
    sort(res.begin(),res.end());
    return res;
}

int main(){
    ll N,M;
    cin>>N>>M;
    vector<ll> div = div_factorize(M);
    for(ll i=0;i<div.size();i++){
        ll m = div[div.size()-1-i];
        if(M/m>=N){
            cout<<m<<endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int x,y,z,l=0,r,m;
  cin>>x>>y>>z;
  r=x/y+1;
  while(l+1<r){
    m=(l+r)/2;
    (m*(y+z)+z<=x?l:r)=m;
  }
  cout<<l;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int mini = min(a*b,c);
    cout << mini;
    cout << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";
    return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args)
	{
		// TODO 自動生成されたメソッド・スタブ
		try
		{
			while(true)
			{
				String str[] = input(2);
				if(str[0].equals("0") && str[1].equals("0")) break;
				int a = Integer.parseInt(str[0]);
				int b = Integer.parseInt(str[1]);
				int c = 0;
				for(int i = 1; i <= a ; i++)
				{
					for(int j = i+1; ; j++)
					{
						int k = b - i - j;
						//System.out.println(i + " " + j + " " + k + " " + (j >= k || k > a || k < 1));
						if(j >= k) break;
						if(k > a || k < 1) continue;
						c++;
					}
				}
				System.out.println(c);
			}
		}
		catch(IOException e)
		{
		}
	}

	/*
	public static int Calc(int[] a, int f, int e)
	{
		ArrayList<Integer> list[] = new ArrayList[2];
		return e;
	}
	//*/

	public static String[] input(int Num) throws IOException
	{
		String str[] = new String[Num];
		String str2 = br.readLine();
		int j = 0;
		for(int i = 0; i < Num; i++)
		{
			if(i < Num - 1)
			{
				str[i] = str2.substring(j, str2.indexOf(" ", j));
				j = str2.indexOf(" ", j) + 1;
			}
			else
			{
				str[i] = str2.substring(j);
			}
		}
		return str;
	}

}



Measured memory_bytes: 24308
#include <cstdio>

using namespace std;

int main() {
    char S[256];
    scanf("%s", &S);
    if(*S=='S') {
        printf("Cloudy\n");
    }
    else if(*S=='C') {
        printf("Rainy\n");
    }
    else {
        printf("Sunny\n");
    }
    return 0;
}


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

int main(){
  int N;
  string S;
  
  cin >> N;
//Yが出るかに注目、出ればループを抜けたい(必要条件ではない)
  for (int i = 0; i < N; i++){
    cin >> S;
    if (S == "Y"){
      cout << "Four" << endl;
      break;
    }
    else{
      if (i == N - 1){
        cout << "Three" << endl;
      }
    }
  }
}
        
  

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    vi v ( n ) ;
    for ( int i=0 ; i < n ; i++ ) cin >> v[i] ;

    int ans = 1 ;
    for ( int i=1 ; i < n ; i++ )
    {
        int j = i - 1 ;
        for ( ; j > -1 && v[i] >= v[j] ; j-- ) ;

        if ( j == -1 ) ans ++ ;
    }

    cout << ans ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256