akhauriyash/Code-Regression huggingface dataset:
/**
 *      ABC 112 B
 *      author  : kyomukyomupurin
 *      created : 2018-10-06 21:03:19
**/

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, T; cin >> N >> T;
    int c[N] = {}; int t[N] = {};
    for (auto i = 0; i < N; ++i) {
        cin >> c[i] >> t[i];
    }

    bool flag = false;
    int ans = 1001;

   for (auto i = 0; i < N; ++i) {
       if (t[i] <= T){
           flag = true;
           if (c[i] < ans){
               ans = c[i];
           }
       }
   } 
    if (!flag){
        cout << "TLE" << '\n';
    }
    else {
        cout << ans << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 256
#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 FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n;
  cin >> n;
  vector<int> x(n);
  REP(i, n) cin >> x[i];
  sort(ALL(x));

  int min = INF, sum;

  for(int p = x[0]; p <= x[n - 1]; p++) {
    sum = 0;
    REP(i, n) { sum += (x[i] - p) * (x[i] - p); }
    if(sum < min)
      min = sum;
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long int n,a[1000009],b[1000009],c[1000009],dp[1000000][10];
 	
long long int solve(int i, int z)
{
    long long int ans;

	if(i>n)
	return 0;
	
	if(dp[i][z] != -1)
	return dp[i][z];
	
	if(z==1)
	ans= max(b[i]+solve(i+1,2),c[i]+solve(i+1,3));
	else if(z==2)
	ans= max(a[i]+solve(i+1,1),c[i]+solve(i+1,3));
	else if(z==3)
	ans= max(a[i]+solve(i+1,1),b[i]+solve(i+1,2));
	else
	ans= max(a[i]+solve(i+1,1),max(b[i]+solve(i+1,2),c[i]+solve(i+1,3)));
	
	return dp[i][z]=ans;
}
int main() {
    for(int i=0;i<1000000;i++)
    {
        for(int j=0;j<10;j++)
        dp[i][j]=-1;
    }
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i]>>b[i]>>c[i];
	cout<<solve(1,0);
	return 0;
}

Measured memory_bytes: 93056
// In the name of Allah the Lord of the Worlds.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

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

    int a;
    string ar;
    cin >> a >> ar;
    if(a<3200)cout << "red" << endl;
    else cout << ar << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}
vector<bool>isP(1e6+5);
vector<ll>primes;

int main() {
    fast();
    for (ll i = 2; i<=1e6 ; ++i) {
        if(!isP[i]){
            primes.push_back(i);
            for (ll j = i*i; j <=1e6 ; j+=i) {
                isP[j]=1;
            }
        }
    }
    ll n;cin>>n;
    ll ans=0;
    for (int k = 0; k <primes.size() ; ++k) {
       int cnt=0;
        while (n%primes[k]==0){
            cnt++;
            n/=primes[k];
        }
//        cout<<ans<<" ";
        for (int i = 0; i <=64 ; ++i) {
            if(cnt<(i*(i+1)/2)){
                ans+=(i-1);
                break;
            }
        }
    }
    cout<<ans+(n>1);
}

Measured memory_bytes: 4328
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>
#include <map>
#include <utility>

using namespace std;

int main(){
    string s;
    cin >> s;
    int c = 0;
    int f = 0;

    for(int i = 0; i < 3; i++){
        if(s[i] == 'R'){
            c++;
        }
    }

    if(c == 2 && s[1] == 'S'){
        c=1;
    }
    

    cout << c << endl;
}

Measured memory_bytes: 3592
INF = - 10 ** 20
n = gets.to_i
nums = gets.split.map(&:to_i)
# [num][採用数ぴったりとの差(-1, 0, +1)][直前選んだかどうか]
dp = (n + 1).times.map { 3.times.map { Array.new(2, INF) } }
# 初期化
# dp[0 個目のnum][採用数はぴったり][直前は選んでいない]の最大値は 0
dp[0][1][0] = 0

# n個分ループする（i は遷移元の数字）
n.times do |i|
  # 最適化のため、事前に 1 行分だけ参照渡しをする
  dp_current = dp[i]
  dp_next = dp[i + 1]
  next_num = nums[i]
  3.times do |count|
    next_count = i.odd? ? count - 1 : count
    2.times do |selected|
      if selected == 1
        next if next_count < 0 || next_count > 2
        dp_next[next_count][0] = dp_current[count][1] if dp_next[next_count][0] < dp_current[count][1]
      else
        if next_count < 2
          dp_next[next_count + 1][1] = dp_current[count][0] + next_num if dp_next[next_count + 1][1] < dp_current[count][0] + next_num
        end
        if next_count > - 1
          dp_next[next_count][0] = dp_current[count][0] if dp_next[next_count][0] < dp_current[count][0]
        end
      end
    end
  end
end

puts dp.last[1].max


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

typedef pair<int,int>P;

int n,dis[100005],ans[100009];
vector<P>v[100005];

