akhauriyash/Code-Regression huggingface dataset:
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
int P;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=155;
int n,p;
inline int max(R int x,R int y){return x>y?x:y;}
int solve(int n,int p){
	static int f[N][N];memset(f,0,sizeof(f));
	f[0][0]=1;
	fp(i,0,n-1)fp(j,0,p)if(f[i][j])upd(f[i+1][0],f[i][j]),upd(f[i+1][j+1],f[i][j]);
	R int res=0;fp(i,0,p)upd(res,f[n][i]);
	return res;
}
int f[N][N][N];
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&p,&P);
	if(p&1^1)return printf("%d\n",mul(solve(n>>1,p>>1),solve((n+1)>>1,p>>1))),0;
	f[0][0][0]=1;
	fp(i,1,n+1){
		R int r=(i<<1),l=r-p;
		R bool fr=(r>=1&&r<=n),fl=(l>=1&&l<=n);
		fp(j,0,n)fp(k,0,p)if(f[i-1][j][k]){
//			printf("%d %d %d\n",i,j,k);
			upd(f[i][0][0],f[i-1][j][k]);
			if(fr)upd(f[i][j+1][0],f[i-1][j][k]);
			if(fl)upd(f[i][0][k?k+1:k],f[i-1][j][k]);
			if(fl&&fr)upd(f[i][j+1][max(k+1,j+1)],f[i-1][j][k]);
		}
	}
	printf("%d\n",f[n+1][0][0]);
	return 0;
}

Measured memory_bytes: 12800
n = int(input())
cnt = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

for i in range(n - 1, -1, -1):
    r = b[i] - (a[i] + cnt) % b[i]
    if  r != b[i]:
        cnt += r
print(cnt)


Measured memory_bytes: 10996
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def myfunc(K):
    if K == 1:
        return 1
    elif K == 2:
        return 9

    temp = K
    for a in range(2,K):
        temp += sum([gcd(K,a,b) for b in range(1,a)])*6
    temp += sum([gcd(K,a,a) for a in range(1,K)])*6

    return myfunc(K-1) + temp

K = int(input())

print(myfunc(K))


Measured memory_bytes: 69728
#include <bits/stdc++.h>
 
const int N = 1010;  
typedef long long ll;
 
ll sym0, sym1, sym2;
int n, m, i, j, k;
 
struct cake_t {
  ll a, b, c;
  cake_t() {
    a = b = c = 0;
  }
  cake_t(ll _a, ll _b, ll _c) {
    a = _a;
    b = _b;
    c = _c;
  }
} cakes[N];
 
inline ll calc(cake_t x) {
  return x.a * sym0 + x.b * sym1 + x.c * sym2;  
}
 
inline bool operator < (cake_t p, cake_t q) {
  return calc(p) > calc(q);
}
 
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld %lld", &cakes[i].a, &cakes[i].b, &cakes[i].c);
  }
  ll ans = 0;
  for (sym0 = -1; sym0 <= 1; sym0 += 2) {
    for (sym1 = -1; sym1 <= 1; sym1 += 2) {
      for (sym2 = -1; sym2 <= 1; sym2 += 2) {
        std::sort(cakes + 1, cakes + n + 1);
        ll s0 = 0, s1 = 0, s2 = 0;
        for (int i = 1; i <= m; i++) {
          s0 += cakes[i].a;
          s1 += cakes[i].b;
          s2 += cakes[i].c;
        }        
        //printf("%lld %lld %lld %lld %lld %lld\n", sym0, sym1, sym2, s0, s1, s2);    
        ans = std::max(ans, calc(cake_t(s0, s1, s2)));
      }
    }
  }
  printf("%lld\n", ans);
  return 0;   
}

Measured memory_bytes: 384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false); 
    
    int N; cin >> N;
    vi W(N); REP(i, N) cin >> W[i];

    vi sum(N,0);
    sum[0] = W[0];
    FOR(i, 1, N) sum[i] = sum[i - 1] + W[i];

    int ans = INF;
    REP(i,N) {
        ans = min(ans, abs(sum[i] - (sum[N - 1] - sum[i])));
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cout << '#';
            }
            cout << '\n';
        }
        cout << '\n';
    }
    return 0;
}


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

struct Card { char suit, value; };

