akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

int counttype(string s1,string s2){
    ll sum = 0;
    rep(i,26){
        char c = 'a' + i;
        bool b1 = false;
        bool b2 = false;
        rep(j,s1.size())if(s1[j] == c)b1 = true;
        rep(j,s2.size())if(s2[j] == c)b2 = true;
        if(b1 && b2)sum++;
    }
    return sum;
}
signed main()
{
    gearup;
    ll n;
    string s; cin >> n >> s;
    ll res = 0;
    rep(i,n){
        string s1 = s.substr(0,i);
        string s2 = s.substr(i);
        //out(s1);
        //out(s2);
        res = max(res, counttype(s1,s2));
    }
    out(res);
}

Measured memory_bytes: 3652
#include<stdio.h>
#define N 100000
 
typedef struct{
  int parent;
  int left;
  int right;
}Node;
 
Node Tree[N];
int depth(int);
int Printc(int);
 
main(){
 
  int i,n,id,k,c,q,j;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    Tree[i].parent=-1;
    Tree[i].left=-1;
    Tree[i].right=-1;
  }
 
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      Tree[c].parent=id;
      if(j==0) Tree[id].left=c;
      else Tree[q].right=c;
      q=c;
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,Tree[i].parent,depth(i));
    if(Tree[i].parent == -1)  printf("root, [");
    else if(Tree[i].left == -1)  printf("leaf, [");
    else printf("internal node, [");
    Printc(Tree[i].left);
    printf("]\n");
  }
  return 0;
}
 
 
int Printc(int c){
  if(c==-1) return 0;
  if(Tree[c].right==-1) printf("%d",c);
  else {
    printf("%d, ",c);
    Printc(Tree[c].right);
  }
  return 0;
}

int depth(int c){
  if(Tree[c].parent==-1) return 0;
  return 1+depth(Tree[c].parent);
}

Measured memory_bytes: 3348
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<i32>();
    let n = input[0];
    let x = input[1] - 1;
    let y = input[2] - 1;

    let mut len = vec![0; (n - 1) as usize];

    for i in 0..n {
        for j in i+1..n {
            let index = min(j-i, (x-i).abs() + 1 + (j-y).abs()) - 1;
            len[index as usize] += 1;
        }
    }


    for i in len.iter() {
        println!("{}", i);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=1e5+10;

int n,k;
int x[MAX_N];

void solve(){
    vector<int> diff(n-1);
    for (int i=0;i<n-1;++i) diff[i]=x[i+1]-x[i];
    sort(diff.begin(),diff.end());
    int ans=0;
    for (int i=0;i<n-k;++i) ans+=diff[i];
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    for (;t--;){
        cin >> n >> k;
        for (int i=0;i<n;++i) cin >> x[i];
        solve();
    }
}


Measured memory_bytes: 3908
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
const long long MAX = pow(10, 18);
int main() {
    
    long long N,answer=1;
    cin>>N;
    long long num;
    bool ng =false;
    for(long long i=0;i<N;i++)
    {
    	  cin>>num;
          if(num==0){
    			cout<<0<<endl;
                return 0;
    		}
          if(__int128(answer) * num > MAX){
     		 ng = true;
    	  }
          answer*=num;
    }
    if(ng)cout<<-1<<endl;
    else cout<<answer<<endl;
    
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Contest
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split().Select(int.Parse).OrderBy(i => i).ToArray();
            Console.WriteLine(Math.Max(d[N / 2] - d[N / 2 - 1], 0));
        }
    }
}

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

using namespace std;

int main()
   {
   	int s,w;
   	
   	   cin>>s>>w;
   	   
   	   if(s<=w)
   	     cout<<"unsafe";
   	     
   	    else
   	      cout<<"safe";
			 
			 return 0;
   }