void dfs1(int idx,int pre){
  for(int i=0;i<v[idx].size();i++){
    int next=v[idx][i].first;
    int cost=v[idx][i].second;
    if(next==pre)continue;
    dfs1(next,idx);
    dis[idx]=max(dis[idx],dis[next]+cost);
  }
}

int dfs2(int idx,int d_pre,int pre){
  vector<P>child;
  child.push_back(P(0,-1));
  for(int i=0;i<v[idx].size();i++){
    int next=v[idx][i].first;
    int cost=v[idx][i].second;
    if(next==pre)child.push_back(P(d_pre+cost,next));
    else child.push_back(P(dis[next]+cost,next));
  }
  sort(child.begin(),child.end(),greater<P>());
  int res=child[0].first+child[1].first;
  ans[idx]=max(child[0].first,child[1].first);
  for(int i=0;i<v[idx].size();i++){
    int next=v[idx][i].first;
    int cost=v[idx][i].second;
    if(next==pre)continue;
    res=max(res,dfs2(next,child[next==child[0].second].first,idx));
  }
  return res;
}

int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    int a,b,w;
    cin>>a>>b;a--;b--;
    v[a].push_back(P(b,1));
    v[b].push_back(P(a,1));
  }
  dfs1(0,-1);
  dfs2(0,0,-1);
  for(int i=0;i<n;i++)cout<<(n-1)*2-ans[i]<<endl;
}


Measured memory_bytes: 28000
#include  <iostream>

using namespace std;

int dr(int argDr, int argJoi)
{
	if (!(argDr % argJoi)) { return argDr / argJoi; }
	return (argDr / argJoi) + 1;
}

int main()
{
	int day, dr1, dr2, joi1, joi2;
	
	cin >> day;
	cin >> dr1;
	cin >> dr2;
	cin >> joi1;
	cin >> joi2;
	
	joi1 =	dr(dr1, joi1);
	joi2 =	dr(dr2, joi2);
		
	cout << day - (joi1 > joi2 ? joi1 : joi2) << endl;
}

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

typedef vector<int> vi; 
typedef pair<int,int> p;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1)*4
#define modi 1000000

void solve(){
	
	ll n;
	
	cin >> n;
	
	cout << (1000 - n%1000)%1000 << endl;

}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
	
	ifstream fin ("text.in");
    ofstream fout ("text.out");   
	
	ll t = 1;
	
	
	while(t--) solve();
	
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
#define PI 3.14159265

int main(){
  long a,b,c;
  cout<<fixed;
  cout<<setprecision(8);
  cin>>a>>b>>c;
  cout<<a*b*sin(c*PI/180)/2<<" ";
  double d=sqrt(a*a+b*b-2*a*b*cos(c*PI/180));
  cout<<a+b+d<<" ";
  
  
  cout<<b*sin(c*PI/180)<<endl;
  return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    string S; cin >> S;
    int ans = 0;
    if (S == "RRR") ans = 3;
    else if (S == "RRS") ans = 2;
    else if (S == "SRR") ans = 2;
    else if (S == "RSR") ans = 1;
    else if (S == "RSS") ans = 1;
    else if (S == "SRS") ans = 1;
    else if (S == "SSR") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 3588
import re

s = re.split("[ .,]", input())
sl = len(s)
ans = list()

for i in range(sl) :
  if(2 < len(s[i]) and len(s[i]) < 7) :
    ans.append(s[i])
  else :
    pass

ansl = len(ans)

for i in range(ansl) :
  if(i == ansl - 1) :
    print(ans[i])
  else :
    print(ans[i], end = (" "))


Measured memory_bytes: 6512
n, t = map(int, input().split())
cmin = 10**10
for i in range(n):
  c, ti = map(int, input().split())
  if ti > t:
    continue
  cmin = min(cmin, c)
if cmin == 10**10:
  print('TLE')
else:
  print(cmin)


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

struct data{int a,b,c,d;};

data calc(data p,data q){
  data res;
  res.a=p.a*q.a-p.b*q.b-p.c*q.c-p.d*q.d;
  res.b=p.a*q.b+p.b*q.a+p.c*q.d-p.d*q.c;
  res.c=p.a*q.c-p.b*q.d+p.c*q.a+p.d*q.b;
  res.d=p.a*q.d+p.b*q.c-p.c*q.b+p.d*q.a;
  return res;
}

int main(){
  data p,q;
  int n;
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>p.a>>p.b>>p.c>>p.d;
      cin>>q.a>>q.b>>q.c>>q.d;
      data ans=calc(p,q);
      cout<<ans.a<<' '<<ans.b<<' '<<ans.c<<' '<<ans.d<<endl;
    }
  }
}

Measured memory_bytes: 1160
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
cnt = [sum(a >> j & 1 for a in A) for j in range(50)]
ans = 0


def dfs(x, v, f):
    global ans
    if x < 0:
        ans = max(ans, v)
    elif f:
        dfs(x - 1, v + max(cnt[x], N - cnt[x]) * (1 << x), 1)
    elif K >> x & 1:
        dfs(x - 1, v + (cnt[x]) * (1 << x), 1)  # 0
        dfs(x - 1, v + (N - cnt[x]) * (1 << x), 0)  # 1
    else:
        dfs(x - 1, v + (cnt[x]) * (1 << x), 0)  # 0


