akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,T;
	cin >> N >> T;
	ll ans = INF;
	bool x=false;
	FOR(i,0,N){
		ll c,t;
		cin >> c >> t;
		if(t<=T){ans = min(ans,c);x=true;};
	}
	
	if(x)cout << ans << endl;
	else cout << "TLE" << endl;
}

Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())
A = []
for i in range(K):
    d = int(input())
    temp = list(map(int, input().split()))
    A = A + temp
hito = np.ones(N)
for i in range(len(A)):
    hito[A[i]-1] = 0
print(int(np.sum(hito)))


Measured memory_bytes: 27188
//解説AC

#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;
 
const int maxn = 15;
int n, m;
int dist[maxn][maxn];
int dp[1<<maxn][maxn];
 
int dfs(int s, int v){
 
    if(dp[s][v] >= 0){
        return dp[s][v];
    }
 
    if(s == (1<<n)-1 && v == 0){
        return dp[s][v] = 0;
    }
 
    int ans = inf;
    rep(u,0,n){
        if(!(s >> u & 1)){
            ans = min(ans, dfs(s | 1 << u, u) + dist[v][u]);
        }
    }
 
    dp[s][v] = ans;
    return ans;
 
 
}
 
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
     
    cin >> n >> m;
 
    memset(dp,-1,sizeof(dp));
    fill(dist[0],dist[0]+maxn*maxn,inf);
 
     
 
     
    rep(i,0,m){
        int f, t, c;
        cin >> f >> t >> c;
        dist[f][t] = c;
    }
    int ans = dfs(0,0);
    cout << (ans == inf ? -1 : ans) << endl;
 
}


Measured memory_bytes: 7052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int H, W;
int c[12][12] = {0};
int m[10] = {1000+1}; //m[i]はiを1に変えるのに必要な最小魔力
int w[10] = {0};

int calcmp(vector<int> &v){
	int ret = 0;
	for(int i=v.size()-1; i>0; i--){
		ret += c[v[i]][v[i-1]];
	}
	return ret;
}

