akhauriyash/Code-Regression huggingface dataset:
package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

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

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

//solve

const MAX = 100

var n int
var A [MAX + 1][MAX + 1]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		A[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				A[u-1][v-1] = 1

			}
		}

	}

	for i := 0; i < n; i++ {
		printList(A[i][0:n])
	}

}



Measured memory_bytes: 1780
#include<stdio.h>
    int main(void){
        int d,n,i,s=1;
        scanf("%d %d",&d,&n);
        for(i=0;i<d;i++){
            s*=100;
        }
        if(n==100)
            printf("%d\n",s*(n+1));
        else
            printf("%d\n",s*n);
        return 0;
    }

Measured memory_bytes: 128
<?php
	$tmp = explode(" ",trim(fgets(STDIN)));

	$n = $tmp[0];
	$m = $tmp[1];

	$flag = [];
	$waArray = [];
	$wa = 0;
	$ac = 0;
	for($i=0; $i<$m; $i++){
      $tmp = explode(" ",trim(fgets(STDIN)));
      if(isset($flag[$tmp[0]])){
        //正当済み
      }else{
        if($tmp[1]=="AC"){
          $flag[$tmp[0]] = true;
          $ac++;
          $wa += $waArray[$tmp[0]];
        }else{
          if(isset($waArray[$tmp[0]])){
            $waArray[$tmp[0]]++;
          }else{
            $waArray[$tmp[0]] = 1;
          }
        }
      }
    }

	echo $ac." ".$wa."\n";


