akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    string S;
    cin>>S;
    int goalx, goaly;
    cin>>goalx>>goaly;
    vector<int> xarr, yarr;
    bool axisx = true;
    int tmp = 0;
    for(int i=0;i<S.size();++i){
        if(S[i]=='F'){
            tmp++;
        }
        else{
            if(axisx) {
                xarr.push_back(tmp);
                axisx = false;
            }
            else {
                yarr.push_back(tmp);
                axisx = true;
            }
            tmp = 0;
        }
    }
    if(tmp>0){
        if(axisx) xarr.push_back(tmp);
        else yarr.push_back(tmp);
    }
    int x=0, y=0;
    x += xarr[0];
    vector<int> newx, oldx, newy, oldy;
    oldx.push_back(x);
    oldy.push_back(y);
    for(int i=1;i<xarr.size();++i){
        map<int, int> amap;
        for(int j=0;j<oldx.size();++j){
            if(amap[oldx[j]+xarr[i]]==0){
                newx.push_back(oldx[j]+xarr[i]);
                amap[oldx[j]+xarr[i]]++;
            }
            if(amap[oldx[j]-xarr[i]]==0){
                newx.push_back(oldx[j]-xarr[i]);
                amap[oldx[j]-xarr[i]]++;
            }
        }
        oldx = newx;
        newx.clear();
    }
    for(int i=0;i<yarr.size();++i){
        map<int, int> amap;
        for(int j=0;j<oldy.size();++j){
            if(amap[oldy[j]+yarr[i]]==0){
                newy.push_back(oldy[j]+yarr[i]);
                amap[oldy[j]+yarr[i]]++;
            }
            if(amap[oldy[j]-yarr[i]]==0){
                newy.push_back(oldy[j]-yarr[i]);
                amap[oldy[j]-yarr[i]]++;
            }
        }
        oldy = newy;
        newy.clear();
    }
    bool ansx = false, ansy = false;
    for(int i=0;i<oldx.size();++i){
        if(oldx[i]==goalx) ansx = true;
    }
    for(int i=0;i<oldy.size();++i){
        if(oldy[i]==goaly) ansy = true;
    }
    if((ansx) & (ansy)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N,  Q;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N); 
    REP(i, 0, N){
        ll a;
        cin >> a;
        fw.add(i, a);
    }
    REP(i, 0, Q){
        ll q, a, b;
        cin >> q >> a >> b;
        if(q == 0){
            fw.add(a, b);
        }else{
            cout << fw.sum(a, b) << endl;
        }
    }
}

Measured memory_bytes: 8208
N = input()
H = map(int, input().split())
last_h = float('inf')
ans, cnt = 0, -1
for h in H:
  if last_h >= h:
    cnt += 1
  else:
    if cnt > ans:
      ans = cnt
    cnt = 0
  last_h = h
print(ans if ans > cnt else cnt)

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

int main(){
    int n;
    cin >> n;
    if(n<105)cout << 0 << endl;
    else if(n<135)cout << 1 << endl;
    else if(n<165)cout << 2 << endl;
    else if(n<189)cout << 3 << endl;
    else if(n<195)cout << 4 << endl;
    else cout << 5 << endl;
}

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

using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<vector<int>> c(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        for (int j = 0; j < b[i]; ++j) {
            cin >> c[i][j];
            --c[i][j];
        }
    }
    constexpr int INF = 1'000'000'000;
    const int MX = 1 << N;
    vector<int> dp(MX, INF);
    dp[0] = 0;
    for (int i = 0; i < M; ++i) {
        vector<int> nxt(dp);
        for (int mask = 0; mask < MX; ++mask) {
            int nmask = mask;
            for (int j = 0; j < b[i]; ++j) {
                nmask |= (1 << c[i][j]);
            }
            nxt[nmask] = min(nxt[nmask], dp[mask] + a[i]);
        }
        dp = nxt;
    }
    cout << (dp[MX - 1] == INF ? -1 : dp[MX - 1]) << "\n";

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll K;cin>>K;
	ll 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};
    
	// 解法
	printf("%lld\n", A[K-1]);
}


Measured memory_bytes: 256
// #include <algorithm>
#include <stdio.h>
#include <vector> 
#include <math.h>
using namespace std;

vector<int> parent;
vector<int> Rank;

void makeSet(int x){
  parent.push_back(x);
  Rank.push_back(0);
}
int findSet(int x){
  if( x != parent[x] ){
    parent[x] = findSet(parent[x]);
  }
  return parent[x];
}
void link(int x, int y){
  if( Rank[x] > Rank[y] ){
    parent[y] = x;
  }else{
    parent[x] = y;
    if( Rank[x] == Rank[y] ){
      Rank[y] = Rank[y] + 1;
    }
  }
}