void bubbleSort(struct Card C[], int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N - 1; j >= i; j--) {
      if (C[j].value < C[j-1].value) {
        Card tmp = C[j];
        C[j] = C[j - 1];
        C[j - 1] = tmp;
      }
    }
  }
}

void selectionSort(struct Card C[], int N) {
  int minj;
  for (int i = 0; i < N; i++) {
    minj = i;
    for (int j = i; j < N; j++) {
      if (C[j].value < C[minj].value) {
        minj = j;
      }
    }
    Card tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }
}

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

void print(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

int main() {
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

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

  bubbleSort(C1, N);
  selectionSort(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        String[] N_array = st.nextToken().split("");
        int sum = 0;

        for(String str : N_array) {
            sum += Integer.parseInt(str);
        }
        
        if (sum % 9 == 0) {
            pw.println("Yes");
        } else {
            pw.println("No");
        }

        br.close();
        pw.close();
    }
}

Measured memory_bytes: 49540
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-20 00:17:54
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

template<class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  for (auto key : mp) {
    os << '{' << key.first << ',' << key.second << '}';
  }
  return os;
}

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

std::vector<std::pair<int64, int64>> prime_fact(int64 n){
  std::vector<std::pair<int64, int64>> result;
  for (int64 i = 2; i * i <= n; ++i){
    if (n % i != 0) continue;
    int cnt = 0;
    while (n % i == 0){
      n /= i; ++cnt;
    }
    result.emplace_back(i, cnt);
  }
  if (n != 1) result.emplace_back(n, 1);
  return result;
}