Measured memory_bytes: 13048
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
   char a,b;
   cin >> a >> b;
   if(a == b) {
       cout << 'H' << endl;
   } else cout << 'D' << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> s, t;
  REP(i, n){
    cin >> a[i];
    if(a[i] < 0) t.emplace_back(a[i]);
    else s.emplace_back(a[i]);
  }

  ll S = s.size();
  ll T = t.size();
  bool ok = false;
  if(S > 0){
    if(n == k) ok = (T%2 == 0);
    else ok = true;
  }else{
    ok = (k%2 == 0);
  }

  mint ans = 1;
  if(!ok){
    sort(ALL(a), [](ll x, ll y){return abs(x) < abs(y); });
    REP(i, k) ans *= a[i];
  }else{
    sort(ALL(s));
    sort(ALLr(t));
    if(k%2 == 1){
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while(s.size() >= 2){
      ll x = s.back();
      s.pop_back();
      x *= s.back();
      s.pop_back();
      p.emplace_back(x);
    }
    while(t.size() >= 2){
      ll x = t.back();
      t.pop_back();
      x *= t.back();
      t.pop_back();
      p.emplace_back(x);
    }
    sort(ALLr(p));
    REP(i, k/2) ans *= p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 8124
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
  int X; cin >> X;
  for (int a = -1000; a <= 1000; ++a){
    for (int b = -1000; b <= 1000; ++b){
      if (pow(a, 5) - pow(b, 5) == X){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4040
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut neg = 0;
    let mut abssum = 0;
    for i in 0..n {
        if a[i] < 0 {
            neg += 1;
        }
        abssum += a[i].abs();
    }
    if neg % 2 == 0 {
        puts!("{}\n", abssum);
    } else {
        let mut miabs = 1 << 60;
        for i in 0..n {
            miabs = min(miabs, a[i].abs());
        }
        puts!("{}\n", abssum - 2 * miabs);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <map> //map<string, int> cnt; key とvalue
#include <set>//  set<int> s;
#include <cstdlib>  // abs() for integer
#include <vector>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std;
using ll = long long;
// g++ -std=c++11
int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int Stoi(string S) {
    if(S.empty()) return 0;
    int now = 1;
    if(S[0] >= '2' && S[0] <= '9') {
        now *= (int)(S[0] - '0');
        S.erase(S.begin());
    }
    if(S[0] == 'm') now *= 1000;
    if(S[0] == 'c') now *= 100;
    if(S[0] == 'x') now *= 10;
    S.erase(S.begin());
    return now + Stoi(S);
}

string itoS(int i) {
    if(i == 0) return "";
    string ret;
    int copy = i;
    int digit = 1;
    while(copy >= 10) {
        copy /= 10;
        digit *= 10;
    }
    if(copy >= 2) {
        ret.push_back((char)('0' + copy));
    }
    if(digit == 1000) ret.push_back('m');
    if(digit == 100) ret.push_back('c');
    if(digit == 10) ret.push_back('x');
    if(digit == 1) ret.push_back('i');
    return ret + itoS(i - copy * digit);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--) {
        string a, b;
        cin >> a >> b;
        cout << itoS(Stoi(a) + Stoi(b)) << endl;
    }
    return 0;
}


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

const int kMaxNumItems = 100;
const int kMaxWeightLimit = 100000;

int kWeight[kMaxNumItems], kValue[kMaxNumItems];
int64_t kDP[kMaxWeightLimit + 1];

int main() {
  int num_items, weight_limit;
  cin >> num_items >> weight_limit;

  for (int i = 0; i < num_items; i++) {
    cin >> kWeight[i] >> kValue[i];
  }

  int64_t ans = 0;
  for (int i = 0; i < num_items; i++) {
    for (int w = weight_limit; w >= 0; w--) {
      if (w - kWeight[i] >= 0) {
        kDP[w] = max(kDP[w], kDP[w - kWeight[i]] + kValue[i]);
      }

      ans = max(ans, kDP[w]);
    }
  }
  cout << ans << endl;

  return 0;
}

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll x,k,d;
    ll kaisu;
    cin >> x >> k >> d;
    if(abs(x)>=abs(k*d))
    {
        cout << abs(x)-abs(k*d) << endl;
    }
    else
    {
        kaisu=abs(x)/d;
        if((k-kaisu)%2==0)
        {
            cout << abs(abs(x)-abs(d*kaisu)) << endl;
        }
        else
        {
            cout << abs(abs(x)-abs(d*(kaisu+1))) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3592
package main

import "fmt"

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	// fmt.Println("(", x, ",", y, ")=", gcd(x, y))
	fmt.Println(gcd(x, y))
}



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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


int main(){
    int a, b; cin >> a >> b;
    cout << 6 / a / b << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        for (int length = (S.length() - 1) / 2 * 2;; length -= 2) {
            if (isEven(S.substring(0, length))) {
                return length;
            }
        }
    }

    static boolean isEven(String s) {
        return s.endsWith(s.substring(0, s.length() / 2));
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll A, B, C, X;
    cin >> A >> B >> C >> X;
    ll ans = 0;
    for(ll a = 0; a <= A; a++){
        for(ll b = 0; b <= B; b++){
            for(ll c = 0; c <= C; c++){
                if(a * 500 + b * 100 + c * 50 == X)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
	int a[4];
	for(int i = 0; i < 4; i++) cin >> a[i];
	sort(a, a + 4);
  	if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) puts("YES");
	else puts("NO");
  	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n,g,x,z,v,m,a[4][11]={0},b[4][11]={0},c[4][11]={0},d[4][11]={0};
    cin>>n;
    for(int y = 0 ; y < n ; y++){
        cin>>g>>x>>z>>v;
        if(g==1){
            a[x][z]+=v;
        }else if(g==2){
            b[x][z]+=v;
        }else if(g==3){
            c[x][z]+=v;
        }else{
            d[x][z]+=v;
        }
    }
    for(int i=1;i<=4;i++){
        for(int y = 1 ; y < 4 ; y++ ){
            for(int n = 1 ; n <= 10 ; n++ ){
                if(i==1){
                    cout<<" "<<a[y][n];
                }else if(i==2){
                    cout<<" "<<b[y][n];
                }else if(i==3){
                    cout<<" "<<c[y][n];
                }else{
                    cout<<" "<<d[y][n];
                }
            }
            cout<<endl;
        }
		if(i!=4)cout<<"####################"<<endl;
    }

    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll N;
    cin >> N;
    vector<int> P(N);
    rep(i,N) cin >> P[i];

    ll min_n =INF;
    ll ans = 0;
    rep(i,N)
    {
        if(min_n >= P[i])
        {
            ans++;
            min_n = P[i];
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
void main(){
	string s = readln().chomp();
	string t = readln().chomp();
	int ans;
	foreach(i; 0..s.length){
		if(s[i] != t[i])ans++;
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

int main(){
  int a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;

  if(a==5&&b==5&&c==7){
    cout<<"YES";
  }
  else if(a==5&&c==5&&b==7){
    cout<<"YES";
  }
  else if(c==5&&b==5&&a==7){
    cout<<"YES";
  }

  else{
    cout<<"NO";

  }
  cout<<"\n";

  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f
#define MAR 10e5+100

int main(){
    shutdown;
    int a[5];
    for(int i=1;i<=4;i++)
        scanf("%1d",&a[i]);
    for(int i=-1;i<=1;i+=2){
        for(int j=-1;j<=1;j+=2){
            for(int k=-1;k<=1;k+=2){
                a[2]*=i,a[3]*=j,a[4]*=k;
                if(a[1]+a[2]+a[3]+a[4]==7){
                    for(int s=1;s<=4;s++){
                        if(a[s]>=0&&s!=1)
                            printf("+%d",a[s]);
                        else
                            printf("%d",a[s]);
                    }
                    printf("=7\n");
                    return 0;
                }
                a[2]*=i,a[3]*=j,a[4]*=k;
            }
        }
    }
    return 0;
}


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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }

  vector<vector<int>> dp(h, vector<int>(w, 1e9));
  dp.at(ch).at(cw) = 0;
  deque<P> dq;
  dq.emplace_front(ch, cw);
  while (dq.size()) {
    P p = dq.front();
    dq.pop_front();
    int r = p.first, c = p.second;

    // 歩いて移動
    vector<int> dr = {1, -1, 0, 0};
    vector<int> dc = {0, 0, 1, -1};
    rep(i, 4) {
      int nr = r + dr.at(i);
      int nc = c + dc.at(i);
      if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
      if (s.at(nr).at(nc) == '#') continue;
      if (dp.at(nr).at(nc) > dp.at(r).at(c)) {
        dp.at(nr).at(nc) = dp.at(r).at(c);
        dq.emplace_front(nr, nc);
      }
    }

    // ワープで移動
    rep(i, 5) {
      rep(j, 5) {
        int nr = r - 2 + i;
        int nc = c - 2 + j;
        if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
        if (s.at(nr).at(nc) == '#') continue;
        if (dp.at(nr).at(nc) > dp.at(r).at(c) + 1) {
          dp.at(nr).at(nc) = dp.at(r).at(c) + 1;
          dq.emplace_back(nr, nc);
        }
      }
    }
  }

  cout << (dp.at(dh).at(dw) == 1e9 ? -1 : dp.at(dh).at(dw)) << endl;
  return 0;
}

Measured memory_bytes: 9548
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
    DRI(N);
    int an=0;
    REP(i,N){
        DRII(x,y);
        an+=y-x+1;
    }
    return 0*printf("%d\n",an);
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  if(n == 1)System.out.println("Hello World");
  else{
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.println(a+b);
  }
}}


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

void solve(long long W, long long H, long long N, std::vector<long long> x, std::vector<long long> y,
           std::vector<long long> a) {
    ll minX = 0, minY = 0, maxX = W, maxY = H;
    rep(i, N) {
        switch (a[i]) {
            case 1: minX = max(minX, x[i]); break;
            case 2: maxX = min(maxX, x[i]); break;
            case 3: minY = max(minY, y[i]); break;
            case 4: maxY = min(maxY, y[i]); break;
        }
    }
    if (minX > maxX || minY > maxY) {
        cout << 0 << endl;
    } else {
        cout << (maxX - minX) * (maxY - minY) << endl;
    }
}

int main() {
    long long W;
    scanf("%lld", &W);
    long long H;
    scanf("%lld", &H);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
        scanf("%lld", &a[i]);
    }
    solve(W, H, N, std::move(x), std::move(y), std::move(a));
    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>

using ull = unsigned long long;
using ll = long long;
using namespace std;

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

    vector<int> tops(n), bottoms(n);
    for (int i = 0; i < n; ++i) {
        cin >> tops[i];
    }

    for (int j = 0; j < n; ++j) {
        cin >> bottoms[j];
    }

    int tsum = accumulate(tops.begin(), tops.end(), 0) -tops[0];
    int bsum = accumulate(bottoms.begin(), bottoms.end(), 0) - bottoms[n-1];

    // solve
    // int ans = tops[0] + bottoms[n-1];
    // for (int i = 0 ; i < n-1; ++i) {
    //     // cout << "bsum:" << bsum << endl;
    //     // cout << "tsum:" << tsum << endl;
    //     if (bsum > tsum) {
    //         // choose down
    //         // cout << "down" << endl;
    //         ans += bsum;
    //         break;
    //     } else {
    //         // cout << "right" << endl;
    //         // choose slide
    //         // update values
    //         ans += tops[i+1];
    //         tsum = tsum - tops[i+1];
    //         bsum = bsum - bottoms[i];
    //     }
    // }

    // solve2
    int ans = 0;
    for(int i = 0; i < n; ++i) {

        // int cand = tops[0];
        int cand = 0;
        for(int j = 0; j < n; ++j) {
            if (j < i) {
                cand += tops[j];
            } else if (j == i) {
                // cand += tops[j] + bottoms[j] + (i == 0?-tops[0]:0);
                cand += tops[j] + bottoms[j];
            } else if (j > i) {
                cand += bottoms[j];
            }
            // if (i <= j && j!=n-1) {
            //     cand += bottoms[j];
            // } else if (i>j && j>=1) {
            //     cand += tops[j];
            // }
            // cout << "Progress(i,j)=" << i << "," << j << endl;
            // cout << "cand: " << cand << endl;
        }
        // cout << cand << endl;

        if (cand > ans) {
            ans = cand;
        }        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n, a, b, c, d, ma, mb;

	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	ma = ((n-1)/a+1)*b;
	mb = ((n-1)/c+1)*d;
	if (ma > mb) ma = mb;
	printf("%d\n", ma);
	return 0;
}



Measured memory_bytes: 2140
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  char str[11];
  int ans=(1<<31)-1,temp;
  cin>>str;
  for(int i=0;i<strlen(str)-2;i++){
    temp=(str[i]-'1'+1)*100+(str[i+1]-'1'+1)*10+(str[i+2]-'1'+1);
    if(temp<753) temp=753-temp;
    else temp=temp-753;
    if(ans>temp)ans=temp;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

n = int(input())
l = list(map(int, input().split()))

count = 0

l.sort()

kumiawase = list(itertools.combinations(l,3))

for i in range(len(kumiawase)):
  if kumiawase[i][0] != kumiawase[i][1] and kumiawase[i][1] != kumiawase[i][2]:
    if kumiawase[i][0] + kumiawase[i][1] > kumiawase[i][2]:
      count += 1
      
print(count)

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

using namespace std;

struct Union_Find {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;
    
    Union_Find(int size) : data(size, -1) {}
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }
    int Find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = Find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }
    bool same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -data[Find(x)];
    }
};


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector< vector<int> > lang(m);
	Union_Find uf(n);
	for (int i = 0; i < n; i++) {
		int K;
		cin >> K;
		for (int j = 0; j < K; j++) {
			int L;
			cin >> L;
			L--;
			lang[L].push_back(i);
		}
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < (int)lang[i].size() - 1; j++) {
			uf.Union(lang[i][j], lang[i][j + 1]);
		}
	}

	if (uf.size(0) == n) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main(){
    ll n,m;
    cin>>n>>m;
    ll c=0,A[n],t=0;
    for(ll i=0;i<n;i++){
        cin>>A[i];
        t+=A[i];
    }
    ll a = (t/(4*m));
    if((a*4*m)!=t){
        a+=1;
    }
    for(ll i=0;i<n;i++){
        if(A[i]>=a){
            c+=1;
        }
    }
    if(c>=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;
		
		for(int a = 0; a <= A; a++){
			for(int b = 0; b <= B; b++){
				int cc = X - 500 * a - 100 * b;
				if(cc >= 0 && cc % 50 == 0 && cc / 50 <= C) ans++;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
    LL n,m;
    cin>>n>>m;
    if(2*n>m)
    {
        cout<<max(m/4,m/2)<<endl;
    }
    else
    {
        long long ans=m-2*n ;
        cout<<max(n+ans/4,m/4)<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static final int END_SIGN = 0;

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

		// 標準偏差値のリスト
		ArrayList<Double> standardDeviationList = new ArrayList<Double>();

		int inputCount;
		// 得点の件数を入力、0で終了
		while (EndDecision(inputCount = sc.nextInt())) {
			// 得点リスト
			ArrayList<Double> scores = new ArrayList<Double>();
			for (int i = 0; i < inputCount; i++) {
				scores.add(sc.nextDouble());
			}
			// 標準偏差値を計算し、標準偏差値リストに追加
			standardDeviationList.add(StandardDeviationCalculation(scores));
		}

		// 出力
		for (double value : standardDeviationList) {
			System.out.println(value);
		}

	}

	// 得点リストを受け取り、標準偏差値を返す
	private static double StandardDeviationCalculation(ArrayList<Double> scores) {
		double standardDeviation = 0;
		ArrayList<Double> differenceFromAverageList = new ArrayList<Double>();
		for (double i : scores)
			differenceFromAverageList.add(Math.pow((Average(scores)) - i, 2));
		// 平均との差の２乗の合計から平均を平方根計算し標準偏差値を求める
		standardDeviation = Math.sqrt(Average(differenceFromAverageList));

		return standardDeviation;
	}

	// リストから平均を返す
	private static double Average(ArrayList<Double> List) {
		double sum = 0;
		for (double d : List) {
			sum += d;
		}
		return sum / List.size();
	}

	// 終了判定
	private static boolean EndDecision(int i) {
		if (i == END_SIGN) {
			return false;
		} else {
			return true;
		}
	}

}



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

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

    int l[n];
    for(int i = 0; i < n; i++)  cin >> l[i];
    sort(l, l+n);

    int sum = 0;
    for(int i = 0; i < n-1; i++)    sum += l[i];

    if(l[n-1] < sum)    cout << "Yes" << endl;
    else                cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#include <queue>

using namespace std;

struct Info {
    int x, y, dis;
};

const int MAXN = 205;
const int DIFF[2][4] = {{0, 0, 1, -1}, {1, -1, 0, 0}};

int n, m;
char mp[MAXN][MAXN];
bool vis[MAXN][MAXN];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%s", mp[i] + 1);
    }

    queue<Info> q;
    int dis1 = 1e9;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '@') {
                q.push((Info) {i, j, 0});
                break;
            }
        }
        if (!q.empty()) break;
    }
    while (!q.empty()) {
        Info info = q.front(); q.pop();
        if (mp[info.x][info.y] == '%') {
            dis1 = info.dis;
            break;
        }
        for (int i = 0; i < 4; i++) {
            int nx = info.x + DIFF[0][i], ny = info.y + DIFF[1][i];
            if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
            if (mp[nx][ny] == '#') continue;
            if (vis[nx][ny]) continue;
            q.push((Info) {nx, ny, info.dis + 1});
            vis[nx][ny] = true;
        }
    }
    while (!q.empty()) q.pop();

    memset(vis, 0, sizeof(vis));
    int dis2 = 1e9;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '$') {
                q.push((Info) {i, j, 0});
            }
        }
    }
    while (!q.empty()) {
        Info info = q.front(); q.pop();
        if (mp[info.x][info.y] == '%') {
            dis2 = info.dis;
            break;
        }
        for (int i = 0; i < 4; i++) {
            int nx = info.x + DIFF[0][i], ny = info.y + DIFF[1][i];
            if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
            if (mp[nx][ny] == '#') continue;
            if (vis[nx][ny]) continue;
            q.push((Info) {nx, ny, info.dis + 1});
            vis[nx][ny] = true;
        }
    }

    puts(dis1 < dis2 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 2960
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair<int, long long int> s[4001];

int main() {

    int n, id, p, q, idx;
    for (;;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) { s[i] = {0, 0}; }
        map<int, int> m;
        idx = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &id, &p, &q);
            if (m.find(id) == m.end()) {
                m.insert({id, idx});
                s[idx++] = {id, p*q};
            }
            else {
                s[m[id]].second += p*q;
            }
        }
        bool flag = false;
        for (int i = 0; i < m.size(); i++) {
            if (s[i].second >= 1000000) { flag = true; printf("%d\n", s[i].first); }
        }
        if (!flag) printf("NA\n");
    }

    return 0;
}



Measured memory_bytes: 2748
def prime(n):
  if n==1:
    return False
  elif n==2 or n==3:
    return True
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      return False
  else:
    return True

n=int(input())
primes=[]
for i in range(1,n+1):
  if prime(i):
    primes.append(i)
arr=[0]*(n+1)
for i in range(1,n+1):
  for j in primes:
    if j>i:
      break
    if i%j==0:
      arr[j]+=1
      i=i//j
      while i>1:
        if i%j==0:
          arr[j]+=1
          i=i//j
        else:
          break
ans=1
for i in primes:
  ans=(ans*(arr[i]+1))%(10**9+7)
print(ans%(10**9+7))

Measured memory_bytes: 3064
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    accelerate();
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    for(int r = 0; r*R <= N; ++r) {
        int M = N-r*R;
        for(int g = 0; g*G <= M; ++g) {
            int Q = M-g*G;
            if(Q%B == 0) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n){
        if(v[i] > c[i])ans += v[i] - c[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int temp = 0;
            int max = 0;

            for(int i = 0; i < str.Length; i++)
            {
                if(str[i]=='A' || str[i]=='G' || str[i]=='C' || str[i] == 'T')
                {
                    temp++;
                }
                else
                {
                    if (max < temp) max = temp;
                    temp = 0;
                }
            }

            if (max < temp) max = temp;
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int n, m;
	cin >> n;
	map<int, int> count1 = { };
	for(int i = 0; i < n; i++){
		int d;
		cin >> d;
		count1[d]++;
	}
	cin >> m;
	map<int, int> count2 = { };
	int t[m];
	for(int i = 0; i < m; i++){
		cin >> t[i];
		count2[t[i]]++;
	}
	int ans = 1;
	for(int i = 0; i < m; i++){
		if(count1[t[i]] < count2[t[i]]) ans = 0;
	}
	if(ans == 0) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 19712
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,s,*a = map(int,read().split())

MOD = 998244353
def mul(c,m,dp): #multiply (2+x^c) up to x^m
    for i in range(m,c-1,-1):
        dp[i] *= 2
        dp[i] += dp[i-c]
        dp[i] %= MOD
    for i in range(min(m,c-1),-1,-1):
        dp[i] *= 2
        dp[i] %= MOD

    
dp = [0]*(s+1)
dp[0] = 1

for i in a:
    mul(i,s,dp)

print(dp[-1]%MOD)
#print(dp)





Measured memory_bytes: 68656
n=gets.to_i
a=[]
1.upto(n) do |i|
    (i+1).upto(n) do |j|
        g = n.odd? ? n : n+1
        if i+j != g
            a<< [i,j]
        end
    end
end
puts a.length
puts a.map{|e|e.*(" ")}.*("\n")

    
        

Measured memory_bytes: 3068
#include <iostream>

using namespace std;

int main(){
    int P,Q,R;
    cin >>P>>Q>>R;
    if(P>Q){
        if(P>R){
            cout <<Q+R;
        }
        else{
            cout <<P+Q;
        }
    }else{
        if(Q>R){
            cout <<P+R;
        }else{
            cout <<P+Q;
        }
    }
    return 0;
}

Measured memory_bytes: 384
# -*- coding:utf-8 -*-

def Selection_Sort(A,n):
    for i in range(n):
        mini = i
        for j in range(i,n): #i以上の要素において最小のAをminiに格納
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if A[i] != A[mini]:
            A[i], A[mini] = A[mini], A[i]
    return A
    
def Bubble_Sort(A, n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A
    
n = int(input())
A = input().strip().split()

B = A[:]
A = Bubble_Sort(A,n)
print (' '.join(A))
print ("Stable")
B =Selection_Sort(B,n)
print (' '.join(B))

if A == B:
    print ("Stable")
else:
    print ("Not stable")

Measured memory_bytes: 7808
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module AGC016 =
    let private ``Colorful Hats`` () =
        let n = ReadNextInt ()
        let arr = ReadListOf int n |> Seq.countBy id |> Seq.toArray
        //printfn "arr: %A" arr
        let valid =
            match arr.Length with
            | 1 ->
                let x, _ = arr.[0]
                if n = 1 then x = 0
                else x + 1 = n || x * 2 <= n
            | 2 ->
                let x1, a = min arr.[0] arr.[1]
                let x, _ = max arr.[0] arr.[1]
                //printfn "%d %d | %d %d | %d" x1 a x (n - a) (a + x * 2 - a * 2)
                x1 + 1 = x && a < x && a + (x - a) * 2 <= n
            | _ -> false
        if valid then "Yes" else "No"
        |> printfn "%s"

    let Entry = ``Colorful Hats``

AGC016.Entry ()

Measured memory_bytes: 35028
#include <bits/stdc++.h>
#define MAXN 100005
#define ll long long
using namespace std;


ll dp[MAXN];
int n, k;
vector<ll> v;

ll solve(int i)
{
	if(dp[i] >= 0)
	{
		return dp[i];
	}

	ll res1 = -1;
	for (int j = 1; j <= min(k, i); ++j)
		if(res1 != -1)
			res1 = min(res1, abs(v[i] - v[i-j]) + solve(i - j));
		else
			res1 = abs(v[i] - v[i-j]) + solve(i - j);

	dp[i] = res1;

	return dp[i];

}





int main()
{
    
	ll num;
	cin >> n >> k;
	
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		v.push_back(num);
	}

	dp[0] = 0LL;
	dp[1] = abs(v[0] - v[1]); 

	cout << solve(n - 1) << endl;



    return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int N;
std::vector<std::string> V(12);
VI coeff(10);
int alphabetSize;
std::vector<bool> mostLeft(10);

int sum;
std::vector<bool> used(10);
int dfs(int i) {
    if(i == alphabetSize) return sum == 0;

    int ret = 0;
    REP(d, 10) {
        if(used[d]) continue;
        if(d == 0 && mostLeft[i]) continue;

        used[d] = true;
        sum += d * coeff[i];
        ret += dfs(i+1);
        sum -= d * coeff[i];
        used[d] = false;
    }
    return ret;
}

int main() {
    std::string s, alphabet;;
    while(std::cin >> N && N != 0) {
        alphabet = "";
        REP(i, N) {
            std::cin >> V[i];
            alphabet += V[i];
        }

        UNIQUE(alphabet);
                
        alphabetSize = alphabet.size();
        REP(i, alphabetSize) {
            coeff[i] = 0;
        }
        REP(i, 10) {
            used[i] = false;
            mostLeft[i] = false;
        }

        //left
        REP(i, N-1) {
            int len = V[i].length();
            if(len > 1) mostLeft[(int)alphabet.find(V[i][0])] = true;
            REP(j, len) {
                int p = alphabet.find(V[i][j]);
                coeff[p] += std::pow(10, len-j-1);
            }
        }
        //right
        int len = V[N-1].length();
        if(len > 1) mostLeft[(int)alphabet.find(V[N-1][0])] = true;
        REP(j, len) {
            int p = alphabet.find(V[N-1][j]);
            coeff[p] -= std::pow(10, len-j-1);
        }

        sum = 0;
        std::cout << dfs(0) << std::endl;
    }
}


Measured memory_bytes: 3340
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    long long H, W, D;
    cin >> H >> W >> D;

    vector<vector<long long>> A(H, vector<long long>(W));
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j], A[i][j]--;

    vector<pair<long long, pair<long long, long long>>> P;
    for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) P.push_back(make_pair(A[i][j], make_pair(i, j)));
    sort(P.begin(), P.end());

    vector<long long> dp(H * W, 0);
    for (int i = 0; i < dp.size(); i++) {
        if (i - D >= 0) dp[i] = dp[i - D] + abs(P[i].second.first - P[i - D].second.first) + abs(P[i].second.second - P[i - D].second.second);
    }

    int Q;
    cin >> Q;

    while (Q--) {
        long long L, R;
        cin >> L >> R;
        L--, R--;
        cout << dp[R] - dp[L] << endl;
    }

}

































Measured memory_bytes: 5496
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n;
string s;

ll powmod(ll a, ll b, ll c){
    ll ans = 1;
    while(b){
        if(b&1){
            ans = (ans*a)%c;
        }
        a = (a*a)%c;
        b >>= 1;
    }
    return ans;
}
 
ll getmod(ll mo){
    ll cur = 1;
    ll ans = 0;
    if(mo == 0){
        return 0;
    }
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            ans += cur;
            ans %= mo;
        }
        cur = cur * 2;
        cur %= mo;
    }
    return ans;
}