void unite(int x, int y){
  link(findSet(x), findSet(y));
}

int same(int x, int y){
  if(findSet(x)==findSet(y)){
    return 1;
  }
  return 0;
}

int main(){
  int n, q;
  scanf("%d %d" ,&n ,&q);
  for( int i = 0 ; i < n ; i++ ){
    makeSet(i);
  }
  for( int i = 0 ; i < q ; i++ ){
    int com, x, y;
    scanf("%d %d %d" ,&com ,&x ,&y );
    if(com == 0){
      unite(x ,y);
    }else{
      printf("%d\n" ,same(x ,y));
    }
  }

  return 0;
}



Measured memory_bytes: 2928
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solve(idx, cur, cost):
    #####
    if(idx==n):
        # print(cur)
        flag = 0
        for el in cur:
            if(el<x):
                flag = 1
                break
        if(flag==0):
            return cost
        else:
            return INF

    cur1 = [0]*m
    for i, el in enumerate(a[idx]):
        cur1[i] += el+cur[i]
    temp1 = solve(idx+1, cur1, cost+c[idx])
    temp2 = solve(idx+1, cur, cost)

    return min(temp1, temp2)

n,m,x = MAP()

c = []
a = []

for _ in range(n):
    temp = LIST()
    c.append(temp[0])
    a.append(temp[1:])

curr = [0]*m
ans = solve(0, curr, 0)
if(ans==INF):
    print(-1)
else:
    print(ans)

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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int v[2];v[0]=x2-x1;v[1]=y2-y1;
    int x3,y3,x4,y4;
    x3=-v[1]+x2;
    y3=v[0]+y2;
    x4=-v[0]+x3;
    y4=-v[1]+y3;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int H,W,h,w;
  	int answer;
  
  scanf("%d",&H);
  scanf("%d",&W);
  scanf("%d",&h);
  scanf("%d",&w);
  answer = H*W;
  answer -= h*W+w*(H-h);
  printf("%d",answer);
  return 0; 
}


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

namespace atcoder 
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var input = Console.ReadLine();
            var list = input.Split(" ").Select(s => Int32.Parse(s)).ToList();

            list.Sort();

            var a = list[list.Count/2 - 1];
            var b = list[list.Count/2];

            Console.WriteLine(b - a);
        }
    }
}

Measured memory_bytes: 35872
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
ll n,c,k;
struct node
{
	ll t,id;
}s[120000];
inline bool cmp(node a,node b)
{
	return a.t<b.t;
}
int main()
{
	n=read();
	c=read();
	k=read();
	for(rg int i=1;i<=n;++i)
	{
		s[i].t=read();
		s[i].id=i; 
	}
	stable_sort(s+1,s+1+n,cmp);
	int tot=0;
	int cnt=1;//当前第几个客人 
	double h=0;
	while(1)
	{
		if(cnt>n)
		{
			break;
		}
		int l=s[cnt].t;//最开始的这名客人的起始时间 
		int r=l+k;//终止时间 
		int hh=cnt;//保存开始这名客人的标号 
		ll sum=0;//累加这辆车坐的人数 
		for(rg int i=hh;i<=n;++i)
		{
			if(sum<c&&s[i].t<=r)
			{
				sum++;
			}
			else
			{
				break;
			}
		}
//		cout<<sum<<endl;
		cnt+=sum;
		tot++;
	}
	cout<<tot;
}

Measured memory_bytes: 2560
n=int(input())
song=[input().split() for i in range(n)]
last=input()

import numpy as np

songs = np.array(song)
b=np.argwhere(songs==last)

c=b[0]
d=c[0]
#print(d)

del song[:(int(d)+1)]
#print(song)

x=[song[i][1] for i in range(n-(d+1))]
time=[int(i) for i in x]
print(sum(time))

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

int main()
{
    int a;
    string s;
    int scount = 0;
    int dcount = 0;
    int count = 1000000000;

    cin >> a >> s;
    
    vector<int>  T(a+1);
    T[0] = 0;
    for(int i=0; i<a; i++)
    {
        if(s[i] == '#')
        {
            T[i+1] = T[i]+1;
        }
        else
        {
            T[i+1] = T[i];
        }
            
    }

    for(int i=0;i<a+1;i++)
    {
        scount = T[i];
        dcount = a - i - (T[a] - T[i]);
        count = min(scount + dcount, count);
    }

    cout << count << endl;

    return 0;

    
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=2e5+5;
int a[M],b[M],nxt[M],pr[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	s="$"+s;
	int cur=n+1;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='o')
		{
			cur=i;
			a[i]=1;
			if(i+c+1<=n)
				a[i]+=a[nxt[i+c+1]];
		}
		nxt[i]=cur;
	}
	int j=1;
	for(int i=k;i>=1;i--)
	{
		std::vector<int> v;
		while(j<=n)
		{
			if(s[j]=='x')
			{
				j++;
				continue;
			}
			if(a[j]>=i)
				v.pb(j);
			else
				break;
			j++;
		}
		int p=sz(v)-1;
		if(sz(v)==1)
			cout<<v[0]<<"\n";
		if(v[p]-v[0]>c)
			break;
		j=v[0]+c+1;
	}
	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

	vector <int> vec(N);

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}

	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());


	int s = 0;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			s = vec.at(0) / 2;
		}
		else {
			s += vec.at(i);
		}
		
	}
	cout << s << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main()
{
	int a , b , c;
	cin >> a >> b;
	c = a + b; 
	if(a%3 == 0 || b%3 == 0|| c%3 == 0)
		cout <<"Possible" << endl;
	else
		cout <<"Impossible" << endl;
	return 0;
} 




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = (1<<28);
typedef struct{
  int to; //行き先
  int cap; //容量 
  int rev; //逆辺
} Edge;