template<class T> T mod_pow(T x, T n, T mod) {
  T res = 1;
  while (n > 0) {
    if (n & 1) (res *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return res;
}

template<class T> T gcd(T x, T y) {
  while (y > 0){
    T tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

template<class T> T lcm(T x, T y) {
  if (x == 0 || y == 0) return 0;
  else return x * y / gcd(x, y);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

constexpr int64 MOD = 1e9 + 7;

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

  int n; cin >> n;
  vector<int64> p(n);
  cin >> p;

  vector<int64> p2 = p;

  map<int64, int64> mp;

  for (int i = 0; i < n; ++i) {
    for (int64 j = 2; j * j <= p[i]; ++j) {
      if (p[i] % j != 0) continue;
      int64 cnt = 0;
      while (p[i] % j == 0) {
        p[i] /= j;
        ++cnt;
      }
      mp[j] = max(mp[j], cnt);
    }
    if (p[i] != 1LL) mp[p[i]] = max(mp[p[i]], 1LL);
  }

  debug(mp);

  int64 ans = 0;

  int64 lcm_ = 1;

  for (auto x : mp) {
    lcm_ *= mod_pow(x.first, x.second, MOD);
    lcm_ %= MOD;
  }

  for (int i = 0; i < n; ++i) {
    ans += lcm_ * modinv(p2[i], MOD) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint a(N),b(N);
    REP(i,N) cin>>a[i]>>b[i];

    K++;

    int ans=0;
    for(int i=30;i>=0;i--){
        if(~K>>i&1) continue;

        int S=K&(~(1<<i));
        for(int j=i-1;j>=0;j--) S|=1<<j;

        int sum=0;
        REP(j,N){
            if((S|a[j])==S) sum+=b[j];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
// #define rep(i,n) for(int i=0;i<n;++i)
#define rep(i,i0,n) for(int i=i0;i<n;++i)
#define ALL(x) (x).begin(),(x).end()
#define pb = push_back;
#define INF12 1000000000000 //10^12
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;



int main() {
    string S;
    cin >> S;
    int N = S.size();
    int p[N] = {0};
    int count_RL = 0;
    int count_R = 0;
    int last_R = 0;
    rep(i,0,N) {
        char now = S[i];
        count_RL++;
        if(now == 'R') count_R++;

        // 最後尾
        if(i+1 == N) {
            int v = count_RL/2;
            p[last_R] = v;
            p[last_R+1] = v;
            if(count_RL%2) p[(count_R%2)?last_R:last_R+1]++;
        }
        char next = S[i+1];

        // RからLに切り替わるとき
        if(now == 'R' && next == 'L') {
            last_R = i;
        }

        //  LからRに切り替わるとき
        if(now == 'L' && next == 'R') {
            int v = count_RL/2;
            p[last_R] = v;
            p[last_R+1] = v;
            if(count_RL%2) p[(count_R%2)?last_R:last_R+1]++;

            // カウントリセット
            count_R = 0;
            count_RL = 0;
            continue;
        }
    }

    rep(i,0,N) {
        if(i != 0) cout << " ";
        cout << p[i];
    }
    cout <<  endl;
    return 0;
}


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

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

    int cnt[31] = {};
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;

        int p;
        while(k-- > 0){
            cin >> p;
            cnt[p]++;
        }
    }

    int ans = 0;
    for(int i = 1; i <= m; i++) if(cnt[i] == n) ans++;

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

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++)p[i]=sc.nextInt();
        double[] mean = new double[n];
        mean[0]=(p[0]+1)/2.0;
        for(int i=1;i<n;i++)mean[i]=(p[i]+1)/2.0+mean[i-1];
        double ans = 0;

        for(int i=0;i<n-k+1;i++){
            double temp;
            if(i==0)temp = mean[i+k-1];
            else temp = mean[i+k-1]-mean[i-1];
            ans=Math.max(ans,temp);
        }

        System.out.println(ans);

    }

}




Measured memory_bytes: 74392
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 1000

int main()
{
    int N, K;
    int sum = 0;
    vector<int> l;

    cin >> N >> K;
    
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }

    sort(l.begin(), l.end(), greater<int>());

    for(int i = 0; i < K; i++) {
        sum += l[i]; 
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAXN 200000
int a[MAXN];

int main(void) {
  int n, m;
  scanf("%i %i", &n, &m);
  
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%i %i", &u, &v);
    a[u]++;
    a[v]++;
  }
  
  for (int i = 1; i <= m; i++) {
    if (a[i] % 2) {
      puts("NO");
      return 0;
    }
  }
  
  puts("YES");
  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	int N,M,a;
	while(1){

		cin >> N >> M;
		if(N==0 && M==0) break;

		vector<int>S,D;
		rep(i,N){
			cin >> a;
			S.push_back(a);
		}

		rep(i,M){
			cin >> a;
			D.push_back(a);
		}

		int p=0;
		rep(i,M){

			p+=D[i];
			if(p<N-1) p+=S[p];

			if(p>=N-1){
			cout << i+1 << endl;
			break;
			}
		}

		S.clear(); D.clear();
	}

	return 0;
}

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

#define ll long long
#define mod 998244353
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

signed main()
{
    

    int n,k;
    cin>>n>>k;
    int ans[n+1];
    mem(ans,0);

    vector<pair<int,int>> v;
    ffor(i,0,k)
    {
        int x,y;
        cin>>x>>y;
        v.pb({x,y});
    }

    sort(all(v));

    int pre[n+1];
    mem(pre,0);
    ans[1]=1;
    pre[1]=1;

    ffor(i,2,n+1)
    {
        for(auto j:v)
        {
            if(i-j.ff<1) break;
            int l=max(1LL,i-j.ss);
            int r=max(1LL, i-j.ff);
            ans[i]=(ans[i]+pre[r]-pre[l-1]+mod)%mod;
            ans[i]=ans[i]%mod;
            if(l==1) break;
        }
        pre[i]=pre[i-1]+ans[i];
        pre[i]=pre[i]%mod;
       // cout<<i<<" "<<ans[i]<<endl;
    }
    cout<<ans[n];
    
    return 0;
}



Measured memory_bytes: 6720
N, A, B = map(int, input().split())
S = input()

win = 0
inter = 1
ans = []
for i in range(len(S)):
    if S[i] == "a":
        if win < A + B:
            ans.append("Yes")
            win += 1
        else:
            ans.append("No")
    elif S[i] == "b":
        if win < A + B and inter <= B:
            ans.append("Yes")
            win += 1
        else:
            ans.append("No")
        inter += 1
    else:
        ans.append("No")

for a in ans:
    print(a)


Measured memory_bytes: 4784
N = int(input())
B = list(map(int, input().split()))

def main():
    n = N
    S = []
    while B:
        tmp = -1
        for i in range(n):
            if B[i] == i+1:
                tmp = B[i]
                j = i
        if tmp == -1:
            return -1
        else:
            S.append(B.pop(j))
            n -= 1
    return S[::-1]

res = main()
if res == -1:
    print(-1)
else:
    for i in range(N):
        print(res[i])

Measured memory_bytes: 3064
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    string str;
    while(T --> 0)
    {
        cin>>n>>str;
        vector<int> R,G;
        map<int,bool> B;
        for(i=0;i<n;i++)
        if( str[i] == 'R')
            R.push_back(i);
        else if( str[i] == 'G')
            G.push_back(i);
        else
            B[i]=1;

        
        int ans=R.size()*G.size()*B.size();
        for(auto a:R)
        for(auto b:G)
        {
            if( (a+b)%2==0 and B[(a+b)/2] )
                ans--;
            if( B[2*a-b])
                ans--;
            if( B[2*b-a])
                ans--;
        }
        cout<<ans;
    }
    return 0;
}


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

namespace MyProgram{
    class AtCoder{
        static void Main(){
            string S = Console.ReadLine();
            int sum=0;
            for(var i=1;i<S.Length;i++){
                if(S[i]!=S[i-1]){
                    sum++;
                }
            }
            Console.WriteLine(sum);
        }
    } 
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    //X[0]~X[M-1]に格納する
    int* X;
    NEW(X,M);
    for(int i=0;i<M;i++){
        scanf("%d",&X[i]);
    }
    qsort(X,M,sizeof(int),asc);

    //for(int k=0;k<M;k++) printf("%d ",X[k]);
    //printf("\n");

    long ans=0;
    if(N>=M) ans=0;
    else{
        int* Y;
        NEW(Y,M-1);
        for(int i=0;i<M-1;i++){
            Y[i]=X[i+1]-X[i];
        }
        qsort(Y,M-1,sizeof(int),asc);
        //for(int k=0;k<M-1;k++) printf("%d ",Y[k]);
        //printf("\n");

        int j=0;
        while(M>N){
            ans+=Y[j];
            j++;
            M--;
        }
    }
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 1396
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    count = 0
    if p[i] < p[i-1]:
        count += 1
    if p[i] < p[i+1]:
        count += 1
    if count == 1:
        ans += 1

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld\n",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;
double e;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    //scan(n);

    ll A[10], B[10];
    for(int i=0; i<5; i++)
    {
        cin>> B[i];
        if(B[i]%10!=0)
        {
            if(minn>(B[i]%10))
            {
                minn=B[i]%10;
                x=B[i];
            }
        }
    }
    for(int i=0; i<5; i++)
    {
        if(B[0]==B[i])
        {
            sum++;
        }
    }
    if(sum==5)
    {
        cnt+=x;
        e = (double)B[0]/10.00;
        e=ceil(e);
        e*=10.00;
        cnt+=((int)(e*4));
    }
    else
    {
        for(i=0; i<5; i++)
        {
            if(B[i]==x)
            {
                cnt+=B[i];
            }
            else
            {
                e = (double)B[i]/10.00;
                e=ceil(e);
                e*=10.00;
                cnt+=((int)e);
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    if n == 1:
        print("Yes")
        return
    h = list(map(int, readline().rstrip().split()))
    for i in range(n - 1):
        right = h[n - i - 1]
        left = h[n - i - 2]
        if left == right + 1:
            h[n - i - 2] -= 1
        if left > right + 1:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 21604
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        int[] kane = new int[N];

        for(int i=0;i<N;i++){
            kane[i] = scan.nextInt();
        }
        Arrays.sort(kane);
        int min = kane[N-1] - kane[0];
        for(int i=0;i<N-M+1;i++){
            int x = kane[N-1-i];
            int y = kane[N-M-i];
            int z = x-y;
            if(z==0){
                min = 0;
                break;
            }else if(min>z){
                min=z;
            }
        }

        System.out.println(min);

    }
}

Measured memory_bytes: 50540
#include<iostream>
using namespace std;
int main(){
  int H,N;
  cin >> H >> N;
  for(int i=0;i<N;i++){
    int j;
    cin >> j;
    H -= j;
  }
  if(H<=0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] str = new String[H];
        char[][] c = new char[H][W];
        int[] count = new int[100];
        boolean[] test1 = new boolean[H];
        boolean[] test2 = new boolean[W];
        for(int i=0; i < H; i++){
            str[i] = sc.next();
            //System.out.println(str[i]);
            for(int j=0; j < W; j++){
                c[i][j] = str[i].charAt(j);
                //System.out.print(c[i][j]);
            }
            //System.out.print("\n");
        }
        for(int i=0; i < H; i++){
            for(int j=0; j < W; j++){
                if(c[i][j] == '#'){
                    test1[i] = true;
                    test2[j] = true;
                }
            }
        }
        for(int i=0; i < H; i++){
            for(int j=0; j < W; j++){
                if(test1[i] && test2[j]){
                    System.out.print(c[i][j]);
                }
                if(test1[i] && j==W-1){
                    System.out.println("");
                }
            }
        }
    }
}

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

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  char next_turn = 'a', winner;

  while(true) {
    if(next_turn == 'a') {
      if(sa.size() == 0) {
        winner = 'A';
        cout << winner << endl;
        return 0;
      }
      next_turn = sa[0];
      sa.erase(0, 1);
    }
    else if(next_turn == 'b') {
      if(sb.size() == 0) {
        winner = 'B';
        cout << winner << endl;
        return 0;
      }
      next_turn = sb[0];
      sb.erase(0, 1);
    }
    else if(next_turn == 'c') {
      if(sc.size() == 0) {
        winner = 'C';
        cout << winner << endl;
        return 0;
      }
      next_turn = sc[0];
      sc.erase(0, 1);
    }
  }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int A, B;
    std::cin >> A >> B;

    if (B == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }   

    int cnt = 1, socket = A;

    while (socket < B) {
        socket += (A - 1);
        ++cnt;
    }

    std::cout << cnt << std::endl;
     
    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
s = input()
flag = 0
for i in range(a):
    if s[i]>='0' and s[i]<='9': pass
    else: flag=1
if s[a]!='-': flag=1
for i in range(a+1, len(s)):
    if s[i]>='0' and s[i]<='9': pass
    else: flag=1
if flag==1: print("No")
else: print("Yes")

Measured memory_bytes: 3064
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a, b = nm()

if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

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

using namespace std;

int main(){
        int N;
        cin>>N;
        for (int i = 0; i < N; i++) {
                string a,b,c,d;
                cin>>a;
                cin>>b;
                int x=max(a.length(),b.length());
                for (int j = 0; j < x-a.length()+1; j++) {
                        c+="0";
                }
                for (int j = 0; j < x-b.length()+1; j++) {
                        d+="0";
                }
                c+=a;
                d+=b;
                for (int j = 0; j < x+1; j++) {
                        c[j]+=d[j]-'0';
                }
                for (int j = x; j >= 0; j--) {
                        if(c[j]>'9'){
                                c[j]-=10;
                                c[j-1]++;
                        }
                }

                if(c[0]!='0'){
                        if(x>=80){
                                cout<<"overflow"<<endl;
                                continue;
                        }
                        cout<<c[0];
                }else{
                        if(x>=81){
                        cout<<"overflow"<<endl;
                        continue;}
                }
                for (int j = 1; j <= x; j++) {
                        cout<<c[j];
                }
                cout<<endl;
        }

}

Measured memory_bytes: 1208
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = [''.join(sorted(list(input()[:-1].decode()))) for _ in range(n)]

    nc2 = [i * (i - 1) // 2 for i in range(10 ** 5 + 1)]

    summary = {}

    for si in s:
        if si in summary:
            summary[si] += 1
        else:
            summary[si] = 1

    ans = 0

    for si in summary:
        ans += nc2[summary[si]]

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 63708
using System;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var list = Console.ReadLine().Trim().Split(' ');
            var count = 0;
            if (list[0] == list[1]) count++;
            if (list[0] == list[2]) count++;
            if (list[1] == list[2]) count++;

            Console.WriteLine(count == 1 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
    private static final long MOD = 1_000_000_007;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final int[] tArray = new int[n];
        final int[] aArray = new int[n];

        int max = 0;
        for (int i = 0; i < n; i++) {
            final int t = scanner.nextInt();
            max = Math.max(t, max);
            tArray[i] = t;
        }

        for (int i = 0; i < n; i++) {
            final int a = scanner.nextInt();
            max = Math.max(a, max);
            aArray[i] = a;
        }

        long sum = 1;
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            final int t = tArray[i], a = aArray[i];
            if (t == max && a == max) {
                flag = true;
            }

            if (i > 0 && i < n - 1) {
                if (t != tArray[i - 1] || a != aArray[i + 1]) {
                    continue;
                }
                sum = sum * Math.min(t, a) % MOD;
            }
        }

        System.out.println(flag ? sum : 0);
    }
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll x;
    cin>>x;

    ans = (x/11)*2;
    if(x%11 > 6)ans+=2;
    else if(x%11!=0)ans++;


    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			char[] s = in.next().toCharArray();
			int n = s.length;
			int ans = 0;
			int b = 0;
			for (int i = 0; i < n; i++) {
				if (s[i] == 'g') {
					if (b > 0) {
						--b;
						++ans;
					} else {
						++b;
					}
				} else {
					if (b > 0) {
						--b;
					} else {
						--ans;
						++b;
					}
				}
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

	}
}



Measured memory_bytes: 11092
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
long long modpow(long long a, long long n) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<pair<pair<ll,ll>,int>>Py;
    for(int i=0;i<m;i++){
        ll p,y;cin>>p>>y;
        Py.pb(mp(mp(p,y),i));
    }
    sort(all(Py));
    vector<pair<int,string>>ans;
    int now=1;
    for(int i=0;i<m;i++){
        string pp="";
        pp+=to_string(Py[i].fi.fi);
        while(pp.length()<6){
            pp="0"+pp;
        }
        string ppp="";
        if(i)
            if(Py[i].fi.fi>Py[i-1].fi.fi)
                now=1;
        ppp+=to_string(now++);
        while(ppp.length()<6){
            ppp="0"+ppp;
        }
        string pu=pp+ppp;
        ans.pb(mp(Py[i].se,pu));
    }
    sort(all(ans));
    for(int i=0;i<m;i++)
        cout<<ans[i].se<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 10864
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }


int main() {
  int n; cin>>n;
  vector<int> a(n);
  rep(i, n) cin>>a[i];
  sort(a.begin(), a.end());
  set<int> s(a.begin(), a.end());

  int ans = 0;
  rep(i, n) {
    if (i == 0 and n >= 2 and a[i] == a[i+1]) continue;
    if (i == n-1 and n >= 2 and a[i] == a[i-1]) continue;
    if (i != 0 and i != n-1 and (a[i] == a[i-1] or a[i] == a[i+1])) continue;

    bool ok = true;
    if (a[i] == 1) {
      ++ans;
      continue;
    }
    for (int j = 1; j * j <= a[i]; ++j) {
      if (j == 1) {
        if (s.find(j) != s.end()) {
          ok = false;
          break;
        } else continue;
      }
      if (a[i] % j == 0) {
        int rem = a[i] / j;
        if (s.find(j) != s.end() or s.find(rem) != s.end()) {
          ok = false;
          break;
        }
      }
    }
    if (ok) ++ans;
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 13488
#include<cstdio>
#include<string>
#include<algorithm>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
using namespace std;
int h[100000];
 
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i = 0;i<n;i++){
		scanf("%d",&h[i]);
	}
	k--;
	sort(h,h+n);
	int min = h[k] - h[0];
	for(int i = 1;i<n-k;i++){
		int t = h[k+i] - h[i];
		if(t<min)min = t;
	}
	printf("%d\n",min);
	
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int a;

	scanf("%d\n",&a);

    if(a==3){ 
		printf("YES\n");
	}
	else if(a==5){
		printf("YES\n");
	}
	else if(a==7){
		printf("YES\n");
	}
    else {
		printf("NO\n");
    }

	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int w, h, n; cin >> w >> h >> n;
  int minX = 0, minY = 0, maxX = w, maxY = h;

  rep(i, n) {
    int x, y, a; cin >> x >> y >> a;
    if (a == 1) minX = max(minX, x);
    if (a == 2) maxX = min(maxX, x);
    if (a == 3) minY = max(minY, y);
    if (a == 4) maxY = min(maxY, y);
  }

  if (minX < maxX && minY < maxY)
    outl((maxX - minX) * (maxY - minY));
  else
    outl(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))

    #山1の降水量
    def check(x):
        s = x
        for i in a:
            x = i * 2 - x
        if s>=x:
            return 1
        else:
            return 0

    left = -1
    right = 10**10
    while right - left > 1:
        mid = (right+left) // 2
        if check(mid*2):
            right = mid
        else:
            left = mid
    res = [right*2]
    for i in a:
        res.append(i*2 - res[-1])
    res = map(str, res[:-1])
    print(' '.join(res))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19216
#include<iostream>

using namespace std;

int main(){
	int m,
		f,
		ans,
		siki=1,
		r;

	for (int i = 0; i < 50; i++){
		cin >> m >> f >> r;
		siki = 1;
		if (m == -1 && f == -1 && r == -1){
			break;
		}
		if (m == -1 || f == -1 || m + f < 30){
			cout << "F" << endl;
		}
		if (30 <= m + f&&m + f < 50 && r >= 50){
			cout << "C" << endl;
			siki = 0;
		}
		if (30 <= m + f&&m + f < 50 && m != -1 && siki != 0 && f!=-1){
			cout << "D" << endl;
			
		}
		if (50 <= m + f && m + f < 65){
			cout << "C" << endl;
		}
		
		if (65 <= m + f&&m + f < 80){
			cout << "B" << endl;
		}
		if (80 <= m + f){
			cout << "A" << endl;
		}
	}
}


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

using namespace std;
struct pct
{
    int x, y, id;
    bool operator<(pct b)
    {
        return x<b.x;
    }
};
int n,i;
pct a[200005];
int ans[200005];
int dsu[200005];
int sz[200005];
int mini[200005];
int maxi[200005];
int dsu_grup(int p)
{
    if(dsu[p]==p)
        return p;

    dsu[p]=dsu_grup(dsu[p]);
    return dsu[p];
}
void dsu_merge(int x, int y)
{
    x=dsu_grup(x);
    y=dsu_grup(y);

    dsu[y]=x;
    sz[x]+=sz[y];
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i].x>>a[i].y;
        a[i].id=i;
    }
    sort(a+1, a+n+1);
    for(i=1;i<=n;i++)
    {
        dsu[i]=i;
        sz[i]=1;
    }

    mini[0]=n+1;
    for(i=1;i<=n;i++)
        mini[i]=min(mini[i-1], a[i].y);

    maxi[n+1]=0;
    for(i=n;i>=1;i--)
        maxi[i]=max(maxi[i+1], a[i].y);

    for(i=1;i<n;i++)
    {
        if(mini[i]<maxi[i+1])
            dsu_merge(i, i+1);
    }

    for(i=1;i<=n;i++)
    {
        ans[a[i].id]=sz[dsu_grup(i)];
    }
    for(i=1;i<=n;i++)
        cout<<ans[i]<<' ';
    return 0;
}


