akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			n = sc.nextInt();
			m = sc.nextInt();
			if(n == 0 && m == 0)break;
			else calc(n, m);
			
		}
	}
	public void calc(int n, int m){
		code = new int[m];
		xs = new int[n+1];
		 memo = new int[n+1][256];
		 for(int i = 0; i < n+1; i++){
			 Arrays.fill(memo[i], Integer.MAX_VALUE); 
		 }
		for(int i = 0; i < m; i++){
			code[i] = sc.nextInt();
		}
		for(int i = 1; i < n+1; i++){
			xs[i] = sc.nextInt();
		}
		
		memo[0][128] = 0;
		for(int i = 1; i < n+1; i++){
			for(int y = 0; y < 256; y++){
				if(memo[i-1][y] != Integer.MAX_VALUE){
					for(int j = 0; j < m; j++){
						int t = y + code[j];
						if(t > 255) t = 255;
						if(t < 0) t = 0;
						int me1= memo[i][t];
						int me2 = memo[i-1][y] + (xs[i] - t) * (xs[i] - t);
						memo[i][t] = Math.min(me1, me2);
					}
				}
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int y = 0; y < 256; y++){
			ans = Math.min(ans, memo[n][y]);
		}
		System.out.println(ans);
		
	}
	int n;
	int m;
	int[] code;
	int[] xs;
	int[][] memo;
	
	/*public int iter(int y, int i){
		if(i >= n) 
			return 0;
		else if(memo[i][y] != Integer.MAX_VALUE) 
			return memo[i][y];
		else{
			for(int j = 0; j < m; j++){
				int t = y + code[j];
				if(t > 255) t = 255;
				if(t < 0) t = 0;
				memo[i][y] = Math.min(memo[i][y], (xs[i] - t)*(xs[i] - t) + iter(t, i+1));
			}
			return memo[i][y];
		}
	}*/
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 154720
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> B(N+1);
    FOR(i, 0, N){
        ll a;
        cin >> a;
        A[i] = a;
        B[a] = i;
    }

    set<ll> se;
    se.insert(-1);
    se.insert(N);

    ll sum = 0;

    FOR(a, 1, N+1){
        ll index = B[a];

        //auto it = lower_bound(ALL(se), index);
        auto it = se.lower_bound(index);
        
        ll right = *it;
        it--;
        ll left = *it;

        sum += a * (right-index) * (index-left);

        se.insert(index);
    }

    p(sum);

    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

char s[100005];
 
int main(){
	cin>>s;
	
	int len = strlen(s),i=0;
	bool bExist;
	char c = 'a';
	
	do{
		bExist = false;
		for(i=0;i<len;i++){
			if (s[i] == c){
				bExist = true;
				break;
			}
		}
		if (!bExist) break;
		c++;
	}while(c<='z');
	
	if ((!bExist) && (c<='z')) {
		cout<<c;
		return 0;
	}	
	cout<<"None";
	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  int wi[n];
  int vi[n];
  int ac = 0;
  for(int i = 0; i<n;i++){
    cin >> wi[i] >> vi[i];
    ac+= vi[i];
  }
  long long dp[2][ac+1];
  fill(*dp, *dp+2*(ac+1),1000000000000);
  dp[0][0]  = 0;
  bool f = 1;
  for(int i = 1; i<=n;i++){
    for(int j = 0; j<=ac;j++){
      if(j>=vi[i-1]){
	dp[f][j] = min(dp[!f][j],dp[!f][j-vi[i-1]]+wi[i-1]);
      }else{
	dp[f][j] = dp[!f][j];
      }
    }
    f = !f;
  }
  int ans = 0;
  for(int i = 0; i<=ac;i++){
    if(dp[!f][i]<=w){
      ans = max(ans,i);
    }
  }
  cout << ans <<'\n';
  return 0;
}


Measured memory_bytes: 5168
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter, Binary};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
#[derive(Copy, Clone)]
struct Dice {
    top: usize, north: usize, east: usize
}
impl Dice {
    fn rotate_north(&self) -> Dice {
        Dice{top: 7 - self.north, north: self.top, east: self.east}
    }
    fn rotate_south(&self) -> Dice {
        Dice{top: self.north, north: 7 - self.top, east: self.east}
    }
    fn rotate_east(&self) -> Dice {
        Dice{top: 7 - self.east, north: self.north, east: self.top}
    }
    fn rotate_west(&self) -> Dice {
        Dice{top: self.east, north: self.north, east: 7 - self.top}
    }
}
impl Default for Dice {
    fn default() -> Self {
        Dice{top: 1, north: 2, east: 4}
    }
}
fn main() {
    loop {
        let_all!(n: usize);
        if n == 0 {
            return
        }
        let mut dice = Dice::default();
        for _ in 0 .. n {
            match &read_line!().trim()[..] {
                "north" => dice = dice.rotate_north(),
                "south" => dice = dice.rotate_south(),
                "east" => dice = dice.rotate_east(),
                "west" => dice = dice.rotate_west(),
                _ => unreachable!()
            }
        }
        println!("{}", dice.top);
    }
}