vector<Edge> g[10005]; //グラフの表現
bool used[10005]; //DFSですでに調べたかのフラグ

//fromからtoへ向かう容量capの辺をグラフを追加する
void add_edge(int from,int to,int cap);

//増加パスをDFSで探す
int dfs(int v,int t,int f);

//sからtへの最大流を求める
int max_flow(int s,int t);

int main(){
  ios_base::sync_with_stdio(false);

  int s,t,a,b,c;
  cin >> s >> t;
  for(int i=0;i<t;i++){
    cin >> a >> b >> c;
    add_edge(a,b,c);
  }
  cout << max_flow(0,s-1) << endl;
  return 0; 
}

void add_edge(int from,int to,int cap)
{
  g[from].push_back((Edge){to,cap,g[to].size()});
  g[to].push_back((Edge){from,0,g[from].size()-1});
  return;
}

int dfs(int v,int t,int f)
{
  if(v == t) return f;
  used[v] = true; //訪れた場所をtrue
  
  for(int i=0;i<g[v].size();i++){
    Edge &e = g[v][i];
    if( !used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d; //容量をdだけ引く
	g[e.to][e.rev].cap += d; //逆流をdだけたす
	return d;
      }
    }
  }

  return 0;
}

int max_flow(int s,int t)
{
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}


Measured memory_bytes: 3468
def extended_gcd(a, b)
  last_remainder, remainder = a.abs, b.abs
  x, last_x, y, last_y = 0, 1, 1, 0
  while remainder != 0
    last_remainder, (quotient, remainder) = remainder, last_remainder.divmod(remainder)
    x, last_x = last_x - quotient*x, x
    y, last_y = last_y - quotient*y, y
  end

  return last_remainder, last_x * (a < 0 ? -1 : 1)
end

def modinv(e, et=MOD)
  g, x = extended_gcd(e, et)
  if g != 1
    raise 'The maths are broken!'
  end
  x % et
end

require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,a,b = gets.chomp.split.map(&:to_i)
require 'openssl'

def all(n)
  ret = 2.to_bn.mod_exp(n, MOD) - 1
  ret
end

def nck(n,k)
  ans = 1
  k.times do |i|
    ans = ans * (n-i) % MOD
    ans = ans * modinv(i+1) % MOD
  end
  ans
end

ans = all(n) - nck(n,a) - nck(n,b)
while ans < 0
  ans += MOD
end
puts (ans + MOD)%MOD


Measured memory_bytes: 4724
// inputに入力データ全体が入る
function Main(input) {
  "use strict";
	const lines = input.split("\n");
  let nums = lines.map(s => parseInt(s, 10));
  nums.pop()
  const k = nums.pop();

  let n ;
  while (true) {
    n = nums.shift()
    if (n === undefined) break;
    if (!nums.every(x => Math.abs(n - x) <= k )) {
      break;
    }
  }
	//出力
  console.log( n === undefined ? "Yay!" : ":(")
}
// Exec
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  cout << pow(2.0, m) * (1900 * m + 100 * (n - m)) << endl;

  return 0;
}


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

using namespace std;
typedef pair<int,int> ii;

int n;
long long mod = 1000000007;
long long tree[400005];
int pre[200005];

void update(int i, int v){
    i += n;
    while(i > 0){
        tree[i] += v;
        tree[i] %= mod;
        i >>= 1;
    }
}

long long query(int l, int r){
    long long ans = 0ll;
    for(l += n, r += n;l < r;l >>= 1, r >>= 1){
        if(l&1){
            ans += tree[l];
            ans %= mod;
            l++;
        }
        if(r&1){
            r--;
            ans += tree[r];
            ans %= mod;
        }
    }
    return ans;
}