dfs(49, 0, 0)
print(ans)


Measured memory_bytes: 14836
#include <iostream>
#include <map>

using namespace std;
using ull = unsigned long long;

int main(int argc, const char * argv[]) {
    
    int N, M;
    cin >> N >> M;
    
    map<ull,ull> mp;
    int A, B;
    for (int i=0; i<N; ++i)
    {
        cin >> A >> B;
        mp[A] += B;
    }
    
    ull money = 0;
    for(auto x : mp)
    {
        if (x.second >= M)
        {
            money += M * x.first;
            break;
        }
        money += x.first * x.second;
        M -= x.second;
    }
    
    cout << money << endl;
    
    return 0;
}


Measured memory_bytes: 6528
#ABC085B
n=int(input())
l=[]
for i in range(n):
	l.append(input())
#set型のオブジェクトはコンストラクタset()でも生成できる。
#引数としてリストやタプルのようなイテラブルオブジェクトを指定すると、重複する要素が除外されて一意な値のみが要素となるsetオブジェクトが生成される。
s_l=set(l)
#s_l=sorted(s_l)
#set to list by sorted
#print(type(s_l))
ans=len(s_l)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#define int long long int
vector<vector<int>> vec1,vec2;
void function2(int initial,int final,vector<int> &vec,int status)
{
	if(initial>final)
	{
		if(status==1)
		{
			vec1.push_back(vec);
		}
		else
		{
			vec2.push_back(vec);
		}
	}
	else
	{
		vec.push_back(initial);
		function2(initial+1,final,vec,status);
		vec.pop_back();
		function2(initial+1,final,vec,status);
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h,w,k;
	cin>>h>>w>>k;
	char mat[h][w];
	int i,j;
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			cin>>mat[i][j];
		}
	}
	int answer=0;
	vector<int> vec;
	function2(0,h-1,vec,1);
	vec.clear();
	function2(0,w-1,vec,2);
	for(auto p:vec1)
	{
		for(auto p2:vec2)
		{
			char mat2[h][w];
			for(i=0;i<h;i++)
			{
				for(j=0;j<w;j++)
				{
					mat2[i][j]=mat[i][j];
				}
			}
			for(int x:p)
			{
				for(j=0;j<w;j++)
				{
				    mat2[x][j]='R';
				}
			}
			for(int x:p2)
			{
				for(i=0;i<h;i++)
				{
					mat2[i][x]='R';
				}
			}
			int count=0;
			for(i=0;i<h;i++)
			{
				for(j=0;j<w;j++)
				{
					if(mat2[i][j]=='#')
					  count++;
				}
			}
			if(count==k)
			   answer++;
		}
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 3664
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize);

    let mut ans = 0;

    for i in 1..(n + 1) {
        ans += (((2 * i) + ((n / i) - 1) * i) * (n / i)) / 2;
    }

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


Measured memory_bytes: 2144
N = int(input())
S = 's' + input()
dp1 = [0] * (N+1)
dp2 = [0] * (N+1)
dp = [0] * (N+1)
for i in range(1, N):
    if S[i] == 'E':
        dp1[i+1] = dp1[i] + 1
    else:
        dp1[i+1] = dp1[i]
    if S[-i] == 'W':
        dp2[-(i+1)] = dp2[-i] + 1
    else:
        dp2[-(i+1)] = dp2[-i]
    dp[i+1] += dp1[i+1]
    dp[-(i+1)] += dp2[-(i+1)]
print(N-1-max(dp))


Measured memory_bytes: 29672
s = input()
A,B,C,D = s[0],s[1],s[2],s[3]

for op1,op2,op3 in [("+","+","+"),("+","+","-"),("+","-","+"),("+","-","-"),("-","+","+"),("-","+","-"),("-","-","+"),("-","-","-")]:
    if eval(A+op1+B+op2+C+op3+D) == 7:
        print(A+op1+B+op2+C+op3+D+"=7")
        break

Measured memory_bytes: 3064
import collections
n = int(input())
s = [input() for i in range(n)]
if n == 1:
  print("".join(sorted(s[0])))