Measured memory_bytes: 5024
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    if (a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


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

int main(void) {
    char S[500005];
    long long a[500005], b[500005], N, i, x, r, s, M;
    scanf("%s", S);
    N=strlen(S);
    if (S[0]=='<') {
        r=0; x=1;
    }
    else {
        b[1]=0; r=0; x=2;
    }
    for (i=1; i<N; i++) {
        if (S[i]!=S[i-1]) {
            b[x]=r+1;
            r=0; x++;
            // printf("%d ", r);
            continue;
        }
        r++;
        // printf("%d ", r);
    }
    b[x]=r+1;
    if (x%2==1) {
        x++;
        b[x]=0;
    }
    // printf("\n");
    // printf("%s\n", S);
    // for (i=1; i<=x; i++) printf("%d ", b[i]);
    // printf("\n");
    s=0;
    for (i=1; i<=x/2; i++) {
        if (b[2*i-1]>b[2*i]) M=b[2*i-1];
        else M=b[2*i];
        // printf("%lld ", b[2*i-1]*(b[2*i-1]-1)/2+b[2*i]*(b[2*i]-1)/2+M);
        s+=b[2*i-1]*(b[2*i-1]-1)/2+b[2*i]*(b[2*i]-1)/2+M;
    }
    // printf("\n");
    printf("%lld\n", s);
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

    ll a, b; 
    cin >> a >> b ; 
    cout << (a-b)+1 << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.7f\n", ans); 相対誤差

int main() {
  string s;
  cin>>s;
  std::vector<int> ki={'R','U','D'};
  std::vector<int> gu={'L','U','D'};
  rep(i,s.size()){
    if (i%2 == 0){
      if (s[i] == 'L') {
        cout<<"No"<<endl;
        return 0;
      }
    } else {
      if (s[i] == 'R') {
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

long long int gcd(long long int a,long long int b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

int main(){
    int n;
    cin >> n;
    long long int c[n];
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    if(n==1){
        cout << c[0] << endl;
    }
    else{
        long long int ans =0;
        ans = c[0] / gcd(c[0],c[1]) * c[1];
        for(int i=2;i<n;i++){
            ans = max(ans,c[i]) / gcd(c[i],ans) * min(ans,c[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<n+n*n+n*n*n<<"\n";
    }
    return 0;
}

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

int main() {
    int n, sum;
    cin >> n;
    vector<int> vec1(n), vec2(n);
    sum = 0;

    for(int i = 0; i < n; i++) {
        cin >> vec1.at(i) >> vec2.at(i);
        sum += vec2.at(i) - vec1.at(i) + 1;
    }
    cout << sum << endl;
}

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

using namespace std;

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

    vector <int> inH(inN);
    for(int i=0; i<inN; i++)
    {
        cin >> inH[i];
    }

    bool isPossible = true;
    for(int i=1; i<inN-1; i++)
    {
        if(inH[i] - inH[i-1] > 0)
        {
            inH[i] -= 1;
        }

        if(inH[i] > inH[i+1])
        {
            isPossible = false;
            break;
        }
    }

    if(isPossible == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long 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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b; cin >> a >> b;
    if(a+b==15) cout << "+" << endl;
    else if(a*b==15) cout << "*" << endl;
    else cout << "x" << endl;
    return 0;
}


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


int N;
int bit[26][2010000];

//aの位置にwを追加
void add(int a,int c,int w){
    a++;
    for(int x=a;x<=N+1;x+=(x&(-x)) ){
        bit[c][x] += w;
    }
}

//v[0] + ... + v[a-1]
int sum(int a,int c){
    ll ret=0;
    for(int x=a;x>0;x-=(x&(-x)) ){
        ret+=bit[c][x];
    }
    return ret;
}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n,q;
    string s;
    cin>>n>>s>>q;
    N=n;
    for(int i=0;i<n;i++){
        add(i,(int)(s[i]-'a'),1);
    }
    while(q--){
        int aa;
        cin>>aa;
        if(aa==1){
            int p;
            char c;
            cin>>p>>c;
            p--;
            if(s[p]==c)continue;
            add(p,(int)(s[p]-'a'),-1);
            add(p,(int)(c-'a'),1);
            s[p] = c;
        }
        else{
            int l,r;
            cin>>l>>r;
            l--;
            //string d="";
            //for(int i=l;i<r;i++)d += s[i];
            int ans = 0;
            for(int i=0;i<26;i++){
                int ret = sum(r,i) - sum(l,i);
                //cerr << d << " " << (char)(i+'a') << " " << l << " " << r << " " << ret << endl;
                if(ret>0){
                    ans++;
                }
            }
            cout << ans << "\n";
        }
    }
}

Measured memory_bytes: 97052
/*
    author: blue_matrix
*/
#include <bits/stdc++.h>
using namespace std;

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<ll> h(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    vector<set<ll>> v(n+1,set<ll> ());
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].insert(h[b]);
        v[b].insert(h[a]);
    }
    ll count=0;
    // cout<<"hello"<<endl;
    for(ll i=1;i<=n;i++)
    {
        if(v[i].empty())
        {
            count++;
            continue;
        }
        if(*v[i].rbegin()<h[i])
        count++;
    }
    cout<<count<<endl;
    // dbg(v);
    return 0;
}

Measured memory_bytes: 17940
def main():
  w, h, k = map(int, raw_input().split())
  area = [[0 for _ in xrange(w)] for _ in xrange(h)]

  for _ in xrange(k):
    x, y, mode = map(int, raw_input().split())
    for a in xrange(h):
      for b in xrange(w):
        if mode == 1 and b < x:
          area[a][b] = 1
        if mode == 3 and a < y:
          area[a][b] = 1

        if mode == 2 and b >= x:
          area[a][b] = 1
        if mode == 4 and a >= y:
          area[a][b] = 1

  vol = 0
  for i in xrange(h):
    for j in xrange(w):
      elem = area[i][j]
      if elem == 0:
        vol += 1
  print(vol)


main()

Measured memory_bytes: 2696
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
N, M = list(map(int, input().split()))
uf = UnionFind(N)

for _ in range(M):
  X, Y, Z = list(map(int, input().split()))
  uf.union(X-1,Y-1)
  
print(uf.group_count())

  

Measured memory_bytes: 7876
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(ll i=(ll)(s);i<(ll)(e);++i)

int main(){
	ll n; cin>>n;
	ll cnt=0;
	for(ll a=1; a<n; ++a){
		ll bn = (n-1) / a;
		for(ll b=1; b<=bn; ++b){
			ll c = n - a*b;
			if(c<=0) break;
			if(a*b + c == n){
				cnt++;
			}
		}
	}

	cout<< cnt <<endl;
}


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

using namespace std;

int main() {
  #ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
  #endif
  int n;
  while(scanf("%d", &n) != EOF) {
    int ans = 1;
    while((ans << 1) <= n) ans <<= 1;
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        x = (c * e - b * f) / (a * e - b * d) + 0.0
        y = (c * d - a * f) / (b * d - a * e) + 0.0
        print(Decimal(str(x)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP), Decimal(str(y)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP))
    except:
        break


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


struct Shop{
  string name;
  int score;
  Shop(){}
  friend bool operator<(const Shop&a,const Shop&b){
    if(a.name == b.name)return a.score > b.score;
    return a.name < b.name;
  }
};

int main(){
  int n;
  cin>>n;
  Shop shop[200];
  for(int i = 0; i < n; ++i){
    cin>>shop[i].name>>shop[i].score;
  }
  int idx[200];
  for(int i = 0; i < 200; ++i){
    idx[i]=i;
  }
  for(int i = 0; i < n; ++i){
    for(int j = 1; j < n - i; ++j){
      if(shop[j] < shop[j-1]){
	swap(shop[j],shop[j - 1]);
	swap(idx[j],idx[j - 1]);
      }
    }
  }
  for(int i = 0; i < n; ++i){
    cout<<idx[i]+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int x[9][9]; int N, M, A[9], P[9], cx, pows[9][9];
int power2(int a, int b) { int res = 1; for (int i = 0; i < b; i++) { res *= a; }return res; }
int main() {
	for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { pows[i][j] = power2(i, j); } }
	cin >> N >> M; for (int i = 0; i < M; i++) { cin >> A[i]; x[i + 1][A[i]] = 1; }
	for (int i = 1; i <= N; i++) {
		cx = i;
		for (int j = 1; j <= M; j++) {
			if (x[j][cx] == 1) { cx++; }
			else if (x[j][cx - 1] == 1) { cx--; }
		}
		P[i] = cx;
	}
	int Q = M, maxv, S, cy;
	int D[9], F[9], y[9][9];
	for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) y[i][j] = 0;
	for (int i = 0; i < pows[M][M] * 3 / 4; i++) {
		if (i >= 1) {
			for (int j = 0; j < M; j++) y[D[j] + 1][A[j]] = 0;
		}
		for (int j = 0; j < M; j++) {
			D[j] = (i / pows[M][j]) % M;
			y[D[j] + 1][A[j]]++;
		}
		for (int j = 0; j < M; j++) {
			if (y[D[j] + 1][A[j]] >= 2 || y[D[j] + 1][A[j] + 1] >= 1) goto E;
		}
		for (int j = 1; j <= N; j++) {
			cy = j;
			for (int k = 1; k <= M; k++) {
				if (y[k][cy] == 1) cy++;
				else if (y[k][cy - 1] == 1) cy--;
			}
			F[j] = cy;
		}
		for (int j = 1; j <= N; j++) {
			if (P[j] != F[j]) goto E;
		}
		maxv = 0;
		for (int j = 1; j <= M; j++) {
			S = (i / pows[M][j - 1]) % M;
			maxv = max(maxv, S + 1);
		}
		if (Q > maxv) Q = maxv;
	E:;
	}
	cout << Q << endl;
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int N, L;
    cin >> N >> L;
    if (L >= 0)
    {
        cout << ((2 * L + N - 1) * N) / 2 - L;
    }
    else if (L < 0 && N + L - 1 >= 0)
    {
        cout << ((2 * L + N - 1) * N) / 2;
    }
    else
    {
        cout << ((2 * L + N - 1) * N) / 2 - (L + N - 1);
    }
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

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

    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double area = w * h / 2;
    int yn;
    if (abs(w / 2 - x) < 1e-6 and abs(h / 2 - y) < 1e-6)
        yn = 1;
    else
        yn = 0;
    cout << setprecision(10) << area << " " << yn << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define mp(a,b) make_pair(a,b)
using namespace std;

int main(){
	int n;
	cin>>n;
	map<char,int> m;
	m['m']=1000;
	m['c']=100;
	m['x']=10;
	m['i']=1;
	REP(z,0,n){
		string left,right,ans;
		int lnum=0,rnum=0;
		cin>>left>>right;
		for(unsigned int i=0;i<left.size();i++){
			if(left[i]=='m'||left[i]=='c'||left[i]=='x'||left[i]=='i'){
				lnum+=m[left[i]];
			}else{
				lnum+=stoi(&left[i])*m[left[i+1]];
				i++;
			}
		}
		for(unsigned int i=0;i<right.size();i++){
			if(right[i]=='m'||right[i]=='c'||right[i]=='x'||right[i]=='i'){
				rnum+=m[right[i]];
			}else{
				rnum+=stoi(&right[i])*m[right[i+1]];
				i++;
			}
		}
		lnum+=rnum;
		if(lnum/1000>1)	ans+=to_string(lnum/1000);
		if(lnum/1000>0) ans+='m';
		lnum%=1000;
		if(lnum/100>1)	ans+=to_string(lnum/100);
		if(lnum/100>0)	ans+='c';
		lnum%=100;
		if(lnum/10>1)	ans+=to_string(lnum/10);
		if(lnum/10>0) 	ans+='x';
		lnum%=10;
		if(lnum>1)		ans+=to_string(lnum);
		if(lnum>0)		ans+='i';

		p(ans);
	}

	return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
int main(void)
{
	int i, j;
	int n, cnt[6]={0};
	double height=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%lf",&height);
		     if(height>=185.0)cnt[5]++;
		else if(height>=180.0)cnt[4]++;
		else if(height>=175.0)cnt[3]++;
		else if(height>=170.0)cnt[2]++;
		else if(height>=165.0)cnt[1]++;
		else cnt[0]++;
	}
	for(i=0; i<6; i++)
	{
		printf("%d:",i+1);
		for(j=0; j<cnt[i]; j++)
			printf("*");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
n = gets.to_i

if n < 105
  puts 0
elsif n <= 106
  puts 1
else
  count = 1
  107.step(n, 2) do |i|
    divisors = [1, i]
    3.step(i-1, 2) do |j|
      if divisors.include?(j)
        if divisors.size == 8
          count += 1
        end
        
        break;
      end
      
      if i % j == 0
        divisor = i / j
        divisors.push(j)
        divisors.push(divisor)
      end
    end
    
    #p divisors
  end
  
  puts count
end


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

ll f (ll a, ll m) {
    ll ret = 0;
    while (m < a) {
        m <<= 1;
        ret ++;
    }
    return ret;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    ll ng = 0, ok = 0;
    rep (i, n) {
        cin >> a[i];
        chmax(ok, a[i] + 1);
    }
    eprintf("%lld\n", ok);
    while (ok - ng > 1) {
        ll med = (ok + ng) / 2;
        ll sum = 0;
        rep (i, n) sum += (a[i] - 1) / med;
        if (sum <= k) ok = med;
        else ng = med;
    }

    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N,A,B;
    int ans=0;
    cin>>A>>B;

    ans=max(A+B,max(A-B,A*B));

    Out(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=1e9+7;

vector<int>g[55], edge[55];

int t[55], c;

void dfs(int x)
{
    if(t[x]) return;
    t[x]=++c;
    for(auto u:g[x])
    {
        dfs(u);
    }
}

int flg=0, no;
void dfs1(int x, int p, int y)
{
    if(x==y)
    {
        flg=1; return;
    }
    for(auto u:g[x])
    {
        if(u==p) continue;
        dfs1(u, x, y);
        if(flg)
        {
            edge[max(t[u], t[x])-2].push_back(no);
            return;
        }
    }
}

ll dp[55][(1<<20)+5], pw[55], n, m;

ll call(int p, int mask)
{
    if(p==n) return (mask==(1<<m)-1);

    if(mask==(1<<m)-1) return pw[n-p];

    if(~dp[p][mask]) return dp[p][mask];

    int tmp=mask;

    for(auto u:edge[p]) tmp|=(1<<u);

    ll ret=call(p+1, tmp)+call(p+1, mask);

    return dp[p][mask]=ret;
}
int main()
{
    FasterIO;

    pw[0]=1;
    for(int i=1; i<=50; i++) pw[i]=pw[i-1]*2LL;

    cin>>n;
    for(int i=1; i<n; i++)
    {
        int x, y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);

    cin>>m;
    for(int i=0; i<m; i++)
    {
        int x, y;
        cin>>x>>y;
        no=i; flg=0;
        dfs1(x, 0, y);
    }

    n--;

    mem(dp, -1);

    ll r=call(0, 0);

    cout<<r<<endl;

    return 0;
}


Measured memory_bytes: 450944
#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;

int H,W;
const int MAX=1000;
char A[MAX][MAX];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};

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

    cin>>H>>W;
    queue<P> que;
    int ctn[H][W]={2000};
    rep(i,0,H) {
        rep(j,0,W) {
            cin>>A[i][j];
            if(A[i][j]=='#') {
                que.push(P(i,j));
                ctn[i][j]=0;
            }
        }
    }

    while(!que.empty()) {
        P p=que.front();
        que.pop();
        rep(i,0,4) {
            int x=p.fi+dx[i];
            int y=p.se+dy[i];
            if(0<=x and x<=H-1 and 0<=y and y<=W-1) {
                if(A[x][y]=='.') {
                    A[x][y]='#';
                    ctn[x][y]=ctn[p.fi][p.se]+1;
                    que.push(P(x,y));
                }
            }
        }
    }
    int ans=0;
    rep(i,0,H) {
        rep(j,0,W) {
            ans=max(ans,ctn[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}




   


Measured memory_bytes: 25396
s = int(input())
A = [s]

for i in range(1000000):
    if A[i] % 2 == 0:
        if A[i] // 2 in A:
            print(i + 2)
            break
        A.append(A[i] // 2)
    else:
        if 3 * A[i] + 1 in A:
            print(i + 2)
            break
        A.append(3 * A[i] + 1)

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

void tree(vector<int> &h,int start,int end,int &ans){
	int t=1000;//木の高さ
	int tmp;//木の添字
	for(int i=start;i<=end;i++){
		if(t>h[i]){
			t=h[i];
			tmp=i;
		}
	}
	ans+=t;
	for(int i=start;i<=end;i++)h[i]-=t;
	if(*max_element(h.begin()+start,h.begin()+end)>=0){
		if(tmp-1>=start)tree(h,start,tmp-1,ans);
		if(tmp+1<=end)tree(h,tmp+1,end,ans);
	}
}


signed main(){
	int N,ans;
	ans=0;
	cin>>N;
	vector<int> h(N);
	for(int i=0;i<N;i++)cin>>h[i];
	tree(h,0,N-1,ans);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main()
{
  int N=1000000;
  int k,x;
  std::cin>>k>>x;
  int l =std::max(-N,x-k+1);
  int r =std::min(N,x+k-1);
  for(int i=l;i<=r;i++){std::cout <<i<<std::endl;}
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char S[20];
    scanf("%s", &S);
    getchar();
    if (S[2] == S[3] && S[4] == S[5])
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3184
<?php
// Your code here!
   function gcb( $max, $min )
{
	while( 0 != $min ) {
		$n = $min;
		$min = $max%$min;
		$max = $n;
	
	}
	
	return $max;
}

	$nums = explode( " ", trim( fgets( STDIN ) ) );
	$max = intval(max( $nums ));
	$min = intval(min( $nums ));
	echo gcb($max, $min);
?>



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

int main(void) {
    int n; string s;
    cin >> n >> s;

    if (n % 2 != 0) {
        cout << "No\n";
    } else if (s.substr(0, n/2) == s.substr(n/2, n)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


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

const int MAXN = 2e5 + 5;

int N;
vector <int> adj[MAXN];
int path, node;

void dfs(int x, int p, int d) {
	if (d > path) {
		path = d;
		node = x;
	}
	for (auto it : adj[x])
		if (it != p)
			dfs(it, x, d + 1);
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	dfs(1, 0, 0);
	path = 0;
	dfs(node, 0, 0);
	
	puts(path % 3 == 1 ? "Second" : "First");
	
	return 0;
}

Measured memory_bytes: 20608
D, N = map(int, input().split())

if D == 0:
	if N == 100:
		print(101)
	else:
		print(N)
elif D == 1:
	if N == 100:
		print(10100)
	else:
		print(N * 100)
else:
	if N == 100:
		print(1010000)
	else:
		print(N * 10000)

Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(){
	int a[5],b[5];
	int x;
	while(cin>>x){
		a[0]=x;
		for( int i=1 ; i<4 ; i++ )
			cin >> a[i];
		for( int i=0 ; i<4 ; i++ )
			cin >> b[i];
		int hit=0,blow=0;
		for( int i=0 ; i<4 ; i++ ){
			for( int j=0 ; j<4 ; j++ ){
				if( a[i]==b[j] ){
					if( i==j )
						hit++;
					else
						blow++;
				}
			}
		}
		cout << hit <<" "<< blow << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

#define MAX_N 200001
struct UnionFind{
    int par[MAX_N],rank[MAX_N]; 
    void init(int n){
        for (int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    } 
    int find(int x){
        if (x==par[x]) return (x);
        return (par[x]=find(par[x]));
    }
    void unite(int x, int y){
        x=find(x);y=find(y);       
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
        }
        else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    } 
    bool same(int x, int y){
        return (find(x) == find(y));
    } 
};

map<pint,int> tb;
int main(){
    int n,k,l,fs,sc;
    cin>>n>>k>>l;
    UnionFind uf1,uf2;
    uf1.init(n);
    uf2.init(n);
    rep(i,k){
        cin>>fs>>sc;
        uf1.unite(fs-1,sc-1);
    }
    rep(i,l){
        cin>>fs>>sc;
        uf2.unite(fs-1,sc-1);
    }
    rep(i,n){
        ++tb[mp(uf1.find(i),uf2.find(i))];
    }
    rep(i,n){
        cout<<tb[mp(uf1.find(i),uf2.find(i))]<<" ";
    }
    cout<<endl;
    return 0;
}

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

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

	cout<<n*(n-1)/2+m*(m-1)/2<<endl;

	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	vector<int> A(N);

	rep(i, 0, N)
	{
		cin >> A[i];
	}

	int ans = INF;
	rep(i, -100, 101)
	{
		int sum = 0;
		rep(j, 0, N)
		{
			sum += (i - A[j])*(i - A[j]);
		}
		chmin(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = list(map(int,input().split()))
#a = l.index(max(l))
#b = l[0:a]
#c = l[a:]
max_l = l[0]
count = 0
for i in range(1,len(l)):
    if max_l >= l[i]:
        count =count + (max_l - l[i])
    else:
        max_l = l[i]
print(count)

Measured memory_bytes: 32168
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  char a[50][51],b[50][51];
  int n,m,i,j,k,l,o;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)scanf("%s",a[i]);
  for(i=0;i<m;i++)scanf("%s",b[i]);
  for(i=0;i<=n-m;i++)for(j=0;j<=n-m;j++){
    o=1;
    for(k=0;k<m;k++)for(l=0;l<m;l++)if(a[i+k][j+l]!=b[k][l])o=0;
    if(o){printf("Yes");return 0;}
  }
  printf("No");
}


Measured memory_bytes: 128
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    int n = Integer.parseInt(br.readLine());
    int[] arr = new int[n];
    int nOdd = 0;
    int n4 = 0;
    int n2 = 0;
    String[] s = br.readLine().split(" ");
    for (int i=0; i<n; i++) {
      int val = Integer.parseInt(s[i]);
      if (val%4==0)
        n4++;
      else if (val%2==0)
        n2++;
      else
        nOdd++;
    }
    if (n4>=nOdd || (n4==nOdd-1 && n4+nOdd==n))
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


Measured memory_bytes: 37588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

const int INF = 1e9;

int main(){
	int N;
	double T,A;
	cin >> N >> T >> A;
	int ans = 0;
	double X = 100000.0;
	double H;
	for(int i = 0; i < N; i++){
		cin >> H;
		double temp = fabs(A-(T-H*0.006));
		if(temp < X){
			X = temp;
			ans = i+1;
		}
	}
	cout << ans << endl;
}	

Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let l = read::<f64>();
    println!("{}", (l / 3.) * (l / 3.) * (l / 3.));
}

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(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.util.*;

public class Main
{
	public static void main (String[] args)
	{
		Scanner sc = new Scanner (System.in);

		int a1= sc.nextInt();
		int a2= sc.nextInt();
		int a3= sc.nextInt();

		if ((a1+a2+a3) > 21)
			System.out.println ("bust");
		else
			System.out.println ("win");
	}
}

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

int main()
{
    int A,B,C,X,Y;
    long long ans = 0;
    long long ans2 = 0;
    cin >> A >> B >> C >> X >> Y;

    if(A+B > 2*C){
        ans = 2*min(X,Y)*C;
        if(X > Y){
            ans += (X-Y)*A;
        }else{
            ans += (Y-X)*B;
        }
        ans2 = 2*max(X,Y)*C;
        ans = min(ans,ans2);
    }else{
        ans = A*X+B*Y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(1){
		c-=b;
		if(c<=0){
			printf("Yes\n");
			return 0;
		}
		a-=d;
		if(a<=0){
			printf("No\n");
			return 0;
		}
	}
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  char a[3][4];
  for(int i=0; i<2; i++){
    for(int j=0; j<3; j++){
      cin >> a[i][j];
    }
  }

  int cnt=0;
  for(int i=0; i<3; i++){
    if(a[0][i] == a[1][i]){
      cnt++;
    }
  }
  cout << cnt;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	for (int i = 0; i < 100000; i++){
		a[i] = 0;
		b[i] = 0;
	}
	int c;
	int k;
	int s;
	int p, q;
	int n, m;
	int x, y, z;
	c = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	c = 0;
	for (int i = 0; i < n; i++){
		if (a[i] % 2 == 1)c++;

	}
	if (c%2==1)	printf("NO\n");
	else	printf("YES\n");

	return 0;
}

Measured memory_bytes: 512
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int maxnum=-1;
        int maxi=-1;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            
            if(b+c>maxi){
                maxnum=a;
                maxi=b+c;
            }
        }
        cout<<maxnum<<" "<<maxi<<endl;
    }

    
}

Measured memory_bytes: 1160