Measured memory_bytes: 9888
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var num, last, stat, res int
	fmt.Scan(&last)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&num)
		if num > last {
			if stat == 1 {
				res++
			} else {
				stat = 1
			}
		}
		if num < last {
			if stat == -1 {
				res++
			} else {
				stat = -1
			}
		}
		last = num
	}
	fmt.Print(res)
}


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

using namespace std;
#define ull unsigned long long
#define ll long long
const int inf = 1e9;
const int MAXN = 4e6+4;

vector<vector<int>> vect(3e5+1, vector<int>(0));
vector<bool> was(3e5+1, false);
vector<int> arr(3e5+1, 0);
vector<int> depth(3e5+1, 0);
vector<int> colors;
ll mod=1e9+7;
void solve(){
    int t1, t2;
    cin>>t1>>t2;
    ull a1, a2,b1,b2;
    cin>>a1>>a2>>b1>>b2;

    if(a1*t1+a2*t2==b1*t1+b2*t2){
        cout<<"infinity";
        return;
    }
    if(a1<b1){
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a1*t1+a2*t2>b1*t1+b2*t2){
        cout<<0;
        return;
    }

    ll delta2=-(a1*t1+a2*t2)+(b1*t1+b2*t2);
    ll delta1=a1*t1-b1*t1;
    ll k=(delta2+delta1)/delta2;
    ll ans=2l*((delta2+delta1)/delta2)-1;
    if((k-1)*delta2-delta1==0) ans--;
    cout<<ans;

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n=1;
    for(int i=0;i<n;i++) solve();
    return 0;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
const long long maxx = 1000000000000000000LL;
int main(){
  prep();
  int m;
  cin >> m;
  pair<int, int> arr[m];
  long long sum = 0;
  long long len = 0;
  for (int i=0; i<m; i++){
      long long dig, cnt;
      cin >> dig >> cnt;
      arr[i] = {dig, cnt};
      sum += dig*cnt;
      len += cnt;
  }
  
  cout << sum/9+len-1-(sum%9 == 0);
  return 0; 
}

Measured memory_bytes: 1792