int main()
{
    //freopen("i.txt","r",stdin);

    ios_base::sync_with_stdio(false);


    cin >> n;
    int arr[n];
    fill(pre,pre+200005,-1);
    for(int i = 0;i < n;i++){
        cin >> arr[i];
        arr[i]--;
    }
    vector<ii> stuff;
    for(int i = 0;i < n;i++){
        int x = arr[i];
        if(pre[x] == -1){
            pre[x] = i;
        }
        else{
            if(pre[x] != i - 1) stuff.push_back(ii(pre[x],i));
            pre[x] = i;
        }
    }



    long long ans = 1ll;
    update(0,1);

    sort(stuff.begin(),stuff.end());

    for(int i = 0;i < stuff.size();i++){
        int x = stuff[i].first;
        int y = stuff[i].second;
        long long ways = query(0,x+1);
        ans += ways;
        ans %= mod;

        update(y,ways);
    }

    cout << ans;
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  rep(i,n) ans+=i;
  cout << ans << endl;
}


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

const int N = 200000;

int main(){
    int n; scanf("%d", &n);
    long long ans = 0, _max = 0;
    for (int i = 1; i <= n; ++i){
        int x; scanf("%d", &x);
        if (i > 1){
            if (x < _max){
                ans += _max - x;
            }
        }
        _max = max(_max, (long long)x);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
#define int long long
#define N 110
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int h,w;
string mp[N];

bool palin(string str){
  int k = str.size()/2;
  for(int i=0;i<k;i++) if(str[i] != str[str.size()-1-i]) return 0;
  return 1;
}

void Swap(int i,int j){for(int k=0;k<h;k++) swap(mp[k][i],mp[k][j]);}


bool ok(int n,int a=0){
  for(int i=0;i<n;i++) 
    for(int j=0;j<=a;j++) if(mp[i][j] != mp[i][w-j-1]) return 0;
  //for(int i=0;i<n;i++) if(!palin(mp[i])) return 0;
  return 1;  
}

int can(string str){
  int cnt[26]={};
  for(char ch:str) cnt[ch-'a']++;
  int c = 0 ;
  for(int i=0;i<26;i++) c += cnt[i] % 2;
  if(str.size() % 2) return c <=1;
  return c == 0;
}

bool check2(map<string,int> cnt,int n){
  int  c = 0;
  for(pair<string,int> p:cnt) c+=p.second%2;
  if(n%2 == 0) return c == 0;
  return c <=1;
}


bool check(){
  int cnt[26]={};
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) cnt[mp[i][j]-'a']++;

  int cnt2[26]={},sum = 0;
  for(int i=0;i<26;i++) cnt2[i] += cnt[i] % 4,sum += cnt2[i];
  if(sum == 0) return 1;
  int res = 0;
  if(sum > (w % 2) * h + (h % 2) * w) return 0;
 
  int c = 0;
  for(int i=0;i<26;i++) c += cnt[i]%2;
  if(h % 2 || w % 2) res |= c <= 1;
  else res |= c == 0;
  
  
  return res;
}


signed main(){
  
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>mp[i];

  int ans = check();
  cout<<(ans? "Yes":"No")<<endl;
  
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;	cin>>a>>b;
	if(a<b)	FOR(i,0,b)	cout<<a;
	else if(b<a)	FOR(i,0,a)	cout<<b;
	else FOR(i,0,a)	cout<<a;
	cout<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define L 1000000

int main() {

  int n,S[L],q,T[L];
  int i,j,num=0;

  scanf("%d", &n);

  for( i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    /* code */
    scanf("%d", &T[i]);
  }

  for ( i = 0; i < q; i++) {
    for ( j = 0; j < n; j++) {
      /* code */
      if (T[i]==S[j]) {
        /* code */
        num++;
        break;
      }
    }
  }


  printf("%d\n", num);

  return 0;
}



Measured memory_bytes: 2108
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

n = ii()
a,b = input().split()
c = ''

for i in range(n):
	c+=(a[i]+b[i])
print(c)

Measured memory_bytes: 3316
import java.util.*;

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

    x = x - a;
    while(0 <= x){
      x = x - b;
    }

    x += b;
    System.out.println(x);
  }
}


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