else:
  c = []
  for i in s:
    c.append(collections.Counter(i))
  a = c[0] & c[1]
  for i in range(2, n):
    a &= c[i]
  ans = []
  a = a.most_common()
  for i in a:
    ans.append(i[0]*i[1])
  print("".join(sorted(ans)))

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  string s;
  bool ret = false;
  cin >> s;
  for(int i = 0; i < s.size(); i++) for(int j = i+1; j < s.size(); j++) ret |= s[i] == 'C' && s[j] == 'F';
  if(ret) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string solve(long long n) {
	vector<long long> v;
	long long cur = 1;
	for(int i = 1; cur * 100 <= n + 1000; i++) {
		v.push_back(cur);
		cur *= i + 7;
		cur /= i;
	}
	vector<int> c(v.size());
	for (int i = v.size() - 1; i >= 0; i--) {
		while (n >= v[i]) {
			n -= v[i];
			c[i]++;
		}
	}
	string ret;
	for (int i = 0; i < v.size(); i++) {
		ret += "FESTIVA" + string(c[i], 'L');
	}
	return ret;
}
int main() {
	long long n;
	cin >> n;
	cout << solve(n) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	string s;
	while (cin >> s)
	{
		if (s == "0") break;
		int l = s.size();
		map<string, int> used;
		used[s] = 0;
		queue<string> que;
		que.push(s);
		while (que.size())
		{
			string t = que.front();
			que.pop();
			bool f = true;
			REP(i, l)
			{
				if (t[i] != t[0]) f = false;
			}
			if (f)
			{
				cout << used[t] << endl;
				goto end;
			}
			REP(i, l-1)
			{
				if (t[i] != t[i + 1])
				{
					char c = 'r' + 'g' + 'b' - t[i] - t[i + 1];
					string tmp = t;
					tmp[i] = c; tmp[i + 1] = c;
					if (used.find(tmp) == used.end())
					{
						used[tmp] = used[t] + 1;
						que.push(tmp);
					}
				}
			}
		}
		puts("NA");
	end:;
	}

	return 0;
}

Measured memory_bytes: 2884
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[inf]*100010
  dp[0]=0
  for i in range(n):
    for j in range(1,k+1):
      if i+j<n:
        dp[i+j]=min(dp[i+j],dp[i]+abs(l[i+j]-l[i]))

  return dp[n-1]