ll play(ll x){
    ll v = 1;
    while(x != 0){
        v++;
        ll b = __builtin_popcountl(x);
        x = x % b;
    }
    return v;
}

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n;
    cin>>s;
    reverse(s.begin(), s.end());
    ll set_bit=0;
    for (int i = 0; i < n; ++i)
    {
        if(s[i]=='1'){
            set_bit++;
        }
    }

    if(set_bit==0){
        for (int i = 0; i < n; ++i)
        {
            cout<<1<<endl;
        }
        return 0;
    }

    ll m1 = getmod(set_bit-1);
    ll m2 = getmod(set_bit+1);

    vector<ll> ans;
    for (int i = 0; i < n; ++i)
    {
        if(s[i]=='1'){
            ll b=set_bit-1;
            if(b==0){
                ans.push_back(0);
                continue;
            }
            ll x = b-powmod(2, i, b);
            ll curr = (m1+x)%b;
            ans.push_back(play(curr));

        }
        else{
            ll b = set_bit + 1;
            ll x = powmod(2, i, b);
            ll curr = (m2 + x) % b;
            ans.push_back(play(curr));
        }
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i)
    {
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int M, K;
    cin >> M >> K;
    int len = 1;
    rep(i,M) len *= 2;
    if (M <= 1 && K > 0 || len <= K) {
        cout << -1 << endl;
        return 0;
    } else if (M == 0) {
        printf("0 0\n");
        return 0;
    } else if (M == 1) {
        printf("0 0 1 1\n");
        return 0;
    }

    rep(i,len) {
        if (i != K) cout << i << " ";
    }
    cout << K << " ";
    for (int i = len - 1; i >= 0; i--) {
        if (i != K) cout << i << " ";
    }
    cout << K << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N; cin >> N;
	int O = 0;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp % 2 == 1) O++;
	}
	if (O % 2 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}

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

int main() {
  long long int k;
  cin>>k;
  queue<long long int> n;
  rep(i,1,10){n.push(i);}
  long long int ans;
  rep(i,1,k+1){
    ans = n.front();
    //if(i>99990){cout<<ans<<endl;}
    n.pop();
    long long int tmp = (ans%10)+(ans*10);
    if(tmp%10!=0){n.push(tmp-1);}
    n.push(tmp);
    if(tmp%10!=9){n.push(tmp+1);}
    /*
    if(ans%10!=0){n.push((10*ans)+(ans%10)-1);}
    n.push((10*ans)+(ans%10));
    if(ans%10!=9){n.push((10*ans)+(ans%10)+1);}
    */
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1792