void dfs(int i, vector<int> &v1, vector<int> &v2){
	if(v2.size() >= 10 || i == 1){
		return;
	}
	
	v2.push_back(i);
	int v = calcmp(v2);
	if(m[i] > v){
		m[i] = v;
	}
	v2.pop_back();

	for(int j=0; j<v1.size(); j++){
		int a = v1[j];
		if(a == i || a < 0){
			continue;
		}
		v2.push_back(a);
		v1[j] = -1;
		dfs(i, v1, v2);
		v1[j] = a;
		v2.pop_back();
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int i=0; i<=9; i++){
		m[i] = 1000 + 1;
		w[i] = 0;
	}
	m[1] = 0;

	cin >> H >> W;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			cin >> c[i][j];
		}
	}

	for(int i=1; i<=H; i++){
		for(int j=1; j<=W; j++){
			int a;
			cin >> a;
			w[a]++;
		}
	}

	vector<int> v1, v2;
	v2.push_back(1);
	v1.push_back(0);
	for(int i=2; i<=9; i++) v1.push_back(i);

	for(int i=0; i<=9; i++){
		dfs(i, v1, v2);
	}

	long long ans = 0;
	for(int i=0; i<=9; i++){
		ans += (w[i] * m[i]);
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3744
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn; // 標準入力から NSString を得る
+(void)printf:(NSString*)format, ...; // 標準出力へ出力
@end

@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if (length >= 1 && [result characterAtIndex:length-1] == '\n') { // 入力末尾に改行文字があれば削除
        [result deleteCharactersInRange:NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    va_end(arguments);
}
@end


int main() {
    @autoreleasepool {
        NSString *input = [StdIO stringFromStdIn];
        NSArray *numbers = [input componentsSeparatedByString:@" "];
        NSInteger a = [[numbers objectAtIndex: 0] integerValue];
        NSInteger b = [[numbers objectAtIndex: 1] integerValue];
        [StdIO printf: (a*b % 2 == 0) ? @"Even" : @"Odd"];
    }
    return 0;
}

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  vi v;
  int q;
  cin>>q;
  while(q--){
    int t;
    cin>>t;
    if(t==0){
      int x;
      cin>>x;
      v.PB(x);
    }if(t==1){
      int x;
      cin>>x;
      cout<<v[x]<<endl;
    }if(t==2){
      v.pop_back();
    }
  }


}


Measured memory_bytes: 5008
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <queue>
typedef long long lint;
const int N=1e5+5;
int n,val[N*3];
lint psum[N],ssum[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	std::priority_queue <int> pq;
	n=nxi();
	for(int i=1; i<=n*3; ++i){
		val[i]=nxi();
	}
	{
		lint sum=0;
		for(int i=1; i<=n; ++i){
			sum+=val[i];
			pq.push(-val[i]);
		}
		psum[0]=sum;
		for(int i=1; i<=n; ++i){
			pq.push(-val[n+i]);
			sum+=val[n+i]+pq.top();
			pq.pop();
			psum[i]=sum;
		}
	}
	while(!pq.empty()) pq.pop();
	{
		lint sum=0;
		for(int i=1; i<=n; ++i){
			sum+=val[n*2+i];
			pq.push(val[n*2+i]);
		}
		ssum[n+1]=sum;
		for(int i=n; i>=1; --i){
			pq.push(val[n+i]);
			sum+=val[n+i]-pq.top();
			pq.pop();
			ssum[i]=sum;
		}
	}
	lint ans=-1e15;
	for(int i=0; i<=n; ++i){
		apx(ans,psum[i]-ssum[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    int all,biggest,ans;
    cin>>a>>b>>c;
    all=a+b+c;
    biggest=max(a,max(b,c));
    ans=all-biggest;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt64() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solve()
	writer.Flush()
}

func solve() {
	a, b, c := nextInt(), nextInt(), nextInt()
	if b-a == c-b {
		out("YES")
	} else {
		out("NO")
	}
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    int n;
    int m=100000;
    cin>>n;
    for(int i=0;i<n;i++){
        m*=1.05;
        if(m%1000!=0){
        int a;
        a=m%1000;
        m+=1000-a;
    }


    }

    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        System.out.println(main.solve());
    }
    String solve() throws IOException {
        boolean flag = true;
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            int a = sc.nextInt();
            if(a%2==0){
                flag &= (a%3==0)||(a%5==0);
            }
        }
        return flag?"APPROVED":"DENIED";
    }
}



Measured memory_bytes: 23764
#include <iostream>

using namespace std;


int main(){
    int a,b,c,divisorNum = 0;
    cin >> a >> b >> c;
    for(int i = a;i<=b;++i){
        if(c%i == 0){
            divisorNum++;
        }
    }
    cout << divisorNum << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    string s;
    cin >> s;
    ce(s.substr(0, 3));
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(123456789012345678)
#define MAX_V 1000


int main(void){
	int N;	cin >> N;
	ll W;		cin >> W;
	vector<ll> w(N), v(N);
	rep(i,N){
		cin >> w[i] >> v[i];
	}

	int V = N * MAX_V;
	vector< vector<ll> > dp;
	rep(i, N+1){
		dp.push_back(vector<ll>());
		rep(j,V+1){
			dp[i].push_back(LINF);
		}
	}
	dp[0][0] = 0;

	rep(i,N){
		rep(sum_v, V+1){
			if(sum_v < v[i]){
				dp[i+1][sum_v] = dp[i][sum_v];
			}else{
				dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v-v[i]]+w[i]);
			}
		}
	}
	ll res = 0;
	rep(sum_v, V+1){
		if(dp[N][sum_v] <= W)	res =  sum_v;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 80248
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin  >> n;
    vector<int> a(4);
    a.at(0)=n/1000;
    a.at(1)=n/100-a.at(0)*10;
    a.at(2)=n/10-a.at(0)*100-a.at(1)*10;
    a.at(3)=n%10;
    int i;
    int h=0;
    for(i=0;i<4;i++){
        if(a.at(i)==2){
            h++;
        }
    }
    cout << h << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

#define FOR(i,m,n) for(ll i=(m); (i)<(ll)(n); ++(i))
#define REP(i,n) FOR(i,0,n)
#define MAX 10000+1

void countingSort(const ll* const a, ll* const b, ll* const c, const ll k, const ll n){
  REP(i,k) c[i] = 0; // *(c+i) = 0でもいけた
  REP(i,n) ++c[a[i]]; // a+i != nullptrはだめだった
  FOR(i,1,k) c[i] += c[i-1];
  for(ll i=n-1; i>=0; --i) b[(c[a[i]]--)-1] = a[i];
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n; cin >> n;
  ll a[n], b[n], c[MAX];
  REP(i,n) cin >> a[i];
  countingSort(a, b, c, MAX, n);
  REP(i,n) cout << b[i] << " \n"[i==n-1];
  return 0;
}


Measured memory_bytes: 34472
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}
	buildMaxHeap(elems)
	printInts(elems)
}

func buildMaxHeap(elems []int) {
	for i := len(elems) / 2; i >= 1; i-- {
		maxHeapify(i, elems)
	}
}

func maxHeapify(nodeId int, elems []int) {
	largest := nodeId - 1
	l := nodeId*2 - 1
	r := nodeId * 2
	if l < len(elems) && elems[l] > elems[largest] {
		largest = l
	}
	if r < len(elems) && elems[r] > elems[largest] {
		largest = r
	}
	if largest != nodeId-1 {
		elems[nodeId-1], elems[largest] = elems[largest], elems[nodeId-1]
		maxHeapify(largest+1, elems)
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	rs := make([]int, n)
	for i, _ := range rs {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		rs[i] = x
	}
	return rs, nil
}

func printInts(elems []int) {
	elemsStr := make([]string, len(elems))
	for i, v := range elems {
		elemsStr[i] = strconv.Itoa(v)
	}
	fmt.Println(" " + strings.Join(elemsStr, " "))
}



Measured memory_bytes: 21712
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

  int n;
  cin>>n;
  if(n&1)
    cout<<2*n;
    
    else
    cout<<n;
   
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


class Main {
    static double comp(double[]p,double[]q,double x){
        double ans=0;
        for(int i=0;i<6;++i)ans+=Math.max(p[i]*x,q[i]*(1-x));
        return ans;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        double[]p=new double[6],q=new double[6];
        for(int i=0;i<6;++i)p[i]=sc.nextDouble()/100;
        for(int i=0;i<6;++i)q[i]=sc.nextDouble()/100;
        double lo=0,hi=1;
        for(int i=0;i<100;++i){
            double mid1=(2*lo+hi)/3;
            double mid2=(lo+2*hi)/3;
            if(comp(p,q,mid1)>comp(p,q,mid2))
                lo=mid1;
            else
                hi=mid2;
        }
        out.println(comp(p,q,lo));
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23252
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    MX = 10**6
    ans = []
    a_map = Counter(A)

    is_prime = [True] * (MX + 1)
    is_prime[0] = False
    is_prime[1] = 1 in a_map
    for i in range(1, MX + 1):
        if not is_prime[i]:
            continue
        if i not in a_map:
            continue
        for j in range(i * 2, MX + 1, i):
            is_prime[j] = False

    ans = 0
    for i in range(N):
        if is_prime[A[i]] and a_map[A[i]] == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 121308
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        s: chars
    }

    let ret = if can_month(&s[..2]) && can_month(&s[2..]) {
        "AMBIGUOUS"
    } else if can_month(&s[..2]) {
        "MMYY"
    } else if can_month(&s[2..]) {
        "YYMM"
    } else {
        "NA"
    };
    println!("{}", ret);
}

fn can_month(v: &[char]) -> bool {
    let a = v[0] as u8 - b'0';
    let b = v[1] as u8 - b'0';
    let c = a * 10 + b;
    1 <= c && c <= 12
}


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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int sum_C = 50 * C;
    int sum_BC = 100 * B + sum_C;

    int ans = 0;
    for (int a = min(A, X / 500); a >= 0 && X - a*500 <= sum_BC; a--) {
        for (int b = min(B, (X - 500*a)/100); b >= 0 && X - a*500 - b*100 <= sum_C; b--) {
            // int c = (X - 500*a - 100*b) / 50;
            // int sum = 500*a+100*b+50*c;
            // cout << FMT4(a,b,c,sum)<< endl;
            ans++;        
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    ll k;
    cin >> k;
    ll n = 50;
    ll ans[n];
    fill_n(ans,n,n-1);
    ll syo = k/n;
    rep(i,n) ans[i]+=syo; 
    ll amari = k%n;
    rep(i,amari){
        rep(j,n){
            if(j==i) ans[j]+=n;
            else ans[j]--;
        }
    }
    cout << n << endl;
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}

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

#define ll long long
#define pb push_back
#define INF 1e9+7
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,m;
	cin>>n>>m;
	ll p=n*(n-1);
	p/=2;
	ll q=m*(m-1);
	q/=2;
	p+=q;
	cout<<p;
	
	
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  a %= 2;
  b %= 2;
  if (a == 1 && b == 1){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n;
int b[110];
int main(){
  cin>>n;
  rep(i,n){
    cin>>b[i];
  }
  int a[110];
  rep(i,n){
    a[i]=i+1-b[i];
    if(a[i]<0){
      prin(-1);
      return 0;
    }
  }
  int res[110];
  int k=n-1;
  rep(i,n){
    int j=n-1;
    while(a[j]!=0&&j>=0){
      a[j]--;
      j--;
    }
    if(j<0){
      prin(-1);
      return 0;
    }
    a[j]--;
    res[k]=b[j];
    k--;
  }
  rep(i,n){
    prin(res[i]);
  }
  
  

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans1 = 0;
  int ans0 = 0;
  // 1, 0 ...
  for (int i = 0; i < S.size(); i++) {
    int index = i;
    if (index % 2 == 0 && S[i] != '1') {
      ans1 += 1;
    }
    if (index % 2 == 1 && S[i] != '0') {
      ans1 += 1;
    }
  }
  // 0, 1 ...
  for (int i = 0; i < S.size(); i++) {
    int index = i;
    if (index % 2 == 0 && S[i] != '0') {
      ans0 += 1;
    }
    if (index % 2 == 1 && S[i] != '1') {
      ans0 += 1;
    }
  }

  cout << min(ans1, ans0) << endl;
};


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

int main() {
	int N, M;
	int L, R;
	int min, max;
	int num_card;
	// N: #ID_card, M: #GATE
	cin >> N >> M;

	cin >> L >> R;
	min = L;
	max = R;
	for (size_t i=0; i<M-1; i++) {
		cin >> L >> R;
		if (L > min) min = L;
		if (R < max) max = R;
	}

	num_card = (max - min + 1);
	if (num_card <= 0) num_card = 0;
	if (num_card >  N) num_card = N;

	cout << num_card << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,i;
  cin >> n;
  for (i=1;i<10;i++) if (n%i==0 && n/i<10) break;
  if (i==10) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n,y = map(int, input().split())
    n1000 = y/1000
    n5000 = 0
    n10000 = 0
    a,b,c = -1, -1, -1
    flag = False
    if n <= n1000:
        for bi in range((y//5000)+1):
            for ci in range((y//10000)+1):
                if n1000-5*bi-10*ci >= 0:
                    if n1000-4*bi-9*ci == n:
                        c = n1000-5*bi-10*ci
                        b = bi
                        a = ci
                        flag = True
                        break
                else:
                    break
            if flag:
                break
    print(int(a),int(b),int(c))
        


if __name__ == "__main__":
    main()

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};


int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>a(n);
  rep(i,0,n){
    cin>>a[i];
    a[i]--;
  }
  vector<ll>b(m+2),c(m+2);
  rep(i,0,n-1){
    res+=(a[i+1]+m-a[i])%m;
    if(a[i]<a[i+1]){
      b[a[i]+2]++;
      b[a[i+1]+1]--;
      c[a[i+1]+1]-=a[i+1]-a[i]-1;
    }
    else{
      b[a[i]+2]++;
      b[m]--;
      b[0]++;
      b[a[i+1]+1]--;
      c[0]+=m-(a[i]+2);
      c[a[i+1]+1]-=a[i+1]+m-a[i]-1;
    }
  }
  //debug(b,m+1);debug(c,m+1);cout<<endl;
  rep(i,0,m)b[i+1]+=b[i];
  c[0]+=b[0];
  rep(i,0,m){
    c[i+1]+=c[i]+b[i+1];
  }
  //debug(b,m+1);debug(c,m+1);
  rep(i,0,m)chmin(res1,res-c[i]);
  cout<<res1<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
int mem[14][14] = {}, i = 0, X[50], Y[50], S[50], flag = 0, max = 0, x, y, s;
int main() {
	char b;
	while (std::cin >> x >> b >> y >> b >> s) {
		Y[i] = y, S[i] = s, X[i] = x;
		i += 1;
	}
		for (int a = 0; a < i; a += 1) {
			if (S[a] >= 1) {
				mem[X[a] + 2][Y[a] + 2] += 1;
				mem[X[a] + 1][Y[a] + 2] += 1;
				mem[X[a] + 3][Y[a] + 2] += 1;
				mem[X[a] + 2][Y[a] + 1] += 1;
				mem[X[a] + 2][Y[a] + 3] += 1;
			}
			if (S[a] >= 2) {
				mem[X[a] + 1][Y[a] + 1] += 1;
				mem[X[a] + 1][Y[a] + 3] += 1;
				mem[X[a] + 3][Y[a] + 1] += 1;
				mem[X[a] + 3][Y[a] + 3] += 1;
			}
			if (S[a] >= 3) {
				mem[X[a]][Y[a] + 2] += 1;
				mem[X[a] + 4][Y[a] + 2] += 1;
				mem[X[a] + 2][Y[a] + 4] += 1;
				mem[X[a] + 2][Y[a]] += 1;
			}
		}
		for (int i = 0; i < 10; i += 1)
			for (int j = 0; j < 10; j += 1) {
				if (0 == mem[i + 2][j + 2])
					flag += 1;
				if (max < mem[i + 2][j + 2])
					max = mem[i + 2][j + 2];
			}
		std::cout << flag << std::endl;
		std::cout << max << std::endl;
	return 0;
}

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

using namespace std;

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

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

#endif


void Main() {
    // a1は大きければ大きいほど良く，a2は[n/2]に近いほどよい
    // (n+1)Cr >> (n+1)Cr (これは帰納的に使える)
    ll n; cin >> n;
    vector<ll> a(n); rep(i, n){cin >> a.at(i);}
    sort(a.begin(), a.end(), greater<ll>()); // 昇順 ascending
    ll a_i = a.at(0);
    ll diff = 0;
    ll ans = 0;
    rep(i, n){
        ll tmp = min(a.at(i), a_i - a.at(i));
        if (tmp > diff){diff = tmp; ans = a.at(i);}
    }
    cout << a_i << " " << ans << endl;
}

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


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

int main() {
	int h,w,k;
	cin>>h>>w>>k;
	vector<string> s(h);
	for (auto& str : s) cin >> str;
		int ans = 0;
	for (int bsr = 0; bsr < (1<<h); ++bsr) {
		for (int bsc = 0; bsc < (1<<w); ++bsc) {
			auto done = s;
			int cnt = 0;
			for (int i = 0; i < h; ++i) if (bsr&(1<<i)) {
				for (int j = 0; j < w; ++j) {
					done[i][j] = '*';
				}
			}
			for (int i = 0; i < w; ++i) if (bsc&(1<<i)) {
				for (int j = 0; j < h; ++j) {
					done[j][i] = '*';
				}
			}
			for (int i = 0; i < h; ++i) {
				for (int j = 0; j < w; ++j) {
					if (done[i][j] == '#')
						++cnt;
				}
			}
			// cout << bsr << " " << bsc << endl;
			// for (auto s : done) {
			// 	cout << s << endl;
			// }
			// cout << "$$$" << endl;
			if (cnt==k) {
				++ans;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int A, B;
    double low, high;
    cin >> A >> B;
    if((low = 12.5 * A) < 10 * B) low = 10 * B;
    if((high = 12.5 * (A + 1)) > 10 * (B + 1)) high = 10 * (B + 1);
    if(high - low >= 1){
        if(low - ((int)low) == 0) cout << low << endl;
        else cout << (int) low + 1 << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
S = set()

for _ in range(int(input())):
    order = tuple(map(int,input().split()))
    value = order[1]

    if order[0] == 0:
        S.add(value)
        print(len(S))
    elif order[0] == 1:
        if value in S:
            print(1)
        else:
            print(0)
    elif order[0] == 2:
        S.discard(value)
    else:
        if len(S) > order[2] - order[1]:
            for i in range(order[1],order[2]+1):
                if i in S:
                    print(i)
        else:
            tmp = sorted(S)
            for i in tmp:
                if order[1] <= i <= order[2]:
                    print(i)


Measured memory_bytes: 23348
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

struct Info {
  int x, y, h;

  bool operator < (const Info &I) const {
    if (h != I.h) return h > I.h;
    else if (x != I.x) return x < I.x;
    else return y < I.y;
  }
};

int main() {
  int n;
  cin >> n;
  vector<Info> a(n);
  rep(i, n) {
    Info t;
    cin >> t.x >> t.y >> t.h;
    a[i] = t;
  }

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

  rep(i, 101) {
    rep(j, 101) {
      int ch = a[0].h + abs(a[0].x - i) + abs(a[0].y - j);
      bool res = true;
      FOR(k, 1, n) {
        int kh = max(0, ch - abs(a[k].x - i) - abs(a[k].y - j));
        if (kh != a[k].h) {
          res = false;
          break;
        }
      }
      if (res) {
        cout << i << " " << j << " " << ch << endl;
        return 0;
      }
    }
  }



  
  return 0;
}

Measured memory_bytes: 256
// 2012/07/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[10000001];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<=10000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<=10000000; i++){
		if(is_prime[i]){
			for(int j=i+i; j<=10000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=n; i>=13; i--){
			if(is_prime[i]&&is_prime[i-2]&&is_prime[i-6]&&is_prime[i-8]){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
int n, m, tot, ans;
char s[22][22];
int num[22][22];
bool mark[22][22];
int dlx[444], dly[444];
int nex[5] = {0, 0, 1, -1};
int ney[5] = {1, -1, 0, 0};
void bfs(int x, int y){
    int hd = 0, tl = 1;
    dlx[1] = x; dly[1] = y;
    memset(mark, 0, sizeof(mark));
    mark[x][y] = 1;
    num[x][y] = 0;
    while(hd < tl){
        hd++;
        int nx = dlx[hd], ny = dly[hd];
        ans = max(ans, num[nx][ny]);
        for(int i = 0;i <= 3; i++){
            int tox = nx + nex[i], toy = ny + ney[i];
            if(mark[tox][toy])continue;
            if(tox > n || tox < 1 || toy > m || toy < 1 || s[tox][toy] == '#')continue;
            mark[tox][toy] = 1;
            num[tox][toy] = num[nx][ny] + 1;
            dlx[++tl] = tox; dly[tl] = toy;
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i = 1;i <= n; i++){
        cin>>s[i] + 1;
    }
    for(int i = 1;i <= n; i++){
        for(int j = 1;j <= m; j++){
            if(s[i][j] != '#')bfs(i, j);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
K, T = map(int, input().split())
a = list(map(int, input().split()))

if T == 1:
    print(K - 1)
else:
    M = max(a)
    rest = sum(a) - M

    if rest >= M - 1:
        print(0)
    else:
        print(M - rest - 1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <iostream>
#include <set>
 
int main(void){
  int w,h,n;cin >> w >> h >> n;
  vector<vector<int>> rect(w,vector<int>(h,false));
  int x,y,a;
  for(int i=0;i<n;i++){
    cin >> x >> y >> a;
    if(a==1 || a==2){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(a==1){
            rect[j][i] |= (j<x);
          } else {
            rect[j][i] |= (j>=x);
          }
        }
      }
    } else {
      for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
          if(a==3){
            rect[i][j] |= (j<y);
          } else {
            rect[i][j] |= (j>=y);
          }
        }
      }
    }
  }
  
  int area=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(!rect[j][i]) area++;
    }
  }
  
  cout << area << endl;
  return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	int n;
	cin >> n;
	ll ans = n;
	int cnt = sqrt(n);
	FOR(i, 2, cnt) {
		if (n%i == 0) {
			if (!v.empty()) {
				if (v.back() != i) {
					v.push_back(i);
					ans /= i;
				}
			}
			else {
				v.push_back(i);
				ans /= i;
			}
			n /= i;
			i--;
		}
	}
	if (n != 1) {
		v.push_back(n);
		ans /= n;
	}
	REP(i, v.size()) ans *= v[i] - 1;
	cout << ans << endl;
}

Measured memory_bytes: 3204
// ABC108_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N;
    cin >> N;
    
    cout << (N/2) * ((N+1)/2) << "\n";
    
    return 0;
}

Measured memory_bytes: 256
//2018.12.29 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
const int kcz=1e9+7;
const int N=3e3+10;
namespace MAIN{
    int n,q;
    int a[N];
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int Add(const res &x,const res &y){
        return x+y>=kcz?x+y-kcz:x+y;
    }
    inline int qpow(res x,res y){
        res ret=1;
        while(y){
            if(y&1)ret=1LL*x*ret%kcz;
            x=1LL*x*x%kcz,y>>=1;
        }
        return ret;
    }
    int f[N][N],g[N][N],ans,INV,X[N],Y[N];
    inline void MAIN(){
        n=read(),q=read(),INV=qpow(2,kcz-2);
        for(res i=1;i<=n;i++){
            a[i]=read();
            for(res j=i+1;j<=n;j++)f[i][j]=1;
        }
        for(res i=1;i<=q;i++)X[i]=read(),Y[i]=read();
        for(res t=1;t<=q;t++){
            res x=X[q-t+1],y=Y[q-t+1];
            for(res i=1;i<=n;i++)g[x][i]=f[x][i],g[i][x]=f[i][x],g[y][i]=f[y][i],g[i][y]=f[i][y];
            for(res i=1;i<=n;i++){
                f[x][i]=1LL*Add(f[x][i],g[y][i])*INV%kcz,f[i][x]=1LL*Add(f[i][x],g[i][y])*INV%kcz;
                f[y][i]=1LL*Add(f[y][i],g[x][i])*INV%kcz,f[i][y]=1LL*Add(f[i][y],g[i][x])*INV%kcz;
            }
            f[x][y]=f[y][x]=1LL*Add(g[x][y],g[y][x])*INV%kcz;
        }
        for(res i=1;i<=n;i++)
            for(res j=1;j<=n;j++)if(a[i]>a[j])add(ans,f[i][j]);
        printf("%lld\n",1LL*qpow(2,q)*ans%kcz);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 70912
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

constexpr int MOD = 1000000000 + 7;

class Combination {
   private:
    long long maxn;
    long long mod;
    vector<long long> fact, rev_fact;

   public:
    // コンストラクタ。maxn: 組み合わせのnの最大値。m: mod
    Combination(long long maxn, long long mod) : maxn(maxn), mod(mod) {
        setFact(maxn);
    }

    // 1からnの階乗とその逆元を前計算
    void setFact(long long n) {
        fact.resize(n + 1);
        rev_fact.resize(n + 1);
        fact[0] = 1;
        for (long long i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        rev_fact[n] = modpow(fact[n], mod - 2, mod);
        for (long long i = n - 1; i >= 0; i--) {
            rev_fact[i] = rev_fact[i + 1] * (i + 1);
            rev_fact[i] %= mod;
        }
    }

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

    // n種類のものからk個選ぶ場合の数
    long long c(long long n, long long k) {
        if (!(0 <= n && n <= maxn) || !(0 <= k && k <= maxn)) return -1;
        return (((fact[n] * rev_fact[k]) % mod) * rev_fact[n - k]) % mod;
    }

    // n種類のものから重複を許してk個選ぶ場合の数
    // n+k-1<=maxn とすること
    long long h(long long n, long long k) { return c(n + k - 1, k); }

    // n種類のものからk個選んで並び替える場合の数
    long long p(long long n, long long k) {
        if (!(0 <= n && n <= maxn) || !(0 <= k && k <= maxn)) return -1;
        return fact[n] * rev_fact[n - k] % mod;
    }
};

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

    int s;
    cin >> s;

    Combination Combi(10000000, MOD);

    int ans = 0;

    // i: 数列の長さ
    // 数列の長さ毎に条件を満たす数列を数え上げる
    for (int i = 1; i <= s / 3; i++) {
        // とりあえず数列を3で埋める
        // 分配する数字
        const int j = s - 3 * i;

        // 残りの数字jを分配する
        // 重複組合せ

        ans += Combi.h(i, j);
        ans %= MOD;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 159484
#include<iostream>
using namespace std;
int main()
{
    long long N,A,B,C,D,ans=0;
    cin>>N>>A>>B>>C>>D;
    for(int i=0;i<N;i++)
      if(C*i-D*(N-1-i)<= B-A&&B-A<= D*i-C*(N-1-i))ans=1;

if(ans) cout << "YES"<< endl;
else cout << "NO"<< endl;
}

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

int n, cnt[5];
int main() {
	scanf("%d", &n);
	for (int x, i = 1; i <= n; i++) {
		scanf("%d", &x); cnt[x % 4]++;
	}
	cnt[1] += cnt[3];
	if (cnt[1] > cnt[0]) {
		if (cnt[1] == cnt[0] +1 && cnt[0] + cnt[1] == n) {
			puts("Yes"); return 0;
		}
		puts("No"); return 0;
	}
	puts("Yes");
}

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 reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
ab?d
c??f
def?h
*/

int ans=1e9;
string a,b,c;
bool ab[20010],ac[20010],bc[20010];

bool match(char a, char b){
	return (a==b || a=='?' || b=='?');
}

int main(void){
	cin>>a>>b>>c;
	int am=a.size(),bm=b.size(),cm=c.size();  // b.size()みたいなのは符号なし整数型で、intとの演算で負になったらオーバーフローするからWAになる。

	rep(i,am)rep(j,bm)if(!match(a[i],b[j]))ab[i-j+10000]=true;
	rep(i,am)rep(j,cm)if(!match(a[i],c[j]))ac[i-j+10000]=true;
	rep(i,bm)rep(j,cm)if(!match(b[i],c[j]))bc[i-j+10000]=true;
	
	reg(i,-4000,4000){  // b
		reg(j,-4000,4000){  // c
			bool ok=true;
			if(ab[i+10000])ok=false;
			if(ac[j+10000])ok=false;
			if(bc[j-i+10000])ok=false;
			if(ok)ans = min(ans, max({am, bm+i, cm+j})-min({0,i,j}));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256