print(main())


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

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if (b > n) {
        cout << (ll)(a*n/b) - a*(ll)(n/b) << endl;
    } else {
        cout << (ll)(a*(b-1)/b) - a*(ll)((b-1)/b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline--------------------------------------------
    X,Y,Z,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    A = A[:min(K,X)]
    B = list(map(int,input().split()))
    B.sort(reverse = True)
    B = B[:min(K,X)]
    C = list(map(int,input().split()))
    C.sort(reverse = True)
    C = C[:min(K,X)]
    Pre = []
    for i in range(min(X,K)):
        for j in range(min(Y,K)):
            Pre.append(A[i]+B[j])
    Pre.sort(reverse = True)
    Pre = Pre[:K]
    ans = []
    for i in range(min(Z,K)):
        for j in Pre:
            ans.append(j+C[i])
    ans.sort(reverse = True)
    for i in range(K):
        print(ans[i])



if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 163276
solve4 w h x y r = decision flag
  where
    flag = r <= x && x <= (w-r) && r <= y && y <= (h-r)
    decision True = "Yes"
    decision False = "No"

main = do
  temp <- getLine
  let [w,h,x,y,r] = map read . words $ temp
  putStrLn $ solve4 w h x y r



Measured memory_bytes: 3692
#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d",&a,&b,&c);
	if (a < b)
		if (b < c)
			printf("Yes\n");
		else
			printf("No\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 2596
_, k = gets.split("\s").map(&:to_i)
p = gets.split("\s").map(&:to_i)
max = 0.0
now = 0.0
p_range = []

p.each do |i|
  if p_range.size >= k
    former = p_range.shift
    now -= (1+former)/2.0
  end
  p_range.push(i)
  now += (1+i)/2.0

  max = now if now > max
end

p max

Measured memory_bytes: 16644
l = [ 0 for i in range(33)]
l[0] = 1
l[1] = 1

def f(n):
    if n == 2:
        if l[n] != 0:
            return l[2]
        else:
            l[2] = l[0] + l[1]
            return l[0] + l[1]
    elif n < 2:
        return l[n]
    else:
        if l[n] != 0:
            return l[n]
        else:
            l[n] = f(n-1) + f(n-2) + f(n-3)
            return l[n]
        
while True:
    n = int(input())
    if n == 0:
        exit()
    else:

        print(f(n)//3650+1)


Measured memory_bytes: 5600
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1

struct Node
{
	int p;
	int l;
	int r;
};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].p == NIL)
	{
		cout << "root, ";
	}
	else if (T[u].l == NIL)
	{
		cout << "leaf, ";
	}
	else
	{
		cout << "internal node, ";
	}

	cout << "[";
	for (int i = 0, c = T[u].l; c != NIL; ++i, c = T[c].r)
	{
		if (i)
		{
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}

void rec(int u, int p)
{
	D[u] = p;
	if (T[u].r != NIL)
	{
		rec(T[u].r, p);
	}
	if (T[u].l != NIL)
	{
		rec(T[u].l, p + 1);
	}
}

void solve()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		T[i].p = T[i].l = T[i].r = NIL;
	}
	int c, l, r;
	for (int i = 0; i < n; ++i)
	{
		int v, d;
		cin >> v >> d;
		for (int j = 0; j < d; ++j)
		{
			cin >> c;
			if (j == 0)
			{
				T[v].l = c;
			}
			else
			{
				T[l].r = c;
			}
			l = c;
			T[c].p = v;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		if (T[i].p == NIL)
		{
			r = i;
		}
	}
	rec(r, 0);
	for (int i = 0; i < n; ++i)
	{
		print(i);
	}
}

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



Measured memory_bytes: 7760
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a,b=mp()
p=lmp()
ans=[0,0,0]
for i in p:
    if i<=a:
        ans[0]+=1
    elif i<=b:
        ans[1]+=1
    else:
        ans[2]+=1
print(min(ans))

Measured memory_bytes: 77504
#include <cstdio>
using namespace std;

const int lim = 1000010;

int dp[lim];

int main(){
	for(int s = 1; s < lim; s *= 5){
		for(int t = s; t < lim; t *= 3){
			for(int u = t; u < lim; u *= 2){
				dp[u] = 1;
			}
		}
	}
	for(int i = 1; i < lim; ++i){
		dp[i] += dp[i - 1];
	}

	int x, y;
	while(scanf("%d%d", &x, &y) == 2){
		printf("%d\n", dp[y] - dp[x - 1]);
	}
}

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

int main()
{
  int n;
  int ret;
  
  cin >> n;
  
  if(n == 1)
  {
    ret = 1;
  }
  else
  {
    ret = n * n * n;
  }
  
  cout << ret << endl;
}

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

int main() {
  string s; cin >> s;
  int n = s.size();
  bool flag = true;
  for (int i = 0; i < n; i ++) {
    if (i % 2 == 0 && s[i] == 'L') flag = false;
    if (i % 2 == 1 && s[i] == 'R') flag = false;
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int N, M, R; cin >> N >> M >> R;
    vector<int> r(R); rep(i, R) cin >> r[i];
    vector<vector<int>> dist(N+1, vector<int>(N+1,0));
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) {
        if(i==j) dist[i][j] = 0;
        else dist[i][j] = 1001001001;
    }
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        dist[a][b] = dist[b][a] = c;
    }
    for(int k=1;k<=N;k++) {
        for(int i=1;i<=N;i++) {
            for(int j=1;j<=N;j++) {
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    sort(r.begin(), r.end());
    ll ans = 1e18;
    do {
        ll d = 0;
        for(int i=0;i<r.size()-1;i++) {
            d += dist[r[i]][r[i+1]];
        }
        ans = min(ans, d);
    }while(next_permutation(r.begin(), r.end()));
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), d(110, 0);
    rep(i, 0, n){
        cin >> a[i];
        d[a[i]]++;
    }
    int MAX = *max_element(all(a));
    int MIN = *min_element(all(a));
    bool f = true;
    if(d[MIN] == 1){
        if(MAX != 2 * MIN) f = false;
        rep(i, MIN + 1, MAX + 1) if(d[i] < 2) f = false;
    }else if(d[MIN] == 2){
        if(MAX != 2 * MIN - 1) f = false;
        rep(i, MIN + 1, MAX + 1) if(d[i] < 2) f = false;
    }else{
        f = false;
    }
    cout << (f ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
int main()
{
	fast;
	ll x; cin>>x;

	ll coin = (x%500)/5;
	ll p = 5*coin;
	ll sum = (x/500)*1000;

	ll ans = sum+p;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll N, K;
    input(N, K);

    ll res = 0;
    while (N > 0)
    {
        res++;
        N /= K;
    }

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

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


int main() {
  int mod = 1000000007;
  int n;
  cin >> n;
  ll sum = 0, ans = 0;

  rep(i, n) {
    int a;
    cin >> a;
    ans = (ans + a * sum) % mod;
    sum = (sum + a) % mod;
  }

  cout << ans << endl;

  return 0;
}
/*
*/


Measured memory_bytes: 3632
//
// Created by rajshah9914 on 29/03/20.
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,c;
    cin>>n>>c;
    long long a,b;
    vector<long long>w,val;
    for(long long i=0;i<n;i++)
    {
        cin>>a>>b;
        w.push_back(a);
        val.push_back(b);
    }
    long long dp[c+1];
    memset(dp,0,sizeof(dp));
    for(long long i=0;i<n;i++)
    {
        for(long long j=c;j>=w[i];j--)
        {
            dp[j]=max(dp[j],dp[j-w[i]]+val[i]);
        }
    }
    long long ans=0;
    for(long long i=0;i<=c;i++)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(x) begin(x), end(x)

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = int64_t;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;
using vb = vector<bool>;
constexpr int MOD1 = 1000000007;

template <int MOD> struct modnum {
    int v;
    modnum() : v(0) {
    }
    modnum(ll _v) : v(_v % MOD) {
        if (v < 0)
            v += MOD;
    }
    explicit operator int() const {
        return v;
    }
    friend istream &operator>>(istream &i, modnum &n) {
        ll v;
        i >> v;
        n = modnum(v);
        return i;
    }
    friend ostream &operator<<(ostream &o, const modnum &n) {
        return o << n.v;
    }

    friend bool operator==(const modnum &a, const modnum &b) {
        return a.v == b.v;
    }
    friend bool operator!=(const modnum &a, const modnum &b) {
        return a.v != b.v;
    }

    modnum &operator+=(const modnum &o) {
        v += o.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    modnum &operator-=(const modnum &o) {
        v -= o.v;
        if (v < 0)
            v += MOD;
        return *this;
    }
    modnum &operator*=(const modnum &o) {
        v = int(ll(v) * ll(o.v) % MOD);
        return *this;
    }
    modnum operator-() {
        modnum res;
        if (v)
            res.v = MOD - v;
        return res;
    }
    friend modnum operator+(const modnum &a, const modnum &b) {
        return modnum(a) += b;
    }
    friend modnum operator-(const modnum &a, const modnum &b) {
        return modnum(a) -= b;
    }
    friend modnum operator*(const modnum &a, const modnum &b) {
        return modnum(a) *= b;
    }

    modnum pow(int e) const {
        if (e == 0)
            return 1;
        if (e & 1)
            return *this * this->pow(e - 1);
        return (*this * *this).pow(e / 2);
    }

    modnum inv() const {
        int g = MOD, x = 0, y = 1;
        for (int r = v; r != 0;) {
            int q = g / r;
            g %= r;
            swap(g, r);
            x -= q * y;
            swap(x, y);
        }

        assert(g == 1);
        assert(y == MOD || y == -MOD);
        return x < 0 ? x + MOD : x;
    }
    modnum &operator/=(const modnum &o) {
        return (*this) *= o.inv();
    }
    friend modnum operator/(const modnum &a, const modnum &b) {
        return modnum(a) /= modnum(b);
    }

    static modnum fact(int n) {
        static vector<modnum<MOD>> fact = {1};
        while (fact.size() <= n)
            fact.push_back(fact.back() * fact.size());
        return fact[n];
    }
    static modnum ncr(int n, int r) {
        if (r < 0 || n < r)
            return 0;
        return fact(n) / (fact(r) * fact(n - r));
    }
};

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

    string s;
    cin >> s;

    modnum<MOD1> ans = 0, cast = 1;

    int d = s.size();
    int ctr = 0;

    for (int i = 0; i < d; i++) {
        if (s[i] == '1') {
            ans += (2 * cast).pow(ctr) * (3 * cast).pow(d - i - 1);
            ctr++;
        }
    }
    ans += (2 * cast).pow(ctr);

    cout << ans;

    return 0;
}


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

int main(){
    int n, k;
    char c;
    cin >> n;
    int trump[4][13];
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            trump[i][j]=0;
        }

    }
    for(int i=0;i<n;i++){
        cin >> c;
        cin >> k;
        if(c=='S')trump[0][k-1]=1;
        else if(c=='H')trump[1][k-1]=1;
        else if(c=='C')trump[2][k-1]=1;
        else if(c=='D')trump[3][k-1]=1;
        
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(trump[i][j]==0){
                if(i==0)cout << 'S';
                else if(i ==1)cout << 'H';
                else if(i ==2)cout << 'C';
                else if(i ==3)cout << 'D';

                cout << " ";
                cout << j+1 << endl;
            }
        }
        
    }

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const ll mxN=1e9;
const ll mod = 1e9+7;

ll pow(ll a,ll b){

    ll r =1;

    while(b){
        if(b%2!=0) r=(r*a);
        a=(a*a);
        b/=2;
    }

    return r;
}

const int sz = 5e5+20;
ll fact[sz], inv[sz];
void pre(){
	fact[0] = 1;
	inv[0] = pow(fact[0], mod-2);
	for(int i=1;i<sz;i++){
		fact[i] = (fact[i-1]*i)%mod;
	}
}

int allmask;
int dp[1<<21];
int n;
vector<vector<int>> v(22);

int count(int a,int j){
    
    if(a==allmask) return 1;
    if(j>=n) return 0;

    if(dp[a]!=-1) return dp[a];
    
    int ways = 0;
    for(int i=0;i<v[j].size();i++){
        if(!(a&(1<<v[j][i]))) ways=(count(a|(1<<v[j][i]),j+1)+ways)%mod;
    }

    dp[a]=ways;
    return ways;
}

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

    cin>>n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int a;
            cin>>a;
            if(a) v[i].push_back(j);
        }
    }

    memset(dp,-1,sizeof(dp));
    allmask = (1<<n)-1;

    cout<<count(0,0);
}

Measured memory_bytes: 11808
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
ll gi(){
    ll x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
int gc(){
    char ch=getchar();
    while(ch<'A'||ch>'Z')ch=getchar();
    return ch;
}
const int N=405;
struct edge{int to,nxt,w;ll cost;}E[N*N];
int n,m,x[N],y[N],t[N],a[N],b[N],L[N],R[N],D[N],U[N],head[N],cnt,S,T,vis[N],pe[N];
ll v[N],dis[N],ans;queue<int>Q;
void link(int u,int v,ll w){
    E[++cnt]=(edge){v,head[u],1,w};head[u]=cnt;
    E[++cnt]=(edge){u,head[v],0,-w};head[v]=cnt;
}
bool spfa(ll &res){
    memset(dis,63,sizeof(dis));
    dis[S]=0;Q.push(S);
    while(!Q.empty()){
        int u=Q.front();Q.pop();vis[u]=0;
        for(int i=head[u],v;i;i=E[i].nxt)
            if(E[i].w&&dis[v=E[i].to]>dis[u]+E[i].cost){
                dis[v]=dis[u]+E[i].cost;pe[v]=i;
                if(!vis[v])vis[v]=1,Q.push(v);
            }
    }
    if(dis[T]==dis[0])return false;res+=dis[T];
    for(int i=T;i!=S;i=E[pe[i]^1].to)--E[pe[i]].w,++E[pe[i]^1].w;
    return true;
}
ll cal(int k){
    for(int i=1;i<=k;++i)L[i]=D[i]=0,R[i]=U[i]=233;
    for(int i=1;i<=m;++i)
        if(b[i]<k){
            if(t[i]=='L')L[b[i]+1]=a[i]+1;
            if(t[i]=='R')R[k-b[i]]=a[i]-1;
            if(t[i]=='D')D[b[i]+1]=a[i]+1;
            if(t[i]=='U')U[k-b[i]]=a[i]-1;
        }
    for(int i=2;i<=k;++i)L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
    for(int i=k-1;i;--i)R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
    memset(head,0,sizeof(head));cnt=1;S=n+k<<1|1;T=n+k+1<<1;
    for(int i=1;i<=n;++i)link(i,n+i,-v[i]-1000000000000000ll);
    for(int i=1;i<=k;++i){
        link(S,n+n+i,0);link(n+n+k+i,T,0);
        for(int j=1;j<=n;++j){
            if(L[i]<=x[j]&&x[j]<=R[i])link(n+n+i,j,0);
            if(D[i]<=y[j]&&y[j]<=U[i])link(n+j,n+n+k+i,0);
        }
    }
    ll res=0;while(spfa(res));return -res-1000000000000000ll*k;
}
int main(){
    n=gi();
    for(int i=1;i<=n;++i)x[i]=gi(),y[i]=gi(),v[i]=gi();
    m=gi();
    for(int i=1;i<=m;++i)t[i]=gc(),a[i]=gi(),b[i]=gi();
    for(int i=1;i<=n;++i)ans=max(ans,cal(i));
    printf("%lld\n",ans);return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  string s;
  cin>>s;
  n=s.size();
  for(int i=1;i<n;++i){
    if(i>1&&s[i-2]==s[i])cout<<i-1<<" "<<i+1,exit(0);
    else if(s[i-1]==s[i])cout<<i<<" "<<i+1,exit(0);
  }
  cout<<"-1 -1";
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <string>
using namespace std;
typedef pair< string, string > P;
main()
{
    int n,m,f;
    cin>> n >> f;
    map< P, int > mp;
    for( int i = 0; i < n; i++ )
    {
        cin >> m;
        vector< string > v(m);
        for( int j = 0; j < m; j++ ) cin >> v[j];
        for( int j = 0; j < m; j++ )
        {
            for( int k = j + 1; k < m; k++ )
            {
                mp[ P( min( v[j], v[k] ), max( v[j], v[k] ) )]++;
            }
        }
    }
    vector<P> v;
    for( auto p : mp )
    {
        if( p.second >= f ) v.emplace_back( p.first );
    }
    cout << v.size() << endl;
    for( P p : v )
    {
        cout << p.first << ' ' << p.second << endl;
    }
    return 0;
}




Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string>
#include <typeinfo>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;


int main(){
	int a,b;
	cin>>a>>b;
	int h=b-a;
	for(int i=(b-a)-1;i>0;i--)h+=i;
	cout<<h-b<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
result = [1] * N
for i in range(M):
  x, y = list(map(int, input().split()))
  x, y = x - 1, y - 1
  if H[x] > H[y]:
    result[y] = 0
  elif H[x] < H[y]:
    result[x] = 0
  else:
    result[x] = 0
    result[y] = 0

print(sum(result))

Measured memory_bytes: 20144
#include<vector>
#include<iostream>
#include<numeric>
#include<list>
#include<limits>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>

#define pi 3.141592653589793
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

using namespace std;
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;

const int MOD = 10e9 + 7;
const int INF = 10e9 ;

template <typename T>
std::ostream& operator<<(ostream& os, 
                        const vector<T> &v)
{
    for (T const& i: v) {
        os << i << " ";
    }
    os<<endl;
    return os;
}

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
vector<int> sieve(int n){
    vector<bool> s(n, true);
    for(int i =2 ; i*i <= n; i++ )
        if(s[i])
            for(int j=2*i; j< n; j +=i )
                s[j] = false;

    vector<int> primes;
    for(int i =0; i<n; i++)
        if( s[i] )
            primes.push_back(s[i]);

    return primes;
}

int main(){

        int n,m;
        cin>>n>>m;
        vector<double> ar(n);
        for(auto &i: ar) cin>>i;
        double sum = 0;
        for(auto i: ar) sum+= i;
        long count = 0; 
        for(auto i: ar){
            double temp = sum / ( 4.0 * m );
            if( i >= temp ) 
                count++;
        }
        if( count >= m)
            cout<<"Yes";
        else
            cout<<"No";
   

    return 0;
}

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

int main() {
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
 
  if(K<=A) cout<<K;
  else if(K<=A+B) cout<<A;
  else cout<<2*A+B-K;  
  
}

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

signed main(){
    string o,e; cin>>o>>e;
    string ans="";
    rep(i,o.size()+e.size()){
        ans+=(i%2?e.at(i/2):o.at(i/2));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int main()
{
  ll n;cin>>n;
  vector<ll> z(n);
  vector<ll> used(1000010,0);
  for (ll i=0;i<n;i++)
  {
    ll a;cin>>a;
    z[i]=a;
    used[a]++;
  }
  
  ll ans=0;
  for (ll i=0;i<n;i++)
  {
    //z[i] の約数列挙
    vector<ll> b(0,0);
    ll nn = z[i];
    for (ll j=1;j*j<=nn;j++)
    {
      if (nn % j ==0)
      {
        b.push_back(j);
        if (nn/j == j) continue;
        b.push_back(nn/j);
      }
    }
    ll bsz = b.size();
    for (ll j=0;j<bsz;j++)
    {
      if (b[j]<nn && used[b[j]]>0) break;
      if (b[j]==nn && used[b[j]]>1) break;
      if (j==bsz-1) ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12760
S = list(input())

if S[0] == 'A':
  isC = 0
  for i in S[2:len(S)-1]:
    if i == 'C':
      isC += 1
  else:
    if isC == 1:
      for i in range(len(S)):
        if S[i] == 'A' or S[i] =='C' or S[i].islower():
          pass
        else:
          print('WA')
          break
      else:
        print('AC')
    else:
      print('WA')
else:
  print('WA')

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<int> l(q),r(q);
    for(int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
    }
    int count[n+1];
    int tmp=0;
    count[0]=tmp;
//    cout << "\n";
    for(int i = 0; i < n-1; i++) {
        if(s[i]=='A'&& s[i+1]=='C') tmp++;
        count[i+1]=tmp;
//        cout << i << " " << count[i+1] << "\n";
    }
    count[n]=count[n-1];

    for(int i = 0; i < q; i++) {
        cout << count[r[i]-1]-count[l[i]-1] << "\n";
    }


    return 0;
}

Measured memory_bytes: 2176
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            int n = int.Parse(Console.ReadLine());
            int count = 0;
            for (int i = 1; i <= n; i += 2)
            {
                if (Judge(i))
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }

        static bool Judge(int n)
        {
            int yakusu_count = 0;

            for(int i = 1;i <= n;i += 2)
            {
                if(n % i == 0)
                {
                    yakusu_count += 1;
                }
            }
            if(yakusu_count == 8 )
            {
                return true;
            }
            return false;
        }
    }
}


Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	if e-a > k || e-b > k || e-c > k || e-d > k {
		fmt.Println(":(")
		return
	}
	fmt.Println("Yay!")
}


Measured memory_bytes: 512
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	X := nextInt()
	ans := 0
	for i := 0; i < N; i++ {
		ans = gcdof2numbers(abs(nextInt(), X), ans)
	}
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func abs(a int, b int) int {
	if a > b {
		return a - b
	} else {
		return b - a
	}
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
     
    using namespace std;
     
    int a[300010];
    int n;
     
    int main() {
        ios_base::sync_with_stdio(0);
        cin >> n;
        n *= 3;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a, a + n);
        int tk = 0;
        long long res = 0;
        for (int i = n - 2; i >= 0; i-=2) {
            res += a[i];
            if (++tk == n / 3) break;
        }
        cout << res << "\n";
        return 0;
    }

Measured memory_bytes: 1408
def examA():
    C = [SI()for _ in range(3)]
    ans = C[0][0]+C[1][1]+C[2][2]
    print(ans)
    return

def examB():
    N, M = LI()
    P = [0]*N
    S = [LSI()for _ in range(M)]
    pena = 0
    ac = set()
    for p,s in S:
        p = int(p)-1
        if s=="WA":
            P[p] += 1
        else:
            if p in ac:
                continue
            ac.add(p)
            pena += P[p]

    print(len(ac),pena)
    return

def examC():
    W, H, N = LI()
    lx, rx, ly, ry = 0, W, 0, H
    A = [LI()for _ in range(N)]
    for x,y,a in A:
        if a==1:
            lx = max(lx,x)
        elif a==2:
            rx = min(rx,x)
        elif a==3:
            ly = max(ly,y)
        elif a==4:
            ry = min(ry,y)
    ans = max(0,rx-lx)*max(0,ry-ly)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 39152
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i, n) {
    int p;
    cin >> p;
    if (p >= k) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256