Measured memory_bytes: 3616
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	string S;
	cin >> S;

	int Q;
	cin >> Q;

	int q, F;
	char C;
	bool rev = false;
	string head;
	string tail;
	for (int i=0; i<Q; i++) {
		cin >> q;

		if (q == 1) {
			if (rev == false) rev = true;
			else rev = false;
		} else {
			cin >> F >> C;
			if (rev == false) {
				if (F == 1) {
					head.push_back(C);
				} else {
					tail.push_back(C);
				}
			} else {
				if (F == 1) {
					tail.push_back(C);
				} else {
					head.push_back(C);
				}
			}
		}
	}

	reverse(head.begin(), head.end());
	string ans = head + S + tail;

	if (rev) reverse(ans.begin(), ans.end());

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
int w[105],v[105];
long long dp[105][100005];
int main()
{
    int N,W;
    cin >> N >> W;
    for(int i=1;i<=N;i++)
        cin >> w[i] >> v[i];
    for(int i=1;i<=N;i++)
        for(int j=1;j<=1e5;j++)
            dp[i][j] = j<w[i]? dp[i-1][j] : max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    cout << dp[N][W];
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main(){
    int N; string S; cin >> N >> S;
    int ans = 0;
    int x = 0;
    rep(i,N) {
        if(S[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

with sys.stdin as f:
    s_input = f.read()

    in_list = s_input.splitlines()
    n = int(in_list[0])
    a = int(in_list[1])

    if n % 500 <= a:
        print("Yes")
    else:
        print("No")
        
sys.exit(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

const long MOD = 1000000007;

long power(long a, long b) {
    long res = 1;
    while (b > 0) {
        if (b & 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}


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

    int n, k;
    cin >> n >> k;
    vector<long> cnt(k + 1);
    for (int d = 1; d <= k; d++) {
        cnt[d] = power(k / d, n);
    }
    for (int d = k; d >= 1; d--) {
        for (int x = 2; d * x <= k; x++) {
            cnt[d] -= cnt[d * x];
            if (cnt[d] < 0) cnt[d] += MOD;
        }
    }
    long res = 0;
    for (int d = 1; d <= k; d++) {
        res += d * cnt[d];
        res %= MOD;
    }
    cout << res << "\n";

    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll K, A, B;

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

    std::cin >> K >> A >> B;

    ll mx = 0;
    if(B <= A + 1){
        mx = K + 1;
    }else if(A - 1 > K){
        mx = K + 1;
    }else{
        ll n = K - (A - 1);
        mx = A + (B - A) * (n / 2) + (n % 2);
    }

    std::cout << mx << std::endl;
}


Measured memory_bytes: 256
h,w,k = [int(x) for x in input().split()]
i = 0
ans = [[1]*w for _ in range(h)]
flag = 0
for j in range(h):
    i+=1
    x = list(input())
    cnt = 0
    for z in range(len(x)):
        if x[z]=="#":
            cnt+=1
            if cnt>=2:
                i+=1
        ans[j][z] = i
        if flag:
            for kk in range(j):
                ans[kk][z] = i
    
    if cnt>=1 and flag:
        flag = 0
    if (cnt==0 and j==0) or flag:
        flag = 1
        i-=1
    if cnt==0 and j>=1 and not flag:
        for z in range(len(x)):
            ans[j][z] = ans[j-1][z]
        i-=1
for j in ans:
    print(" ".join([str(x) for x in j]))



Measured memory_bytes: 44392
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
     ll n,a[200005],q,sum=0;
     cin>>n;
    
     for(int i=0;i<n;i++)
     {
       cin>>a[i];
       sum=sum^a[i];
     }    
    for(int i=0;i<n;i++)
    {
       cout<<(a[i]^sum);
      cout<<" ";
    }
       
     cout<<"\n";
     return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans;
  if(n < 600)
    ans = 8;
  else if(n < 800)
    ans = 7;
  else if(n < 1000)
    ans = 6;
  else if(n < 1200)
    ans = 5;
  else if(n < 1400)
    ans = 4;
  else if(n < 1600)
    ans = 3;
  else if(n < 1800)
    ans = 2;
  else
    ans = 1;
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(){
	int N, R;
	scanf("%d %d", &N, &R);
	
	if (N >= 10){
		printf("%d \n", R);
	}
	else{
		printf("%d \n", R + 100 * (10-N));
	} 
	return 0;
}

Measured memory_bytes: 3204
n = int(input())
a = list(map(int, input().split()))

ans = 0
diff = 0
for i in range(1, n):
  tmp_diff = a[i] - a[i - 1]
  if tmp_diff != 0 and diff == 0:
    diff = tmp_diff
    continue
  if not(tmp_diff == 0 or tmp_diff * diff > 0):
    ans += 1
    diff = 0
    continue
print(ans + 1)

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

int main() {
    int n, ans=1;
    string s;
    cin >> n >> s;

    for(int i=0; i<n; i++) {
        if(i==n-1) break;
        if(s.at(i) != s.at(i+1)) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
ll f[N], h[N], n;
int main()
{
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> h[i];
    f[n - 2] = abs(h[n - 2] - h[n - 1]);
    for (int i = n - 3; i >= 0; i--)
        f[i] = min(f[i + 1] + abs(h[i + 1] - h[i]), f[i + 2] + abs(h[i + 2] - h[i]));
    cout << f[0];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define ll long long
#define int long long
#define ld long double
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 3e5 , N = 1e5 + 5 , SQ = 600 , base = 1999 , mod = 1e9 + 7 , INF = 1e18 , lg = 17;

int n , a[maxn] , dp[maxn];

int32_t main() {
    FAST
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    fill(dp , dp + maxn , INF);
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
        if(i - 1 >= 0) {
            dp[i] = min(dp[i] , dp[i - 1] + abs(a[i] - a[i - 1]));
        }
        if(i - 2 >= 0) {
            dp[i] = min(dp[i] , dp[i - 2] + abs(a[i] - a[i - 2]));
        }
    }
    cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int k; cin >> k;
    queue<ll> a;

    for (int j = 0; j < 9; ++j) {
        a.push(j+1);
    }

    for (int i = 0; i < k-1; i++){
        if(a.front()%10!=0){
            a.push(a.front()*10 + a.front()%10 - 1);
        }
        if(a.front()%10==0){
            a.push(a.front()*10);
        } else {
            a.push(a.front()*10 + a.front()%10);
        }
        if(a.front()%10!=9){
            a.push(a.front()*10 + a.front()%10 + 1);
        }
        a.pop();
    }

    cout << a.front() << endl;

    return 0;

}


Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

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

    int snk[100]={};
    int d=0;
    rep(i,k){
        cin>>d;
        rep(j,d){
            int temp=0;
            cin>>temp;
            if(snk[temp-1]==0)snk[temp-1]=1;
        }
    }
    int ans=0;
    rep(i,n){
        if(snk[i]==0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>

using namespace std;

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    long long t = 0;
    for (long long  i=1; i <= b; ++i) {
        t +=a ;
        if (t % b == c) {
            cout << "YES";
            return;
        }
    }
    cout << "NO";

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3120
package main

import (
	"fmt"
)

func main() {
	var (
		s, t, u string
		a, b    int
	)
	fmt.Scanf("%s %s", &s, &t)
	fmt.Scanf("%d %d", &a, &b)
	fmt.Scanf("%s", &u)

	if u == s {
		a--
	} else if u == t {
		b--
	}

	fmt.Println(a, b)
}


Measured memory_bytes: 512
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	a, b, c, d := scanInt(), scanInt(), scanInt(), scanInt()
	fmt.Fprintln(wr, max(a*c, max(b*d, max(a*d, b*c))))
}


Measured memory_bytes: 1776
n = int(input())
x = list(map(int, input().split()))
mean1 = sum(x)//len(x)
mean2 = mean1+1
ans1 = 0
ans2 = 0
for num in x:
    ans1 += (num - mean1)**2
    ans2 += (num - mean2)**2
print(min(ans1,ans2))

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	string k = "Yes";
	while(a>0 || c>0)
	{
		c -= b;
		if(c <= 0)
		{
			k = "Yes";
			break;
		}
		a -= d;
		if(a <= 0)
		{
			k = "No";
			break;
		}
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3632
data = list(map(int,input().split()))
n = data[0]
x = data[1]
l = list(map(int,input().split()))
bound = [0]
for i in range(n):
        data = bound[i] + l[i]
        bound.append(data)
print(len(list(filter(lambda z:z<=x,bound))))

Measured memory_bytes: 3064
import math
from operator import itemgetter
n,k = map(int,input().split())

lst1 = [list(map(int,input().split())) for i in range(n)]
lst1.sort(key=itemgetter(1),reverse=True)
ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

for i in range(n):
    if lst1[i][1] > x:
        k -= lst1[i][1]
        ans += 1
    if k <= 0:
        print(ans)
        exit()


print(ans + math.ceil(k/x) )


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

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

int n,m;
vi x,y,z;

void solve() {
  cin>>n>>m;
  x.resize(n);
  y.resize(n);
  z.resize(n);
  rep(i,0,n) cin>>x[i]>>y[i]>>z[i];

  int res=0;
  rep(bit,0,(1<<3)) {
    vi b;
    rep(i,0,n) {
      int tmp=0;
      if(bit&(1<<0)) tmp+=x[i];
      else tmp-=x[i];

      if(bit&(1<<1)) tmp+=y[i];
      else tmp-=y[i];

      if(bit&(1<<2)) tmp+=z[i];
      else tmp-=z[i];

      b.pb(tmp);
    }
    SORTG(b);
    int sum=0;
    rep(i,0,m) sum+=b[i];
    chmax(res,sum);
  }
  cout<<res<<endl;
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n;cin >> n;
  vector<ll> a(n);
  int ind = 0;
  ll xsum = 0;
  ll sum = 0;
  ll ans =0;
  rep(i,n){
    cin >> a[i];
    xsum ^= a[i];
    sum += a[i];
    while(sum != xsum ){
      xsum ^= a[ind];
      sum -= a[ind];
      ind++;
    }
    ans += i - ind + 1;
    //cout << i << " " << ind << endl;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> graph;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> group(n, -1);

    int num = 0;
    rep(i, n)
    {
        if (group[i] != -1)
        {
            continue;
        }
        deque<int> que;
        que.push_back(i);
        while (!que.empty())
        {
            int cur = que.front();
            que.pop_front();
            if (group[cur] != -1)
            {
                continue;
            }
            group[cur] = num;
            for (auto &&next : graph[cur])
            {
                if (group[next] == -1)
                    que.push_back(next);
            }
        }
        num++;
    }
    vector<int> gnum(n, 0);
    rep(i, n)
    {
        gnum[group[i]]++;
    }
    int ans = 0;
    rep(i, n)
    {
        chmax(ans, gnum[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27020
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i*500 + j*100 + k*50 == x:
                ans += 1

print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        solve(X);
    }
    static void solve(int X){
        int L = 0;
        int R = 1000000000;
        while(true){
            int M = (L+R)/2;
            if(L==M)break;
            if(check(M,X)){
                R=M;
            }else{
                L=M;
            }
        }
        if(!check(L,X))L++;
        System.out.println(L);
    }
    static boolean check(int N, int X){
        long P = (long)(N)*(N+1)/2;
        if(P>=X){
            return true;
        }else{
            return false;
        }
    }
}


Measured memory_bytes: 21844
import java.io.BufferedInputStream



// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    fun iterateTokens(): Iterator<String> {
        val reader = BufferedInputStream(System.`in`).bufferedReader()
        val iterator = reader.lineSequence()
                .map { it.split(" ") }
                .reduce { left, right -> left + right }
                .iterator()
        return iterator
    }
    val tokens = iterateTokens()
    val N = tokens.next().toLong()
    val K = tokens.next().toLong()
    solve(N, K)
}

fun solve(N: Long, K: Long){
    if (K == 1L ){
        println(0)
        return}
    println(N - K)
    return
}



Measured memory_bytes: 35880
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long int
using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> x(n);
  
  rep(i,n) cin >> x[i];
  int ans = 1001001001;
  
  for ( int p = 1; p <= 100; ++p ) {
    int now = 0;
    rep(i, n) now += (x[i] - p) * (x[i] - p);
    ans = min(ans, now);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
#define int LL
using namespace std;
const int N   = 51;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

int n,a[N],b[N];
int S[N],tp;
LL ans;

struct xx
{
	int v,next;
}E[N*N<<1];
int G,head[N],vis[N];

void add(int x,int y)
{
	E[++G]=(xx){y,head[x]};
	head[x]=G;
}

void dfs(int x)
{
	for (int i=head[x];i;i=E[i].next)
	  if (!vis[E[i].v]) vis[E[i].v]=1,dfs(E[i].v);
	return ;
}

int solve(int x)
{
	int flag=1;
	G=0;memset(head,0,sizeof(head));
	rep(i,1,50) 
	{
		rep(j,1,x) 
		  add(i,i%j);
	}
	  
	rep(i,1,50) rep(j,1,tp) add(i,i%S[j]);
	rep(i,1,n) 
	{
		memset(vis,0,sizeof(vis));
		vis[a[i]]=1;
		dfs(a[i]);
		if (!vis[b[i]]) 
		{
			flag=0;
			break;
		}
	}
	return flag;
}
int R;
signed main()
{
	read(n);
	rep(i,1,n) read(a[i]),R=max(R,a[i]);
	rep(i,1,n) read(b[i]);
	for (int i=50;i>=0;--i)
	   if (!solve(i)) 
	     S[++tp]=i+1;
	rep(i,1,tp) ans+=1ll<<S[i];
	return printf("%lld",S[1]==51?-1:ans),0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod = 998244353;
const int N = 1200000;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int a, b, m;
    cin >> a >> b >> m;
    vector <int> v1(a), v2(b);
    for (int i = 0; i < a; i++) cin >> v1[i];
    for (int i = 0; i < b; i++) cin >> v2[i];
    int ans = 1e9;
    for (int i = 1; i <= m; i++){
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = min(ans, v1[x] + v2[y] - c);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    ans = min(ans, v1[0] + v2[0]);
    cout << ans;
}


Measured memory_bytes: 1792
N,K=gets.split.map(&:to_i)
R,S,P=gets.split.map(&:to_i)
sc=Hash.new{0}
sc["r"]=P
sc["s"]=R
sc["p"]=S
T=gets.chomp
ans=0
take=false
K.times do |i|
  ((N+K-1-i)/K).times do |j|
    if j==0
      ans+=sc[T[i+K*j]]
      take=true
    else
      if T[i+K*j]!=T[i+K*(j-1)] || !take
        ans+=sc[T[i+K*j]]
        take=true
      else
        take=false
      end
    end
  end
end
puts ans

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, M;
	cin >>N >>M;
	int S=(N*(N-1)+M*(M-1))/2;
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,x,y,m,z;
	cin>>n>>k>>x>>y;
	m=k*x+(n-k)*y;
	z=n*x;
	if(n>k)cout<<m<<endl;
	else   cout<<z<<endl;
	return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int  INF =  1e9;
const ll LINF = 1e18;
const ll MOD = 1e9+7;
const int SIZE = 100;

template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}

template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
 
ll fac[SIZE], inv[SIZE], facinv[SIZE];
void make() {
	fac[0] = fac[1] = 1; inv[1] = 1; facinv[0] = facinv[1] = 1;
	for (ll i = 2; i < SIZE; i++) {
		fac[i] = (fac[i-1] * i) % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		facinv[i] = facinv[i-1] * inv[i] % MOD;
	}
}
ll combi(ll a, ll b) {
	if (a < b) return 0;
	return fac[a] * (facinv[b] * facinv[a-b] % MOD) % MOD;
}

int main() {
	ll n;
	scanf ("%lld", &n);
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	
	ll buf = a[0];
	for (ll i = 0; i < n; i++) {
		buf = lcm(buf, a[i]);
	}
	printf("%lld\n", buf);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

vector<int> t;
ll s[300][300];
int main() {
	ll n, m, r,ans = INF64;
	cin >> n >> m >> r;
	REPO(i, n) {
		REPO(j, n) {
			if (i != j)s[i][j] = INF64;
		}
	}
	REP(i, r) {
		int a;
		cin >> a;
		t.push_back(a);
	}
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		s[a][b] = c;
		s[b][a] = c;
	}
	sort(ALL(t));
	REPO(k, n) REPO(i, n) REPO(j, n) s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
	do {
		ll a = 0;
		REP(i, r - 1) a += s[t[i]][t[i + 1]];
		ans = min(a, ans);
	} while (next_permutation(ALL(t)));
	cout << ans << endl;
}


Measured memory_bytes: 768
def read_input():
    a, b, c = map(int, input().split())
    return a, b, c


def submit():
    a, b, c = read_input()

    top = max(a, b, c)
    buttom = min(a, b, c)
    mid = a + b + c - top - buttom

    ones = top - mid
    doubles = (top - (buttom + ones)) // 2

    if (top - (buttom + ones)) % 2 == 0:
        print(ones + doubles)
    else:
        print(ones + doubles + 2)

if __name__ == '__main__':
    submit()


Measured memory_bytes: 3064
solve :: Int -> Int -> [Int] -> Int
solve ma _ [] = ma
solve ma mi (n:nx)
  | ma < n - mi = solve (n-mi) (mini mi n) nx
  | otherwise = solve ma (mini mi n) nx
  where mini mi n = if n < mi then n else mi

main = getContents >>= print . (\(a:b:x) -> solve (b-a) a (b:x)) . tail . map read . words

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

int main(){
  int num[17][17];
  int n;

  while(1){
    int count=1;
    cin>>n;
    if(n==0)break;

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	num[i][j]=0;
      }
    }
    
    int dx,dy;
    dx=(n+1)/2;
    dy=(n+1)/2-1;

    while(1){
      if(count>n*n)break;
      if(dx>=n)dx=0;
      else if(dy>=n)dy=0;
      else if(dy<0)dy=n-1;
      else if(num[dx][dy]==0){
	num[dx][dy]=count;
	count++;
	dx+=1;
	dy+=1;
      }else if(num[dx][dy]!=0){
	dx+=1;
	dy-=1;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	printf("%4d",num[i][j]);
      }
      cout<<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M; ll L;
ll E[310][310];
int F[310][310];

void solve() {
	cin >> N >> M >> L;
	rep(i, 0, N) {
		rep(j, 0, N) {
			E[i][j] = linf;
		}
	}
	rep(i, 0, M) {
		int a, b; cin >> a >> b; a--; b--;
		ll cost; cin >> cost;
		MIN(E[a][b], cost);
		MIN(E[b][a], cost);
	}
	rep(k, 0, N) {
		rep(i, 0, N) {
			rep(j, 0, N) {
				MIN(E[i][j], E[i][k] + E[k][j]);
			}
		}
	}
	rep(i, 0, N) {
		rep(j, 0, N) {
			if(E[i][j] <= L) F[i][j] = 1;
			else F[i][j] = inf;
		}
	}
	rep(k, 0, N) {
		rep(i, 0, N) {
			rep(j, 0, N) {
				MIN(F[i][j], F[i][k] + F[k][j]);
			}
		}
	}
	int Q;
	cin >> Q;
	while(Q--) {
		int s, t; cin >> s >> t; s--; t--;
		if(F[s][t] == inf) cout << -1 << "\n";
		else cout << F[s][t] - 1 << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	lli N,A,B;
	cin>>N>>A>>B;
	lli ans;
	if(A>B)ans=0;
	else if(A==B)ans=1;
	else if(N==1)ans=0;
	else ans=(B-A)*(N-2)+1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}

fn main() {
    
    const M : u64 = 1_000_000_007;
    
    const N : usize = 13;
    
    let s : Vec<char> = read::<String>().chars().collect();

    let mut dp = [0; N];
    dp[0] = 1;
    
    for item in s {
        let mut next_dp = [0; N];
        
        if item == '?'{
            // ? = 0..10
            for i in 0..10 {
                for j in 0..N {
                    next_dp[ ((j * 10) + i) % N] += dp[j];
                    next_dp[ ((j * 10) + i) % N] %= M;
                }
            }
        }
        
        else {
            let i = item as usize - '0' as usize;
            
            for j in 0..N {
                next_dp[ ((j * 10) + i) % N] += dp[j];
                next_dp[ ((j * 10) + i) % N] %= M;
            }
        }
 
        // copy dp
        for i in 0..N{
            dp[i] = next_dp[i];
        }
    }
    
    println!("{}", dp[5]);
    
}

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

signed main(){
  
  int N, K;
  string s;

  cin>>N>>K;
  cin>>s;
  
  s[K-1] = tolower(s[K-1]);
  
  cout<<s<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import numpy as np


w, h, n = map(int, input().split())
v = np.zeros((h, w), dtype=np.int)
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        v[:, :x] = 1
    elif a == 2:
        v[:, x:] = 1
    elif a == 3:
        v[:y, :] = 1
    else:
        v[y:, :] = 1
print(w*h-np.sum(v))



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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b,m,ma=INF,mb=INF,x,y,c;
	cin >> a >> b >> m;
	vll aa(a),bb(b);
	rep(i,a){
		cin >> aa[i];
		chmin(ma,aa[i]);
	}
	rep(i,b){
		cin >> bb[i];
		chmin(mb,bb[i]);
	}
	ll tmp=ma+mb;
	rep(i,m){
		cin >> x >> y >> c;
		chmin(tmp,aa[x-1]+bb[y-1]-c);
	}
	cout << tmp << endl;
	return 0;
}

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

using namespace std;

const long long mod=1e9+7;

long long a[2005];

void sq()
{
    a[0]=a[1]=a[2]=1;
    for(int i=3;i<=2000;i++) 
		a[i]=(a[i-3]+a[i-1])%mod;
}
int main()
{
	int n;
	cin>>n;
    sq();
    if(n<3) 
		cout<<0<<endl;
    else 
		cout<<a[n-3]<<endl;
    return 0;
}

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

struct Edge {
	int to, weight;
};

int main()
{
	int n, u, k, v, c, distance[100]{}, upd_num = 1;
	bool must_update[100]{ 1 };
	std::vector<Edge> dest[100];

	std::cin >> n;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			std::cin >> v >> c;
			dest[u].push_back({ v, c });
		}
		if (i)
			distance[i] = 2000000000;
	}

	while (upd_num)
		for (int i = 0; i < n && upd_num; i++)
		{
			if (!must_update[i]) continue;

			must_update[i] = false;
			upd_num--;
			for (auto e : dest[i])
			{
				int tmp = distance[i] + e.weight;
				if (tmp < distance[e.to])
				{
					distance[e.to] = tmp;
					if (!must_update[e.to])
					{
						must_update[e.to] = true;
						upd_num++;
					}
				}
			}
		}

	for (int i = 0; i < n; i++)
	{
		std::cout << i << " " << distance[i] << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

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

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

    ll N, X;
    cin >> N >> X;

    ll ans = INF;
    rep(i, N){
        ll x;
        cin >> x;
        x -= X;
        if(ans == INF) ans = x;
        else ans = gcd(ans, x);
    }
    print(abs(ans));

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


vector<Int> frompoInt(216000);
Int dp[216000];
Int n, C, h[216000];
void add(vector<Int> &bit, Int ind, Int val){
  ind++;
  while(ind < bit.size()){
    bit[ind] = max(bit[ind], val);
    ind += ind & -ind;
  }
}

Int sum(vector<Int> &bit, Int ind){
  ind++;
  Int res = 0;
  while(ind){
    res = max(res, bit[ind]);
    ind -= ind & -ind;
  }
  return res;
}

Int calc(Int x, Int f){
  return (h[f] - h[x]) * (h[f] - h[x]) + C + dp[f];
}

int main(){
  cin >> n >> C;
  
  fill(dp, dp + n, LINF);
  dp[0] = 0;
  for(Int i = 0;i < n;i++)cin >> h[i];
  for(Int i = 0;i < n;i++){

    Int bottom = i, top = n;
    if(i)dp[i] = calc(i, sum(frompoInt,i));
    while(top - bottom > 1){
      Int mid = (top + bottom) / 2;
      if(calc(mid, i) >= calc(mid, sum(frompoInt, mid)))bottom = mid;
      else top = mid;
    }
    add(frompoInt, top, i);
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

const int MAX = 510000;
const int MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep(i, 2, MAX){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

    COMinit();

    ll N, A, B, K;
    cin >> N >> A >> B >> K;

    ll res = 0LL;
    for (ll a = 0LL; a <= N; ++a) {
        // a*A + b*B == K
        ll bB = K - a*A;
        if (bB % B != 0) continue;

        // a + b <= N
        ll b = bB / B;
        //if (b > N) continue;
        
        res += COM(N, a) * COM(N, b) % MOD;
        res %= MOD;
    }

    cout << res << endl;
}

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

int main(){
    int N,D,cnt=0;
    double T;
    cin >> N >> D;
    int x[N][D];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> x[i][j];
        }
    }
    for(int i=0;i<N-1;i++){
        
        for(int j=i+1;j<N;j++){
            int T=0;
            for(int k=0;k<D;k++){
            T+=pow(x[i][k]-x[j][k],2);
            }
            
             double ans = pow((double)T,0.5);
        if(ans == (int)ans)
            cnt++;
        }
       
    }
    cout << cnt << endl;


}


Measured memory_bytes: 512