int main(int argc,char** argv)
{

	int a,b;
	cin >> a >> b;

	int dif = b-a;
	int tmp1=0,tmp2=0;

	for(int i = 1; i < 1000; i++){
		tmp1 += i;
		tmp2 = tmp1 + i+1;
		if(tmp2 - tmp1 == dif){
			cout << tmp1 - a <<endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
public class Main {
  private static void solve() {
    long x = nl();
    long y = nl();
    
    long now = x;
    int count = 1;
    while (now * 2 <= y) {
      count ++;
      now *= 2;
    }
    System.out.println(count);
  }

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

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

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

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

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

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

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

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

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

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

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

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




Measured memory_bytes: 22612
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int d;
		char ch;
		int[] s = new int[66];
		for(int i = 0; i < n; i++){
			ch = input.next().charAt(0);
			d = input.nextInt();
			if (ch == 'S')s[d] = 1;
			if (ch == 'H')s[d+13] = 1;
			if (ch == 'C')s[d+26] = 1;
			if (ch == 'D')s[d+39] = 1;
		}
		for(int i = 1; i <= 52; i++)
		{
			if(s[i] == 0) 
			{
				if (i < 14)System.out.println("S " + i);
				else if (i < 27)System.out.println("H " + (i-13));
				else if (i < 40)System.out.println("C " + (i-26));
				else System.out.println("D " + (i-39));
			}
		}
	}
}

Measured memory_bytes: 26324
S = input()

n = len(S)-1

def calc(s):
    return sum(list(map(int, s.split("+"))))

def dfs(i, S, k):
    ans = 0
    if i==n:
        return calc(S)

    ans += dfs(i+1, S, k)
    ans += dfs(i+1, S[:i+1+k] + "+" + S[i+1+k:], k+1)

    return ans

if n==0:
    print(S)
else:
    print(dfs(0, S, 0))



Measured memory_bytes: 3064
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    allxor=0
    for i in range(n):
        allxor = allxor ^ a[i]
    if allxor == 0:
        return 'Yes'
    else:
        return 'No'

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)


Measured memory_bytes: 20556
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));

        // 主処理
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < a.length; i++) {
            set.add(a[i]);
        }
        boolean judge = n == set.size();
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 53548
n = int(input())
l = list(map(int, input().split()))

# print(n)
# print(l)

l_s = sorted(l, reverse=True)

# print(l_s)

longest = l_s.pop(0)

# print(longest)
# print(l_s)

if longest < sum(l_s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int mysum = 0;

    if (n >= 1 && n < 10) {
        mysum += n;
    } else if (n >= 10 && n < 100) {
        mysum += 10 - 1;
    } else if (n >= 100 && n < 1000) {
        mysum += n - 100 + 1;
        mysum += 10 - 1;
    } else if (n >= 1000 && n < 10000) {
        mysum += 10 - 1;
        mysum += 1000 - 100;
    } else if (n >= 10000 && n < 100000) {
        mysum += n - 10000 + 1;
        mysum += 10 - 1;
        mysum += 1000 - 100;
    } else {
        mysum += 10 - 1;
        mysum += 1000 - 100;
        mysum += 100000 - 10000;

    }

    printf("%d", mysum);

    return 0;
}


Measured memory_bytes: 1704
string = gets
string.strip!

characters = %w[a b c d e f g h i j k l m n o p q r s t u v w x y z]

chars = string.chars.uniq
chars.each do |char|
  index = characters.index(char)
  if index
    characters.delete_at(index)
  end
end

if characters.empty?
  puts 'None'
else
  puts characters.first
end


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


class Program {

	public static double[,] leng;
	//static long mod = 1000000007;
	static long mod =998244353; 
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res = "";


		string res = "";


		int n = int.Parse(Console.ReadLine());
		int[] vals = new int[n]; ;
		int[][] pos = new int[n][];
		for ( int i = 0; i < n; i++ ) {;
			vals = parseAry(Console.ReadLine().Split(cs));
			pos[i] = (int[])vals.Clone();
		}

		leng = new double[n, n];

		for ( int i = 0; i < n; i++ ) {
			for ( int k = 0; k < n; k++ ) {
				leng[i, k] = (double)Math.Sqrt((( pos[i][0] - pos[k][0] ) * ( pos[i][0] - pos[k][0] )) + (( pos[i][1] - pos[k][1] )*(pos[i][1] - pos[k][1])));

			}
		}


		int[] flg = Enumerable.Repeat(1, n).ToArray(); 
		for ( int i = 0; i < n; i++ ) {

			int[] nex=(int[])flg.Clone();
			nex[i]=0;
			root(n, i, nex,0);
		}

		double re = 1.0 * total / z;
			Console.WriteLine(re);

		return;

	}
	static public double total = 0;
	static public double z = 0;

	static void root(int n,int now,int[] flg,double sums) {

		if ( flg.Sum() == 0 ) {
			total += sums; z++; return; }

		for(int i=0;i<n;i++){
			if ( flg[i] == 0 ) { continue; }
			double sss= sums+leng[now, i];
			int[] nex = (int[])flg.Clone();
			nex[i] = 0;
			root(n, i, nex, sss);
		}

				

		return;
	}



	//	int配列をスペース区切りの文字列に変換
	static string stringBuilderArrayInt(int[] a) {
		StringBuilder sb = new StringBuilder();

		for ( int i = 0; i < a.Length; i++ ) {
			sb.Append(a[i] + " "); 
		}
		if ( sb.Length > 1 ) {
			sb = sb.Remove(sb.Length - 1, 1);
		}
		return sb.ToString(); ;
	}


	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}



}

Measured memory_bytes: 17484
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        
        int white = N*M;
        int black = 0;
        
        for(int i=0; i<=N; i++){
            for(int j=0; j<=M; j++){
                black = N*j + M*i -2*j*i;
                if(black == K){
                    System.out.println("Yes");
                    return;
                }


            }
            
        }     
        
        
          System.out.println("No");
        }
    }

Measured memory_bytes: 35696
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


ll a[200010];
ll sum[200010];

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

    ll n;
    cin >> n;
    rep(i, n){
        cin >> a[i];
        sum[i+1] = a[i] + sum[i];
    }

    ll res = inf;
    reps(i, 1, n){
        res = min(res, abs(sum[n]-2*sum[i]));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
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 main() {
    string s,t;
    cin >> s >> t;
    cout << t << s << "\n";
    }


Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include<vector>
#include<cstring>
#include<set>
#include <cstdio>
#include<queue>
#include<map>
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define endl '\n'
#define forup(i,a,n) for( int i =a; i < n; i++)
#define llforup(i,a,n) for( ll i =a; i < n; i++)
#define fordown(i,a,n) for( int i =a; i >= n; i--)
#define fornot(i,a,n) for( int i=a;!n;i++)
#define mod  (ll)(1e9+7)
#define ifempty(a)  if(!a)
using namespace std;
typedef long long ll;
inline int readnum()
{
	int p, data = 0; char ch = 0;
	while ((ch != ' - ') && ch < '0' || ch>'9') ch = getchar();//相当于正则表达式的搜索，跳过不需要的字符
	if (ch == '- ')p = -1, ch = getchar();
	else p = 1;
	while (ch >= '0' && ch <= '9') data = data * 10 + ch - '0', ch = getchar();//搜索需要的字符
	return data * p;
}
//E-mail 374656045@qq.com
#define MAX (unsigned)1e8
bool nprime[MAX+1];//自动初始化
int prime[MAX+1];//习惯性加一
class solve {
private:
	int N; int temp; int ans = 0;
	char ch;
public:
	solve()
	{
		N = read();
		int bound = EulerScreen()+1;//OK
		forup(i, 0, N)
		{
			temp = read();
			if (BinarySearch(prime, bound, temp))ans++;
		}
		cout << ans << endl;
	}
	inline int read()
	{
		int data = 0;
		//while (ch == ' ' || ch == '\n')ch = getchar();//工程惯用法
		ch = getchar();
		while (ch != ' ' && ch != '\n' && ch != EOF)
		{
			data = data * 10 + ch - '0';
			ch = getchar();
		}
		return data;
	}
	int EulerScreen()
	{
		int bound = -1;
		forup(i, 2, MAX)
		{
			if (!nprime[i])prime[++bound] = i;//vis是合数
			for (int j = 0; j <= bound && i * prime[j] <= MAX;j++)//检查边界,自左向右判断防止溢出
			{
				nprime[i * prime[j]] = true;//不能用isprime做来减少计算，该算法只能默认是素数
				if (i % prime[j] == 0)break;
			}
		}
		return bound;
	}
	 bool BinarySearch(int *A,int bound,int key)//升序排列的数组适用
	{
		int left=0; int right=bound;
		int mid;
		while (left < right)
		{
			mid = (left + right) / 2;
			if (A[mid] == key)return true;
			if (A[mid] > key)right = mid;//因为向下取整故0+1=1,1/2=0,不用减一。
			else if (A[mid] < key)left = mid + 1;//因为除法向下取整，所以不加一会出现3+4=7,7/2=3的死循环，这样的处理是为了应对小数
		}//多加一个else可以提升速度
		return false;
	}
};
int main(void)
{
	ios_base::sync_with_stdio(0); cin.tie(0);//慎用，cin和scanf混用会导致非MSC++WA
#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve solution;
#ifdef DEBUG
	fclose(stdin);//关闭文件 
	fclose(stdout);//关闭文件 
#endif
	return 0;

}




Measured memory_bytes: 123308
n = gets.to_i
sp = []
n.times do |i|
  s, p = gets.chomp.split
  sp << {:i => i+1, :s=> s, :p=>p.to_i}
end

sp.sort_by!{|x| [x[:s], -x[:p]]}

sp.each{ |x| puts x[:i] }


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

int main(){
	priority_queue<long long int> pq;
	int n,m;
	while(cin>>n>>m){
		while(!pq.empty()){
			pq.pop();
		}
		long long int total = 0;
		for(int i=0;i<n;i++){
			long long int temp;
			cin>>temp;
			pq.push(temp);
		}
		for(int i=0;i<m;i++){
			int temp = pq.top();
			pq.pop();
			pq.push(temp/2);
		}
		while(!pq.empty()){
			total+=pq.top();
			pq.pop();
		}
		cout<<total<<endl;
	}
	return 0;
}

Measured memory_bytes: 4292
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N, ans = 0;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    for(int i = 0; i < N; i++)  cin >> A[i];
    for(int i = 0; i < N; i++)  cin >> B[i];
    for(int i = 0; i < N-1; i++)    cin >> C[i];
    for(int i = 0; i < N; i++){
        ans += B[i];
    }
    for(int i = 0; i < N-1; i++){
        if(A[i]+1 == A[i+1]){
            ans += C[A[i]-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,ans=-1,tmp=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    if(n==1) ans=0;
    else{
        int r=n-1;
        while(1){
            while(v[r-1]>=v[r]){
                tmp++;
                r--;
                if(r<=0) break;
            }
            if(r<=0){
                ans=max(ans,tmp);
                break;
            }
            ans=max(ans,tmp);
            tmp=0;
            r--;
            if(r-1<=0) break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin>>a>>b;
	if (a<=8&&b<=8){
		cout<<"Yay!";
	}
	else {
		cout<<":(";
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var s string

	fmt.Scan(&s)

	c0 := float64(0)
	c1 := float64(0)
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			c0++
		} else if s[i] == '1' {
			c1++
		}
	}

	num := int64(math.Min(c0, c1) * 2)
	fmt.Println(num)
}


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

int main(int argc, char* argv[])
{
	int P,Q,R;
	cin>>P>>Q>>R;
	int MinD=P+Q+R;
	//A,B,C
	if (MinD>P+Q){
		MinD=P+Q;
	}
	if (MinD>P+R){
		MinD=P+R;
	}
	if (MinD>Q+R){
		MinD=Q+R;
	}

	cout<<MinD<<endl;
	return 0;
}

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

int main(){
    int w, h, n;
    cin >> w >> h >> n;

    int xl=0, xu=w, yl=0, yu=h;
    
    rep(i, n){
        int x, y, a;
        cin >> x >> y >> a;
        if(a==1){
            xl = max(xl, x);
        }else if(a==2){
            xu = min(xu, x);
        }else if(a==3){
            yl = max(yl, y);
        }else if(a==4){
            yu = min(yu, y);            
        }
    }
    printf("%d\n", max(xu-xl, 0)*max(yu-yl, 0));
    return 0;
}

Measured memory_bytes: 256
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let () =
  let s = read_line () in
  let n = String.length s in
  (*
   * "A" : dp.(i).(0).(0)
   * "?" : dp.(i).(0).(1)
   * 'AB' : dp.(i).(1).(0)
   * "A?" "?B" : dp.(i).(1).(1)
   * "??" : dp.(i).(1).(2)
   * "ABC" : dp.(i).(2).(0)
   * "AB?" "?BC" "A?C" : dp.(i).(2).(1)
   * "A??" "?B?" "??C" : dp.(i).(2).(2)
   * "???" : dp.(i).(2).(3)
   *)
  let dp =
    Array.init (n + 1) @@ fun _ ->
      Array.init 3 @@ fun j ->
        Array.make (j + 2) 0 in
  for i = 0 to n - 1 do
    dp.(i + 1).(0).(0) <- dp.(i).(0).(0) +^ if s.[i] = 'A' then 1 else 0;
    dp.(i + 1).(0).(1) <- dp.(i).(0).(1) +^ if s.[i] = '?' then 1 else 0;
    dp.(i + 1).(1).(0) <- dp.(i).(1).(0) +^ if s.[i] = 'B' then dp.(i).(0).(0) else 0;
    dp.(i + 1).(1).(1) <- dp.(i).(1).(1) +^ if s.[i] = '?' then dp.(i).(0).(0) else if s.[i] = 'B' then dp.(i).(0).(1) else 0;
    dp.(i + 1).(1).(2) <- dp.(i).(1).(2) +^ if s.[i] = '?' then dp.(i).(0).(1) else 0;
    dp.(i + 1).(2).(0) <- dp.(i).(2).(0) +^ if s.[i] = 'C' then dp.(i).(1).(0) else 0;
    dp.(i + 1).(2).(1) <- dp.(i).(2).(1) +^ if s.[i] = '?' then dp.(i).(1).(0) else if s.[i] = 'C' then dp.(i).(1).(1) else 0;
    dp.(i + 1).(2).(2) <- dp.(i).(2).(2) +^ if s.[i] = '?' then dp.(i).(1).(1) else if s.[i] = 'C' then dp.(i).(1).(2) else 0;
    dp.(i + 1).(2).(3) <- dp.(i).(2).(3) +^ if s.[i] = '?' then dp.(i).(1).(2) else 0;
  done;
  Printf.printf "%d\n" @@
  dp.(n).(2).(0) *^ power ( *^ ) 1 3 dp.(n).(0).(1)
  +^ dp.(n).(2).(1) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 1)
  +^ dp.(n).(2).(2) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 2)
  +^ dp.(n).(2).(3) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 3)


Measured memory_bytes: 16768
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        if(0 <= r && r < 1200){
            System.out.println("ABC");
            return;
        }
        else if(1200 <= r && r < 2800){
            System.out.println("ARC");
            return;
        }
        System.out.println("AGC");
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 300;
const int INF = 1e9;

string s;
int ans[N], n;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cin >> s;
	for(int i = ('A' - 0); i <= ('Z' - 0); ++i) {
		int j = i;
		for(int it = 1; it <= n; ++it) {
			if(j + 1 > ('Z' - 0)) j = ('A' - 1);
			++j;
		}
		ans[i] = j;
//		cout << i <<' '<< j <<'\n';
	}	
	fo(i, 0, sz(s) - 1, 1) {
		cout << char(ans[(s[i] - 0)]);
	}
	return 0;
}













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b;
  cin >> a >> b;
  if((a+b)%2==0){
    cout << (a+b)/2 << endl;
  }
  if ((a+b)%2 ==1){
  cout << (a+b)/2 +1 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
map<string,ll> name;
int main()
{
	ll n,m,i,j,k,kk,aa,bb,t,p,a,b,c,d;
     cin>>n;
     string s;
     k=0;
     for(i=0;i<n;i++)
     {
     	cin>>s;
     	if(name[s]==0)
     	{
     		name[s]=1;
     		k++;
		 }
	 }
	 cout<<k<<endl;
}

Measured memory_bytes: 19224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tmp;
        while (true){
            int judge = sc.nextInt();
            if (judge == 0) break;
            int sum = sc.nextInt(), max = sum, min = sum;
            for (int i = 1; i < judge; i++){
                tmp = sc.nextInt();
                sum += tmp;
                if (tmp >= max) max = tmp;
                if (tmp <= min) min = tmp;
            }
            sum -= max + min;
            System.out.println(sum / (judge - 2));
        }
    }
}

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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n + 1, 0);
	for (int i = 0; i < n; i++) cin >> a[i];
	unsigned long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] + a[i + 1] <= x) continue;
			ans += a[i + 1] + a[i] - x;
			if (a[i] < x) {
				a[i + 1] = x - a[i];
			}
			else {
				a[i] = x;
				a[i + 1] = 0;
			}
		
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c[][] = new int[3][3];

		int sum = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				c[i][j] = sc.nextInt();
				sum += c[i][j];
			}
		}

		if (sum % 3 != 0 || sum / 3 != c[0][0] + c[1][1] + c[2][2]) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

		sc.close();

	}

}

Measured memory_bytes: 35748
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

int main(){
    int N,M;
    int A[9];
    cin>>N>>M;
    rep(i,M) {
        cin>>A[i];
        A[i]--;
    }
    int num[9];
    num[0]=2;
    num[1]=5;
    num[2]=5;
    num[3]=4;
    num[4]=5;
    num[5]=6;
    num[6]=3;
    num[7]=7;
    num[8]=6;
    int d[8];
    rep(i,8) d[i]=-1;
    rep(i,M){
        d[num[A[i]]]=max(d[num[A[i]]],A[i]+1);
    }
    string dp[10001];
    rep(i,N+1) dp[i]="a";
    dp[0]="";
    Rep(i,N){
        rep(j,8){
            if(d[j]<0) continue;
            if(i-j<0) continue;
            if(dp[i-j][0]=='a') continue;
            if(dp[i][0]=='a') dp[i]=to_string(d[j])+dp[i-j];
            else{
                if(dp[i].size()>1+dp[i-j].size()) continue;
                else if(dp[i].size()==1+dp[i-j].size()){
                    if(dp[i][0]<to_string(d[j])[0]) dp[i]=to_string(d[j])+dp[i-j];
                }else dp[i]=to_string(d[j])+dp[i-j];
            }
        }
    }
    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 32384
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

mod = 998244353

N, K = rl()
lr = []
for i in range(K):
	l, r = rl()
	lr.append((l,r))
lr.sort()

dp = [0] * (N+1)
dp[1] = 1
dp[2] = -1

ans = 0
s = 0
flags = [1] * K
for i in range(1, N+1):
	s += dp[i]
	s %= mod
	for k in range(K):
		if flags[k] == 0:
			break
		l, r = lr[k]
		if i+l <= N:
			dp[i+l] += s
			if i+r+1 <= N:
				dp[i+r+1] -= s
			else:
				ans += s
				ans %= mod
				break
		else:
			flags[k] = 0
			break
print(ans)



Measured memory_bytes: 70820